git: a076e2060c07 - main - powerpc64: fix the calculation of Maxmem

From: Leandro Lupori <luporl_at_FreeBSD.org>
Date: Wed, 15 Dec 2021 11:57:39 UTC
The branch main has been updated by luporl:

URL: https://cgit.FreeBSD.org/src/commit/?id=a076e2060c07307e7416759075db71f23de722c0

commit a076e2060c07307e7416759075db71f23de722c0
Author:     Leandro Lupori <luporl@FreeBSD.org>
AuthorDate: 2021-12-15 11:49:47 +0000
Commit:     Leandro Lupori <luporl@FreeBSD.org>
CommitDate: 2021-12-15 11:49:47 +0000

    powerpc64: fix the calculation of Maxmem
    
    The calculation of Maxmem was skipping the last phys_avail segment,
    because of a wrong stop condition.
    
    This was detected when using QEMU/PowerNV with Radix MMU and low
    memory (2G). In this case opal_pci would allocate a DMA window that
    was too small to cover all physical memory, resulting in reading all
    zeroes from disk when using memory that was not inside the allocated
    window.
    
    Reviewed by:            jhibbits
    Sponsored by:           Instituto de Pesquisas Eldorado (eldorado.org.br)
    Differential Revision:  https://reviews.freebsd.org/D33449
    MFC after:              2 weeks
---
 sys/powerpc/aim/mmu_oea64.c | 2 +-
 sys/powerpc/aim/mmu_radix.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/powerpc/aim/mmu_oea64.c b/sys/powerpc/aim/mmu_oea64.c
index 728f388ffb08..b3a4a225126f 100644
--- a/sys/powerpc/aim/mmu_oea64.c
+++ b/sys/powerpc/aim/mmu_oea64.c
@@ -1162,7 +1162,7 @@ moea64_late_bootstrap(vm_offset_t kernelstart, vm_offset_t kernelend)
 	 * Calculate the last available physical address.
 	 */
 	Maxmem = 0;
-	for (i = 0; phys_avail[i + 2] != 0; i += 2)
+	for (i = 0; phys_avail[i + 1] != 0; i += 2)
 		Maxmem = MAX(Maxmem, powerpc_btop(phys_avail[i + 1]));
 
 	/*
diff --git a/sys/powerpc/aim/mmu_radix.c b/sys/powerpc/aim/mmu_radix.c
index 420a7a227c10..788bd7f22a0a 100644
--- a/sys/powerpc/aim/mmu_radix.c
+++ b/sys/powerpc/aim/mmu_radix.c
@@ -2066,7 +2066,7 @@ mmu_radix_late_bootstrap(vm_offset_t start, vm_offset_t end)
 	 * vm_page_array (upper bound).
 	 */
 	Maxmem = 0;
-	for (i = 0; phys_avail[i + 2] != 0; i += 2)
+	for (i = 0; phys_avail[i + 1] != 0; i += 2)
 		Maxmem = MAX(Maxmem, powerpc_btop(phys_avail[i + 1]));
 
 	/*