hw/arm/raspi4b: fix guest RAM capped at ~1 GiB regardless of machine size
Status from this message: Applied to target-arm.next, thanks.
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest2 patches 1 replyApplied
- v22 patches 1 replySuperseded
- v12 patches 1 replySuperseded
Changes in v3 from the cover letter
- Folded the RAM-size check into the existing test_arm_raspi4_initrd test instead of a new standalone boot, per Peter's review -- saves the extra full-kernel-boot the suite would otherwise pay for.
- Trimmed the explanatory comment in the test to a couple of lines; the details are in git history, per Peter's review.
Patches in v3 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | hw/arm/raspi4b: fix guest never seeing more than ~1 GiB of RAMhw/ | +1 | 0 replies | |
| 2/2 | tests/functional/aarch64: add raspi4b full-RAM regression testtests/ | +17 | 0 replies |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | Philippe Mathieu-Daudé |
|---|---|
| 1/2 | R-b |
| 2/2 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v3 0/2] hw/arm/raspi4b: fix guest RAM capped at ~1 GiB regardless of machine size
While working on unrelated raspi4b issues, I noticed the guest never seemed to have as much RAM as I'd given it and tracked it down to hw/arm/raspi4b.c's raspi4_modify_dtb(): it decides whether to add a second memory node above the 1 GiB peripheral hole by checking info->ram_size, but that field is the boot loader's RAM budget for where it's allowed to place the kernel/initrd/dtb image, itself always capped to at most UPPER_RAM_BASE - vcram_size by raspi_base_machine_init(). Since that capped value can never exceed UPPER_RAM_BASE by construction, the condition was never true for any raspi4b configuration -- the second node was never added, and the guest never saw more than ~1 GiB of RAM regardless of the machine's nominal size. board_ram_size(info->board_id), computed one line above in the same function, is the value that was actually needed.
Patch 1 fixes it (one line); patch 2 adds a regression test.
Confirmed via direct measurement inside the guest ("free -h" / /proc/meminfo) on raspi4b's default 2 GiB configuration:
before: MemTotal: 943524 kB (~921 MiB)
after: MemTotal: 1905824 kB (~1861 MiB)Also verified against two real, unmodified Raspberry Pi OS releases (Debian 11/Bullseye and Debian 13/Trixie): both now report ~1.8 GiB of usable RAM instead of ~900 MiB, with clean boots, working SSH, and no kernel errors on either.
I also looked into extending this to raspi4b's real 4 GiB and 8 GiB hardware variants (real boards exist in 1/2/4/8 GiB configurations), since board_ram_size()'s encoding already supports arbitrary sizes and this same bug meant the necessary split-memory-node path had never actually been exercised at any size, ever. 2 GiB now works cleanly with this fix (tested above); 4 GiB hits a real kernel panic (kernel BUG at arch/arm64/mm/mmu.c:192! in early page-table setup, addresses landing in the BCM2711 peripheral region around 0xfc000000) that looks like it needs the "high peripheral alias" real BCM2711 firmware sets up for boards with enough RAM to otherwise collide with that region -- out of scope for this series, so I'm leaving 4/8 GiB support for later and keeping this fix minimal.
checkpatch.pl is clean (0 errors, 0 warnings) on both patches, and the series builds standalone from a clean worktree (--target-list=aarch64-softmmu). All 5 tests in tests/functional/aarch64/test_raspi4.py pass, including the 4 pre-existing ones (no regression) and the RAM check added here.
v3:
- Folded the RAM-size check into the existing test_arm_raspi4_initrd test instead of a new standalone boot, per Peter's review -- saves the extra full-kernel-boot the suite would otherwise pay for.
- Trimmed the explanatory comment in the test to a couple of lines; the details are in git history, per Peter's review.
v2:
- Dropped the explanatory comment added in raspi4_modify_dtb() in patch 1 -- the commit message already covers it, per Philippe's review.
- Picked up Philippe Mathieu-Daudé's Reviewed-by on patch 1.
Marcelo Manzo (2):
hw/arm/raspi4b: fix guest never seeing more than ~1 GiB of RAM tests/functional/aarch64: add raspi4b full-RAM regression test
hw/arm/raspi4b.c | 2 +- tests/functional/aarch64/test_raspi4.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.1