Add a helper to deduplicate code, now and in the future, and to avoid a RDMSR every time a VPID test wants to do a basic functionality check. Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> --- x86/vmx.h | 8 ++++++++ x86/vmx_tests.c | 17 +++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/x86/vmx.h b/x86/vmx.h index 4936120..289f175 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -823,6 +823,14 @@ static inline bool is_invept_type_supported(u64 type) return ept_vpid.val & (EPT_CAP_INVEPT_SINGLE << (type - INVEPT_SINGLE)); } +static inline bool is_invvpid_type_supported(unsigned long type) +{ + if (type < INVVPID_ADDR || type > INVVPID_CONTEXT_LOCAL) + return false; + + return ept_vpid.val & (VPID_CAP_INVVPID_ADDR << (type - INVVPID_ADDR)); +} + extern u64 *bsp_vmxon_region; extern bool launched; diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 507e485..950f527 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -3161,14 +3161,7 @@ static void ept_access_test_force_2m_page(void) static bool invvpid_valid(u64 type, u64 vpid, u64 gla) { - u64 msr = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP); - - TEST_ASSERT(msr & VPID_CAP_INVVPID); - - if (type < INVVPID_ADDR || type > INVVPID_CONTEXT_LOCAL) - return false; - - if (!(msr & (1ull << (type + VPID_CAP_INVVPID_TYPES_SHIFT)))) + if (!is_invvpid_type_supported(type)) return false; if (vpid >> 16) @@ -3321,13 +3314,13 @@ static void invvpid_test(void) if (!(msr & VPID_CAP_INVVPID)) test_skip("INVVPID not supported.\n"); - if (msr & VPID_CAP_INVVPID_ADDR) + if (is_invvpid_type_supported(INVVPID_ADDR)) types |= 1u << INVVPID_ADDR; - if (msr & VPID_CAP_INVVPID_CXTGLB) + if (is_invvpid_type_supported(INVVPID_CONTEXT_GLOBAL)) types |= 1u << INVVPID_CONTEXT_GLOBAL; - if (msr & VPID_CAP_INVVPID_ALL) + if (is_invvpid_type_supported(INVVPID_ALL)) types |= 1u << INVVPID_ALL; - if (msr & VPID_CAP_INVVPID_CXTLOC) + if (is_invvpid_type_supported(INVVPID_CONTEXT_LOCAL)) types |= 1u << INVVPID_CONTEXT_LOCAL; if (!types) -- 2.34.0.rc2.393.gf8c9666880-goog