git: c930d356a3a1 - stable/13 - powerpc64: fix the calculation of Maxmem

From: Leandro Lupori <luporl_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 14:37:31 UTC
The branch stable/13 has been updated by luporl:

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

commit c930d356a3a1d08a1b300edf5fd14334fe65f6a1
Author:     Leandro Lupori <luporl@FreeBSD.org>
AuthorDate: 2021-12-15 11:49:47 +0000
Commit:     Leandro Lupori <luporl@FreeBSD.org>
CommitDate: 2022-01-10 14:36:56 +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
    
    (cherry picked from commit a076e2060c07307e7416759075db71f23de722c0)
---
 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 41771c3650f3..1abf65ab35b3 100644
--- a/sys/powerpc/aim/mmu_oea64.c
+++ b/sys/powerpc/aim/mmu_oea64.c
@@ -1165,7 +1165,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 333fa234fb4b..da32b66334a0 100644
--- a/sys/powerpc/aim/mmu_radix.c
+++ b/sys/powerpc/aim/mmu_radix.c
@@ -2055,7 +2055,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]));
 
 	/*