KVM: VMX: Make sure single type invvpid is supported before issuing invvpid instruction
authorGui Jianfeng <guijianfeng@cn.fujitsu.com>
Fri, 4 Jun 2010 00:51:39 +0000 (08:51 +0800)
committerAvi Kivity <avi@redhat.com>
Sun, 1 Aug 2010 07:39:26 +0000 (10:39 +0300)
According to SDM, we need check whether single-context INVVPID type is supported
before issuing invvpid instruction.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
Reviewed-by: Sheng Yang <sheng@linux.intel.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/include/asm/vmx.h
arch/x86/kvm/vmx.c

index 104cf86a75627099f558f69fff9b5d4873b5fad2..b4e28400c9ff4f68934788ffa39a453f565fd306 100644 (file)
@@ -376,6 +376,8 @@ enum vmcs_field {
 #define VMX_EPT_EXTENT_CONTEXT_BIT             (1ull << 25)
 #define VMX_EPT_EXTENT_GLOBAL_BIT              (1ull << 26)
 
+#define VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT      (1ull << 9) /* (41 - 32) */
+
 #define VMX_EPT_DEFAULT_GAW                    3
 #define VMX_EPT_MAX_GAW                                0x4
 #define VMX_EPT_MT_EPTE_SHIFT                  3
index 2201e38162059cec8e64adc14750b75cce390297..945265361885c7a7ba85220a0f99f11397395936 100644 (file)
@@ -360,6 +360,11 @@ static inline bool cpu_has_vmx_invept_global(void)
        return vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT;
 }
 
+static inline bool cpu_has_vmx_invvpid_single(void)
+{
+       return vmx_capability.vpid & VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT;
+}
+
 static inline bool cpu_has_vmx_ept(void)
 {
        return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -504,7 +509,8 @@ static inline void vpid_sync_vcpu_all(struct vcpu_vmx *vmx)
        if (vmx->vpid == 0)
                return;
 
-       __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
+       if (cpu_has_vmx_invvpid_single())
+               __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
 }
 
 static inline void ept_sync_global(void)