Skip to contentSkip to conversation

KVM VMX: Make sure single type invvpid is supported before issuing this instruction

PATCH Superseded Gui Jianfeng 3 participants 8 messages Jun 3, 2010 – Jun 4, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM VMX: Make sure single type invvpid is supported before issuing this instruction

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +2 -0
index 104cf86..6fa40d0 100644
@@ -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_EPT_INVVPID_SINGLE_CONTEXT_BIT      (1ull << (41 - 32))
+
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
 #define VMX_EPT_MT_EPTE_SHIFT			3
arch/x86/kvm/vmx.c +7 -1
index 0e561a5..e2d12bf 100644
@@ -355,6 +355,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_EPT_INVVPID_SINGLE_CONTEXT_BIT;
+}
+
 static inline bool cpu_has_vmx_ept(void)
 {
 	return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -499,7 +504,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)
Signature · 1 line
1.6.5.2
#1 lore raw
Quoted 14 lines · On Thursday 03 June 2010 16:44:34 Gui Jianfeng wrote:

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +0 -0
index 104cf86..6fa40d0 100644

arch/x86/include/asm/vmx.h enum vmcs_field { · line 377

Quoted 2 lines
arch/x86/include/asm/vmx.h +0 -0
@@ -376,6 +376,8 @@ enum vmcs_field {
 #define VMX_EPT_EXTENT_CONTEXT_BIT		(1ull << 25)
 #define VMX_EPT_EXTENT_GLOBAL_BIT		(1ull << 26)

Hi Jianfeng

arch/x86/include/asm/vmx.h enum vmcs_field { · line 380

Quoted 3 lines
arch/x86/include/asm/vmx.h +2 -0
+#define VMX_EPT_INVVPID_SINGLE_CONTEXT_BIT      (1ull << (41 - 32))
+

VPID is not a part of EPT. And you can keep consistent with the names above, like:
VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT

And comments it later maybe better than indirectly (41 - 32)?

Others looks fine to me.

--
regards
Yang, Sheng

Quoted 29 lines
arch/x86/include/asm/vmx.h +0 -0
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
 #define VMX_EPT_MT_EPTE_SHIFT			3
arch/x86/kvm/vmx.c +7 -1
index 0e561a5..e2d12bf 100644
@@ -355,6 +355,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_EPT_INVVPID_SINGLE_CONTEXT_BIT;
+}
+
 static inline bool cpu_has_vmx_ept(void)
 {
 	return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -499,7 +504,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)
#2 lore raw
Quoted 19 lines · Sheng Yang
Quoted 14 lines · On Thursday 03 June 2010 16:44:34 Gui Jianfeng wrote:

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +0 -0
index 104cf86..6fa40d0 100644

arch/x86/include/asm/vmx.h enum vmcs_field { · line 377

Quoted 2 lines
arch/x86/include/asm/vmx.h +0 -0
@@ -376,6 +376,8 @@ enum vmcs_field {
 #define VMX_EPT_EXTENT_CONTEXT_BIT		(1ull << 25)
 #define VMX_EPT_EXTENT_GLOBAL_BIT		(1ull << 26)

Hi Jianfeng

Quoted 8 lines

arch/x86/include/asm/vmx.h enum vmcs_field { · line 380

Quoted 2 lines
arch/x86/include/asm/vmx.h +2 -0
+#define VMX_EPT_INVVPID_SINGLE_CONTEXT_BIT      (1ull << (41 - 32))
+

VPID is not a part of EPT. And you can keep consistent with the names above, like:
VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT

And comments it later maybe better than indirectly (41 - 32)?

Ok, will post an updated version.

Thanks,
Gui

Quoted 37 lines

Others looks fine to me.

--
regards
Yang, Sheng

Quoted 29 lines
arch/x86/include/asm/vmx.h +0 -0
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
 #define VMX_EPT_MT_EPTE_SHIFT			3
arch/x86/kvm/vmx.c +7 -1
index 0e561a5..e2d12bf 100644
@@ -355,6 +355,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_EPT_INVVPID_SINGLE_CONTEXT_BIT;
+}
+
 static inline bool cpu_has_vmx_ept(void)
 {
 	return vmcs_config.cpu_based_2nd_exec_ctrl &
@@ -499,7 +504,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)
#3 lore raw

PATCH v2 1/1 KVM VMX: Make sure single type invvpid is supported before issuing invvpid instruction

In reply to Sheng Yang

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |   14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +2 -0
index 104cf86..4e78b25 100644
@@ -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)
+
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
 #define VMX_EPT_MT_EPTE_SHIFT			3
arch/x86/kvm/vmx.c +13 -1
index 0e561a5..f363fe3 100644
@@ -355,6 +355,17 @@ 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)
+{
+	/* 
+	 *  bit 41 of IA32_VMX_EPT_VPID_CAP MSR indicates whehter the 
+	 *  single-context INVVPID type is supported. vmx_capability.vpid 
+	 *  represents the higher 32 bits of IA32_VMX_EPT_VPID_CAP MSR, so
+	 *  VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT(bit 9) is used here.
+	 */
+	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 &
@@ -499,7 +510,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)
Signature · 1 line
1.6.5.2
#4 lore raw

Re: [PATCH v2] KVM VMX: Make sure single type invvpid is supported before issuing invvpid instruction

Quoted 28 lines · On Thursday 03 June 2010 17:45:22 Gui Jianfeng wrote:

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |   14 +++++++++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +2 -0
index 104cf86..4e78b25 100644
@@ -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)
+
 #define VMX_EPT_DEFAULT_GAW			3
 #define VMX_EPT_MAX_GAW				0x4
 #define VMX_EPT_MT_EPTE_SHIFT			3
arch/x86/kvm/vmx.c +0 -0
index 0e561a5..f363fe3 100644
@@ -355,6 +355,17 @@ static inline bool cpu_has_vmx_invept_global(void)
 	return vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT;

arch/x86/kvm/vmx.c static inline bool cpu_has_vmx_invept_global(void) · line 365

Quoted 10 lines
arch/x86/kvm/vmx.c +8 -0
 }
 
+static inline bool cpu_has_vmx_invvpid_single(void)
+{
+	/*
+	 *  bit 41 of IA32_VMX_EPT_VPID_CAP MSR indicates whehter the
+	 *  single-context INVVPID type is supported. vmx_capability.vpid
+	 *  represents the higher 32 bits of IA32_VMX_EPT_VPID_CAP MSR, so
+	 *  VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT(bit 9) is used here.
+	 */

The comment is better with the VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT marco, since it would also applied to other similar ones.

And I have checked my sent mail, found the word "later" maybe the reason you put the comment here... In fact I meant something like

#define VMX_EPT_INVVPID_SINGLE_CONTEXT_BIT (1 << 9) /* (41 - 32) */

Sorry if the word caused confusing...

--
regards
Yang, Sheng

Quoted 16 lines
arch/x86/kvm/vmx.c +5 -1
+	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 &
@@ -499,7 +510,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)
#5 lore raw

PATCH v3 1/1 KVM VMX: Make sure single type invvpid is supported before issuing invvpid instruction

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +2 -0
index 104cf86..b4e2840 100644
@@ -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
arch/x86/kvm/vmx.c +7 -1
index 0e561a5..240a407 100644
@@ -355,6 +355,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 &
@@ -499,7 +504,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)
Signature · 1 line
1.6.5.2
Reviewed-by on v3 1/1
#6 lore raw

Re: [PATCH v3] KVM VMX: Make sure single type invvpid is supported before issuing invvpid instruction

Quoted 4 lines · On Friday 04 June 2010 08:51:39 Gui Jianfeng wrote:

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

--
regards
Yang, Sheng

Quoted 44 lines
---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/vmx.h +1 -0
index 104cf86..b4e2840 100644
@@ -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
arch/x86/kvm/vmx.c +7 -1
index 0e561a5..240a407 100644
@@ -355,6 +355,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 &
@@ -499,7 +504,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)
#7 lore raw

Re: [PATCH v3] KVM VMX: Make sure single type invvpid is supported before issuing invvpid instruction

In reply to Gui Jianfeng
Quoted 8 lines · Gui Jianfeng

According to SDM, we need check whether single-context INVVPID type is supported before issuing invvpid instruction.

---
 arch/x86/include/asm/vmx.h |    2 ++
 arch/x86/kvm/vmx.c         |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)

Applied, thanks.