aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWanpeng Li <wanpeng.li@hotmail.com>2017-10-18 19:02:19 -0400
committerRadim Krčmář <rkrcmar@redhat.com>2017-10-20 12:05:01 -0400
commit61f1dd9099aba56b7e6e3c3c4b9ad13199bba06e (patch)
tree32b7ad5b347661dc5559e5acb6542a718ad5d3dd
parent575b3a2cb439b03fd603ea77c73c76f3ed237596 (diff)
KVM: VMX: Fix VPID capability detection
In my setup, EPT is not exposed to L1, the VPID capability is exposed and can be observed by vmxcap tool in L1: INVVPID supported yes Individual-address INVVPID yes Single-context INVVPID yes All-context INVVPID yes Single-context-retaining-globals INVVPID yes However, the module parameter of VPID observed in L1 is always N, the cpu_has_vmx_invvpid() check in L1 KVM fails since vmx_capability.vpid is 0 and it is not read from MSR due to EPT is not exposed. The VPID can be used to tag linear mappings when EPT is not enabled. However, current logic just detects VPID capability if EPT is enabled, this patch fixes it. Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Jim Mattson <jmattson@google.com> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
-rw-r--r--arch/x86/kvm/vmx.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index dba0f6ad4e57..e6c8ffa84968 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3681,14 +3681,25 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
3681 SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE | 3681 SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
3682 SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY); 3682 SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY);
3683 3683
3684 rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP,
3685 &vmx_capability.ept, &vmx_capability.vpid);
3686
3684 if (_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) { 3687 if (_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) {
3685 /* CR3 accesses and invlpg don't need to cause VM Exits when EPT 3688 /* CR3 accesses and invlpg don't need to cause VM Exits when EPT
3686 enabled */ 3689 enabled */
3687 _cpu_based_exec_control &= ~(CPU_BASED_CR3_LOAD_EXITING | 3690 _cpu_based_exec_control &= ~(CPU_BASED_CR3_LOAD_EXITING |
3688 CPU_BASED_CR3_STORE_EXITING | 3691 CPU_BASED_CR3_STORE_EXITING |
3689 CPU_BASED_INVLPG_EXITING); 3692 CPU_BASED_INVLPG_EXITING);
3690 rdmsr(MSR_IA32_VMX_EPT_VPID_CAP, 3693 } else if (vmx_capability.ept) {
3691 vmx_capability.ept, vmx_capability.vpid); 3694 vmx_capability.ept = 0;
3695 pr_warn_once("EPT CAP should not exist if not support "
3696 "1-setting enable EPT VM-execution control\n");
3697 }
3698 if (!(_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_VPID) &&
3699 vmx_capability.vpid) {
3700 vmx_capability.vpid = 0;
3701 pr_warn_once("VPID CAP should not exist if not support "
3702 "1-setting enable VPID VM-execution control\n");
3692 } 3703 }
3693 3704
3694 min = VM_EXIT_SAVE_DEBUG_CONTROLS | VM_EXIT_ACK_INTR_ON_EXIT; 3705 min = VM_EXIT_SAVE_DEBUG_CONTROLS | VM_EXIT_ACK_INTR_ON_EXIT;