diff mbox series

[kvm-unit-tests,38/39] nVMX: Add helper to check if VPID is supported

Message ID 20211125012857.508243-39-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86/access: nVMX: Big overhaul | expand

Commit Message

Sean Christopherson Nov. 25, 2021, 1:28 a.m. UTC
Add a helper to check for VPID support to deduplicate code, now and in
the future.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/vmx.h       | 6 ++++++
 x86/vmx_tests.c | 6 ++----
 2 files changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/x86/vmx.h b/x86/vmx.h
index 401715c..4423986 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -844,6 +844,12 @@  static inline bool is_invept_type_supported(u64 type)
 	return ept_vpid.val & (EPT_CAP_INVEPT_SINGLE << (type - INVEPT_SINGLE));
 }
 
+static inline bool is_vpid_supported(void)
+{
+	return (ctrl_cpu_rev[0].clr & CPU_SECONDARY) &&
+	       (ctrl_cpu_rev[1].clr & CPU_VPID);
+}
+
 static inline bool is_invvpid_supported(void)
 {
 	return ept_vpid.val & VPID_CAP_INVVPID;
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 316105b..172d385 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -3304,8 +3304,7 @@  static void invvpid_test(void)
 	unsigned types = 0;
 	unsigned type;
 
-	if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
-	    !(ctrl_cpu_rev[1].clr & CPU_VPID))
+	if (!is_vpid_supported())
 		test_skip("VPID not supported");
 
 	if (!is_invvpid_supported())
@@ -4099,8 +4098,7 @@  static void test_vpid(void)
 	u16 vpid = 0x0000;
 	int i;
 
-	if (!((ctrl_cpu_rev[0].clr & CPU_SECONDARY) &&
-	    (ctrl_cpu_rev[1].clr & CPU_VPID))) {
+	if (!is_vpid_supported()) {
 		printf("Secondary controls and/or VPID not supported\n");
 		return;
 	}