KVM: x86: Purge kvm_x86_ops->*_supported()
cover KVM: x86: Purge kvm_x86_ops->*_supported()
Our benevolent dictator decreed that "all *_supported() should be removed, and the code moved from __do_cpuid_func() to set_supported_cpuid"[*].
To make that happen, move CPUID and MSR checks from x86 into SVM/VMX via the existing ->set_supported_cpuid() and a ->new has_virtualized_msr() ops respectively.
As usual, there's a fair amount of cleanup in between the mechanical changes. Most notable is the introduction of cpuid entry accessors and mutators to replace all of the code to manipulate individual feature bits in cpuid entries, which is error prone and annoying. MPX (*sigh*) also gets a healthly dose of cleanup.
I don't love every patch in this series. Specifically, adding an extra call to ->set_supported_cpuid() to handle XSAVES is ugly. But, I do like that it purges all ->*_supported() hooks. And practically speaking, odds are good that CPUID 0xD.1 will get more feature bits, i.e. keeping ->xsaves_supported() would likely lead to another ->*_supported() hook.
Paolo also expressed a dislike for clearing bits in set_supported_cpuid(). I don't have a strong opinion regarding clearing bits, but the alternative approach, i.e. leave the bits clear and then set them in vendor code, gets quite kludgy because the vendor code (mostly VMX) would need to manually recheck boot_cpu_data to ensure it wasn't advertising a feature that the user/kernel expressly disabled. IMO, forcing manual checks is more likely to introduce errors and provides less insight into why VMX needs to adjust the advertised CPUID values (VMCS != CPUID).
Tested on Intel by verifying the output of KVM_GET_SUPPORTED_CPUID is identical before and after (on almost every patch) on a Haswell and Coffee Lake. The big untested pieces are PKU and PT on Intel, and everything AMD.
[*] https://lkml.kernel.org/r/[email protected]
Sean Christopherson (26):
KVM: x86: Remove superfluous brackets from case statement
KVM: x86: Take an unsigned 32-bit int for has_emulated_msr()'s index
KVM: x86: Snapshot MSR index in a local variable when processing lists
KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
KVM: x86: Move MSR_TSC_AUX existence checks into vendor code
KVM: x86: Move MSR_IA32_BNDCFGS existence checks into vendor code
KVM: VMX: Add helpers to query Intel PT mode
KVM: x86: Move RTIT (Intel PT) MSR existence checks into vendor code
KVM: x86: Calculate the supported xcr0 mask at load time
KVM: x86: Use supported_xcr0 to detect MPX support
KVM: x86: Make kvm_mpx_supported() an inline function
KVM: x86: Drop explicit @func param from ->set_supported_cpuid()
KVM: x86: Use u32 for holding CPUID register value in helpers
KVM: x86: Introduce cpuid_entry_{get,has}() accessors
KVM: x86: Introduce cpuid_entry_{change,set,clear}() mutators
KVM: x86: Add Kconfig-controlled auditing of reverse CPUID lookups
KVM: x86: Handle MPX CPUID adjustment in vendor code
KVM: x86: Handle INVPCID CPUID adjustment in vendor code
KVM: x86: Handle UMIP emulation CPUID adjustment in VMX code
KVM: x86: Handle PKU CPUID adjustment in SVM code
KVM: x86: Handle RDTSCP CPUID adjustment in VMX code
KVM: x86: Handle XSAVES CPUID adjustment in VMX code
KVM: x86: Handle Intel PT CPUID adjustment in vendor code
KVM: x86: Clear output regs for CPUID 0x14 if PT isn't exposed to
guest
KVM: x86: Handle main Intel PT CPUID leaf in vendor code
KVM: VMX: Directly query Intel PT mode when refreshing PMUs
arch/x86/include/asm/kvm_host.h | 12 +-- arch/x86/kvm/Kconfig | 10 +++ arch/x86/kvm/cpuid.c | 147 +++++++++++++------------------- arch/x86/kvm/cpuid.h | 85 +++++++++++++++--- arch/x86/kvm/svm.c | 88 ++++++++++--------- arch/x86/kvm/vmx/capabilities.h | 25 ++++-- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/pmu_intel.c | 2 +- arch/x86/kvm/vmx/vmx.c | 119 ++++++++++++++++++-------- arch/x86/kvm/vmx/vmx.h | 4 +- arch/x86/kvm/x86.c | 76 +++++++---------- arch/x86/kvm/x86.h | 10 +-- 12 files changed, 331 insertions(+), 249 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/26 KVM: x86: Remove superfluous brackets from case statement
Remove unnecessary brackets from a case statement that unintentionally encapsulates unrelated case statements in the same switch statement. While technically legal and functionally correct syntax, the brackets are visually confusing and potentially dangerous, e.g. the last of the encapsulated case statements has an undocumented fall-through that isn't flagged by compilers due the encapsulation.
--- arch/x86/kvm/x86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/x86.c +2 -2
@@ -5260,7 +5260,7 @@ static void kvm_init_msr_list(void) !intel_pt_validate_hw_cap(PT_CAP_single_range_output))) continue;break ; - case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: { + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:if (!kvm_x86_ops->pt_supported () || msrs_to_save_all[i] -MSR_IA32_RTIT_ADDR0_A >=intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 )
@@ -5275,7 +5275,7 @@ static void kvm_init_msr_list(void)if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_EVENTSEL0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ; - } +break ;default :break ; }
Signature · 1 line
2.24.1
Re: [PATCH 01/26] KVM: x86: Remove superfluous brackets from case statement
Quoted 26 lines · Sean Christopherson
Remove unnecessary brackets from a case statement that unintentionally encapsulates unrelated case statements in the same switch statement. While technically legal and functionally correct syntax, the brackets are visually confusing and potentially dangerous, e.g. the last of the encapsulated case statements has an undocumented fall-through that isn't flagged by compilers due the encapsulation.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/x86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/kvm/x86.c +1
-1@@ -5260,7 +5260,7 @@ static void kvm_init_msr_list(void) !intel_pt_validate_hw_cap(PT_CAP_single_range_output))) continue;break ; - case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: { + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:if (!kvm_x86_ops->pt_supported () || msrs_to_save_all[i] -MSR_IA32_RTIT_ADDR0_A >=intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 )
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5281
Quoted 8 lines
arch/x86/kvm/x86.c +1
-1@@ -5275,7 +5275,7 @@ static void kvm_init_msr_list(void)if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_EVENTSEL0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ; - } +break ;default :break ; }
Signature · 1 line
Vitaly
Re: [PATCH 01/26] KVM: x86: Remove superfluous brackets from case statement
Quoted 30 lines · Vitaly Kuznetsov
Quoted 28 lines · Sean Christopherson
Remove unnecessary brackets from a case statement that unintentionally encapsulates unrelated case statements in the same switch statement. While technically legal and functionally correct syntax, the brackets are visually confusing and potentially dangerous, e.g. the last of the encapsulated case statements has an undocumented fall-through that isn't flagged by compilers due the encapsulation.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/x86.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/kvm/x86.c +1
-1@@ -5260,7 +5260,7 @@ static void kvm_init_msr_list(void) !intel_pt_validate_hw_cap(PT_CAP_single_range_output))) continue;break ; - case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: { + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:if (!kvm_x86_ops->pt_supported () || msrs_to_save_all[i] -MSR_IA32_RTIT_ADDR0_A >=intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 )@@ -5275,7 +5275,7 @@ static void kvm_init_msr_list(void)if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_EVENTSEL0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))
Quoted 8 lines
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5281
Quoted 6 lines
arch/x86/kvm/x86.c +1
-1continue ; - } +break ;default :break ; }Reviewed-by Vitaly Kuznetsov <[email protected]>
Thanks for the review(s), but don't bother reviewing the rest of this series. Most of it is superseded by the kvm_cpu_caps mega-series, and I'll spin the MSR patches into their own series.
PATCH 2/26 KVM: x86: Take an unsigned 32-bit int for has_emulated_msr()'s index
In reply to Sean ChristophersonTake a u32 for the index in has_emulated_msr() to match hardware, which treats MSR indices as unsigned 32-bit values. Functionally, taking a signed int doesn't cause problems with the current code base, but could theoretically cause problems with 32-bit KVM, e.g. if the index were checked via a less-than statement, which would evaluate incorrectly for MSR indices with bit 31 set.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1050,7 +1050,7 @@ struct kvm_x86_ops {int (*hardware_setup)(void );/* __init */ void (*hardware_unsetup)(void );/* __exit */ bool (*cpu_has_accelerated_tpr)(void ); -bool (*has_emulated_msr)(int index); +bool (*has_emulated_msr)(u32 index);void (*cpuid_update)(struct kvm_vcpu *vcpu);struct kvm *(*vm_alloc)(void );
arch/x86/kvm/svm.c +1 -1
@@ -5985,7 +5985,7 @@ static bool svm_cpu_has_accelerated_tpr(void)return false; } -static bool svm_has_emulated_msr (int index) +static bool svm_has_emulated_msr (u32 index) {switch (index) {case MSR_IA32_MCG_EXT_CTL :
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -6274,7 +6274,7 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, *exit_fastpath =handle_fastpath_set_msr_irqoff (vcpu); } -static bool vmx_has_emulated_msr (int index) +static bool vmx_has_emulated_msr (u32 index) {switch (index) {case MSR_IA32_SMBASE :
Signature · 1 line
2.24.1
Re: [PATCH 02/26] KVM: x86: Take an unsigned 32-bit int for has_emulated_msr()'s index
Quoted 45 lines · Sean Christopherson
Take a u32 for the index in
has_emulated_msr()to match hardware, which treats MSR indices as unsigned 32-bit values. Functionally, taking a signed int doesn't cause problems with the current code base, but could theoretically cause problems with 32-bit KVM, e.g. if the index were checked via a less-than statement, which would evaluate incorrectly for MSR indices with bit 31 set.Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)arch/x86/include/asm/kvm_host.h +1
-1@@ -1050,7 +1050,7 @@ struct kvm_x86_ops {int (*hardware_setup)(void );/* __init */ void (*hardware_unsetup)(void );/* __exit */ bool (*cpu_has_accelerated_tpr)(void ); -bool (*has_emulated_msr)(int index); +bool (*has_emulated_msr)(u32 index);void (*cpuid_update)(struct kvm_vcpu *vcpu);struct kvm *(*vm_alloc)(void );arch/x86/kvm/svm.c +1
-1@@ -5985,7 +5985,7 @@ static bool svm_cpu_has_accelerated_tpr(void)return false; } -static bool svm_has_emulated_msr (int index) +static bool svm_has_emulated_msr (u32 index) {switch (index) {case MSR_IA32_MCG_EXT_CTL :arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, · line 6280
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +1
-1@@ -6274,7 +6274,7 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, *exit_fastpath =handle_fastpath_set_msr_irqoff (vcpu); } -static bool vmx_has_emulated_msr (int index) +static bool vmx_has_emulated_msr (u32 index) {switch (index) {case MSR_IA32_SMBASE :
Signature · 1 line
Vitaly
PATCH 3/26 KVM: x86: Snapshot MSR index in a local variable when processing lists
In reply to Sean ChristophersonSnapshot the MSR index when processing the virtualized and emulated MSR lists in kvm_init_msr_list() to improve code readability, particularly in the RTIT and PerfMon MSR checks.
No functional change intended.
--- arch/x86/kvm/x86.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)
arch/x86/kvm/x86.c +13 -9
@@ -5214,7 +5214,7 @@ long kvm_arch_vm_ioctl(struct file *filp,static void kvm_init_msr_list (void ) {struct x86_pmu_capability x86_pmu; -u32 dummy[2 ]; +u32 dummy[2 ], msr_index;unsigned i; BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
@@ -5227,14 +5227,16 @@ static void kvm_init_msr_list(void) num_msr_based_features =0 ;for (i =0 ; i <ARRAY_SIZE (msrs_to_save_all); i++) { -if (rdmsr_safe (msrs_to_save_all[i], &dummy[0 ], &dummy[1 ]) <0 ) + msr_index = msrs_to_save_all[i]; + +if (rdmsr_safe (msr_index, &dummy[0 ], &dummy[1 ]) <0 )continue ;/* * Even MSRs that are valid in the host may not be exposed * to the guests in some cases. */ -switch (msrs_to_save_all[i]) { +switch (msr_index) {case MSR_IA32_BNDCFGS :if (!kvm_mpx_supported ())continue ;
@@ -5262,17 +5264,17 @@ static void kvm_init_msr_list(void)break ; case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:if (!kvm_x86_ops->pt_supported () || - msrs_to_save_all[i] -MSR_IA32_RTIT_ADDR0_A >= + msr_index -MSR_IA32_RTIT_ADDR0_A >=intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 )continue ;break ; case MSR_ARCH_PERFMON_PERFCTR0 ... MSR_ARCH_PERFMON_PERFCTR0 + 17: -if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_PERFCTR0 >= +if (msr_index -MSR_ARCH_PERFMON_PERFCTR0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ;break ; case MSR_ARCH_PERFMON_EVENTSEL0 ... MSR_ARCH_PERFMON_EVENTSEL0 + 17: -if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_EVENTSEL0 >= +if (msr_index -MSR_ARCH_PERFMON_EVENTSEL0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ;break ;
@@ -5280,14 +5282,16 @@ static void kvm_init_msr_list(void)break ; } - msrs_to_save[num_msrs_to_save++] = msrs_to_save_all[i]; + msrs_to_save[num_msrs_to_save++] = msr_index; }for (i =0 ; i <ARRAY_SIZE (emulated_msrs_all); i++) { -if (!kvm_x86_ops->has_emulated_msr (emulated_msrs_all[i])) + msr_index = emulated_msrs_all[i]; + +if (!kvm_x86_ops->has_emulated_msr (msr_index))continue ; - emulated_msrs[num_emulated_msrs++] = emulated_msrs_all[i]; + emulated_msrs[num_emulated_msrs++] = msr_index; }for (i =0 ; i <ARRAY_SIZE (msr_based_features_all); i++) {
Signature · 1 line
2.24.1
Re: [PATCH 03/26] KVM: x86: Snapshot MSR index in a local variable when processing lists
Quoted 74 lines · Sean Christopherson
Snapshot the MSR index when processing the virtualized and emulated MSR lists in
kvm_init_msr_list()to improve code readability, particularly in the RTIT and PerfMon MSR checks.No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/x86.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)arch/x86/kvm/x86.c +9
-8@@ -5214,7 +5214,7 @@ long kvm_arch_vm_ioctl(struct file *filp,static void kvm_init_msr_list (void ) {struct x86_pmu_capability x86_pmu; -u32 dummy[2 ]; +u32 dummy[2 ], msr_index;unsigned i; BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,@@ -5227,14 +5227,16 @@ static void kvm_init_msr_list(void) num_msr_based_features =0 ;for (i =0 ; i <ARRAY_SIZE (msrs_to_save_all); i++) { -if (rdmsr_safe (msrs_to_save_all[i], &dummy[0 ], &dummy[1 ]) <0 ) + msr_index = msrs_to_save_all[i]; + +if (rdmsr_safe (msr_index, &dummy[0 ], &dummy[1 ]) <0 )continue ;/* * Even MSRs that are valid in the host may not be exposed * to the guests in some cases. */ -switch (msrs_to_save_all[i]) { +switch (msr_index) {case MSR_IA32_BNDCFGS :if (!kvm_mpx_supported ())continue ;@@ -5262,17 +5264,17 @@ static void kvm_init_msr_list(void)break ; case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:if (!kvm_x86_ops->pt_supported () || - msrs_to_save_all[i] -MSR_IA32_RTIT_ADDR0_A >= + msr_index -MSR_IA32_RTIT_ADDR0_A >=intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 )continue ;break ; case MSR_ARCH_PERFMON_PERFCTR0 ... MSR_ARCH_PERFMON_PERFCTR0 + 17: -if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_PERFCTR0 >= +if (msr_index -MSR_ARCH_PERFMON_PERFCTR0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ;break ; case MSR_ARCH_PERFMON_EVENTSEL0 ... MSR_ARCH_PERFMON_EVENTSEL0 + 17: -if (msrs_to_save_all[i] -MSR_ARCH_PERFMON_EVENTSEL0 >= +if (msr_index -MSR_ARCH_PERFMON_EVENTSEL0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))continue ;break ;@@ -5280,14 +5282,16 @@ static void kvm_init_msr_list(void)break ; } - msrs_to_save[num_msrs_to_save++] = msrs_to_save_all[i]; + msrs_to_save[num_msrs_to_save++] = msr_index; }for (i =0 ; i <ARRAY_SIZE (emulated_msrs_all); i++) { -if (!kvm_x86_ops->has_emulated_msr (emulated_msrs_all[i]))
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5297
Quoted 10 lines
arch/x86/kvm/x86.c +4
-1+ msr_index = emulated_msrs_all[i]; + +if (!kvm_x86_ops->has_emulated_msr (msr_index))continue ; - emulated_msrs[num_emulated_msrs++] = emulated_msrs_all[i]; + emulated_msrs[num_emulated_msrs++] = msr_index; }for (i =0 ; i <ARRAY_SIZE (msr_based_features_all); i++) {
Signature · 1 line
Vitaly
PATCH 4/26 KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
In reply to Sean ChristophersonAdd a hook, ->has_virtualized_msr(), to allow moving vendor specific checks into SVM/VMX and ultimately facilitate the removal of the piecemeal ->*_supported() hooks.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 6 ++++++ arch/x86/kvm/vmx/vmx.c | 6 ++++++ arch/x86/kvm/x86.c | 2 ++ 4 files changed, 15 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1050,6 +1050,7 @@ struct kvm_x86_ops {int (*hardware_setup)(void );/* __init */ void (*hardware_unsetup)(void );/* __exit */ bool (*cpu_has_accelerated_tpr)(void ); +bool (*has_virtualized_msr)(u32 index);bool (*has_emulated_msr)(u32 index);void (*cpuid_update)(struct kvm_vcpu *vcpu);
arch/x86/kvm/svm.c +6 -0
@@ -5985,6 +5985,11 @@ static bool svm_cpu_has_accelerated_tpr(void)return false; } +static bool svm_has_virtualized_msr (u32 index) +{ +return true; +} +static bool svm_has_emulated_msr (u32 index) {switch (index) {
@@ -7379,6 +7384,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .hardware_enable = svm_hardware_enable, .hardware_disable = svm_hardware_disable, .cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr, + .has_virtualized_msr = svm_has_virtualized_msr, .has_emulated_msr = svm_has_emulated_msr, .vcpu_create = svm_create_vcpu,
arch/x86/kvm/vmx/vmx.c +6 -0
@@ -6274,6 +6274,11 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, *exit_fastpath =handle_fastpath_set_msr_irqoff (vcpu); } +static bool vmx_has_virtualized_msr (u32 index) +{ +return true; +} +static bool vmx_has_emulated_msr (u32 index) {switch (index) {
@@ -7754,6 +7759,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .hardware_enable = hardware_enable, .hardware_disable = hardware_disable, .cpu_has_accelerated_tpr = report_flexpriority, + .has_virtualized_msr = vmx_has_virtualized_msr, .has_emulated_msr = vmx_has_emulated_msr, .vm_init = vmx_vm_init,
arch/x86/kvm/x86.c +2 -0
@@ -5279,6 +5279,8 @@ static void kvm_init_msr_list(void)continue ;break ;default : +if (!kvm_x86_ops->has_virtualized_msr (msr_index)) +continue ;break ; }
Signature · 1 line
2.24.1
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 79 lines · Sean Christopherson
Add a hook, ->has_virtualized_msr(), to allow moving vendor specific checks into SVM/VMX and ultimately facilitate the removal of the piecemeal ->*_supported() hooks.
No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 6 ++++++ arch/x86/kvm/vmx/vmx.c | 6 ++++++ arch/x86/kvm/x86.c | 2 ++ 4 files changed, 15 insertions(+)arch/x86/include/asm/kvm_host.h +1
-0@@ -1050,6 +1050,7 @@ struct kvm_x86_ops {int (*hardware_setup)(void );/* __init */ void (*hardware_unsetup)(void );/* __exit */ bool (*cpu_has_accelerated_tpr)(void ); +bool (*has_virtualized_msr)(u32 index);bool (*has_emulated_msr)(u32 index);void (*cpuid_update)(struct kvm_vcpu *vcpu);arch/x86/kvm/svm.c +6
-0@@ -5985,6 +5985,11 @@ static bool svm_cpu_has_accelerated_tpr(void)return false; } +static bool svm_has_virtualized_msr (u32 index) +{ +return true; +} +static bool svm_has_emulated_msr (u32 index) {switch (index) {@@ -7379,6 +7384,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .hardware_enable = svm_hardware_enable, .hardware_disable = svm_hardware_disable, .cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr, + .has_virtualized_msr = svm_has_virtualized_msr, .has_emulated_msr = svm_has_emulated_msr, .vcpu_create = svm_create_vcpu,arch/x86/kvm/vmx/vmx.c +6
-0@@ -6274,6 +6274,11 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, *exit_fastpath =handle_fastpath_set_msr_irqoff (vcpu); } +static bool vmx_has_virtualized_msr (u32 index) +{ +return true; +} +static bool vmx_has_emulated_msr (u32 index) {switch (index) {@@ -7754,6 +7759,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .hardware_enable = hardware_enable, .hardware_disable = hardware_disable, .cpu_has_accelerated_tpr = report_flexpriority, + .has_virtualized_msr = vmx_has_virtualized_msr, .has_emulated_msr = vmx_has_emulated_msr, .vm_init = vmx_vm_init,arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5285
Quoted 7 lines
arch/x86/kvm/x86.c +2
-0@@ -5279,6 +5279,8 @@ static void kvm_init_msr_list(void)continue ;break ;default : +if (!kvm_x86_ops->has_virtualized_msr (msr_index)) +continue ;break ; }
Shouldn't break anything by itself, so
Signature · 1 line
Vitaly
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 3 lines · Vitaly Kuznetsov
Sean Christopherson <[email protected]> writes:
Reviewed-by Vitaly Kuznetsov <[email protected]>
Stooooooop! Everything from this point on is obsoleted by kvm_cpu_caps!
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 7 lines · Sean Christopherson
Quoted 3 lines · Vitaly Kuznetsov
Sean Christopherson <[email protected]> writes:
Reviewed-by Vitaly Kuznetsov <[email protected]>Stooooooop! Everything from this point on is obsoleted by
kvm_cpu_caps!
Oops, this was only a week old series! Patches are rottening fast nowadays!
Signature · 1 line
Vitaly
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 5 lines · Vitaly Kuznetsov
Quoted 3 lines · Sean Christopherson
Quoted 2 lines · Vitaly Kuznetsov
Sean Christopherson <[email protected]> writes:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Vitaly Kuznetsov <[email protected]>Stooooooop! Everything from this point on is obsoleted by
kvm_cpu_caps!Oops, this was only a week old series! Patches are rottening fast nowadays!
Sorry :-(
I dug deeper into the CPUID crud after posting this series because I really didn't like the end result for vendor-specific leafs, and ended up coming up with (IMO) a much more elegant solution.
https://lkml.kernel.org/r/[email protected]/
or on patchwork
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 20 lines · Sean Christopherson
Quoted 5 lines · Vitaly Kuznetsov
Quoted 3 lines · Sean Christopherson
Quoted 2 lines · Vitaly Kuznetsov
Sean Christopherson <[email protected]> writes:
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Vitaly Kuznetsov <[email protected]>Stooooooop! Everything from this point on is obsoleted by
kvm_cpu_caps!Oops, this was only a week old series! Patches are rottening fast nowadays!
Sorry :-(
I dug deeper into the CPUID crud after posting this series because I really didn't like the end result for vendor-specific leafs, and ended up coming up with (IMO) a much more elegant solution.
Quoted 6 lines
https://lkml.kernel.org/r/[email protected]/
or on patchwork
Thanks, I saw it. I tried applying it to kvm/next earlier today but failed. Do you by any chance have a git branch somewhere? I'll try to review it and test at least AMD stuff (if AMD people don't beat me to it of course).
Signature · 1 line
Vitaly
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 9 lines · Vitaly Kuznetsov
Quoted 8 lines · Sean Christopherson
I dug deeper into the CPUID crud after posting this series because I really didn't like the end result for vendor-specific leafs, and ended up coming up with (IMO) a much more elegant solution.
https://lkml.kernel.org/r/[email protected]/
or on patchwork
Quoted 7 lines
Quoted 2 lines
Thanks, I saw it. I tried applying it to kvm/next earlier today but failed. Do you by any chance have a git branch somewhere? I'll try to review it and test at least AMD stuff (if AMD people don't beat me to it of course).
Have you tried kvm/queue? I'm pretty sure I based the code on kvm/queue. If that doesn't work, I'll push a tag to my github repo.
This is exactly why I usually note the base for large series. *sigh*
Re: [PATCH 04/26] KVM: x86: Add a kvm_x86_ops hook to query virtualized MSR support
Quoted 13 lines · Sean Christopherson
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Sean Christopherson
I dug deeper into the CPUID crud after posting this series because I really didn't like the end result for vendor-specific leafs, and ended up coming up with (IMO) a much more elegant solution.
https://lkml.kernel.org/r/[email protected]/
or on patchwork
Quoted 7 lines
Quoted 4 lines
Thanks, I saw it. I tried applying it to kvm/next earlier today but failed. Do you by any chance have a git branch somewhere? I'll try to review it and test at least AMD stuff (if AMD people don't beat me to it of course).
Have you tried kvm/queue? I'm pretty sure I based the code on kvm/queue. If that doesn't work, I'll push a tag to my github repo.
My bad, kvm/queue worked like a charm!
Quoted 2 lines
This is exactly why I usually note the base for large series. *sigh*
Pull requests, anyone? :-)
Signature · 1 line
Vitaly
PATCH 5/26 KVM: x86: Move MSR_TSC_AUX existence checks into vendor code
In reply to Sean ChristophersonMove the MSR_TSC_AUX existence check into vendor code using the newly introduced ->has_virtualized_msr() hook to help pave the way toward the removal of ->rdtscp_supported().
No functional change intended.
--- arch/x86/kvm/svm.c | 7 +++++++ arch/x86/kvm/vmx/vmx.c | 7 +++++++ arch/x86/kvm/x86.c | 4 ---- 3 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +7 -0
@@ -5987,6 +5987,13 @@ static bool svm_cpu_has_accelerated_tpr(void)static bool svm_has_virtualized_msr (u32 index) { +switch (index) { +case MSR_TSC_AUX : +return boot_cpu_has (X86_FEATURE_RDTSCP ); +default : +break ; + } +return true; }
arch/x86/kvm/vmx/vmx.c +7 -0
@@ -6276,6 +6276,13 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu,static bool vmx_has_virtualized_msr (u32 index) { +switch (index) { +case MSR_TSC_AUX : +return cpu_has_vmx_rdtscp (); +default : +break ; + } +return true; }
arch/x86/kvm/x86.c +0 -4
@@ -5241,10 +5241,6 @@ static void kvm_init_msr_list(void)if (!kvm_mpx_supported ())continue ;break ; -case MSR_TSC_AUX : -if (!kvm_x86_ops->rdtscp_supported ()) -continue ; -break ;case MSR_IA32_RTIT_CTL :case MSR_IA32_RTIT_STATUS :if (!kvm_x86_ops->pt_supported ())
Signature · 1 line
2.24.1
Re: [PATCH 05/26] KVM: x86: Move MSR_TSC_AUX existence checks into vendor code
Quoted 54 lines · Sean Christopherson
Move the
MSR_TSC_AUXexistence check into vendor code using the newly introduced ->has_virtualized_msr() hook to help pave the way toward the removal of ->rdtscp_supported().No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/svm.c | 7 +++++++ arch/x86/kvm/vmx/vmx.c | 7 +++++++ arch/x86/kvm/x86.c | 4 ---- 3 files changed, 14 insertions(+), 4 deletions(-)arch/x86/kvm/svm.c +7
-0@@ -5987,6 +5987,13 @@ static bool svm_cpu_has_accelerated_tpr(void)static bool svm_has_virtualized_msr (u32 index) { +switch (index) { +case MSR_TSC_AUX : +return boot_cpu_has (X86_FEATURE_RDTSCP ); +default : +break ; + } +return true; }arch/x86/kvm/vmx/vmx.c +7
-0@@ -6276,6 +6276,13 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu,static bool vmx_has_virtualized_msr (u32 index) { +switch (index) { +case MSR_TSC_AUX : +return cpu_has_vmx_rdtscp (); +default : +break ; + } +return true; }arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5246
Quoted 10 lines
arch/x86/kvm/x86.c +0
-4@@ -5241,10 +5241,6 @@ static void kvm_init_msr_list(void)if (!kvm_mpx_supported ())continue ;break ; -case MSR_TSC_AUX : -if (!kvm_x86_ops->rdtscp_supported ()) -continue ; -break ;case MSR_IA32_RTIT_CTL :case MSR_IA32_RTIT_STATUS :if (!kvm_x86_ops->pt_supported ())
Signature · 1 line
Vitaly
PATCH 6/26 KVM: x86: Move MSR_IA32_BNDCFGS existence checks into vendor code
In reply to Sean ChristophersonMove the MSR_IA32_BNDCFGS existence check into vendor code by way of ->has_virtualized_msr(). AMD does not support MPX, and given that Intel is in the process of removing MPX, it's extremely unlikely AMD will ever support MPX.
Note, invoking ->has_virtualized_msr() requires an extra retpoline, but kvm_init_msr_list() is not a hot path. As alluded to above, the motivation is to quarantine MPX as much as possible.
No functional change intended.
--- arch/x86/kvm/svm.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 2 ++ arch/x86/kvm/x86.c | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +2 -0
@@ -5990,6 +5990,8 @@ static bool svm_has_virtualized_msr(u32 index)switch (index) {case MSR_TSC_AUX :return boot_cpu_has (X86_FEATURE_RDTSCP ); +case MSR_IA32_BNDCFGS : +return false;default :break ; }
arch/x86/kvm/vmx/vmx.c +2 -0
@@ -6279,6 +6279,8 @@ static bool vmx_has_virtualized_msr(u32 index)switch (index) {case MSR_TSC_AUX :return cpu_has_vmx_rdtscp (); +case MSR_IA32_BNDCFGS : +return kvm_mpx_supported ();default :break ; }
arch/x86/kvm/x86.c +0 -4
@@ -5237,10 +5237,6 @@ static void kvm_init_msr_list(void)* to the guests in some cases. */ switch (msr_index) { -case MSR_IA32_BNDCFGS : -if (!kvm_mpx_supported ()) -continue ; -break ;case MSR_IA32_RTIT_CTL :case MSR_IA32_RTIT_STATUS :if (!kvm_x86_ops->pt_supported ())
Signature · 1 line
2.24.1
Re: [PATCH 06/26] KVM: x86: Move MSR_IA32_BNDCFGS existence checks into vendor code
Quoted 49 lines · Sean Christopherson
Move the
MSR_IA32_BNDCFGSexistence check into vendor code by way of ->has_virtualized_msr(). AMD does not support MPX, and given that Intel is in the process of removing MPX, it's extremely unlikely AMD will ever support MPX.Note, invoking ->has_virtualized_msr() requires an extra retpoline, but
kvm_init_msr_list()is not a hot path. As alluded to above, the motivation is to quarantine MPX as much as possible.No functional change intended.
Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/svm.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 2 ++ arch/x86/kvm/x86.c | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-)arch/x86/kvm/svm.c +2
-0@@ -5990,6 +5990,8 @@ static bool svm_has_virtualized_msr(u32 index)switch (index) {case MSR_TSC_AUX :return boot_cpu_has (X86_FEATURE_RDTSCP ); +case MSR_IA32_BNDCFGS : +return false;default :break ; }arch/x86/kvm/vmx/vmx.c +2
-0@@ -6279,6 +6279,8 @@ static bool vmx_has_virtualized_msr(u32 index)switch (index) {case MSR_TSC_AUX :return cpu_has_vmx_rdtscp (); +case MSR_IA32_BNDCFGS : +return kvm_mpx_supported ();default :break ; }arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static void kvm_init_msr_list(void) · line 5242
Quoted 10 lines
arch/x86/kvm/x86.c +0
-4@@ -5237,10 +5237,6 @@ static void kvm_init_msr_list(void)* to the guests in some cases. */ switch (msr_index) { -case MSR_IA32_BNDCFGS : -if (!kvm_mpx_supported ()) -continue ; -break ;case MSR_IA32_RTIT_CTL :case MSR_IA32_RTIT_STATUS :if (!kvm_x86_ops->pt_supported ())
Signature · 1 line
Vitaly
PATCH 7/26 KVM: VMX: Add helpers to query Intel PT mode
In reply to Sean ChristophersonAdd helpers to query which of the (two) supported PT modes is active. The primary motivation is to help document that there is a third PT mode (host-only) that's currently not supported by KVM. As is, it's not obvious that PT_MODE_SYSTEM != !PT_MODE_HOST_GUEST and vice versa, e.g. that "pt_mode == PT_MODE_SYSTEM" and "pt_mode != PT_MODE_HOST_GUEST" are two distinct checks.
No functional change intended.
--- arch/x86/kvm/vmx/capabilities.h | 18 ++++++++++++++++++ arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 26 +++++++++++++------------- arch/x86/kvm/vmx/vmx.h | 4 ++-- 4 files changed, 34 insertions(+), 16 deletions(-)
arch/x86/kvm/vmx/capabilities.h +18 -0
@@ -353,4 +353,22 @@ static inline bool cpu_has_vmx_intel_pt(void) (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL); } +/* +* Processor Trace can operate in one of three modes: +* a. system-wide: trace both host/guest and output to host buffer +* b. host-only: only trace host and output to host buffer +* c. host-guest: trace host and guest simultaneously and output to their +* respective buffer +* +* KVM currently only supports (a) and (c). +*/ +static inline bool vmx_pt_mode_is_system (void ) +{ +return pt_mode ==PT_MODE_SYSTEM ; +} +static inline bool vmx_pt_mode_is_host_guest (void ) +{ +return pt_mode ==PT_MODE_HOST_GUEST ; +} +#endif /* __KVM_X86_VMX_CAPS_H */
arch/x86/kvm/vmx/nested.c +1 -1
@@ -4543,7 +4543,7 @@ static int enter_vmx_operation(struct kvm_vcpu *vcpu) vmx->nested.vmcs02_initialized = false; vmx->nested.vmxon = true; -if (pt_mode ==PT_MODE_HOST_GUEST ) { +if (vmx_pt_mode_is_host_guest ()) { vmx->pt_desc.guest.ctl =0 ;pt_update_intercept_for_msr (vmx); }
arch/x86/kvm/vmx/vmx.c +13 -13
@@ -1059,7 +1059,7 @@ static unsigned long segment_base(u16 selector)static inline bool pt_can_write_msr (struct vcpu_vmx *vmx) { -return (pt_mode ==PT_MODE_HOST_GUEST ) && +return vmx_pt_mode_is_host_guest () && !(vmx->pt_desc.guest.ctl &RTIT_CTL_TRACEEN ); }
@@ -1093,7 +1093,7 @@ static inline void pt_save_msr(struct pt_ctx *ctx, u32 addr_range)static void pt_guest_enter (struct vcpu_vmx *vmx) { -if (pt_mode ==PT_MODE_SYSTEM ) +if (vmx_pt_mode_is_system ())return ;/*
@@ -1110,7 +1110,7 @@ static void pt_guest_enter(struct vcpu_vmx *vmx)static void pt_guest_exit (struct vcpu_vmx *vmx) { -if (pt_mode ==PT_MODE_SYSTEM ) +if (vmx_pt_mode_is_system ())return ;if (vmx->pt_desc.guest.ctl &RTIT_CTL_TRACEEN ) {
@@ -1856,24 +1856,24 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)return vmx_get_vmx_msr (&vmx->nested.msrs, msr_info->index, &msr_info->data);case MSR_IA32_RTIT_CTL : -if (pt_mode !=PT_MODE_HOST_GUEST ) +if (!vmx_pt_mode_is_host_guest ())return 1 ; msr_info->data = vmx->pt_desc.guest.ctl;break ;case MSR_IA32_RTIT_STATUS : -if (pt_mode !=PT_MODE_HOST_GUEST ) +if (!vmx_pt_mode_is_host_guest ())return 1 ; msr_info->data = vmx->pt_desc.guest.status;break ;case MSR_IA32_RTIT_CR3_MATCH : -if ((pt_mode !=PT_MODE_HOST_GUEST ) || +if (!vmx_pt_mode_is_host_guest () || !intel_pt_validate_cap (vmx->pt_desc.caps, PT_CAP_cr3_filtering))return 1 ; msr_info->data = vmx->pt_desc.guest.cr3_match;break ;case MSR_IA32_RTIT_OUTPUT_BASE : - if ((pt_mode != PT_MODE_HOST_GUEST) || + if (!vmx_pt_mode_is_host_guest() || (!intel_pt_validate_cap(vmx->pt_desc.caps, PT_CAP_topa_output) && !intel_pt_validate_cap(vmx->pt_desc.caps,
@@ -1882,7 +1882,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = vmx->pt_desc.guest.output_base;break ;case MSR_IA32_RTIT_OUTPUT_MASK : - if ((pt_mode != PT_MODE_HOST_GUEST) || + if (!vmx_pt_mode_is_host_guest() || (!intel_pt_validate_cap(vmx->pt_desc.caps, PT_CAP_topa_output) && !intel_pt_validate_cap(vmx->pt_desc.caps,
@@ -1892,7 +1892,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)break ; case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: index = msr_info->index -MSR_IA32_RTIT_ADDR0_A ; -if ((pt_mode !=PT_MODE_HOST_GUEST ) || +if (!vmx_pt_mode_is_host_guest () || (index >=2 *intel_pt_validate_cap (vmx->pt_desc.caps, PT_CAP_num_address_ranges)))return 1 ;
@@ -2098,7 +2098,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)return 1 ;return vmx_set_vmx_msr (vcpu, msr_index, data);case MSR_IA32_RTIT_CTL : -if ((pt_mode !=PT_MODE_HOST_GUEST ) || +if (!vmx_pt_mode_is_host_guest () ||vmx_rtit_ctl_check (vcpu, data) || vmx->nested.vmxon)return 1 ;
@@ -4001,7 +4001,7 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)u32 exec_control = vmcs_config.cpu_based_2nd_exec_ctrl; -if (pt_mode ==PT_MODE_SYSTEM ) +if (vmx_pt_mode_is_system ()) exec_control &= ~(SECONDARY_EXEC_PT_USE_GPA |SECONDARY_EXEC_PT_CONCEAL_VMX );if (!cpu_need_virtualize_apic_accesses (vcpu)) exec_control &= ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES ;
@@ -4242,7 +4242,7 @@ static void init_vmcs(struct vcpu_vmx *vmx)if (cpu_has_vmx_encls_vmexit ())vmcs_write64 (ENCLS_EXITING_BITMAP ,-1ull ); -if (pt_mode ==PT_MODE_HOST_GUEST ) { +if (vmx_pt_mode_is_host_guest ()) {memset (&vmx->pt_desc,0 ,sizeof (vmx->pt_desc));/* Bit[6~0] are forced to 1, writes are ignored. */ vmx->pt_desc.guest.output_mask =0x7F ;
@@ -6309,7 +6309,7 @@ static bool vmx_has_emulated_msr(u32 index)static bool vmx_pt_supported (void ) { -return pt_mode ==PT_MODE_HOST_GUEST ; +return vmx_pt_mode_is_host_guest (); }static void vmx_recover_nmi_blocking (struct vcpu_vmx *vmx)
arch/x86/kvm/vmx/vmx.h +2 -2
@@ -449,7 +449,7 @@ static inline void vmx_segment_cache_clear(struct vcpu_vmx *vmx)static inline u32 vmx_vmentry_ctrl (void ) {u32 vmentry_ctrl = vmcs_config.vmentry_ctrl; -if (pt_mode ==PT_MODE_SYSTEM ) +if (vmx_pt_mode_is_system ()) vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |VM_ENTRY_LOAD_IA32_RTIT_CTL );/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
@@ -460,7 +460,7 @@ static inline u32 vmx_vmentry_ctrl(void)static inline u32 vmx_vmexit_ctrl (void ) {u32 vmexit_ctrl = vmcs_config.vmexit_ctrl; -if (pt_mode ==PT_MODE_SYSTEM ) +if (vmx_pt_mode_is_system ()) vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |VM_EXIT_CLEAR_IA32_RTIT_CTL );/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
Signature · 1 line
2.24.1
PATCH 8/26 KVM: x86: Move RTIT (Intel PT) MSR existence checks into vendor code
In reply to Sean ChristophersonMove the Processor Trace MSR checks into VMX to help pave the way toward removing ->pt_supported().
No functional change intended.
--- arch/x86/kvm/svm.c | 6 ++++++ arch/x86/kvm/vmx/vmx.c | 16 ++++++++++++++++ arch/x86/kvm/x86.c | 23 ----------------------- 3 files changed, 22 insertions(+), 23 deletions(-)
arch/x86/kvm/svm.c +6 -0
@@ -5991,6 +5991,12 @@ static bool svm_has_virtualized_msr(u32 index)case MSR_TSC_AUX :return boot_cpu_has (X86_FEATURE_RDTSCP );case MSR_IA32_BNDCFGS : +case MSR_IA32_RTIT_CTL : +case MSR_IA32_RTIT_STATUS : +case MSR_IA32_RTIT_CR3_MATCH : +case MSR_IA32_RTIT_OUTPUT_BASE : +case MSR_IA32_RTIT_OUTPUT_MASK : + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B:return false;default :break ;
arch/x86/kvm/vmx/vmx.c +16 -0
@@ -6281,8 +6281,24 @@ static bool vmx_has_virtualized_msr(u32 index)return cpu_has_vmx_rdtscp ();case MSR_IA32_BNDCFGS :return kvm_mpx_supported (); +case MSR_IA32_RTIT_CTL : +case MSR_IA32_RTIT_STATUS : +return vmx_pt_mode_is_host_guest (); +case MSR_IA32_RTIT_CR3_MATCH : +return vmx_pt_mode_is_host_guest () && +intel_pt_validate_hw_cap (PT_CAP_cr3_filtering); +case MSR_IA32_RTIT_OUTPUT_BASE : +case MSR_IA32_RTIT_OUTPUT_MASK : +return vmx_pt_mode_is_host_guest () && + (intel_pt_validate_hw_cap (PT_CAP_topa_output) || +intel_pt_validate_hw_cap (PT_CAP_single_range_output)); + case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: +return vmx_pt_mode_is_host_guest () && + (index -MSR_IA32_RTIT_ADDR0_A < +intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 );default :break ; + }return true;
arch/x86/kvm/x86.c +0 -23
@@ -5237,29 +5237,6 @@ static void kvm_init_msr_list(void)* to the guests in some cases. */ switch (msr_index) { -case MSR_IA32_RTIT_CTL : -case MSR_IA32_RTIT_STATUS : -if (!kvm_x86_ops->pt_supported ()) -continue ; -break ; -case MSR_IA32_RTIT_CR3_MATCH : -if (!kvm_x86_ops->pt_supported () || - !intel_pt_validate_hw_cap (PT_CAP_cr3_filtering)) -continue ; -break ; -case MSR_IA32_RTIT_OUTPUT_BASE : -case MSR_IA32_RTIT_OUTPUT_MASK : -if (!kvm_x86_ops->pt_supported () || - (!intel_pt_validate_hw_cap (PT_CAP_topa_output) && - !intel_pt_validate_hw_cap (PT_CAP_single_range_output))) -continue ; -break ; - case MSR_IA32_RTIT_ADDR0_A ... MSR_IA32_RTIT_ADDR3_B: -if (!kvm_x86_ops->pt_supported () || - msr_index -MSR_IA32_RTIT_ADDR0_A >= -intel_pt_validate_hw_cap (PT_CAP_num_address_ranges) *2 ) -continue ; -break ; case MSR_ARCH_PERFMON_PERFCTR0 ... MSR_ARCH_PERFMON_PERFCTR0 + 17:if (msr_index -MSR_ARCH_PERFMON_PERFCTR0 >=min (INTEL_PMC_MAX_GENERIC , x86_pmu.num_counters_gp))
Signature · 1 line
2.24.1
PATCH 9/26 KVM: x86: Calculate the supported xcr0 mask at load time
In reply to Sean ChristophersonAdd a new global variable, supported_xcr0, to track which xcr0 bits can be exposed to the guest instead of calculating the mask on every call. The supported bits are constant for a given instance of KVM.
This paves the way toward eliminating the ->mpx_supported() call in kvm_mpx_supported(), e.g. eliminates multiple retpolines in VMX's nested VM-Enter path, and eventually toward eliminating ->mpx_supported() altogether.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 15 ++------------- arch/x86/kvm/svm.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 4 ++++ arch/x86/kvm/x86.c | 14 +++++++++++--- arch/x86/kvm/x86.h | 7 +------ 5 files changed, 20 insertions(+), 22 deletions(-)
arch/x86/kvm/cpuid.c +2 -13
@@ -52,16 +52,6 @@ bool kvm_mpx_supported(void) }EXPORT_SYMBOL_GPL (kvm_mpx_supported); -u64 kvm_supported_xcr0 (void ) -{ -u64 xcr0 =KVM_SUPPORTED_XCR0 & host_xcr0; - -if (!kvm_mpx_supported ()) - xcr0 &= ~(XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR ); - -return xcr0; -} -#define F feature_bitint kvm_update_cpuid (struct kvm_vcpu *vcpu)
@@ -107,8 +97,7 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) vcpu->arch.guest_xstate_size =XSAVE_HDR_SIZE +XSAVE_HDR_OFFSET ; }else { vcpu->arch.guest_supported_xcr0 = - (best->eax | ((u64 )best->edx <<32 )) & -kvm_supported_xcr0 (); + (best->eax | ((u64 )best->edx <<32 )) & supported_xcr0; vcpu->arch.guest_xstate_size = best->ebx =xstate_required_size (vcpu->arch.xcr0, false); }
@@ -644,7 +633,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, }case 0xd : {int idx, i; -u64 supported =kvm_supported_xcr0 (); +u64 supported = supported_xcr0; entry->eax &= supported; entry->ebx =xstate_required_size (supported, false);
arch/x86/kvm/svm.c +2 -0
@@ -1368,6 +1368,8 @@ static __init int svm_hardware_setup(void)init_msrpm_offsets (); + supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR ); +if (boot_cpu_has (X86_FEATURE_NX ))kvm_enable_efer_bits (EFER_NX );
arch/x86/kvm/vmx/vmx.c +4 -0
@@ -7620,6 +7620,10 @@ static __init int hardware_setup(void)WARN_ONCE (host_bndcfgs,"KVM: BNDCFGS in host will be lost" ); } +if (!kvm_mpx_supported ()) + supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS | +XFEATURE_MASK_BNDCSR ); +if (!cpu_has_vmx_vpid () || !cpu_has_vmx_invvpid () || !(cpu_has_vmx_invvpid_single () ||cpu_has_vmx_invvpid_global ())) enable_vpid =0 ;
arch/x86/kvm/x86.c +11 -3
@@ -180,6 +180,11 @@ struct kvm_shared_msrs {static struct kvm_shared_msrs_global __read_mostly shared_msrs_global;static struct kvm_shared_msrs __percpu *shared_msrs; +#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \ + | XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \ + | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ + | XFEATURE_MASK_PKRU) +static u64 __read_mostly host_xss;struct kvm_stats_debugfs_item debugfs_entries[] = {
@@ -226,6 +231,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { };u64 __read_mostly host_xcr0; +u64 __read_mostly supported_xcr0; +EXPORT_SYMBOL_GPL (supported_xcr0);struct kmem_cache *x86_fpu_cache;EXPORT_SYMBOL_GPL (x86_fpu_cache);
@@ -4081,8 +4088,7 @@ static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu,* CPUID leaf 0xD, index 0, EDX:EAX. This is for compatibility * with old userspace. */ -if (xstate_bv & ~kvm_supported_xcr0 () || - mxcsr & ~mxcsr_feature_mask) +if (xstate_bv & ~supported_xcr0 || mxcsr & ~mxcsr_feature_mask)return -EINVAL ;load_xsave (vcpu, (u8 *)guest_xsave->region); }else {
@@ -7310,8 +7316,10 @@ int kvm_arch_init(void *opaque)perf_register_guest_info_callbacks (&kvm_guest_cbs); -if (boot_cpu_has (X86_FEATURE_XSAVE )) +if (boot_cpu_has (X86_FEATURE_XSAVE )) { host_xcr0 =xgetbv (XCR_XFEATURE_ENABLED_MASK ); + supported_xcr0 = host_xcr0 &KVM_SUPPORTED_XCR0 ; + }kvm_lapic_init ();if (pi_inject_timer ==-1 )
arch/x86/kvm/x86.h +1 -6
@@ -280,13 +280,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, int emulation_type, void *insn, int insn_len);enum exit_fastpath_completion handle_fastpath_set_msr_irqoff (struct kvm_vcpu *vcpu); -#define KVM_SUPPORTED_XCR0 (XFEATURE_MASK_FP | XFEATURE_MASK_SSE \ - | XFEATURE_MASK_YMM | XFEATURE_MASK_BNDREGS \ - | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ - | XFEATURE_MASK_PKRU)extern u64 host_xcr0; - -extern u64 kvm_supported_xcr0 (void ); +extern u64 supported_xcr0;extern unsigned int min_timer_period_us;
Signature · 1 line
2.24.1
PATCH 10/26 KVM: x86: Use supported_xcr0 to detect MPX support
In reply to Sean ChristophersonQuery supported_xcr0 when checking for MPX support instead of invoking ->mpx_supported() and drop ->mpx_supported() as kvm_mpx_supported() was its last user. Rename vmx_mpx_supported() to cpu_has_vmx_mpx() to better align with VMX/VMCS nomenclature.
Modify VMX's adjustment of xcr0 to call cpus_has_vmx_mpx() (renamed from vmx_mpx_supported()) directly to avoid reading supported_xcr0 before it's fully configured.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/cpuid.c | 3 +-- arch/x86/kvm/svm.c | 6 ------ arch/x86/kvm/vmx/capabilities.h | 2 +- arch/x86/kvm/vmx/vmx.c | 3 +-- 5 files changed, 4 insertions(+), 12 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1164,7 +1164,7 @@ struct kvm_x86_ops { enum x86_intercept_stage stage);void (*handle_exit_irqoff)(struct kvm_vcpu *vcpu,enum exit_fastpath_completion *exit_fastpath); -bool (*mpx_supported)(void ); +bool (*xsaves_supported)(void );bool (*umip_emulated)(void );bool (*pt_supported)(void );
arch/x86/kvm/cpuid.c +1 -2
@@ -47,8 +47,7 @@ static u32 xstate_required_size(u64 xstate_bv, bool compacted)bool kvm_mpx_supported (void ) { -return ((host_xcr0 & (XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR )) - && kvm_x86_ops->mpx_supported ()); +return supported_xcr0 & (XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR ); }EXPORT_SYMBOL_GPL (kvm_mpx_supported);
arch/x86/kvm/svm.c +0 -6
@@ -6102,11 +6102,6 @@ static bool svm_invpcid_supported(void)return false; } -static bool svm_mpx_supported (void ) -{ -return false; -} -static bool svm_xsaves_supported (void ) {return boot_cpu_has (X86_FEATURE_XSAVES );
@@ -7489,7 +7484,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .rdtscp_supported = svm_rdtscp_supported, .invpcid_supported = svm_invpcid_supported, - .mpx_supported = svm_mpx_supported, .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, .pt_supported = svm_pt_supported,
arch/x86/kvm/vmx/capabilities.h +1 -1
@@ -100,7 +100,7 @@ static inline bool cpu_has_load_perf_global_ctrl(void) (vmcs_config.vmexit_ctrl &VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ); } -static inline bool vmx_mpx_supported (void ) +static inline bool cpu_has_vmx_mpx (void ) {return (vmcs_config.vmexit_ctrl &VM_EXIT_CLEAR_BNDCFGS ) && (vmcs_config.vmentry_ctrl &VM_ENTRY_LOAD_BNDCFGS );
arch/x86/kvm/vmx/vmx.c +1 -2
@@ -7620,7 +7620,7 @@ static __init int hardware_setup(void)WARN_ONCE (host_bndcfgs,"KVM: BNDCFGS in host will be lost" ); } -if (!kvm_mpx_supported ()) +if (!cpu_has_vmx_mpx ()) supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR );
@@ -7888,7 +7888,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .check_intercept = vmx_check_intercept, .handle_exit_irqoff = vmx_handle_exit_irqoff, - .mpx_supported = vmx_mpx_supported, .xsaves_supported = vmx_xsaves_supported, .umip_emulated = vmx_umip_emulated, .pt_supported = vmx_pt_supported,
Signature · 1 line
2.24.1
PATCH 11/26 KVM: x86: Make kvm_mpx_supported() an inline function
In reply to Sean ChristophersonExpose kvm_mpx_supported() as a static inline so that it can be inlined in kvm_intel.ko.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 6 ------ arch/x86/kvm/cpuid.h | 1 - arch/x86/kvm/x86.h | 5 +++++ 3 files changed, 5 insertions(+), 7 deletions(-)
arch/x86/kvm/cpuid.c +0 -6
@@ -45,12 +45,6 @@ static u32 xstate_required_size(u64 xstate_bv, bool compacted)return ret; } -bool kvm_mpx_supported (void ) -{ -return supported_xcr0 & (XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR ); -} -EXPORT_SYMBOL_GPL (kvm_mpx_supported); -#define F feature_bitint kvm_update_cpuid (struct kvm_vcpu *vcpu)
arch/x86/kvm/cpuid.h +0 -1
@@ -7,7 +7,6 @@#include <asm/processor.h> int kvm_update_cpuid (struct kvm_vcpu *vcpu); -bool kvm_mpx_supported (void );struct kvm_cpuid_entry2 *kvm_find_cpuid_entry (struct kvm_vcpu *vcpu,u32 function,u32 index); int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
arch/x86/kvm/x86.h +5 -0
@@ -283,6 +283,11 @@ enum exit_fastpath_completion handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcextern u64 host_xcr0;extern u64 supported_xcr0; +static inline bool kvm_mpx_supported (void ) +{ +return supported_xcr0 & (XFEATURE_MASK_BNDREGS |XFEATURE_MASK_BNDCSR ); +} +extern unsigned int min_timer_period_us;extern bool enable_vmware_backdoor;
Signature · 1 line
2.24.1
PATCH 12/26 KVM: x86: Drop explicit @func param from ->set_supported_cpuid()
In reply to Sean ChristophersonDrop the explicit @func param from ->set_supported_cpuid() and instead pull the CPUID function from the relevant entry. This sets the stage for hardening guest CPUID updates in future patches, e.g. allows adding run-time assertions that the CPUID feature being changed is actually a bit in the referenced CPUID entry.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1149,7 +1149,7 @@ struct kvm_x86_ops {void (*set_tdp_cr3)(struct kvm_vcpu *vcpu,unsigned long cr3); -void (*set_supported_cpuid)(u32 func,struct kvm_cpuid_entry2 *entry); +void (*set_supported_cpuid)(struct kvm_cpuid_entry2 *entry);bool (*has_wbinvd_exit)(void );
arch/x86/kvm/cpuid.c +1 -1
@@ -789,7 +789,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,break ; } - kvm_x86_ops->set_supported_cpuid (function, entry); + kvm_x86_ops->set_supported_cpuid (entry); r =0 ;
arch/x86/kvm/svm.c +2 -2
@@ -6052,9 +6052,9 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)#define F feature_bit -static void svm_set_supported_cpuid (u32 func,struct kvm_cpuid_entry2 *entry) +static void svm_set_supported_cpuid (struct kvm_cpuid_entry2 *entry) { -switch (func) { +switch (entry->function) {case 0x1 :if (avic) entry->ecx &= ~F (X2APIC );
arch/x86/kvm/vmx/vmx.c +2 -2
@@ -7134,9 +7134,9 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu) } } -static void vmx_set_supported_cpuid (u32 func,struct kvm_cpuid_entry2 *entry) +static void vmx_set_supported_cpuid (struct kvm_cpuid_entry2 *entry) { -if (func ==1 && nested) +if (entry->function ==1 && nested) entry->ecx |=feature_bit (VMX ); }
Signature · 1 line
2.24.1
PATCH 13/26 KVM: x86: Use u32 for holding CPUID register value in helpers
In reply to Sean ChristophersonChange the intermediate CPUID output register values from "int" to "u32" to match both hardware and the storage type in struct cpuid_reg.
No functional change intended.
--- arch/x86/kvm/cpuid.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/kvm/cpuid.h +3 -3
@@ -95,7 +95,7 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature)return reverse_cpuid[x86_leaf]; } -static __always_inline int *guest_cpuid_get_register(struct kvm_vcpu *vcpu, unsigned x86_feature) +static __always_inline u32 *guest_cpuid_get_register(struct kvm_vcpu *vcpu, unsigned x86_feature) {struct kvm_cpuid_entry2 *entry;const struct cpuid_reg cpuid =x86_feature_cpuid (x86_feature);
@@ -121,7 +121,7 @@ static __always_inline int *guest_cpuid_get_register(struct kvm_vcpu *vcpu, unsi static __always_inline bool guest_cpuid_has(struct kvm_vcpu *vcpu, unsigned x86_feature) { -int *reg; +u32 *reg; reg =guest_cpuid_get_register (vcpu, x86_feature);if (!reg)
@@ -132,7 +132,7 @@ static __always_inline bool guest_cpuid_has(struct kvm_vcpu *vcpu, unsigned x86_ static __always_inline void guest_cpuid_clear(struct kvm_vcpu *vcpu, unsigned x86_feature) { -int *reg; +u32 *reg; reg =guest_cpuid_get_register (vcpu, x86_feature);if (reg)
Signature · 1 line
2.24.1
PATCH 14/26 KVM: x86: Introduce cpuid_entry_{get,has}() accessors
In reply to Sean ChristophersonIntroduce accessors to retrieve feature bits from CPUID entries and use the new accessors where applicable. Using the accessors eliminates the need to manually specify the register to be queried at no extra cost (binary output is identical) and will allow adding runtime consistency checks on the function and index in a future patch.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 9 +++++---- arch/x86/kvm/cpuid.h | 46 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 13 deletions(-)
arch/x86/kvm/cpuid.c +5 -4
@@ -68,7 +68,7 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) best->edx |=F (APIC );if (apic) { -if (best->ecx &F (TSC_DEADLINE_TIMER )) +if (cpuid_entry_has (best,X86_FEATURE_TSC_DEADLINE_TIMER )) apic->lapic_timer.timer_mode_mask =3 <<17 ;else apic->lapic_timer.timer_mode_mask =1 <<17 ;
@@ -96,7 +96,8 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) } best =kvm_find_cpuid_entry (vcpu,0xD ,1 ); -if (best && (best->eax & (F (XSAVES ) |F (XSAVEC )))) +if (best && (cpuid_entry_has (best,X86_FEATURE_XSAVES ) || +cpuid_entry_has (best,X86_FEATURE_XSAVEC ))) best->ebx =xstate_required_size (vcpu->arch.xcr0, true);/*
@@ -155,7 +156,7 @@ static void cpuid_fix_nx_cap(struct kvm_vcpu *vcpu)break ; } } -if (entry && (entry->edx &F (NX )) && !is_efer_nx ()) { +if (entry &&cpuid_entry_has (entry,X86_FEATURE_NX ) && !is_efer_nx ()) { entry->edx &= ~F (NX );printk (KERN_INFO "kvm: guest NX capability removed\n" ); }
@@ -371,7 +372,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index) entry->ebx |=F (TSC_ADJUST ); entry->ecx &= kvm_cpuid_7_0_ecx_x86_features; - f_la57 = entry->ecx &F (LA57 ); + f_la57 =cpuid_entry_get (entry,X86_FEATURE_LA57 );cpuid_mask (&entry->ecx,CPUID_7_ECX );/* Set LA57 based on hardware capability. */ entry->ecx |= f_la57;
arch/x86/kvm/cpuid.h +37 -9
59 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH 15/26 KVM: x86: Introduce cpuid_entry_{change,set,clear}() mutators
In reply to Sean ChristophersonIntroduce mutators to modify feature bits in CPUID entries and use the new mutators where applicable. Using the mutators eliminates the need to manually specify the register to modify query at no extra cost and will allow adding runtime consistency checks on the function/index in a future patch.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 62 +++++++++++++++++++------------------------- arch/x86/kvm/cpuid.h | 31 ++++++++++++++++++++++ arch/x86/kvm/svm.c | 11 ++++---- 3 files changed, 62 insertions(+), 42 deletions(-)
arch/x86/kvm/cpuid.c +26 -36
@@ -57,15 +57,12 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)return 0 ;/* Update OSXSAVE bit */ -if (boot_cpu_has (X86_FEATURE_XSAVE ) && best->function ==0x1 ) { - best->ecx &= ~F (OSXSAVE ); -if (kvm_read_cr4_bits (vcpu,X86_CR4_OSXSAVE )) - best->ecx |=F (OSXSAVE ); - } +if (boot_cpu_has (X86_FEATURE_XSAVE ) && best->function ==0x1 ) +cpuid_entry_change (best,X86_FEATURE_OSXSAVE , +kvm_read_cr4_bits (vcpu,X86_CR4_OSXSAVE )); - best->edx &= ~F (APIC ); -if (vcpu->arch.apic_base &MSR_IA32_APICBASE_ENABLE ) - best->edx |=F (APIC ); +cpuid_entry_change (best,X86_FEATURE_APIC , + vcpu->arch.apic_base &MSR_IA32_APICBASE_ENABLE );if (apic) {if (cpuid_entry_has (best,X86_FEATURE_TSC_DEADLINE_TIMER ))
@@ -75,14 +72,9 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu) } best =kvm_find_cpuid_entry (vcpu,7 ,0 ); -if (best) { -/* Update OSPKE bit */ -if (boot_cpu_has (X86_FEATURE_PKU ) && best->function ==0x7 ) { - best->ecx &= ~F (OSPKE ); -if (kvm_read_cr4_bits (vcpu,X86_CR4_PKE )) - best->ecx |=F (OSPKE ); - } - } +if (best &&boot_cpu_has (X86_FEATURE_PKU ) && best->function ==0x7 ) +cpuid_entry_change (best,X86_FEATURE_OSPKE , +kvm_read_cr4_bits (vcpu,X86_CR4_PKE )); best =kvm_find_cpuid_entry (vcpu,0xD ,0 );if (!best) {
@@ -119,12 +111,10 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)if (!kvm_check_has_quirk (vcpu->kvm,KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT )) { best =kvm_find_cpuid_entry (vcpu,0x1 ,0 ); -if (best) { -if (vcpu->arch.ia32_misc_enable_msr &MSR_IA32_MISC_ENABLE_MWAIT ) - best->ecx |=F (MWAIT ); -else - best->ecx &= ~F (MWAIT ); - } +if (best) +cpuid_entry_change (best,X86_FEATURE_MWAIT , + vcpu->arch.ia32_misc_enable_msr & +MSR_IA32_MISC_ENABLE_MWAIT ); }/* Update physical-address width */
@@ -157,7 +147,7 @@ static void cpuid_fix_nx_cap(struct kvm_vcpu *vcpu) } }if (entry &&cpuid_entry_has (entry,X86_FEATURE_NX ) && !is_efer_nx ()) { - entry->edx &= ~F (NX ); +cpuid_entry_clear (entry,X86_FEATURE_NX );printk (KERN_INFO "kvm: guest NX capability removed\n" ); } }
@@ -369,7 +359,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index) entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;cpuid_mask (&entry->ebx,CPUID_7_0_EBX );/* TSC_ADJUST is emulated */ - entry->ebx |=F (TSC_ADJUST ); +cpuid_entry_set (entry,X86_FEATURE_TSC_ADJUST ); entry->ecx &= kvm_cpuid_7_0_ecx_x86_features; f_la57 =cpuid_entry_get (entry,X86_FEATURE_LA57 );
@@ -380,22 +370,22 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index) entry->ecx |= f_pku;/* PKU is not yet implemented for shadow paging. */ if (!tdp_enabled || !boot_cpu_has (X86_FEATURE_OSPKE )) - entry->ecx &= ~F (PKU ); +cpuid_entry_clear (entry,X86_FEATURE_PKU ); entry->edx &= kvm_cpuid_7_0_edx_x86_features;cpuid_mask (&entry->edx,CPUID_7_EDX );if (boot_cpu_has (X86_FEATURE_IBPB ) &&boot_cpu_has (X86_FEATURE_IBRS )) - entry->edx |=F (SPEC_CTRL ); +cpuid_entry_set (entry,X86_FEATURE_SPEC_CTRL );if (boot_cpu_has (X86_FEATURE_STIBP )) - entry->edx |=F (INTEL_STIBP ); +cpuid_entry_set (entry,X86_FEATURE_INTEL_STIBP );if (boot_cpu_has (X86_FEATURE_SPEC_CTRL_SSBD ) ||boot_cpu_has (X86_FEATURE_AMD_SSBD )) - entry->edx |=F (SPEC_CTRL_SSBD ); +cpuid_entry_set (entry,X86_FEATURE_SPEC_CTRL_SSBD );/* * We emulate ARCH_CAPABILITIES in software even * if the host doesn't support it. */ - entry->edx |=F (ARCH_CAPABILITIES ); +cpuid_entry_set (entry,X86_FEATURE_ARCH_CAPABILITIES );break ;case 1 : entry->eax &= kvm_cpuid_7_1_eax_x86_features;
@@ -509,7 +499,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,cpuid_mask (&entry->ecx,CPUID_1_ECX );/* we support x2apic emulation even if host does not support * it since we emulate x2apic in software */ - entry->ecx |=F (X2APIC ); +cpuid_entry_set (entry,X86_FEATURE_X2APIC );break ;/* function 2 entries are STATEFUL. That is, repeated cpuid commands * may return different values. This forces us to get_cpu() before
@@ -741,23 +731,23 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,* record that in cpufeatures so use them. */ if (boot_cpu_has (X86_FEATURE_IBPB )) - entry->ebx |=F (AMD_IBPB ); +cpuid_entry_set (entry,X86_FEATURE_AMD_IBPB );if (boot_cpu_has (X86_FEATURE_IBRS )) - entry->ebx |=F (AMD_IBRS ); +cpuid_entry_set (entry,X86_FEATURE_AMD_IBRS );if (boot_cpu_has (X86_FEATURE_STIBP )) - entry->ebx |=F (AMD_STIBP ); +cpuid_entry_set (entry,X86_FEATURE_AMD_STIBP );if (boot_cpu_has (X86_FEATURE_SPEC_CTRL_SSBD ) ||boot_cpu_has (X86_FEATURE_AMD_SSBD )) - entry->ebx |=F (AMD_SSBD ); +cpuid_entry_set (entry,X86_FEATURE_AMD_SSBD );if (!boot_cpu_has_bug (X86_BUG_SPEC_STORE_BYPASS )) - entry->ebx |=F (AMD_SSB_NO ); +cpuid_entry_set (entry,X86_FEATURE_AMD_SSB_NO );/* * The preference is to use SPEC CTRL MSR instead of the * VIRT_SPEC MSR. */ if (boot_cpu_has (X86_FEATURE_LS_CFG_SSBD ) && !boot_cpu_has (X86_FEATURE_AMD_SSBD )) - entry->ebx |=F (VIRT_SSBD ); +cpuid_entry_set (entry,X86_FEATURE_VIRT_SSBD );break ; }case 0x80000019 :
arch/x86/kvm/cpuid.h +31 -0
@@ -135,6 +135,37 @@ static __always_inline bool cpuid_entry_has(struct kvm_cpuid_entry2 *entry,return cpuid_entry_get (entry, x86_feature); } +static __always_inline void cpuid_entry_clear(struct kvm_cpuid_entry2 *entry, +unsigned x86_feature) +{ +u32 *reg =cpuid_entry_get_reg (entry, x86_feature); + + *reg &= ~__feature_bit (x86_feature); +} + +static __always_inline void cpuid_entry_set(struct kvm_cpuid_entry2 *entry, +unsigned x86_feature) +{ +int *reg =cpuid_entry_get_reg (entry, x86_feature); + + *reg |=__feature_bit (x86_feature); +} + +static __always_inline void cpuid_entry_change(struct kvm_cpuid_entry2 *entry, +unsigned x86_feature,bool set) +{ +int *reg =cpuid_entry_get_reg (entry, x86_feature); + +/* +* Open coded instead of using cpuid_entry_{clear,set}() to coerce the +* compiler into using CMOV instead of Jcc when possible. +*/ +if (set) + *reg |=__feature_bit (x86_feature); +else + *reg &= ~__feature_bit (x86_feature); +} + static __always_inline int *guest_cpuid_get_register(struct kvm_vcpu *vcpu, unsigned x86_feature) {struct kvm_cpuid_entry2 *entry;
arch/x86/kvm/svm.c +5 -6
@@ -6057,16 +6057,16 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)switch (entry->function) {case 0x1 :if (avic) - entry->ecx &= ~F (X2APIC ); +cpuid_entry_clear (entry,X86_FEATURE_X2APIC );break ;case 0x80000001 :if (nested) - entry->ecx |= (1 <<2 );/* Set SVM bit */ +cpuid_entry_set (entry,X86_FEATURE_SVM );break ;case 0x80000008 :if (boot_cpu_has (X86_FEATURE_LS_CFG_SSBD ) ||boot_cpu_has (X86_FEATURE_AMD_SSBD )) - entry->ebx |=F (VIRT_SSBD ); +cpuid_entry_set (entry,X86_FEATURE_VIRT_SSBD );break ;case 0x8000000A : entry->eax =1 ;/* SVM revision 1 */
@@ -6078,12 +6078,11 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)/* Support next_rip if host supports it */ if (boot_cpu_has (X86_FEATURE_NRIPS )) - entry->edx |=F (NRIPS ); +cpuid_entry_set (entry,X86_FEATURE_NRIPS );/* Support NPT for the guest if enabled */ if (npt_enabled) - entry->edx |=F (NPT ); - +cpuid_entry_set (entry,X86_FEATURE_NPT ); } }
Signature · 1 line
2.24.1
PATCH 16/26 KVM: x86: Add Kconfig-controlled auditing of reverse CPUID lookups
In reply to Sean ChristophersonAdd WARNs in the low level __cpuid_entry_get_reg() to assert that the function and index of the CPUID entry and reverse CPUID entry match. Wrap the WARNs in a new Kconfig, KVM_CPUID_AUDIT, as the checks add almost no value in a production environment, i.e. will only detect blatant KVM bugs and fatal hardware errors. Add a Kconfig instead of simply wrapping the WARNs with an off-by-default #ifdef so that syzbot and other automated testing can enable the auditing.
--- arch/x86/kvm/Kconfig | 10 ++++++++++ arch/x86/kvm/cpuid.h | 5 +++++ 2 files changed, 15 insertions(+)
arch/x86/kvm/Kconfig +10 -0
@@ -96,6 +96,16 @@ config KVM_MMU_AUDIT This option adds a R/W kVM module parameter 'mmu_audit', which allows auditing of KVM MMU events at runtime. +config KVM_CPUID_AUDIT + bool "Audit KVM reverse CPUID lookups" + depends on KVM + help + This option enables runtime checking of reverse CPUID lookups in KVM + to verify the function and index of the referenced X86_FEATURE_* match + the function and index of the CPUID entry being accessed. + + If unsure, say N. + # OK, it's a little counter-intuitive to do this, but it puts it neatly under # the virtualization menu. source "drivers/vhost/Kconfig"
arch/x86/kvm/cpuid.h +5 -0
@@ -98,6 +98,11 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature) static __always_inline u32 *__cpuid_entry_get_reg(struct kvm_cpuid_entry2 *entry,const struct cpuid_reg *cpuid) { +#ifdef CONFIG_KVM_CPUID_AUDIT +WARN_ON_ONCE (entry->function != cpuid->function); +WARN_ON_ONCE (entry->index != cpuid->index); +#endif +switch (cpuid->reg) {case CPUID_EAX :return &entry->eax;
Signature · 1 line
2.24.1
PATCH 17/26 KVM: x86: Handle MPX CPUID adjustment in vendor code
In reply to Sean ChristophersonMove the MPX CPUID adjustments into vendor code to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 3 +-- arch/x86/kvm/svm.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-)
arch/x86/kvm/cpuid.c +1 -2
@@ -322,7 +322,6 @@ static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,static inline void do_cpuid_7_mask (struct kvm_cpuid_entry2 *entry,int index) {unsigned f_invpcid = kvm_x86_ops->invpcid_supported () ?F (INVPCID ) :0 ; -unsigned f_mpx =kvm_mpx_supported () ?F (MPX ) :0 ;unsigned f_umip = kvm_x86_ops->umip_emulated () ?F (UMIP ) :0 ;unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;unsigned f_la57;
@@ -331,7 +330,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)/* cpuid 7.0.ebx */ const u32 kvm_cpuid_7_0_ebx_x86_features =F (FSGSBASE ) |F (BMI1 ) |F (HLE ) |F (AVX2 ) |F (SMEP ) | -F (BMI2 ) |F (ERMS ) | f_invpcid |F (RTM ) | f_mpx |F (RDSEED ) | +F (BMI2 ) |F (ERMS ) | f_invpcid |F (RTM ) |F (MPX ) |F (RDSEED ) |F (ADX ) |F (SMAP ) |F (AVX512IFMA ) |F (AVX512F ) |F (AVX512PF ) |F (AVX512ER ) |F (AVX512CD ) |F (CLFLUSHOPT ) |F (CLWB ) |F (AVX512DQ ) |F (SHA_NI ) |F (AVX512BW ) |F (AVX512VL ) | f_intel_pt;
arch/x86/kvm/svm.c +3 -0
@@ -6059,6 +6059,9 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)if (avic)cpuid_entry_clear (entry,X86_FEATURE_X2APIC );break ; +case 0x7 : +cpuid_entry_clear (entry,X86_FEATURE_MPX ); +break ;case 0x80000001 :if (nested)cpuid_entry_set (entry,X86_FEATURE_SVM );
arch/x86/kvm/vmx/vmx.c +12 -2
@@ -7136,8 +7136,18 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)static void vmx_set_supported_cpuid (struct kvm_cpuid_entry2 *entry) { -if (entry->function ==1 && nested) - entry->ecx |=feature_bit (VMX ); +switch (entry->function) { +case 0x1 : +if (nested) +cpuid_entry_set (entry,X86_FEATURE_VMX ); +break ; +case 0x7 : +if (!kvm_mpx_supported ()) +cpuid_entry_clear (entry,X86_FEATURE_MPX ); +break ; +default : +break ; + } }static void vmx_request_immediate_exit (struct kvm_vcpu *vcpu)
Signature · 1 line
2.24.1
PATCH 18/26 KVM: x86: Handle INVPCID CPUID adjustment in vendor code
In reply to Sean ChristophersonMove the INVPCID CPUID adjustments into vendor code to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code. Drop ->invpcid_supported() since CPUID adjustment was the only user.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/cpuid.c | 3 +-- arch/x86/kvm/svm.c | 7 +------ arch/x86/kvm/vmx/vmx.c | 10 +++------- 4 files changed, 5 insertions(+), 16 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1145,7 +1145,6 @@ struct kvm_x86_ops {u64 (*get_mt_mask)(struct kvm_vcpu *vcpu,gfn_t gfn,bool is_mmio);int (*get_lpage_level)(void );bool (*rdtscp_supported)(void ); -bool (*invpcid_supported)(void );void (*set_tdp_cr3)(struct kvm_vcpu *vcpu,unsigned long cr3);
arch/x86/kvm/cpuid.c +1 -2
@@ -321,7 +321,6 @@ static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,static inline void do_cpuid_7_mask (struct kvm_cpuid_entry2 *entry,int index) { -unsigned f_invpcid = kvm_x86_ops->invpcid_supported () ?F (INVPCID ) :0 ;unsigned f_umip = kvm_x86_ops->umip_emulated () ?F (UMIP ) :0 ;unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;unsigned f_la57;
@@ -330,7 +329,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)/* cpuid 7.0.ebx */ const u32 kvm_cpuid_7_0_ebx_x86_features =F (FSGSBASE ) |F (BMI1 ) |F (HLE ) |F (AVX2 ) |F (SMEP ) | -F (BMI2 ) |F (ERMS ) | f_invpcid |F (RTM ) |F (MPX ) |F (RDSEED ) | +F (BMI2 ) |F (ERMS ) |F (INVPCID ) |F (RTM ) |F (MPX ) |F (RDSEED ) |F (ADX ) |F (SMAP ) |F (AVX512IFMA ) |F (AVX512F ) |F (AVX512PF ) |F (AVX512ER ) |F (AVX512CD ) |F (CLFLUSHOPT ) |F (CLWB ) |F (AVX512DQ ) |F (SHA_NI ) |F (AVX512BW ) |F (AVX512VL ) | f_intel_pt;
arch/x86/kvm/svm.c +1 -6
@@ -6061,6 +6061,7 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)break ;case 0x7 :cpuid_entry_clear (entry,X86_FEATURE_MPX ); +cpuid_entry_clear (entry,X86_FEATURE_INVPCID );break ;case 0x80000001 :if (nested)
@@ -6099,11 +6100,6 @@ static bool svm_rdtscp_supported(void)return boot_cpu_has (X86_FEATURE_RDTSCP ); } -static bool svm_invpcid_supported (void ) -{ -return false; -} -static bool svm_xsaves_supported (void ) {return boot_cpu_has (X86_FEATURE_XSAVES );
@@ -7485,7 +7481,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .cpuid_update = svm_cpuid_update, .rdtscp_supported = svm_rdtscp_supported, - .invpcid_supported = svm_invpcid_supported, .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, .pt_supported = svm_pt_supported,
arch/x86/kvm/vmx/vmx.c +3 -7
@@ -1656,11 +1656,6 @@ static bool vmx_rdtscp_supported(void)return cpu_has_vmx_rdtscp (); } -static bool vmx_invpcid_supported (void ) -{ -return cpu_has_vmx_invpcid (); -} -/* * Swap MSR entry in host/guest MSR entry array. */
@@ -4071,7 +4066,7 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) } } -if (vmx_invpcid_supported ()) { +if (cpu_has_vmx_invpcid ()) {/* Exposing INVPCID only when PCID is exposed */ bool invpcid_enabled = guest_cpuid_has(vcpu, X86_FEATURE_INVPCID) &&
@@ -7144,6 +7139,8 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)case 0x7 :if (!kvm_mpx_supported ())cpuid_entry_clear (entry,X86_FEATURE_MPX ); +if (!cpu_has_vmx_invpcid ()) +cpuid_entry_clear (entry,X86_FEATURE_INVPCID );break ;default :break ;
@@ -7885,7 +7882,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .cpuid_update = vmx_cpuid_update, .rdtscp_supported = vmx_rdtscp_supported, - .invpcid_supported = vmx_invpcid_supported, .set_supported_cpuid = vmx_set_supported_cpuid,
Signature · 1 line
2.24.1
PATCH 19/26 KVM: x86: Handle UMIP emulation CPUID adjustment in VMX code
In reply to Sean ChristophersonMove the CPUID adjustment for UMIP emulation into VMX code to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 2 -- arch/x86/kvm/vmx/vmx.c | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/cpuid.c +0 -2
@@ -321,7 +321,6 @@ static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,static inline void do_cpuid_7_mask (struct kvm_cpuid_entry2 *entry,int index) { -unsigned f_umip = kvm_x86_ops->umip_emulated () ?F (UMIP ) :0 ;unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;unsigned f_la57;unsigned f_pku = kvm_x86_ops->pku_supported () ?F (PKU ) :0 ;
@@ -364,7 +363,6 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)cpuid_mask (&entry->ecx,CPUID_7_ECX );/* Set LA57 based on hardware capability. */ entry->ecx |= f_la57; - entry->ecx |= f_umip; entry->ecx |= f_pku;/* PKU is not yet implemented for shadow paging. */ if (!tdp_enabled || !boot_cpu_has (X86_FEATURE_OSPKE ))
arch/x86/kvm/vmx/vmx.c +3 -0
@@ -7141,6 +7141,9 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)cpuid_entry_clear (entry,X86_FEATURE_MPX );if (!cpu_has_vmx_invpcid ())cpuid_entry_clear (entry,X86_FEATURE_INVPCID ); + +if (vmx_umip_emulated ()) +cpuid_entry_set (entry,X86_FEATURE_UMIP );break ;default :break ;
Signature · 1 line
2.24.1
PATCH 20/26 KVM: x86: Handle PKU CPUID adjustment in SVM code
In reply to Sean ChristophersonMove the clearing of the PKU CPUID bit into SVM, which does not yet support virtualizing PKU, to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code. Drop ->pku_supported() since CPUID adjustment was the only user.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/cpuid.c | 4 +--- arch/x86/kvm/svm.c | 7 +------ arch/x86/kvm/vmx/capabilities.h | 5 ----- arch/x86/kvm/vmx/vmx.c | 1 - 5 files changed, 2 insertions(+), 16 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1167,7 +1167,6 @@ struct kvm_x86_ops {bool (*xsaves_supported)(void );bool (*umip_emulated)(void );bool (*pt_supported)(void ); -bool (*pku_supported)(void );int (*check_nested_events)(struct kvm_vcpu *vcpu,bool external_intr);void (*request_immediate_exit)(struct kvm_vcpu *vcpu);
arch/x86/kvm/cpuid.c +1 -3
@@ -323,7 +323,6 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index) {unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;unsigned f_la57; -unsigned f_pku = kvm_x86_ops->pku_supported () ?F (PKU ) :0 ;/* cpuid 7.0.ebx */ const u32 kvm_cpuid_7_0_ebx_x86_features =
@@ -335,7 +334,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)/* cpuid 7.0.ecx*/ const u32 kvm_cpuid_7_0_ecx_x86_features = -F (AVX512VBMI ) |F (LA57 ) |0 /*PKU*/ |0 /*OSPKE*/ |F (RDPID ) | +F (AVX512VBMI ) |F (LA57 ) |F (PKU ) |0 /*OSPKE*/ |F (RDPID ) |F (AVX512_VPOPCNTDQ ) |F (UMIP ) |F (AVX512_VBMI2 ) |F (GFNI ) |F (VAES ) |F (VPCLMULQDQ ) |F (AVX512_VNNI ) |F (AVX512_BITALG ) |F (CLDEMOTE ) |F (MOVDIRI ) |F (MOVDIR64B ) |0 /*WAITPKG*/ ;
@@ -363,7 +362,6 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)cpuid_mask (&entry->ecx,CPUID_7_ECX );/* Set LA57 based on hardware capability. */ entry->ecx |= f_la57; - entry->ecx |= f_pku;/* PKU is not yet implemented for shadow paging. */ if (!tdp_enabled || !boot_cpu_has (X86_FEATURE_OSPKE ))cpuid_entry_clear (entry,X86_FEATURE_PKU );
arch/x86/kvm/svm.c +1 -6
@@ -6060,6 +6060,7 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)cpuid_entry_clear (entry,X86_FEATURE_X2APIC );break ;case 0x7 : +cpuid_entry_clear (entry,X86_FEATURE_PKU );cpuid_entry_clear (entry,X86_FEATURE_MPX );cpuid_entry_clear (entry,X86_FEATURE_INVPCID );break ;
@@ -6120,11 +6121,6 @@ static bool svm_has_wbinvd_exit(void)return true; } -static bool svm_pku_supported (void ) -{ -return false; -} -#define PRE_EX (exit) { .exit_code = (exit), \ .stage = X86_ICPT_PRE_EXCEPT, }#define POST_EX (exit) { .exit_code = (exit), \
@@ -7484,7 +7480,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, .pt_supported = svm_pt_supported, - .pku_supported = svm_pku_supported, .set_supported_cpuid = svm_set_supported_cpuid,
arch/x86/kvm/vmx/capabilities.h +0 -5
@@ -145,11 +145,6 @@ static inline bool vmx_umip_emulated(void)SECONDARY_EXEC_DESC ; } -static inline bool vmx_pku_supported (void ) -{ -return boot_cpu_has (X86_FEATURE_PKU ); -} -static inline bool cpu_has_vmx_rdtscp (void ) { return vmcs_config.cpu_based_2nd_exec_ctrl &
arch/x86/kvm/vmx/vmx.c +0 -1
@@ -7900,7 +7900,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .xsaves_supported = vmx_xsaves_supported, .umip_emulated = vmx_umip_emulated, .pt_supported = vmx_pt_supported, - .pku_supported = vmx_pku_supported, .request_immediate_exit = vmx_request_immediate_exit,
Signature · 1 line
2.24.1
PATCH 21/26 KVM: x86: Handle RDTSCP CPUID adjustment in VMX code
In reply to Sean ChristophersonMove the clearing of the RDTSCP CPUID bit into VMX, which has a separate VMCS control to enable RDTSCP in non-root, to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code. Drop ->rdtscp_supported() since CPUID adjustment was the last remaining user.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/cpuid.c | 3 +-- arch/x86/kvm/svm.c | 6 ------ arch/x86/kvm/vmx/vmx.c | 6 ++++-- 4 files changed, 5 insertions(+), 11 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1144,7 +1144,6 @@ struct kvm_x86_ops {int (*get_tdp_level)(struct kvm_vcpu *vcpu);u64 (*get_mt_mask)(struct kvm_vcpu *vcpu,gfn_t gfn,bool is_mmio);int (*get_lpage_level)(void ); -bool (*rdtscp_supported)(void );void (*set_tdp_cr3)(struct kvm_vcpu *vcpu,unsigned long cr3);
arch/x86/kvm/cpuid.c +1 -2
@@ -410,7 +410,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,unsigned f_gbpages =0 ;unsigned f_lm =0 ;#endif -unsigned f_rdtscp = kvm_x86_ops->rdtscp_supported () ?F (RDTSCP ) :0 ;unsigned f_xsaves = kvm_x86_ops->xsaves_supported () ?F (XSAVES ) :0 ;unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;
@@ -432,7 +431,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,F (MTRR ) |F (PGE ) |F (MCA ) |F (CMOV ) |F (PAT ) |F (PSE36 ) |0 /* Reserved */ | f_nx |0 /* Reserved */ |F (MMXEXT ) |F (MMX ) | -F (FXSR ) |F (FXSR_OPT ) | f_gbpages | f_rdtscp | +F (FXSR ) |F (FXSR_OPT ) | f_gbpages |F (RDTSCP ) | 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW);/* cpuid 1.ecx */ const u32 kvm_cpuid_1_ecx_x86_features =
arch/x86/kvm/svm.c +0 -6
@@ -6096,11 +6096,6 @@ static int svm_get_lpage_level(void)return PT_PDPE_LEVEL ; } -static bool svm_rdtscp_supported (void ) -{ -return boot_cpu_has (X86_FEATURE_RDTSCP ); -} -static bool svm_xsaves_supported (void ) {return boot_cpu_has (X86_FEATURE_XSAVES );
@@ -7476,7 +7471,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .cpuid_update = svm_cpuid_update, - .rdtscp_supported = svm_rdtscp_supported, .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, .pt_supported = svm_pt_supported,
arch/x86/kvm/vmx/vmx.c +4 -2
@@ -7145,6 +7145,10 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)if (vmx_umip_emulated ())cpuid_entry_set (entry,X86_FEATURE_UMIP );break ; +case 0x80000001 : +if (!cpu_has_vmx_rdtscp ()) +cpuid_entry_clear (entry,X86_FEATURE_RDTSCP ); +break ;default :break ; }
@@ -7884,8 +7888,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .cpuid_update = vmx_cpuid_update, - .rdtscp_supported = vmx_rdtscp_supported, - .set_supported_cpuid = vmx_set_supported_cpuid, .has_wbinvd_exit = cpu_has_vmx_wbinvd_exit,
Signature · 1 line
2.24.1
PATCH 22/26 KVM: x86: Handle XSAVES CPUID adjustment in VMX code
In reply to Sean ChristophersonMove the clearing of the XSAVES CPUID bit into VMX, which has a separate VMCS control to enable XSAVES in non-root, to to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code. Add a call to ->set_supported_cpuid() in the leaf 0xD handling so that vendor code can update feature bits in the index=1 sub-leaf (which contains the XSAVES bit) and teach {svm,vmx}_set_supported_cpuid() how to handle non-zero indices.
Drop ->xsaves_supported() since CPUID adjustment was the only user.
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/cpuid.c | 6 ++++-- arch/x86/kvm/svm.c | 9 +++------ arch/x86/kvm/vmx/vmx.c | 9 ++++++++- 4 files changed, 15 insertions(+), 10 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1163,7 +1163,6 @@ struct kvm_x86_ops {void (*handle_exit_irqoff)(struct kvm_vcpu *vcpu,enum exit_fastpath_completion *exit_fastpath); -bool (*xsaves_supported)(void );bool (*umip_emulated)(void );bool (*pt_supported)(void );
arch/x86/kvm/cpuid.c +4 -2
@@ -410,7 +410,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,unsigned f_gbpages =0 ;unsigned f_lm =0 ;#endif -unsigned f_xsaves = kvm_x86_ops->xsaves_supported () ?F (XSAVES ) :0 ;unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;/* cpuid 1.edx */
@@ -467,7 +466,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,/* cpuid 0xD.1.eax */ const u32 kvm_cpuid_D_1_eax_x86_features = -F (XSAVEOPT ) |F (XSAVEC ) |F (XGETBV1 ) | f_xsaves; +F (XSAVEOPT ) |F (XSAVEC ) |F (XGETBV1 ) |F (XSAVES );/* all calls to cpuid_count() should be made on the same cpu */ get_cpu ();
@@ -629,6 +628,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, entry[i].eax &= kvm_cpuid_D_1_eax_x86_features;cpuid_mask (&entry[i].eax,CPUID_D_1_EAX ); entry[i].ebx =0 ; + + kvm_x86_ops->set_supported_cpuid (&entry[i]); +if (entry[i].eax & (F (XSAVES )|F (XSAVEC ))) entry[i].ebx = xstate_required_size(supported,
arch/x86/kvm/svm.c +3 -6
@@ -6054,6 +6054,9 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)static void svm_set_supported_cpuid (struct kvm_cpuid_entry2 *entry) { +if (entry->index) +return ; +switch (entry->function) {case 0x1 :if (avic)
@@ -6096,11 +6099,6 @@ static int svm_get_lpage_level(void)return PT_PDPE_LEVEL ; } -static bool svm_xsaves_supported (void ) -{ -return boot_cpu_has (X86_FEATURE_XSAVES ); -} -static bool svm_umip_emulated (void ) {return false;
@@ -7471,7 +7469,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .cpuid_update = svm_cpuid_update, - .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, .pt_supported = svm_pt_supported,
arch/x86/kvm/vmx/vmx.c +8 -1
@@ -7131,6 +7131,14 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)static void vmx_set_supported_cpuid (struct kvm_cpuid_entry2 *entry) { +if (entry->index) { +if (WARN_ON_ONCE (entry->function !=0xd || entry->index !=1 )) +return ; +if (!vmx_xsaves_supported ()) +cpuid_entry_clear (entry,X86_FEATURE_XSAVES ); +return ; + } +switch (entry->function) {case 0x1 :if (nested)
@@ -7899,7 +7907,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .check_intercept = vmx_check_intercept, .handle_exit_irqoff = vmx_handle_exit_irqoff, - .xsaves_supported = vmx_xsaves_supported, .umip_emulated = vmx_umip_emulated, .pt_supported = vmx_pt_supported,
Signature · 1 line
2.24.1
PATCH 23/26 KVM: x86: Handle Intel PT CPUID adjustment in vendor code
In reply to Sean ChristophersonMove the Processor Trace CPUID adjustment into vendor code to eliminate an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0" pattern in the common CPUID handling code, and to pave the way toward eventually removing ->pt_supported().
No functional change intended.
--- arch/x86/kvm/cpuid.c | 3 +-- arch/x86/kvm/svm.c | 1 + arch/x86/kvm/vmx/vmx.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/cpuid.c +1 -2
@@ -321,7 +321,6 @@ static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,static inline void do_cpuid_7_mask (struct kvm_cpuid_entry2 *entry,int index) { -unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;unsigned f_la57;/* cpuid 7.0.ebx */
@@ -330,7 +329,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)F (BMI2 ) |F (ERMS ) |F (INVPCID ) |F (RTM ) |F (MPX ) |F (RDSEED ) |F (ADX ) |F (SMAP ) |F (AVX512IFMA ) |F (AVX512F ) |F (AVX512PF ) |F (AVX512ER ) |F (AVX512CD ) |F (CLFLUSHOPT ) |F (CLWB ) |F (AVX512DQ ) | -F (SHA_NI ) |F (AVX512BW ) |F (AVX512VL ) | f_intel_pt; +F (SHA_NI ) |F (AVX512BW ) |F (AVX512VL ) |F (INTEL_PT );/* cpuid 7.0.ecx*/ const u32 kvm_cpuid_7_0_ecx_x86_features =
arch/x86/kvm/svm.c +1 -0
@@ -6066,6 +6066,7 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)cpuid_entry_clear (entry,X86_FEATURE_PKU );cpuid_entry_clear (entry,X86_FEATURE_MPX );cpuid_entry_clear (entry,X86_FEATURE_INVPCID ); +cpuid_entry_clear (entry,X86_FEATURE_INTEL_PT );break ;case 0x80000001 :if (nested)
arch/x86/kvm/vmx/vmx.c +2 -0
@@ -7149,6 +7149,8 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)cpuid_entry_clear (entry,X86_FEATURE_MPX );if (!cpu_has_vmx_invpcid ())cpuid_entry_clear (entry,X86_FEATURE_INVPCID ); +if (!vmx_pt_mode_is_host_guest ()) +cpuid_entry_clear (entry,X86_FEATURE_INTEL_PT );if (vmx_umip_emulated ())cpuid_entry_set (entry,X86_FEATURE_UMIP );
Signature · 1 line
2.24.1
PATCH 24/26 KVM: x86: Clear output regs for CPUID 0x14 if PT isn't exposed to guest
In reply to Sean ChristophersonClear the output regs for the main CPUID 0x14 leaf (index=0) if Intel PT isn't exposed to the guest. Leaf 0x14 enumerates Intel PT capabilities and should return zeroes if PT is not supported. Incorrectly reporting PT capabilities is essentially a cosmetic error, i.e. doesn't negatively affect any known kernel, as the existence of PT itself is correctly enumerated via CPUID 0x7.
--- arch/x86/kvm/cpuid.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +3 -1
@@ -651,8 +651,10 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,case 0x14 : {int t, times = entry->eax; -if (!f_intel_pt) +if (!f_intel_pt) { + entry->eax = entry->ebx = entry->ecx = entry->edx =0 ;break ; + }for (t =1 ; t <= times; ++t) {if (*nent >= maxnent)
Signature · 1 line
2.24.1
PATCH 25/26 KVM: x86: Handle main Intel PT CPUID leaf in vendor code
In reply to Sean ChristophersonMove the clearing of the Intel PT CPUID leaf into vendor code to eliminate a call to ->pt_supported(). To handle clearing CPUID 0x14's index>0 sub-leafs, introduce the pattern of adding feature-dependent sub-leafs (index>0 sub-leafs whose existence is enumerated by index=0) after calling ->set_supported_cpuid(). The dependent sub-leafs pattern can be reused for future (Intel) features such as SGX to allow vendor code to disable the feature, e.g. via module param, without having to add a feature specific kvm_x86_ops hook.
No functional change intended.
--- arch/x86/kvm/cpuid.c | 32 ++++++++++++++++---------------- arch/x86/kvm/svm.c | 3 +++ arch/x86/kvm/vmx/vmx.c | 4 ++++ 3 files changed, 23 insertions(+), 16 deletions(-)
arch/x86/kvm/cpuid.c +16 -16
@@ -409,7 +409,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,unsigned f_gbpages =0 ;unsigned f_lm =0 ;#endif -unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;/* cpuid 1.edx */ const u32 kvm_cpuid_1_edx_x86_features =
@@ -648,22 +647,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,break ; }/* Intel PT */ -case 0x14 : { -int t, times = entry->eax; - -if (!f_intel_pt) { - entry->eax = entry->ebx = entry->ecx = entry->edx =0 ; -break ; - } - -for (t =1 ; t <= times; ++t) { -if (*nent >= maxnent) - goto out; -do_host_cpuid (&entry[t], function, t); - ++*nent; - } +case 0x14 :break ; - }case KVM_CPUID_SIGNATURE : {static const char signature[12 ] ="KVMKVMKVM\0\0" ;const u32 *sigptr = (const u32 *)signature;
@@ -778,6 +763,21 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, kvm_x86_ops->set_supported_cpuid (entry); +/* +* Add feature-dependent sub-leafs after ->set_supported_cpuid() to +* properly handle the feature being disabled by SVM/VMX. +*/ +if (function ==0x14 ) { +int t, times = entry->eax; + +for (t =1 ; t <= times; ++t) { +if (*nent >= maxnent) + goto out; +do_host_cpuid (&entry[t], function, t); + ++*nent; + } + } + r =0 ; out:
arch/x86/kvm/svm.c +3 -0
@@ -6068,6 +6068,9 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)cpuid_entry_clear (entry,X86_FEATURE_INVPCID );cpuid_entry_clear (entry,X86_FEATURE_INTEL_PT );break ; +case 0x14 : + entry->eax = entry->ebx = entry->ecx = entry->edx =0 ; +break ;case 0x80000001 :if (nested)cpuid_entry_set (entry,X86_FEATURE_SVM );
arch/x86/kvm/vmx/vmx.c +4 -0
@@ -7155,6 +7155,10 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)if (vmx_umip_emulated ())cpuid_entry_set (entry,X86_FEATURE_UMIP );break ; +case 0x14 : +if (!vmx_pt_mode_is_host_guest ()) + entry->eax = entry->ebx = entry->ecx = entry->edx =0 ; +break ;case 0x80000001 :if (!cpu_has_vmx_rdtscp ())cpuid_entry_clear (entry,X86_FEATURE_RDTSCP );
Signature · 1 line
2.24.1
Re: [PATCH 25/26] KVM: x86: Handle main Intel PT CPUID leaf in vendor code
Quoted 46 lines · Sean Christopherson
arch/x86/kvm/cpuid.c +7
-16@@ -409,7 +409,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,unsigned f_gbpages =0 ;unsigned f_lm =0 ;#endif -unsigned f_intel_pt = kvm_x86_ops->pt_supported () ?F (INTEL_PT ) :0 ;/* cpuid 1.edx */ const u32 kvm_cpuid_1_edx_x86_features =@@ -648,22 +647,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,break ; }/* Intel PT */ -case 0x14 : { -int t, times = entry->eax; - -if (!f_intel_pt) { - entry->eax = entry->ebx = entry->ecx = entry->edx =0 ; -break ; - } - -for (t =1 ; t <= times; ++t) { -if (*nent >= maxnent) - goto out; -do_host_cpuid (&entry[t], function, t); - ++*nent; - } +case 0x14 :break ; - }case KVM_CPUID_SIGNATURE : {static const char signature[12 ] ="KVMKVMKVM\0\0" ;const u32 *sigptr = (const u32 *)signature;@@ -778,6 +763,21 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, kvm_x86_ops->set_supported_cpuid (entry); +/* +* Add feature-dependent sub-leafs after ->set_supported_cpuid() to +* properly handle the feature being disabled by SVM/VMX. +*/ +if (function ==0x14 ) { +int t, times = entry->eax;
arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, · line 781
Quoted 10 lines
arch/x86/kvm/cpuid.c +9
-0+ +for (t =1 ; t <= times; ++t) { +if (*nent >= maxnent) + goto out; +do_host_cpuid (&entry[t], function, t); + ++*nent; + } + } + r =0 ;
I belatedly thought of an alternative that I think I like better. Instead of adding the sub-leafs in common code, introduce a new kvm_x86_ops hook to add vendor specific sub-leafs, e.g.:
kvm_x86_ops->set_supported_cpuid(entry);
r = kvm_x86_ops->add_cpuid_sub_leafs(entry, nent, maxent,
do_host_cpuid);That gets Intel PT (and SGX if/when it gets merged) sub-leafs out of the common x86 code without polluting ->set_supported_cpuid with the extra params and return value. The other hiccup is that SGX will want access to cpuid_mask(), but I don't see an issue with moving that to cpuid.h.
PATCH 26/26 KVM: VMX: Directly query Intel PT mode when refreshing PMUs
In reply to Sean ChristophersonUse vmx_pt_mode_is_host_guest() in intel_pmu_refresh() instead of bouncing through kvm_x86_ops->pt_supported and remove ->pt_supported() as the PMU code was the last remaining user.
Opportunistically clean up the wording of a comment that referenced kvm_x86_ops->pt_supported().
No functional change intended.
--- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c | 6 ------ arch/x86/kvm/vmx/pmu_intel.c | 2 +- arch/x86/kvm/vmx/vmx.c | 6 ------ arch/x86/kvm/x86.c | 7 +++---- 5 files changed, 4 insertions(+), 18 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -1
@@ -1164,7 +1164,6 @@ struct kvm_x86_ops { enum exit_fastpath_completion *exit_fastpath);bool (*umip_emulated)(void ); -bool (*pt_supported)(void );int (*check_nested_events)(struct kvm_vcpu *vcpu,bool external_intr);void (*request_immediate_exit)(struct kvm_vcpu *vcpu);
arch/x86/kvm/svm.c +0 -6
@@ -6108,11 +6108,6 @@ static bool svm_umip_emulated(void)return false; } -static bool svm_pt_supported (void ) -{ -return false; -} -static bool svm_has_wbinvd_exit (void ) {return true;
@@ -7474,7 +7469,6 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .cpuid_update = svm_cpuid_update, .umip_emulated = svm_umip_emulated, - .pt_supported = svm_pt_supported, .set_supported_cpuid = svm_set_supported_cpuid,
arch/x86/kvm/vmx/pmu_intel.c +1 -1
@@ -330,7 +330,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->global_ovf_ctrl_mask = pmu->global_ctrl_mask & ~(MSR_CORE_PERF_GLOBAL_OVF_CTRL_OVF_BUF |MSR_CORE_PERF_GLOBAL_OVF_CTRL_COND_CHGD ); -if (kvm_x86_ops->pt_supported ()) +if (vmx_pt_mode_is_host_guest ()) pmu->global_ovf_ctrl_mask &= ~MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI ;
arch/x86/kvm/vmx/vmx.c +0 -6
@@ -6318,11 +6318,6 @@ static bool vmx_has_emulated_msr(u32 index) } } -static bool vmx_pt_supported (void ) -{ -return vmx_pt_mode_is_host_guest (); -} -static void vmx_recover_nmi_blocking (struct vcpu_vmx *vmx) {u32 exit_intr_info;
@@ -7914,7 +7909,6 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .check_intercept = vmx_check_intercept, .handle_exit_irqoff = vmx_handle_exit_irqoff, .umip_emulated = vmx_umip_emulated, - .pt_supported = vmx_pt_supported, .request_immediate_exit = vmx_request_immediate_exit,
arch/x86/kvm/x86.c +3 -4
@@ -2805,10 +2805,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) !guest_cpuid_has(vcpu, X86_FEATURE_XSAVES))return 1 ;/* -* We do support PT if kvm_x86_ops->pt_supported(), but we do -* not support IA32_XSS[bit 8]. Guests will have to use -* RDMSR/WRMSR rather than XSAVES/XRSTORS to save/restore PT -* MSRs. +* KVM supports exposing PT to the guest, but does not support +* IA32_XSS[bit 8]. Guests have to use RDMSR/WRMSR rather than +* XSAVES/XRSTORS to save/restore PT MSRs. */ if (data !=0 )return 1 ;
Signature · 1 line
2.24.1