microvm fails to boot a Linux guest when given exactly -m 2048M with
ACPI enabled (the default): the kernel decompressor either hangs in an
infinite relocation loop under KASLR, or (with nokaslr) the boot
proceeds but ACPI core init deadlocks and poweroff via \_S5 silently
stops working.
Root cause: microvm places its ACPI tables (RSDP et al.) in the top
4 KiB page of low RAM, and passes acpi_data_size=0 to x86_load_linux().
In roms/linuxboot/x86-common.c the initrd top is clamped to
initrd_addr_max = 0x7fffffff only when below_4g_mem_size - acpi_data_size
exceeds it; with exactly 2 GiB of low RAM (below_4g == 0x80000000) and
acpi_data_size == 0 the clamp does not engage, and the initrd is placed
ending at 0x7fffffff -- right on top of the 4 KiB ACPI/RSDP page,
corrupting it before the kernel ever runs.
The bug is old: acpi_data_size=0 for microvm dates back to the machine
introduction (0ebf007dda, 2019, when microvm had no ACPI). When Gerd
Hoffmann added ACPI support to microvm (8045df14bc, 2020, QEMU 5.2),
the zero reservation was not revisited. It is still present verbatim in
v11.0.3 (hw/i386/microvm.c:333 in that tag).
Minimal reproducer (any recent QEMU, any Linux bzImage+initramfs):
qemu-system-x86_64 -M microvm -accel kvm -m 2048M \
-kernel bzImage -initrd initramfs.cpio.gz \
-append "console=ttyS0" -nographic
The attached patch fixes this by moving the existing PC_FW_DATA
reservation constant (160 KiB, already used by the pc machine) into
include/hw/i386/x86.h and passing it as acpi_data_size from microvm, so
the initrd is always placed below the firmware/ACPI area.
Verification (patched build, guest kernel with KASLR enabled; each cell
= boot to userspace + ACPI poweroff):
accel | 128M | 2047M | 2048M | 2049M
------+------+-------+-------+------
KVM | PASS | PASS | PASS* | PASS
TCG | PASS | PASS | PASS* | PASS
* previously broken; TCG inclusion proves this is accelerator-
independent. 8/8 cells pass with the patch.
scripts/checkpatch.pl is clean on the patch.
Yu Bin (1):
hw/i386/microvm: reserve firmware area when loading kernel with ACPI
hw/i386/microvm.c | 2 +-
hw/i386/pc.c | 10 ----------
include/hw/i386/x86.h | 10 ++++++++++
3 files changed, 11 insertions(+), 11 deletions(-)
--
2.54.0 (Apple Git-157)