x86: hvm: vmx: fix runtime vmx presence check for !CONFIG_INTEL_VMX case
PATCH 1/2 x86: hvm: vmx: fix runtime vmx presence check for !CONFIG_INTEL_VMX case
From: Grygorii Strashko <[email protected]>
Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX code partially built-in, because HVM code uses mix of:
- "cpu_has_vmx" macro, which doesn't account for CONFIG_INTEL_VMX cfg
- "using_vmx()" function, which accounts for CONFIG_INTEL_VMX cfg
for runtime VMX availability checking. As result compiler DCE can't remove all, unreachable VMX code.
Fix it by sticking to "cpu_has_vmx" macro usage only which is updated to account CONFIG_INTEL_VMX cfg.
---
Hi
It could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
bloat-o-meter:
add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-779 (-779)
Function old new delta
guest_wrmsr_viridian 1062 1043 -19 hvm_monitor_descriptor_access 168 133 -35 init_guest_cpu_policies 1200 1164 -36 nestedhvm_setup 274 233 -41 p2m_mem_access_sanity_check 71 27 -44 hvm_set_param 1602 1473 -129 dom0_construct_pvh 4438 3963 -475
Total: Before=3422547, After=3421768, chg -0.02%
xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/nestedhvm.c | 2 +- xen/arch/x86/include/asm/cpufeature.h | 3 ++- xen/arch/x86/include/asm/hvm/hvm.h | 5 ----- xen/arch/x86/mm/p2m-basic.c | 4 ++-- xen/arch/x86/traps.c | 4 ++-- 6 files changed, 8 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/hvm.c +1 -1
@@ -158,7 +158,7 @@ static int __init cf_check hvm_enable(void) {const struct hvm_function_table *fns =NULL ; -if (using_vmx () ) +if ( cpu_has_vmx ) fns =start_vmx ();else if (using_svm () ) fns =start_svm ();
xen/arch/x86/hvm/nestedhvm.c +1 -1
@@ -155,7 +155,7 @@ static int __init cf_check nestedhvm_setup(void)* done, so that if (for example) HAP is disabled, nested virt is * disabled as well. */ -if (using_vmx () ) +if ( cpu_has_vmx )start_nested_vmx (&hvm_funcs);else if (using_svm () )start_nested_svm (&hvm_funcs);
xen/arch/x86/include/asm/cpufeature.h +2 -1
@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3)#define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ)#define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))#define cpu_has_eist boot_cpu_has(X86_FEATURE_EIST)#define cpu_has_ssse3 boot_cpu_has(X86_FEATURE_SSSE3)#define cpu_has_fma boot_cpu_has(X86_FEATURE_FMA)
xen/arch/x86/include/asm/hvm/hvm.h +0 -5
@@ -383,11 +383,6 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src);int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value); -static inline bool using_vmx (void ) -{ -return IS_ENABLED (CONFIG_INTEL_VMX ) && cpu_has_vmx; -} -static inline bool using_svm (void ) {return IS_ENABLED (CONFIG_AMD_SVM ) && cpu_has_svm;
xen/arch/x86/mm/p2m-basic.c +2 -2
@@ -40,7 +40,7 @@ static int p2m_initialise(struct domain *d, struct p2m_domain *p2m)p2m_pod_init (p2m);p2m_nestedp2m_init (p2m); -if (hap_enabled (d) &&using_vmx () ) +if (hap_enabled (d) && cpu_has_vmx ) ret =ept_p2m_init (p2m);else p2m_pt_init (p2m);
@@ -72,7 +72,7 @@ struct p2m_domain *p2m_init_one(struct domain *d)void p2m_free_one (struct p2m_domain *p2m) {p2m_free_logdirty (p2m); -if (hap_enabled (p2m->domain) &&using_vmx () ) +if (hap_enabled (p2m->domain) && cpu_has_vmx )ept_p2m_uninit (p2m);free_cpumask_var (p2m->dirty_cpumask);xfree (p2m);
xen/arch/x86/traps.c +2 -2
@@ -918,7 +918,7 @@ void vcpu_show_execution_state(struct vcpu *v)* region. Despite this being a layering violation, engage the VMCS right * here. This then also avoids doing so several times in close succession. */ -if (using_vmx () &&is_hvm_vcpu (v) ) +if ( cpu_has_vmx &&is_hvm_vcpu (v) ) {ASSERT (!in_irq ());vmx_vmcs_enter (v);
@@ -947,7 +947,7 @@ void vcpu_show_execution_state(struct vcpu *v)console_unlock_recursive_irqrestore (flags); } -if (using_vmx () &&is_hvm_vcpu (v) ) +if ( cpu_has_vmx &&is_hvm_vcpu (v) )vmx_vmcs_exit (v);vcpu_unpause (v);
Signature · 1 line
2.34.1
PATCH 2/2 x86: hvm: svm: fix runtime svm presence check for !CONFIG_AMD_SVM case
From: Grygorii Strashko <[email protected]>
Since commit b99227347230 ("x86: Fix AMD_SVM and INTEL_VMX dependency") the AMD-V support can be gracefully disabled, but it still keeps SVM code partially built-in, because HVM code uses mix of:
- "cpu_has_svm" macro, which doesn't account for CONFIG_AMD_SVM cfg
- "using_svm()" function, which accounts for CONFIG_AMD_SVM cfg
for runtime SVM availability checking. As result compiler DCE can't remove all, unreachable SVM code.
Fix it by sticking to "cpu_has_svm" macro usage only which is updated to account CONFIG_AMD_SVM cfg.
---
Hi
It could be good to have it in 4.21.
bloat-o-meter:
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-98 (-98)
Function old new deltaguest_flush_tlb_flags 71 62 -9init_speculation_mitigations 10024 10011 -13hvm_set_efer 364 288 -76
Total: Before=3656835, After=3656737, chg -0.00%
xen/arch/x86/domain.c | 4 ++-- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/nestedhvm.c | 2 +- xen/arch/x86/include/asm/cpufeature.h | 3 ++- xen/arch/x86/include/asm/hvm/hvm.h | 5 ----- 5 files changed, 6 insertions(+), 10 deletions(-)
xen/arch/x86/domain.c +2 -2
@@ -1824,7 +1824,7 @@ static void load_segments(struct vcpu *n)if ( !(n->arch.flags & TF_kernel_mode) )SWAP (gsb, gss); -if (using_svm () && (n->arch.pv.fs | n->arch.pv.gs) <=3 ) +if ( cpu_has_svm && (n->arch.pv.fs | n->arch.pv.gs) <=3 ) fs_gs_done =svm_load_segs (n->arch.pv.ldt_ents,LDT_VIRT_START (n), n->arch.pv.fs_base, gsb, gss); }
@@ -2142,7 +2142,7 @@ static void __context_switch(void)#ifdef CONFIG_PV /* Prefetch the VMCB if we expect to use it later in the context switch */ -if (using_svm () &&is_pv_64bit_domain (nd) && !is_idle_domain (nd) ) +if ( cpu_has_svm &&is_pv_64bit_domain (nd) && !is_idle_domain (nd) )svm_load_segs_prefetch ();#endif
xen/arch/x86/hvm/hvm.c +1 -1
@@ -160,7 +160,7 @@ static int __init cf_check hvm_enable(void)if ( cpu_has_vmx ) fns =start_vmx (); -else if (using_svm () ) +else if ( cpu_has_svm ) fns =start_svm ();if ( fns )
xen/arch/x86/hvm/nestedhvm.c +1 -1
@@ -157,7 +157,7 @@ static int __init cf_check nestedhvm_setup(void)*/ if ( cpu_has_vmx )start_nested_vmx (&hvm_funcs); -else if (using_svm () ) +else if ( cpu_has_svm )start_nested_svm (&hvm_funcs);return 0 ;
xen/arch/x86/include/asm/cpufeature.h +2 -1
@@ -165,7 +165,8 @@ static inline bool boot_cpu_has(unsigned int feat)/* CPUID level 0x80000001.ecx */ #define cpu_has_cmp_legacy boot_cpu_has(X86_FEATURE_CMP_LEGACY) -#define cpu_has_svm boot_cpu_has(X86_FEATURE_SVM) +#define cpu_has_svm (IS_ENABLED(CONFIG_AMD_SVM) && \ + boot_cpu_has(X86_FEATURE_SVM))#define cpu_has_sse4a boot_cpu_has(X86_FEATURE_SSE4A)#define cpu_has_xop boot_cpu_has(X86_FEATURE_XOP)#define cpu_has_skinit boot_cpu_has(X86_FEATURE_SKINIT)
xen/arch/x86/include/asm/hvm/hvm.h +0 -5
@@ -383,11 +383,6 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src);int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value); -static inline bool using_svm (void ) -{ -return IS_ENABLED (CONFIG_AMD_SVM ) && cpu_has_svm; -} -#ifdef CONFIG_HVM #define hvm_get_guest_tsc (v) hvm_get_guest_tsc_fixed(v, 0)
Signature · 1 line
2.34.1
Re: [XEN][PATCH 2/2] x86: hvm: svm: fix runtime svm presence check for !CONFIG_AMD_SVM case
Quoted 21 lines · Grygorii Strashko
From: Grygorii Strashko<[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the AMD-V support can be gracefully disabled, but it still keeps SVM code partially built-in, because HVM code uses mix of:- "
cpu_has_svm" macro, which doesn't account forCONFIG_AMD_SVMcfg
- "using_svm()" function, which accounts forCONFIG_AMD_SVMcfgfor runtime SVM availability checking. As result compiler DCE can't remove all, unreachable SVM code.
Fix it by sticking to "
cpu_has_svm" macro usage only which is updated to accountCONFIG_AMD_SVMcfg.Signed-off-by Grygorii Strashko<[email protected]>---
HiIt could be good to have it in 4.21.
Quoted 7 lines
bloat-o-meter:
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-98 (-98)
Function old new deltaguest_flush_tlb_flags71 62 -9init_speculation_mitigations10024 10011 -13hvm_set_efer364 288 -76
Total: Before=3656835, After=3656737, chg -0.00%
It doesn't seem critical for the current release stage, so let's consider these changes for 4.22.
Thanks.
~ Oleksii
Quoted 86 lines
xen/arch/x86/domain.c | 4 ++-- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/hvm/nestedhvm.c | 2 +- xen/arch/x86/include/asm/cpufeature.h | 3 ++- xen/arch/x86/include/asm/hvm/hvm.h | 5 ----- 5 files changed, 6 insertions(+), 10 deletions(-)xen/arch/x86/domain.c +2
-2@@ -1824,7 +1824,7 @@ static void load_segments(struct vcpu *n)if ( !(n->arch.flags & TF_kernel_mode) )SWAP (gsb, gss); -if (using_svm () && (n->arch.pv.fs | n->arch.pv.gs) <=3 ) +if ( cpu_has_svm && (n->arch.pv.fs | n->arch.pv.gs) <=3 ) fs_gs_done =svm_load_segs (n->arch.pv.ldt_ents,LDT_VIRT_START (n), n->arch.pv.fs_base, gsb, gss); }@@ -2142,7 +2142,7 @@ static void __context_switch(void)#ifdef CONFIG_PV /* Prefetch the VMCB if we expect to use it later in the context switch */ -if (using_svm () &&is_pv_64bit_domain (nd) && !is_idle_domain (nd) ) +if ( cpu_has_svm &&is_pv_64bit_domain (nd) && !is_idle_domain (nd) )svm_load_segs_prefetch ();#endif xen/arch/x86/hvm/hvm.c +1
-1@@ -160,7 +160,7 @@ static int __init cf_check hvm_enable(void)if ( cpu_has_vmx ) fns =start_vmx (); -else if (using_svm () ) +else if ( cpu_has_svm ) fns =start_svm ();if ( fns )xen/arch/x86/hvm/nestedhvm.c +1
-1@@ -157,7 +157,7 @@ static int __init cf_check nestedhvm_setup(void)*/ if ( cpu_has_vmx )start_nested_vmx (&hvm_funcs); -else if (using_svm () ) +else if ( cpu_has_svm )start_nested_svm (&hvm_funcs);return 0 ;xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -165,7 +165,8 @@ static inline bool boot_cpu_has(unsigned int feat)/* CPUID level 0x80000001.ecx */ #define cpu_has_cmp_legacy boot_cpu_has(X86_FEATURE_CMP_LEGACY) -#define cpu_has_svm boot_cpu_has(X86_FEATURE_SVM) +#define cpu_has_svm (IS_ENABLED(CONFIG_AMD_SVM) && \ + boot_cpu_has(X86_FEATURE_SVM))#define cpu_has_sse4a boot_cpu_has(X86_FEATURE_SSE4A)#define cpu_has_xop boot_cpu_has(X86_FEATURE_XOP)#define cpu_has_skinit boot_cpu_has(X86_FEATURE_SKINIT)xen/arch/x86/include/asm/hvm/hvm.h +0
-5@@ -383,11 +383,6 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src);int hvm_get_param (struct domain *d,uint32_t index,uint64_t *value); -static inline bool using_svm (void ) -{ -return IS_ENABLED (CONFIG_AMD_SVM ) && cpu_has_svm; -} -#ifdef CONFIG_HVM #define hvm_get_guest_tsc (v) hvm_get_guest_tsc_fixed(v, 0)
Quoted 15 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove all, unreachable VMX code.
Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to accountCONFIG_INTEL_VMXcfg.
Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned int feat) · line 140
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3)#define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ)#define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))
I'm pretty sure using_vmx() was introduced precisely to avoid the use of IS_ENABLED() here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time the using_vmx() was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)
Jan
Hi Jan,
Quoted 36 lines · Jan Beulich
Quoted 15 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove all, unreachable VMX code.
Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to accountCONFIG_INTEL_VMXcfg.Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned int feat) · line 140
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3)#define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ)#define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))
Quoted 8 lines
I'm pretty sure
using_vmx()was introduced precisely to avoid the use ofIS_ENABLED()here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time theusing_vmx()was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)
Thank you for your comments and sorry for not digging into the history of the related patches.
All, please ignore these patches as existing places. where cpu_has_vmx/smv are still used, need to be revised one by one.
Signature · 2 lines
Best regards, -grygorii
Quoted 52 lines · Grygorii Strashko
Hi Jan,
Quoted 40 lines · Jan Beulich
Quoted 19 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the
HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX
code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove
all, unreachable VMX code.Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to
accountCONFIG_INTEL_VMXcfg.Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned int feat) · line 140
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat) #define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3) #define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ) #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))Quoted 8 lines
I'm pretty sure
using_vmx()was introduced precisely to avoid the use ofIS_ENABLED()here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time theusing_vmx()was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)
Quoted 7 lines
Thank you for your comments and sorry for not digging into the history of the related patches.
All, please ignore these patches as existing places. where cpu_has_vmx/smv
are still used, need to be revised one by one.
Off the top of my head, fixups to MSR_FEATURE_CONTROL, and AMD SKINIT need cpu_has_vmx/svm not guarded by Kconfig like this.
~Andrew
Quoted 44 lines · Andrew Cooper
Quoted 43 lines · Grygorii Strashko
Hi Jan,
Quoted 40 lines · Jan Beulich
Quoted 19 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the
HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX
code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove
all, unreachable VMX code.Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to
accountCONFIG_INTEL_VMXcfg.Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat) #define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3) #define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ) #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
I'm pretty sure
using_vmx()was introduced precisely to avoid the use ofIS_ENABLED()here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time theusing_vmx()was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)
Apologies if this has already been discussed, but I didn't participate in prior discussions. Targeted lookups in lore are not shedding a lot of light either.
Quoted 9 lines
Quoted 8 lines
Thank you for your comments and sorry for not digging into the history of the related patches.
All, please ignore these patches as existing places. where cpu_has_vmx/smv
are still used, need to be revised one by one.
Quoted 4 lines
Off the top of my head, fixups to
MSR_FEATURE_CONTROL, and AMD SKINIT need cpu_has_vmx/svm not guarded byKconfiglike this.~Andrew
What do you mean? AFAICS SKINIT is guarded by cpu_has_skinit, not cpu_has_svm.
And MSR_IA32_FEATURE_CONTROL tweaking seems self-contained in xen/hvm/vmx/ which is compiled out when !CONFIG_INTEL_VMX.
For the hypothetical case in which we might want to know the real HW value we can go look at the raw policy, as in "raw_cpu_policy.basic.vmx" or "raw_cpu_policy.extd.svm". Or what's mentioned in passing here.
https://lore.kernel.org/xen-devel/[email protected]/
Forcing the common case to use a helper and leaving the rare case in the shorthand macro seems like a bad idea. This ought to follow what cpu_has_nx already does.
Is there a specific code instance in which having IS_ENABLED() in the cpu_has_{svm,vmx} macros would cause issues today? While there are some dubious choices of svm vs vmx with or without negation, they all seem to resolve to correct code, with less codegen after IS_ENABLED() ends up in all the conditionals.
IOW: I have seen fear of incorrectness, but not proof of it. Now, obviously the burden of proof rests on the submitter, indeed, but I'd like to know where we stand in terms of what that proof would look like. A naive grep shows not many sites to check.
$git grep cpu_has_svm | grep -v cpu_has_svm_ | wc -l 6
$git grep cpu_has_vmx | grep -v cpu_has_vmx_ | wc -l 11
cpu_has_X_Y would be off when cpu_has_X is off, but those shouldn't matter for this discussion.
Am I missing something here?
Cheers,
Alejandro
Hi Alejandro,
Quoted 92 lines · Alejandro Vallejo
Quoted 44 lines · Andrew Cooper
Quoted 43 lines · Grygorii Strashko
Hi Jan,
Quoted 40 lines · Jan Beulich
Quoted 19 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the
HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX
code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove
all, unreachable VMX code.Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to
accountCONFIG_INTEL_VMXcfg.Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat) #define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3) #define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ) #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
I'm pretty sure
using_vmx()was introduced precisely to avoid the use ofIS_ENABLED()here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time theusing_vmx()was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)Apologies if this has already been discussed, but I didn't participate in prior discussions. Targeted lookups in lore are not shedding a lot of light either.
Quoted 9 lines
Quoted 8 lines
Thank you for your comments and sorry for not digging into the history of the related patches.
All, please ignore these patches as existing places. where cpu_has_vmx/smv
are still used, need to be revised one by one.Quoted 4 lines
Off the top of my head, fixups to
MSR_FEATURE_CONTROL, and AMD SKINIT need cpu_has_vmx/svm not guarded byKconfiglike this.~Andrew
What do you mean? AFAICS SKINIT is guarded by
cpu_has_skinit, notcpu_has_svm.And
MSR_IA32_FEATURE_CONTROLtweaking seems self-contained in xen/hvm/vmx/ which is compiled out when !CONFIG_INTEL_VMX.For the hypothetical case in which we might want to know the real HW value we can go look at the raw policy, as in "raw_cpu_policy.basic.vmx" or "raw_cpu_policy.extd.svm". Or what's mentioned in passing here.
https://lore.kernel.org/xen-devel/[email protected]/
Forcing the common case to use a helper and leaving the rare case in the shorthand macro seems like a bad idea. This ought to follow what
cpu_has_nxalready does.Is there a specific code instance in which having
IS_ENABLED()in the cpu_has_{svm,vmx} macros would cause issues today? While there are some dubious choices of svm vs vmx with or without negation, they all seem to resolve to correct code, with less codegen afterIS_ENABLED()ends up in all the conditionals.
Quoted 7 lines
IOW: I have seen fear of incorrectness, but not proof of it. Now, obviously the burden of proof rests on the submitter, indeed, but I'd like to know where we stand in terms of what that proof would look like. A naive grep shows not many sites to check.
$git grep
cpu_has_svm| grep -vcpu_has_svm_| wc -l 6
arch/x86/flushtlb.c: bool asid = is_hvm_domain(d) && (cpu_has_svm || shadow); arch/x86/hvm/hvm.c: if ( nestedhvm_enabled(v->domain) && cpu_has_svm && arch/x86/spec_ctrl.c: if ( !cpu_has_svm )
not checked yet.
Quoted 3 lines
$git grep
cpu_has_vmx| grep -vcpu_has_vmx_| wc -l 11
Here:
1) arch/x86/hvm/dom0_build.c: if ( cpu_has_vmx && paging_mode_hap(d) && !vmx_unrestricted_guest(v) )
arch/x86/hvm/hvm.c: if ( !paging_mode_hap(d) || !cpu_has_vmx )
^ is safe to opt-opt. I've sent patch [1]
It gives biggest coverage benefit actually.
2) arch/x86/hvm/viridian/viridian.c: *(u8 *)(p + 7) = (cpu_has_vmx ? 0xc1 : 0xd9);
There is strict dependency on HW. In general, viridian should never be enabled on INTEL, for example, if !INTEL_VMX. So, could be opt out
3) arch/x86/mm/mem_sharing.c: if ( unlikely(!is_hvm_domain(d) || !cpu_has_vmx) )MEM_SHARING has strict dependency on INTEL_VMX, so it is "doesn't matter" case. MEM_SHARING should never be enabled if !INTEL_VMX.
4) arch/x86/hvm/nestedhvm.c: unsigned nr = cpu_has_vmx ? 2 : 3;
There shadow_io_bitmap pages allocated, page number to be used returned by nestedhvm_vcpu_iomap_get(). Opt-out should be safe for !INTEL_VMX as nr==3 and nestedhvm_vcpu_iomap_get() will never overflow shadow_io_bitmap[].
5) arch/x86/mm/mem_access.c: return is_hvm_domain(d) && cpu_has_vmx && hap_enabled(d);
It is p2m_mem_access_sanity_check() called from mem_access_memop(). Seems like whole XENMEM_access_op (MEM_ACCESS) depends on INTEL_VMX on x86. But there is dependency on VM_EVENT is defined already.
How to proceed???
6) arch/x86/hvm/monitor.c: if ( cpu_has_vmx )
This is hvm_monitor_descriptor_access():
if ( cpu_has_vmx )
{
req.u.desc_access.arch.vmx.instr_info = exit_info;
req.u.desc_access.arch.vmx.exit_qualification = vmx_exit_qualification;
}Should be safe to opt-out.
7) arch/x86/cpu-policy.c: if ( cpu_has_vmx )
arch/x86/cpu-policy.c: if ( !cpu_has_vmx )
It is calculate_hvm_max_policy()
Place (a)
if ( cpu_has_vmx )
{
[below features have to be cleared if !INTEL_VMX, so can't just out-out cpu_has_vmx here.
Possible option: remove "if ( cpu_has_vmx )"]
if ( !cpu_has_vmx_rdtscp )
__clear_bit(X86_FEATURE_RDTSCP, fs);
if ( !cpu_has_vmx_invpcid )
__clear_bit(X86_FEATURE_INVPCID, fs);
if ( !cpu_has_vmx_mpx )
__clear_bit(X86_FEATURE_MPX, fs);
if ( !cpu_has_vmx_xsaves )
__clear_bit(X86_FEATURE_XSAVES, fs);
}Place (b)
if ( !cpu_has_vmx )
__clear_bit(X86_FEATURE_PKS, fs);Should be safe to out-out
Quoted 5 lines
cpu_has_X_Ywould be off whencpu_has_Xis off, but those shouldn't matter for this discussion.Am I missing something here?
[1] https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
Signature · 2 lines
Best regards, -grygorii
Quoted 92 lines · Alejandro Vallejo
Quoted 44 lines · Andrew Cooper
Quoted 43 lines · Grygorii Strashko
Hi Jan,
Quoted 40 lines · Jan Beulich
Quoted 19 lines · Grygorii Strashko
From: Grygorii Strashko <[email protected]>
Since commit
b99227347230("x86: FixAMD_SVMandINTEL_VMXdependency") the
HVM Intel VT-x support can be gracefully disabled, but it still keeps VMX
code partially built-in, because HVM code uses mix of:- "
cpu_has_vmx" macro, which doesn't account forCONFIG_INTEL_VMXcfg
- "using_vmx()" function, which accounts forCONFIG_INTEL_VMXcfgfor runtime VMX availability checking. As result compiler DCE can't remove
all, unreachable VMX code.Fix it by sticking to "
cpu_has_vmx" macro usage only which is updated to
accountCONFIG_INTEL_VMXcfg.Quoted 6 lines
Signed-off-by Grygorii Strashko <[email protected]>---
HiIt could be good to have it in 4.21, so vmx/svm disabling option will be in complete state within 4.21 version.
Imo this isn't release critical and has come too late. It's of course Oleksii's call in the end.
Quoted 9 lines
xen/arch/x86/include/asm/cpufeature.h +2
-1@@ -136,7 +136,8 @@ static inline bool boot_cpu_has(unsigned int feat) #define cpu_has_sse3 boot_cpu_has(X86_FEATURE_SSE3) #define cpu_has_pclmulqdq boot_cpu_has(X86_FEATURE_PCLMULQDQ) #define cpu_has_monitor boot_cpu_has(X86_FEATURE_MONITOR) -#define cpu_has_vmx boot_cpu_has(X86_FEATURE_VMX) +#define cpu_has_vmx (IS_ENABLED(CONFIG_INTEL_VMX) && \ + boot_cpu_has(X86_FEATURE_VMX))Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
I'm pretty sure
using_vmx()was introduced precisely to avoid the use ofIS_ENABLED()here. What is completely missing from the description is a discussion of the effect of this change on pre-existing uses of the macro. ISTR there being at least one instance which would break with that change. And no, I'm not looking forward to digging that out again, when I already did at the time theusing_vmx()was suggested and then implemented. (I can't exclude it was the SVM counterpart; we want to keep both in sync in any event, imo.)Apologies if this has already been discussed, but I didn't participate in prior discussions. Targeted lookups in lore are not shedding a lot of light either.
Quoted 9 lines
Quoted 8 lines
Thank you for your comments and sorry for not digging into the history of the related patches.
All, please ignore these patches as existing places. where cpu_has_vmx/smv
are still used, need to be revised one by one.Quoted 4 lines
Off the top of my head, fixups to
MSR_FEATURE_CONTROL, and AMD SKINIT need cpu_has_vmx/svm not guarded byKconfiglike this.~Andrew
What do you mean? AFAICS SKINIT is guarded by
cpu_has_skinit, notcpu_has_svm.And
MSR_IA32_FEATURE_CONTROLtweaking seems self-contained in xen/hvm/vmx/ which is compiled out when !CONFIG_INTEL_VMX.For the hypothetical case in which we might want to know the real HW value we can go look at the raw policy, as in "raw_cpu_policy.basic.vmx" or "raw_cpu_policy.extd.svm". Or what's mentioned in passing here.
https://lore.kernel.org/xen-devel/[email protected]/
Forcing the common case to use a helper and leaving the rare case in the shorthand macro seems like a bad idea. This ought to follow what
cpu_has_nxalready does.Is there a specific code instance in which having
IS_ENABLED()in the cpu_has_{svm,vmx} macros would cause issues today? While there are some dubious choices of svm vs vmx with or without negation, they all seem to resolve to correct code, with less codegen afterIS_ENABLED()ends up in all the conditionals.
Quoted 3 lines
IOW: I have seen fear of incorrectness, but not proof of it. Now, obviously the burden of proof rests on the submitter, indeed, but I'd like to know where we stand in terms of what that proof would look like.
Such a proof could be a statement clarifying that all use sites were audited. If then a reviewer found an issue with that, it would get interesting (as [possibly]
in: it being questionable whether an audit was actually done; what I mean to say here is that it's not a matter of merely stating that an audit was [supposedly] done).
Jan
Quoted 16 lines
A naive grep shows not many
sites to check.$git grep
cpu_has_svm| grep -vcpu_has_svm_| wc -l 6$git grep
cpu_has_vmx| grep -vcpu_has_vmx_| wc -l 11
cpu_has_X_Ywould be off whencpu_has_Xis off, but those shouldn't matter for this discussion.Am I missing something here?
Cheers,
Alejandro