x86/xen: fix memblock_reserve() usage on PVH
Subsystems (2)
cover x86/xen: fix memblock_reserve() usage on PVH
Hello,
First patch is just code movement, the second patch is the actual bugfix.
Thanks, Roger.
Roger Pau Monne (2):
x86/xen: move xen_reserve_extra_memory()
x86/xen: fix memblock_reserve() usage on PVH
arch/x86/include/asm/xen/hypervisor.h | 5 -- arch/x86/platform/pvh/enlighten.c | 3 - arch/x86/xen/enlighten_pvh.c | 107 ++++++++++++++------------ 3 files changed, 58 insertions(+), 57 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/2 x86/xen: move xen_reserve_extra_memory()
In preparation for making the function static.
No functional change.
---
Since this is a pre-requisite for a bugfix, I've tagged it with "Fixes:", not sure if that's appropriate or there's some better tag to use.
--- arch/x86/xen/enlighten_pvh.c | 96 ++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-)
arch/x86/xen/enlighten_pvh.c +48 -48
@@ -27,54 +27,6 @@bool __ro_after_init xen_pvh;EXPORT_SYMBOL_GPL (xen_pvh); -void __init xen_pvh_init (struct boot_params *boot_params) -{ -u32 msr; -u64 pfn; - - xen_pvh =1 ; - xen_domain_type =XEN_HVM_DOMAIN ; - xen_start_flags = pvh_start_info.flags; - - msr =cpuid_ebx (xen_cpuid_base () +2 ); - pfn =__pa (hypercall_page); -wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); - -if (xen_initial_domain ()) - x86_init.oem.arch_setup = xen_add_preferred_consoles; - x86_init.oem.banner = xen_banner; - -xen_efi_init (boot_params); - -if (xen_initial_domain ()) { -struct xen_platform_op op = { - .cmd = XENPF_get_dom0_console, - }; -int ret =HYPERVISOR_platform_op (&op); - -if (ret >0 ) -xen_init_vga (&op.u.dom0_console, -min (ret *sizeof (char ), -sizeof (op.u.dom0_console)), - &boot_params->screen_info); - } -} - -void __init mem_map_via_hcall (struct boot_params *boot_params_p) -{ -struct xen_memory_map memmap; -int rc; - - memmap.nr_entries =ARRAY_SIZE (boot_params_p->e820_table); -set_xen_guest_handle (memmap.buffer, boot_params_p->e820_table); - rc =HYPERVISOR_memory_op (XENMEM_memory_map, &memmap); -if (rc) { -xen_raw_printk ("XENMEM_memory_map failed (%d)\n" , rc); -BUG (); - } - boot_params_p->e820_entries = memmap.nr_entries; -} -/* * Reserve e820 UNUSABLE regions to inflate the memory balloon. *
@@ -141,3 +93,51 @@ void __init xen_reserve_extra_memory(struct boot_params *bootp)xen_add_extra_mem (PFN_UP (e->addr), pages); } } + +void __init xen_pvh_init (struct boot_params *boot_params) +{ +u32 msr; +u64 pfn; + + xen_pvh =1 ; + xen_domain_type =XEN_HVM_DOMAIN ; + xen_start_flags = pvh_start_info.flags; + + msr =cpuid_ebx (xen_cpuid_base () +2 ); + pfn =__pa (hypercall_page); +wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); + +if (xen_initial_domain ()) + x86_init.oem.arch_setup = xen_add_preferred_consoles; + x86_init.oem.banner = xen_banner; + +xen_efi_init (boot_params); + +if (xen_initial_domain ()) { +struct xen_platform_op op = { + .cmd = XENPF_get_dom0_console, + }; +int ret =HYPERVISOR_platform_op (&op); + +if (ret >0 ) +xen_init_vga (&op.u.dom0_console, +min (ret *sizeof (char ), +sizeof (op.u.dom0_console)), + &boot_params->screen_info); + } +} + +void __init mem_map_via_hcall (struct boot_params *boot_params_p) +{ +struct xen_memory_map memmap; +int rc; + + memmap.nr_entries =ARRAY_SIZE (boot_params_p->e820_table); +set_xen_guest_handle (memmap.buffer, boot_params_p->e820_table); + rc =HYPERVISOR_memory_op (XENMEM_memory_map, &memmap); +if (rc) { +xen_raw_printk ("XENMEM_memory_map failed (%d)\n" , rc); +BUG (); + } + boot_params_p->e820_entries = memmap.nr_entries; +}
Signature · 1 line
2.45.2
Re: [PATCH 1/2] x86/xen: move xen_reserve_extra_memory()
Quoted 6 lines · Roger Pau Monne
In preparation for making the function static.
No functional change.
Fixes 38620fc4e893 ('x86/xen: attempt to inflate the memory balloon on PVH')Signed-off-by Roger Pau Monné <[email protected]>
Without the Fixes: tag (can be dropped while committing):
Juergen
PATCH 2/2 x86/xen: fix memblock_reserve() usage on PVH
In reply to Roger Pau MonneThe 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().
---
While the commit that introduced the user-noticeable regression is 73db3abdca58c, I think 38620fc4e893 should have been more careful to not initialize the memblock ranges ahead of the .bss zeroing.
--- arch/x86/include/asm/xen/hypervisor.h | 5 ----- arch/x86/platform/pvh/enlighten.c | 3 --- arch/x86/xen/enlighten_pvh.c | 15 ++++++++++++--- 3 files changed, 12 insertions(+), 11 deletions(-)
arch/x86/include/asm/xen/hypervisor.h +0 -5
@@ -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 */
arch/x86/platform/pvh/enlighten.c +0 -3
@@ -75,9 +75,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;
arch/x86/xen/enlighten_pvh.c +12 -3
@@ -9,6 +9,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>
@@ -41,8 +42,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++) {
@@ -94,6 +96,14 @@ 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) {u32 msr;
@@ -107,8 +117,7 @@ void __init xen_pvh_init(struct boot_params *boot_params) pfn =__pa (hypercall_page);wrmsr_safe (msr, (u32 )pfn, (u32)(pfn >>32 )); -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);
Signature · 1 line
2.45.2
Quoted 11 lines · Roger Pau Monne
The current usage of
memblock_reserve()ininit_pvh_bootparams()is done before the .bss is zeroed, and that used to be fine whenmemblock_reserved_init_regionsimplicitly ended up in the .meminit.data section. However after commit73db3abdca58cmemblock_reserved_init_regionsends 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 callinge820__memory_setup().
Quoted 6 lines
Fixes 38620fc4e893 ('x86/xen: attempt to inflate the memory balloon on PVH')Signed-off-by Roger Pau Monné <[email protected]>---
While the commit that introduced the user-noticeable regression is73db3abdca58c, I think38620fc4e893should have been more careful to not initialize the memblock ranges ahead of the .bss zeroing.
I'd prefer using 73db3abdca58c for the fixes tag. Otherwise you'd need to add this patch to the stable branches, too, which is technically not really needed.
Additionally I'd like to drop the Fixes: tag from the prereq patch, as this one doesn't really fix anything.
I can do both while committing.
Juergen
Quoted 21 lines · Jürgen Groß
Quoted 11 lines · Roger Pau Monne
The current usage of
memblock_reserve()ininit_pvh_bootparams()is done before the .bss is zeroed, and that used to be fine whenmemblock_reserved_init_regionsimplicitly ended up in the .meminit.data section. However after commit73db3abdca58cmemblock_reserved_init_regionsends 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 callinge820__memory_setup().Quoted 6 lines
Fixes 38620fc4e893 ('x86/xen: attempt to inflate the memory balloon on PVH')Signed-off-by Roger Pau Monné <[email protected]>---
While the commit that introduced the user-noticeable regression is73db3abdca58c, I think38620fc4e893should have been more careful to not initialize the memblock ranges ahead of the .bss zeroing.Reviewed-by Juergen Gross <[email protected]>
Quoted 8 lines
I'd prefer using
73db3abdca58cfor the fixes tag. Otherwise you'd need to add this patch to the stable branches, too, which is technically not really needed.Additionally I'd like to drop the Fixes: tag from the prereq patch, as this one doesn't really fix anything.
I can do both while committing.
I was unsure myself (as noted in the post-commit notes) about which "Fixes:" tag to use.
Is there anyway that it can be noted that this commit depends on the previous change also being present? For backport reasons, if anyone ends up backporting 73db3abdca58c it would also need to pick the two patches here.
Thanks, Roger.
Jürgen Groß
maintainerQuoted 31 lines · Roger Pau Monné
Quoted 21 lines · Jürgen Groß
Quoted 11 lines · Roger Pau Monne
The current usage of
memblock_reserve()ininit_pvh_bootparams()is done before the .bss is zeroed, and that used to be fine whenmemblock_reserved_init_regionsimplicitly ended up in the .meminit.data section. However after commit73db3abdca58cmemblock_reserved_init_regionsends 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 callinge820__memory_setup().Quoted 6 lines
Fixes 38620fc4e893 ('x86/xen: attempt to inflate the memory balloon on PVH')Signed-off-by Roger Pau Monné <[email protected]>---
While the commit that introduced the user-noticeable regression is73db3abdca58c, I think38620fc4e893should have been more careful to not initialize the memblock ranges ahead of the .bss zeroing.Reviewed-by Juergen Gross <[email protected]>Quoted 8 lines
I'd prefer using
73db3abdca58cfor the fixes tag. Otherwise you'd need to add this patch to the stable branches, too, which is technically not really needed.Additionally I'd like to drop the Fixes: tag from the prereq patch, as this one doesn't really fix anything.
I can do both while committing.
Quoted 7 lines
I was unsure myself (as noted in the post-commit notes) about which "Fixes:" tag to use.
Is there anyway that it can be noted that this commit depends on the previous change also being present? For backport reasons, if anyone ends up backporting
73db3abdca58cit would also need to pick the two patches here.
This is normal business of backporting. This patch added to a stable kernel would at least result in a build failure. The person doing the backport could it either fixup locally in the backported patch, or look which patch did setup the source to make this patch work.
Juergen