Skip to contentSkip to conversation

ARM EFI: should bootinfo memory banks be reset before retrying ExitBootServices ?

PATCH New Pierre Gondois 3 participants 4 messages Nov 16 – Nov 25

lore
Share & tools
lore
#0 lore raw

Hello,

I am requesting some guidance regarding a boot issue related to the edk2/uefi project. This patchset [1] introduced a change which modified the memory map just before the ExitBootServices, which should be authorized. As described in [2], it seems that xen doesn't handle that case correctly, preventing edk2 to boot valid kernel images.

Does the change suggested in [2] seem sensible ?

Regards,

Pierre

[1] https://github.com/tianocore/edk2/pull/12704
[2] https://github.com/tianocore/edk2/pull/13261#issuecomment-6774136145

Tested-by
#1 lore raw
Quoted 1 line · Pierre Gondois

Hello,

Hello Pierre,
I can reproduce this on QEMU, and the change you suggest fixes it.

My Setup:
- QEMU 11.1.3: -M virt,virtualization=on,acpi=off -cpu cortex-a57 -smp 4 -m 4G
- Firmware: qemu-efi-aarch64 2026.08+ds-3
- Xen: staging 3b65ff9f372fb85 (debug, early printk on PL011), xen.efi started directly from the UEFI shell

Without the change, the first ExitBootServices() call fails, efi_exit_boot() retries, and every RAM bank is added a second time, and Xen hits the BUG in bootmem_region_add():

(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
...
(XEN) Xen BUG at common/page_alloc.c:308
...
(XEN) Xen call trace:

(XEN)    [<00000a00002cb498>] page_alloc.c#bootmem_region_add+0xd8/0xec (PC)
(XEN)    [<00000a00002cb694>] init_boot_pages+0x44/0x1b0 (LR)
(XEN)    [<00000a00002cb694>] init_boot_pages+0x44/0x1b0
(XEN)    [<00000a00002c54f0>] bootinfo.c#dt_unreserved_regions+0x70/0xac
(XEN)    [<00000a00002c5c50>] populate_boot_allocator+0x124/0x1c8
(XEN)    [<00000a00002e2c84>] setup_mm+0x60/0x84
(XEN)    [<00000a00002e337c>] start_xen+0x118/0x988
(XEN)    [<00000a00002001a4>] arch/arm/arm64/head.S#primary_switched+0x4/0x24

...

With your change applied, each bank is listed once and Xen boots through to dom0:

...
(XEN) Checking for initrd in /chosen
(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
(XEN) RAM: 0000000046930000 - 0000000047a4ffff
(XEN) RAM: 0000000047ff4000 - 000000013fffffff
(XEN)
(XEN) MODULE[0]: 0000000045b58000 - 0000000045ccafff Xen (XEN) MODULE[1]: 0000000045cf1000 - 0000000045df3fff Device Tree (XEN) MODULE[2]: 000000013dd4d000 - 000000013fffdf13 Ramdisk (XEN) MODULE[3]: 0000000041bf4000 - 0000000043ffffbf Kernel
...

I see in the x86 that the e820_raw.nr_map in efi_arch_process_memory_map() is reset for each loop iteration. On Arm the bank is appended to the previous iteration. So, I guess resetting the banks is the right call?

Pierre, are you planning to send this fix as a patch to the mailinglist? If so, please add my:

Otherwise I'm happy to post the patch with your Suggested-by.

Thank you,
Julian

Quoted 11 lines

Regards,

Pierre

[1] https://github.com/tianocore/edk2/pull/12704
[2] https://github.com/tianocore/edk2/pull/13261#issuecomment-6774136145

#2 lore raw

Hello Julian,

Quoted 48 lines · Julian Vetter
Quoted 1 line · Pierre Gondois

Hello,

Hello Pierre,
I can reproduce this on QEMU, and the change you suggest fixes it.

My Setup:
- QEMU 11.1.3: -M virt,virtualization=on,acpi=off -cpu cortex-a57 -smp 4 -m 4G
- Firmware: qemu-efi-aarch64 2026.08+ds-3
- Xen: staging 3b65ff9f372fb85 (debug, early printk on PL011), xen.efi started directly from the UEFI shell

Without the change, the first ExitBootServices() call fails, efi_exit_boot() retries, and every RAM bank is added a second time, and Xen hits the BUG in bootmem_region_add():

(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
...
(XEN) Xen BUG at common/page_alloc.c:308
...
(XEN) Xen call trace:
(XEN)    [<00000a00002cb498>] page_alloc.c#bootmem_region_add+0xd8/0xec (PC) (XEN)    [<00000a00002cb694>] init_boot_pages+0x44/0x1b0 (LR) (XEN)    [<00000a00002cb694>] init_boot_pages+0x44/0x1b0
(XEN)    [<00000a00002c54f0>] bootinfo.c#dt_unreserved_regions+0x70/0xac (XEN)    [<00000a00002c5c50>] populate_boot_allocator+0x124/0x1c8 (XEN)    [<00000a00002e2c84>] setup_mm+0x60/0x84
(XEN)    [<00000a00002e337c>] start_xen+0x118/0x988
(XEN)    [<00000a00002001a4>] arch/arm/arm64/head.S#primary_switched+0x4/0x24
...

With your change applied, each bank is listed once and Xen boots through to dom0:

...
(XEN) Checking for initrd in /chosen
(XEN) RAM: 0000000040000000 - 000000004668ffff
(XEN) RAM: 0000000046800000 - 000000004688ffff
(XEN) RAM: 0000000046930000 - 0000000047a4ffff
(XEN) RAM: 0000000047ff4000 - 000000013fffffff
(XEN)
(XEN) MODULE[0]: 0000000045b58000 - 0000000045ccafff Xen (XEN) MODULE[1]: 0000000045cf1000 - 0000000045df3fff Device Tree (XEN) MODULE[2]: 000000013dd4d000 - 000000013fffdf13 Ramdisk (XEN) MODULE[3]: 0000000041bf4000 - 0000000043ffffbf Kernel
...

Quoted 7 lines

I see in the x86 that the e820_raw.nr_map in efi_arch_process_memory_map() is reset for each loop iteration. On Arm the bank is appended to the previous iteration. So, I guess resetting the banks is the right call?

Pierre, are you planning to send this fix as a patch to the mailinglist? If so, please add my:

Otherwise I'm happy to post the patch with your Suggested-by.

Thanks for reproducing/testing the issue. I'm not too familiar with

Thanks for reproducing/testing the issue. I'm not too familiar with xen mailing list, so if you could send the patch it would be of great help,

Regards,
Pierre

#3 lore raw

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

In reply to Pierre Gondois

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().

---
 xen/arch/arm/efi/efi-boot.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
xen/arch/arm/efi/efi-boot.h +10 -0
index 069cc68b0a..44ebc9fbba 100644
@@ -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;
Signature · 10 lines
2.53.0



--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech