diff mbox series

[RFC] xen/device-tree: Switch back to dt_unreserved_regions() in boot allocator

Message ID 20250325113014.1945518-1-oleksandr_tyshchenko@epam.com (mailing list archive)
State New
Headers show
Series [RFC] xen/device-tree: Switch back to dt_unreserved_regions() in boot allocator | expand

Commit Message

Oleksandr Tyshchenko March 25, 2025, 11:30 a.m. UTC
On the device-tree-based Arm64 system, if Xen is built with
CONFIG_ACPI=y, CONFIG_STATIC_MEMORY=y, and the static memory range
is provided in the host device tree, the BUG is triggered in
common/page_alloc.c during Xen's early boot. The BUG occurs when
the first page from the static range is fed to the domain
sub-allocator and finally ends up in mark_page_free().
The pg->count_info & PGC_state is not in the state that
the code expects to see there.

The problem is that the static range gets mistakenly unreserved
in populate_boot_allocator() and reaches init_boot_pages().
This happens since by the time the populate_boot_allocator()
is executed, the evaluated in fw_unreserved_regions()
an acpi_disabled variable is still false (CONFIG_ACPI=y) and
dt_unreserved_regions() which should simply skip that static range
does not get called. The acpi_disabled will be set to the actual
value later on in acpi_boot_table_init().

To avoid unreserving the whole region (including potential reserved
memory ranges such as static memory) open code fw_unreserved_regions()
and add a comment.

Another solution could be to call acpi_boot_table_init() before
setup_mm() in Arm64's start_xen().

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
---
The RFC since I am not sure whether the description is precise
and the fix is correct.

Below the dump, w/o and w/ the fix applied. I also added prints
for the processed memory ranges with "OT:" for the visibility:

********************

- UART enabled -
- Boot CPU booting -
- Current EL 0000000000000008 -
- Initialize CPU -
- Turning on paging -
- Paging turned on -
- Zero BSS -
- Ready -
(XEN) Checking for initrd in /chosen
(XEN) Checking for "xen,static-mem" in domain node
(XEN) RAM: 0000000040000000 - 00000000bfffffff
(XEN) 
(XEN) MODULE[0]: 0000000043200000 - 0000000043343fff Xen         
(XEN) MODULE[1]: 0000000043400000 - 0000000043402fff Device Tree 
(XEN) MODULE[2]: 0000000042e00000 - 0000000043111f82 Ramdisk     
(XEN) MODULE[3]: 0000000040400000 - 0000000042cfffff Kernel      
(XEN)  RESVD[0]: 0000000050000000 - 000000005fffffff
(XEN) 
(XEN) CMDLINE[0000000040400000]:domU0 console=ttyAMA0
(XEN) 
(XEN) Command line: console=dtuart conswitch=ax
(XEN) OT: populate_boot_allocator[475] s 0x40000000 e 0x40400000
(XEN) OT: init_boot_pages[358]         s 0x40000000 e 0x40400000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x42d00000 e 0x42e00000
(XEN) OT: init_boot_pages[358]         s 0x42d00000 e 0x42e00000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43111f83 e 0x43200000
(XEN) OT: init_boot_pages[358]         s 0x43111f83 e 0x43200000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43344000 e 0x43400000
(XEN) OT: init_boot_pages[358]         s 0x43344000 e 0x43400000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43403000 e 0xc0000000
(XEN) OT: init_boot_pages[358]         s 0x43403000 e 0xc0000000 <<<
(XEN) pg MFN 50000 c=0x2180000000000000 o=0 v=0 t=0
(XEN) Xen BUG at common/page_alloc.c:1474
(XEN) ----[ Xen-4.21-unstable  arm64  debug=y  Not tainted ]----
(XEN) CPU:    0
(XEN) PC:     00000a0000222ec0 page_alloc.c#mark_page_free+0xe8/0xf0
(XEN) LR:     00000a0000222ec0
(XEN) SP:     00000a0000307d10
(XEN) CPSR:   00000000600003c9 MODE:64-bit EL2h (Hypervisor, handler)
(XEN)      X0: 00000a0000310040  X1: 0000000000000001  X2: 0000000000000000
(XEN)      X3: 0000000000000000  X4: 0000000000000000  X5: 0000000000000000
(XEN)      X6: 0000000000000000  X7: fefefefefefeff09  X8: 7f7f7f7f7f7f7f7f
(XEN)      X9: 0000000000000080 X10: 7f7f7f7f7f7f7f7f X11: 0101010101010101
(XEN)     X12: 0000000000000008 X13: 0000000000000020 X14: 0000000000000001
(XEN)     X15: 00000a0000a00000 X16: 00000000bff3b8fc X17: 0000000000000000
(XEN)     X18: 00000000beebbdb0 X19: 0000000000050000 X20: 00000a0800380000
(XEN)     X21: 0000000000000010 X22: 00000000000be000 X23: 00000a0800380000
(XEN)     X24: 0000000000000000 X25: 0000000000060000 X26: 0000000000000001
(XEN)     X27: 00000a00002991c8 X28: fffff5f800000000  FP: 00000a0000307d10
(XEN) 
(XEN)   VTCR_EL2: 0000000000000000
(XEN)  VTTBR_EL2: 0000000000000000
(XEN) 
(XEN)  SCTLR_EL2: 0000000030cd183d
(XEN)    HCR_EL2: 0000000000000038
(XEN)  TTBR0_EL2: 0000000043321000
(XEN) 
(XEN)    ESR_EL2: 00000000f2000001
(XEN)  HPFAR_EL2: 0000000000000000
(XEN)    FAR_EL2: 0000000000000000
(XEN) 
(XEN) Xen stack trace from sp=00000a0000307d10:
(XEN)    00000a0000307d20 00000a0000224154 00000a0000307d90 00000a00002261a0
(XEN)    0000000000000010 00000a0000312d38 0000000000050000 00000000000be000
(XEN)    000000000007abfd 00000a0000298ca0 00000a0000298000 0000000000000012
(XEN)    0000000000000040 0000000000000000 00000a00002a5170 0001000000000013
(XEN)    00000a0000307e20 00000a00002ab2c4 00000a00002e5430 00000a00002e53f0
(XEN)    00000a0000298ca0 00000a0000299000 00000a0000298000 00000a0000298000
(XEN)    00000000bffbb6d0 0000000000000000 00000000bfefeccc 00000000beed7ee0
(XEN)    0000000100000014 00000a08000b60a8 0000000000000000 000000000007abfd
(XEN)    0000000001ad9f58 00000a0000312d88 00000a0000307e60 00000a00002c62bc
(XEN)    0000000043400000 00000a0000c01c28 00000a0000312000 0000000000003000
(XEN)    00000a0000a00000 00000000beed7eb8 00000000bedbb730 00000a00002001a4
(XEN)    0000000043200000 fffff60043000000 0000000043400000 0000000000000003
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000 0000000000000000 0000000000000000
(XEN)    0000000000000000 0000000000000000
(XEN) Xen call trace:
(XEN)    [<00000a0000222ec0>] page_alloc.c#mark_page_free+0xe8/0xf0 (PC)
(XEN)    [<00000a0000222ec0>] page_alloc.c#mark_page_free+0xe8/0xf0 (LR)
(XEN)    [<00000a0000224154>] page_alloc.c#free_heap_pages+0x10c/0x528
(XEN)    [<00000a00002261a0>] page_alloc.c#init_heap_pages+0x47c/0x678
(XEN)    [<00000a00002ab2c4>] end_boot_allocator+0x184/0x1b8
(XEN)    [<00000a00002c62bc>] start_xen+0x134/0x9ec
(XEN)    [<00000a00002001a4>] head.o#primary_switched+0x4/0x24
(XEN) 
(XEN) 
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) Xen BUG at common/page_alloc.c:1474
(XEN) ****************************************
(XEN) 
(XEN) Reboot in five seconds...


********************

- UART enabled -
- Boot CPU booting -
- Current EL 0000000000000008 -
- Initialize CPU -
- Turning on paging -
- Paging turned on -
- Zero BSS -
- Ready -
(XEN) Checking for initrd in /chosen
(XEN) Checking for "xen,static-mem" in domain node
(XEN) RAM: 0000000040000000 - 00000000bfffffff
(XEN) 
(XEN) MODULE[0]: 0000000043200000 - 0000000043343fff Xen         
(XEN) MODULE[1]: 0000000043400000 - 0000000043402fff Device Tree 
(XEN) MODULE[2]: 0000000042e00000 - 0000000043111f8f Ramdisk     
(XEN) MODULE[3]: 0000000040400000 - 0000000042cfffff Kernel      
(XEN)  RESVD[0]: 0000000050000000 - 000000005fffffff
(XEN) 
(XEN) CMDLINE[0000000040400000]:domU0 console=ttyAMA0
(XEN) 
(XEN) Command line: console=dtuart conswitch=ax
(XEN) OT: populate_boot_allocator[475] s 0x40000000 e 0x40400000
(XEN) OT: dt_unreserved_regions[50]    s 0x40000000 e 0x40400000
(XEN) OT: init_boot_pages[358]         s 0x40000000 e 0x40400000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x42d00000 e 0x42e00000
(XEN) OT: dt_unreserved_regions[50]    s 0x42d00000 e 0x42e00000
(XEN) OT: init_boot_pages[358]         s 0x42d00000 e 0x42e00000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43111f90 e 0x43200000
(XEN) OT: dt_unreserved_regions[50]    s 0x43111f90 e 0x43200000
(XEN) OT: init_boot_pages[358]         s 0x43111f90 e 0x43200000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43344000 e 0x43400000
(XEN) OT: dt_unreserved_regions[50]    s 0x43344000 e 0x43400000
(XEN) OT: init_boot_pages[358]         s 0x43344000 e 0x43400000 <<<
(XEN) OT: populate_boot_allocator[475] s 0x43403000 e 0xc0000000
(XEN) OT: dt_unreserved_regions[50]    s 0x43403000 e 0xc0000000
(XEN) OT: dt_unreserved_regions[50]    s 0x60000000 e 0xc0000000
(XEN) OT: init_boot_pages[358]         s 0x60000000 e 0xc0000000 <<<
(XEN) OT: dt_unreserved_regions[50]    s 0x43403000 e 0x50000000
(XEN) OT: init_boot_pages[358]         s 0x43403000 e 0x50000000 <<<
(XEN) Domain heap initialised
(XEN) Booting using Device Tree
---
 xen/common/device-tree/bootinfo.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Oleksandr Tyshchenko March 25, 2025, 11:34 a.m. UTC | #1
Hello all.

Please, ignore this second email, it was sent by mistake.
diff mbox series

Patch

diff --git a/xen/common/device-tree/bootinfo.c b/xen/common/device-tree/bootinfo.c
index 76d652c0de..e250801d89 100644
--- a/xen/common/device-tree/bootinfo.c
+++ b/xen/common/device-tree/bootinfo.c
@@ -464,7 +464,13 @@  void __init populate_boot_allocator(void)
             }
 #endif
 
-            fw_unreserved_regions(s, e, init_boot_pages, 0);
+            /*
+             * At this point we do not know yet if we are running on ACPI
+             * system. To avoid unreserving the whole region (including
+             * potential reserved memory ranges such as static memory) open code
+             * fw_unreserved_regions().
+             */
+            dt_unreserved_regions(s, e, init_boot_pages, 0);
             s = n;
         }
     }