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
This commit is contained in:
Leandro Lupori 2021-12-15 08:49:47 -03:00
parent 18679ab1c0
commit a076e2060c
2 changed files with 2 additions and 2 deletions

View File

@ -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]));
/*

View File

@ -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]));
/*