[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/arm: efi: reset bootinfo banks before retrying ExitBootServices()



efi_exit_boot() retries ExitBootServices() once if the first call fail.
But each pass calls efi_arch_process_memory_map(), which on Arm appends
the memory regions to bootinfo_get_mem() (and bootinfo_get_acpi() with
CONFIG_ACPI) without clearing what the previous pass added.

After a retry every RAM bank is therefore registered twice, and
populate_boot_allocator() hits a BUG in bootmem_region_add() on the
overlapping ranges:

  (XEN) RAM: 0000000040000000 - 000000004668ffff
  (XEN) RAM: 0000000040000000 - 000000004668ffff
  ...
  (XEN) Xen BUG at common/page_alloc.c:308
  (XEN)    [<...>] page_alloc.c#bootmem_region_add+0xd8/0xec (PC)
  (XEN)    [<...>] init_boot_pages+0x44/0x1b0
  (XEN)    [<...>] bootinfo.c#dt_unreserved_regions+0x70/0xac
  (XEN)    [<...>] populate_boot_allocator+0x124/0x1c8
  (XEN)    [<...>] setup_mm+0x60/0x84
  (XEN)    [<...>] start_xen+0x118/0x988

This is hit with edk2 since commit 12c5ded287 ("FatPkg: Clean any volume
caches during exit boot services"), which flushes FAT volumes from an
EFI_EVENT_GROUP_BEFORE_EXIT_BOOT_SERVICES handler and can change the
memory map during the first ExitBootServices() call. It reproduces on
QEMU virt with a Debian qemu-efi-aarch64 2026.08 package when xen.efi is
started directly from the ESP.

Reset the bank counters at the start of each pass so the bootinfo view
is rebuilt from the current memory map. x86 already does the equivalent
by resetting e820_raw.nr_map in efi_arch_process_memory_map().

Reported-by: Pierre Gondois <pierre.gondois@xxxxxxx>
Suggested-by: Pierre Gondois <pierre.gondois@xxxxxxx>
Signed-off-by: Julian Vetter <julian.vetter@xxxxxxxxxx>
---
 xen/arch/arm/efi/efi-boot.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h
index 069cc68b0a..44ebc9fbba 100644
--- a/xen/arch/arm/efi/efi-boot.h
+++ b/xen/arch/arm/efi/efi-boot.h
@@ -197,6 +197,16 @@ static EFI_STATUS __init 
efi_process_memory_map_bootinfo(void *map,
 {
     int Index;
 
+    /*
+     * efi_exit_boot() may retry after EFI_INVALID_PARAMETER from
+     * ExitBootServices(). Rebuild the bootinfo view from scratch on each
+     * pass so later boot allocator population doesn't see duplicate banks.
+     */
+    bootinfo_get_mem()->nr_banks = 0;
+#ifdef CONFIG_ACPI
+    bootinfo_get_acpi()->nr_banks = 0;
+#endif
+
     for ( Index = 0; Index < (mmap_size / desc_size); Index++ )
     {
         EFI_MEMORY_DESCRIPTOR *desc_ptr = map + desc_size * Index;
-- 
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.