x86/xen: fix memblock_reserve() usage on PVH
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 25 Jul 2024 07:31:15 +0000 (09:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Apr 2025 08:45:55 +0000 (10:45 +0200)
commit 4c006734898a113a64a528027274a571b04af95a upstream.

The current usage of memblock_reserve() in init_pvh_bootparams() is done before
the .bss is zeroed, and that used to be fine when
memblock_reserved_init_regions implicitly ended up in the .meminit.data
section.  However after commit 73db3abdca58c memblock_reserved_init_regions
ends up in the .bss section, thus breaking it's usage before the .bss is
cleared.

Move and rename the call to xen_reserve_extra_memory() so it's done in the
x86_init.oem.arch_setup hook, which gets executed after the .bss has been
zeroed, but before calling e820__memory_setup().

Fixes: 73db3abdca58c ("init/modpost: conditionally check section mismatch to __meminit*")
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Message-ID: <20240725073116.14626-3-roger.pau@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
[ Context fixup for hypercall_page removal ]
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/include/asm/xen/hypervisor.h
arch/x86/platform/pvh/enlighten.c
arch/x86/xen/enlighten_pvh.c

index 64fbd2dbc5b7615bf35ff8dfe9cacec7df1ca485..a9088250770f2a3d6320040f815f1b9e6cba653b 100644 (file)
@@ -62,11 +62,6 @@ void xen_arch_unregister_cpu(int num);
 #ifdef CONFIG_PVH
 void __init xen_pvh_init(struct boot_params *boot_params);
 void __init mem_map_via_hcall(struct boot_params *boot_params_p);
-#ifdef CONFIG_XEN_PVH
-void __init xen_reserve_extra_memory(struct boot_params *bootp);
-#else
-static inline void xen_reserve_extra_memory(struct boot_params *bootp) { }
-#endif
 #endif
 
 /* Lazy mode for batching updates / context switch */
index a12117f3d4de72c33fae675c0ddb2c37efcb5ad6..00a92cb2c81474782146b801f56a5d5880c8afb7 100644 (file)
@@ -74,9 +74,6 @@ static void __init init_pvh_bootparams(bool xen_guest)
        } else
                xen_raw_printk("Warning: Can fit ISA range into e820\n");
 
-       if (xen_guest)
-               xen_reserve_extra_memory(&pvh_bootparams);
-
        pvh_bootparams.hdr.cmd_line_ptr =
                pvh_start_info.cmdline_paddr;
 
index 89984018141ca91886cd27c621525d3b95075d06..ac0a8adb2c50b103276ff6cfa9079a4040d38911 100644 (file)
@@ -8,6 +8,7 @@
 #include <asm/io_apic.h>
 #include <asm/hypervisor.h>
 #include <asm/e820/api.h>
+#include <asm/setup.h>
 
 #include <xen/xen.h>
 #include <asm/xen/interface.h>
@@ -40,8 +41,9 @@ EXPORT_SYMBOL_GPL(xen_pvh);
  * hypervisor should notify us which memory ranges are suitable for creating
  * foreign mappings, but that's not yet implemented.
  */
-void __init xen_reserve_extra_memory(struct boot_params *bootp)
+static void __init pvh_reserve_extra_memory(void)
 {
+       struct boot_params *bootp = &boot_params;
        unsigned int i, ram_pages = 0, extra_pages;
 
        for (i = 0; i < bootp->e820_entries; i++) {
@@ -93,14 +95,21 @@ void __init xen_reserve_extra_memory(struct boot_params *bootp)
        }
 }
 
+static void __init pvh_arch_setup(void)
+{
+       pvh_reserve_extra_memory();
+
+       if (xen_initial_domain())
+               xen_add_preferred_consoles();
+}
+
 void __init xen_pvh_init(struct boot_params *boot_params)
 {
        xen_pvh = 1;
        xen_domain_type = XEN_HVM_DOMAIN;
        xen_start_flags = pvh_start_info.flags;
 
-       if (xen_initial_domain())
-               x86_init.oem.arch_setup = xen_add_preferred_consoles;
+       x86_init.oem.arch_setup = pvh_arch_setup;
        x86_init.oem.banner = xen_banner;
 
        xen_efi_init(boot_params);