Message ID | 20190712082907.29137-2-tao3.xu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: x86: Enable user wait instructions | expand |
On Fri, Jul 12, 2019 at 04:29:05PM +0800, Tao Xu wrote: > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > index 46af3a5e9209..a4d5da34b306 100644 > --- a/arch/x86/kvm/vmx/nested.c > +++ b/arch/x86/kvm/vmx/nested.c > @@ -2048,6 +2048,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) > SECONDARY_EXEC_ENABLE_INVPCID | > SECONDARY_EXEC_RDTSCP | > SECONDARY_EXEC_XSAVES | > + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | > SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | > SECONDARY_EXEC_APIC_REGISTER_VIRT | > SECONDARY_EXEC_ENABLE_VMFUNC); > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index d98eac371c0a..f411c9ae5589 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -2247,6 +2247,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, > SECONDARY_EXEC_RDRAND_EXITING | > SECONDARY_EXEC_ENABLE_PML | > SECONDARY_EXEC_TSC_SCALING | > + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | > SECONDARY_EXEC_PT_USE_GPA | > SECONDARY_EXEC_PT_CONCEAL_VMX | > SECONDARY_EXEC_ENABLE_VMFUNC | > @@ -3984,6 +3985,25 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) > } > } > > + if (vmcs_config.cpu_based_2nd_exec_ctrl & > + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE) { This should be aligned with the beginning of the conditional. Alternatively, add a vmx_waitpkg_supported() helper, which is fairly ubiquitous even when there is only a single call site. > + /* Exposing WAITPKG only when WAITPKG is exposed */ No need for this comment. It's also oddly worded, e.g. the second "exposed" should probably be "enabled"? > + bool waitpkg_enabled = > + guest_cpuid_has(vcpu, X86_FEATURE_WAITPKG); > + > + if (!waitpkg_enabled) > + exec_control &= ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; > + > + if (nested) { > + if (waitpkg_enabled) > + vmx->nested.msrs.secondary_ctls_high |= > + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; > + else > + vmx->nested.msrs.secondary_ctls_high &= > + ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; > + } > + } > + > vmx->secondary_exec_control = exec_control; > } > > -- > 2.20.1 >
On 7/12/2019 11:13 PM, Sean Christopherson wrote: > On Fri, Jul 12, 2019 at 04:29:05PM +0800, Tao Xu wrote: >> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c >> index 46af3a5e9209..a4d5da34b306 100644 >> --- a/arch/x86/kvm/vmx/nested.c >> +++ b/arch/x86/kvm/vmx/nested.c >> @@ -2048,6 +2048,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) >> SECONDARY_EXEC_ENABLE_INVPCID | >> SECONDARY_EXEC_RDTSCP | >> SECONDARY_EXEC_XSAVES | >> + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | >> SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | >> SECONDARY_EXEC_APIC_REGISTER_VIRT | >> SECONDARY_EXEC_ENABLE_VMFUNC); >> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c >> index d98eac371c0a..f411c9ae5589 100644 >> --- a/arch/x86/kvm/vmx/vmx.c >> +++ b/arch/x86/kvm/vmx/vmx.c >> @@ -2247,6 +2247,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, >> SECONDARY_EXEC_RDRAND_EXITING | >> SECONDARY_EXEC_ENABLE_PML | >> SECONDARY_EXEC_TSC_SCALING | >> + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | >> SECONDARY_EXEC_PT_USE_GPA | >> SECONDARY_EXEC_PT_CONCEAL_VMX | >> SECONDARY_EXEC_ENABLE_VMFUNC | >> @@ -3984,6 +3985,25 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) >> } >> } >> >> + if (vmcs_config.cpu_based_2nd_exec_ctrl & >> + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE) { > > This should be aligned with the beginning of the conditional. > Alternatively, add a vmx_waitpkg_supported() helper, which is fairly > ubiquitous even when there is only a single call site. > OK, Thank you for your suggestion. >> + /* Exposing WAITPKG only when WAITPKG is exposed */ > No need for this comment. It's also oddly worded, e.g. the second > "exposed" should probably be "enabled"? > >> + bool waitpkg_enabled = >> + guest_cpuid_has(vcpu, X86_FEATURE_WAITPKG); >> + >> + if (!waitpkg_enabled) >> + exec_control &= ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; >> + >> + if (nested) { >> + if (waitpkg_enabled) >> + vmx->nested.msrs.secondary_ctls_high |= >> + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; >> + else >> + vmx->nested.msrs.secondary_ctls_high &= >> + ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; >> + } >> + } >> + >> vmx->secondary_exec_control = exec_control; >> } >> >> -- >> 2.20.1 >>
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index a39136b0d509..8f00882664d3 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -69,6 +69,7 @@ #define SECONDARY_EXEC_PT_USE_GPA 0x01000000 #define SECONDARY_EXEC_MODE_BASED_EPT_EXEC 0x00400000 #define SECONDARY_EXEC_TSC_SCALING 0x02000000 +#define SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE 0x04000000 #define PIN_BASED_EXT_INTR_MASK 0x00000001 #define PIN_BASED_NMI_EXITING 0x00000008 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 4992e7c99588..7d2cd4066f64 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -402,7 +402,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ | 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); + F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B) | 0 /*WAITPKG*/; /* cpuid 7.0.edx*/ const u32 kvm_cpuid_7_0_edx_x86_features = diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 46af3a5e9209..a4d5da34b306 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2048,6 +2048,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12) SECONDARY_EXEC_ENABLE_INVPCID | SECONDARY_EXEC_RDTSCP | SECONDARY_EXEC_XSAVES | + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | SECONDARY_EXEC_APIC_REGISTER_VIRT | SECONDARY_EXEC_ENABLE_VMFUNC); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d98eac371c0a..f411c9ae5589 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2247,6 +2247,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, SECONDARY_EXEC_RDRAND_EXITING | SECONDARY_EXEC_ENABLE_PML | SECONDARY_EXEC_TSC_SCALING | + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE | SECONDARY_EXEC_PT_USE_GPA | SECONDARY_EXEC_PT_CONCEAL_VMX | SECONDARY_EXEC_ENABLE_VMFUNC | @@ -3984,6 +3985,25 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx) } } + if (vmcs_config.cpu_based_2nd_exec_ctrl & + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE) { + /* Exposing WAITPKG only when WAITPKG is exposed */ + bool waitpkg_enabled = + guest_cpuid_has(vcpu, X86_FEATURE_WAITPKG); + + if (!waitpkg_enabled) + exec_control &= ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; + + if (nested) { + if (waitpkg_enabled) + vmx->nested.msrs.secondary_ctls_high |= + SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; + else + vmx->nested.msrs.secondary_ctls_high &= + ~SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE; + } + } + vmx->secondary_exec_control = exec_control; }