public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Add a wrapper for reading INVPCID/INVEPT/INVVPID type
@ 2021-10-11 19:46 Vipin Sharma
  2021-10-11 20:23 ` Sean Christopherson
  0 siblings, 1 reply; 7+ messages in thread
From: Vipin Sharma @ 2021-10-11 19:46 UTC (permalink / raw)
  To: pbonzini, seanjc, dmatlack; +Cc: kvm, linux-kernel, Vipin Sharma

Add a common helper function to read invalidation type specified by a
trapped INVPCID/INVEPT/INVVPID instruction.

Add a symbol constant for max INVPCID type.

No functional change intended.

Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
 arch/x86/include/asm/invpcid.h |  1 +
 arch/x86/kvm/vmx/nested.c      |  4 ++--
 arch/x86/kvm/vmx/vmx.c         |  4 ++--
 arch/x86/kvm/vmx/vmx.h         | 12 ++++++++++++
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/invpcid.h b/arch/x86/include/asm/invpcid.h
index 734482afbf81..b5ac26784c1b 100644
--- a/arch/x86/include/asm/invpcid.h
+++ b/arch/x86/include/asm/invpcid.h
@@ -21,6 +21,7 @@ static inline void __invpcid(unsigned long pcid, unsigned long addr,
 #define INVPCID_TYPE_SINGLE_CTXT	1
 #define INVPCID_TYPE_ALL_INCL_GLOBAL	2
 #define INVPCID_TYPE_ALL_NON_GLOBAL	3
+#define INVPCID_TYPE_MAX		3
 
 /* Flush all mappings for a given pcid and addr, not including globals. */
 static inline void invpcid_flush_one(unsigned long pcid,
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index af1bbb73430a..f0605a99e0fc 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -5392,7 +5392,7 @@ static int handle_invept(struct kvm_vcpu *vcpu)
 		return 1;
 
 	vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
-	type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
+	type = vmx_read_invalidation_type(vcpu, vmx_instruction_info);
 
 	types = (vmx->nested.msrs.ept_caps >> VMX_EPT_EXTENT_SHIFT) & 6;
 
@@ -5472,7 +5472,7 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)
 		return 1;
 
 	vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
-	type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
+	type = vmx_read_invalidation_type(vcpu, vmx_instruction_info);
 
 	types = (vmx->nested.msrs.vpid_caps &
 			VMX_VPID_EXTENT_SUPPORTED_MASK) >> 8;
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 1c8b2b6e7ed9..77f72a41dde3 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -5502,9 +5502,9 @@ static int handle_invpcid(struct kvm_vcpu *vcpu)
 	}
 
 	vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
-	type = kvm_register_read(vcpu, (vmx_instruction_info >> 28) & 0xf);
+	type = vmx_read_invalidation_type(vcpu, vmx_instruction_info);
 
-	if (type > 3) {
+	if (type > INVPCID_TYPE_MAX) {
 		kvm_inject_gp(vcpu, 0);
 		return 1;
 	}
diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
index 592217fd7d92..eeafcce57df7 100644
--- a/arch/x86/kvm/vmx/vmx.h
+++ b/arch/x86/kvm/vmx/vmx.h
@@ -522,4 +522,16 @@ static inline bool vmx_guest_state_valid(struct kvm_vcpu *vcpu)
 
 void dump_vmcs(struct kvm_vcpu *vcpu);
 
+/*
+ * When handling a VM-exit for one of INVPCID, INVEPT or INVVPID, read the type
+ * of invalidation specified by the instruction.
+ */
+static inline unsigned long vmx_read_invalidation_type(struct kvm_vcpu *vcpu,
+						       u32 vmx_instr_info)
+{
+	u32 vmx_instr_reg2 = (vmx_instr_info >> 28) & 0xf;
+
+	return kvm_register_read(vcpu, vmx_instr_reg2);
+}
+
 #endif /* __KVM_X86_VMX_H */
-- 
2.33.0.882.g93a45727a2-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-02 19:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-11 19:46 [PATCH] KVM: VMX: Add a wrapper for reading INVPCID/INVEPT/INVVPID type Vipin Sharma
2021-10-11 20:23 ` Sean Christopherson
2021-10-11 20:51   ` Jim Mattson
2021-10-14 16:54     ` Sean Christopherson
2021-10-14 17:05       ` Jim Mattson
2021-11-02 18:12         ` Vipin Sharma
2021-11-02 19:19           ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox