x86/paravirt: Move halt paravirt calls under CONFIG_PARAVIRT
Subsystems (5)
PATCH 1/1 x86/paravirt: Move halt paravirt calls under CONFIG_PARAVIRT
From: "Kirill A. Shutemov" <[email protected]>
CONFIG_PARAVIRT_XXL is mainly defined/used by XEN PV guests. For other VM guest types, features supported under CONFIG_PARAVIRT are self sufficient. CONFIG_PARAVIRT mainly provides support for TLB flush operations and time related operations.
For TDX guest as well, paravirt calls under CONFIG_PARVIRT meets most of its requirement except the need of HLT and SAFE_HLT paravirt calls, which is currently defined under CONFIG_PARAVIRT_XXL.
Since enabling CONFIG_PARAVIRT_XXL is too bloated for TDX guest like platforms, move HLT and SAFE_HLT paravirt calls under CONFIG_PARAVIRT.
Moving HLT and SAFE_HLT paravirt calls are not fatal and should not break any functionality for current users of CONFIG_PARAVIRT.
---
6.12.23 fails to build with the following error if CONFIG_XEN_PV is not set:
arch/x86/coco/tdx/tdx.c: In function ‘tdx_early_init’:arch/x86/coco/tdx/tdx.c:1080:19: error: ‘struct pv_irq_ops’ has no member named ‘safe_halt’
1080 | pv_ops.irq.safe_halt = tdx_safe_halt;
| ^arch/x86/coco/tdx/tdx.c:1081:19: error: ‘struct pv_irq_ops’ has no member named ‘halt’
1081 | pv_ops.irq.halt = tdx_halt;
| ^
This is because XEN_PV selects PARAVIRT_XXL, and 'safe_halt' and 'halt' are only defined for pv_irq_ops if PARAVIRT_XXL is defined.
The build breakage was introduced in 6.12.23 by stable commit 805e3ce5e0e3 which is a backport of 9f98a4f4e721 ("x86/tdx: Fix arch_safe_halt() execution for TDX VMs").
Consider picking up upstream commit 22cc5ca5de52 ("x86/paravirt:
Move halt paravirt calls under CONFIG_PARAVIRT") for stable 6.12.y which fixes the build regression by moving 'safe_halt' and 'halt' out from under the PARAVIRT_XXL config.
This patch is 22cc5ca5de52 backported to 6.12.23. There were a couple of merge conflicts due to the missing upstream commits below:
29188c160061 ("x86/paravirt: Remove the WBINVD callback") 3101900218d7 ("x86/paravirt: Remove unused paravirt_disable_iospace()")
I wasn't sure if it was appropriate to pull those to stable as well and the merge conflicts were trivial.
Thanks!
--- arch/x86/include/asm/irqflags.h | 40 +++++++++++++++++++---------------- arch/x86/include/asm/paravirt.h | 20 +++++++++--------- arch/x86/include/asm/paravirt_types.h | 3 +-- arch/x86/kernel/paravirt.c | 13 +++++++----- 4 files changed, 41 insertions(+), 35 deletions(-)
arch/x86/include/asm/irqflags.h +22 -18
@@ -76,6 +76,28 @@ static __always_inline void native_local_irq_restore(unsigned long flags)#endif +#ifndef CONFIG_PARAVIRT +#ifndef __ASSEMBLY__ +/* +* Used in the idle loop; sti takes one instruction cycle +* to complete: +*/ +static __always_inline void arch_safe_halt(void) +{ +native_safe_halt (); +} + +/* +* Used when interrupts are already enabled or to +* shutdown the processor: +*/ +static __always_inline void halt(void) +{ +native_halt (); +} +#endif /* __ASSEMBLY__ */ +#endif /* CONFIG_PARAVIRT */ +#ifdef CONFIG_PARAVIRT_XXL #include <asm/paravirt.h> #else
@@ -97,24 +119,6 @@ static __always_inline void arch_local_irq_enable(void)native_irq_enable (); } -/* -* Used in the idle loop; sti takes one instruction cycle -* to complete: -*/ -static __always_inline void arch_safe_halt(void) -{ -native_safe_halt (); -} - -/* -* Used when interrupts are already enabled or to -* shutdown the processor: -*/ -static __always_inline void halt(void) -{ -native_halt (); -} -/* * For spinlocks, etc: */
arch/x86/include/asm/paravirt.h +10 -10
@@ -107,6 +107,16 @@ static inline void notify_page_enc_status_changed(unsigned long pfn,PVOP_VCALL3 (mmu.notify_page_enc_status_changed, pfn, npages, enc); } +static __always_inline void arch_safe_halt(void) +{ +PVOP_VCALL0 (irq.safe_halt); +} + +static inline void halt (void ) +{ +PVOP_VCALL0 (irq.halt); +} +#ifdef CONFIG_PARAVIRT_XXL static inline void load_sp0 (unsigned long sp0) {
@@ -170,16 +180,6 @@ static inline void __write_cr4(unsigned long x)PVOP_VCALL1 (cpu.write_cr4, x); } -static __always_inline void arch_safe_halt(void) -{ -PVOP_VCALL0 (irq.safe_halt); -} - -static inline void halt (void ) -{ -PVOP_VCALL0 (irq.halt); -} - extern noinstr void pv_native_wbinvd(void); static __always_inline void wbinvd(void)
arch/x86/include/asm/paravirt_types.h +1 -2
@@ -122,10 +122,9 @@ struct pv_irq_ops {struct paravirt_callee_save save_fl;struct paravirt_callee_save irq_disable;struct paravirt_callee_save irq_enable; - +#endif void (*safe_halt)(void );void (*halt)(void ); -#endif } __no_randomize_layout;struct pv_mmu_ops {
arch/x86/kernel/paravirt.c +8 -5
@@ -100,6 +100,11 @@ int paravirt_disable_iospace(void)return request_resource (&ioport_resource, &reserve_ioports); } +static noinstr void pv_native_safe_halt(void) +{ +native_safe_halt (); +} +#ifdef CONFIG_PARAVIRT_XXL static noinstr void pv_native_write_cr2(unsigned long val) {
@@ -121,10 +126,6 @@ noinstr void pv_native_wbinvd(void)native_wbinvd (); } -static noinstr void pv_native_safe_halt(void) -{ -native_safe_halt (); -}#endif struct pv_info pv_info = {
@@ -182,9 +183,11 @@ struct paravirt_patch_template pv_ops = { .irq.save_fl = __PV_IS_CALLEE_SAVE(pv_native_save_fl), .irq.irq_disable = __PV_IS_CALLEE_SAVE(pv_native_irq_disable), .irq.irq_enable = __PV_IS_CALLEE_SAVE(pv_native_irq_enable), +#endif /* CONFIG_PARAVIRT_XXL */ + +/* Irq HLT ops. */ .irq.safe_halt = pv_native_safe_halt, .irq.halt = native_halt, -#endif /* CONFIG_PARAVIRT_XXL */ /* Mmu ops. */ .mmu.flush_tlb_user = native_flush_tlb_local,
---
base-commit: 83b4161a63b87ce40d9f24f09b5b006f63d95b7c
change-id: 20250415-stable_fixup-c7b936473f53
Best regards,
Signature · 1 line
Brett Mastbergen <[email protected]>
Quoted 21 lines
...
6.12.23 fails to build with the following error ifCONFIG_XEN_PVis not set:
arch/x86/coco/tdx/tdx.c: In function ‘tdx_early_init’:arch/x86/coco/tdx/tdx.c:1080:19: error: ‘struct pv_irq_ops’ has no member named ‘safe_halt’
1080 | pv_ops.irq.safe_halt =tdx_safe_halt;
| ^arch/x86/coco/tdx/tdx.c:1081:19: error: ‘struct pv_irq_ops’ has no member named ‘halt’
1081 | pv_ops.irq.halt =tdx_halt;
| ^This is because
XEN_PVselectsPARAVIRT_XXL, and 'safe_halt' and 'halt' are only defined forpv_irq_opsifPARAVIRT_XXLis defined.The build breakage was introduced in 6.12.23 by stable commit
805e3ce5e0e3which is a backport of9f98a4f4e721("x86/tdx: Fixarch_safe_halt()execution for TDX VMs").
Quoted 8 lines
Consider picking up upstream commit
22cc5ca5de52("x86/paravirt:
Move halt paravirt calls underCONFIG_PARAVIRT") for stable 6.12.y which fixes the build regression by moving 'safe_halt' and 'halt' out from under thePARAVIRT_XXLconfig.This patch is
22cc5ca5de52backported to 6.12.23. There were a couple of merge conflicts due to the missing upstream commits below:
Thanks Brett for looking into this. I have posted a similar patch [1] and I see that the issue you reported is also being discussed already [2].
[1] https://lore.kernel.org/stable/[email protected]/
[2] https://lore.kernel.org/stable/20250410180423.GA3430900@ax162/