Skip to content

Commit

Permalink
nVMX: Add helper to check if VPID is supported
Browse files Browse the repository at this point in the history
Add a helper to check for VPID support to deduplicate code, now and in
the future.

Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
sean-jc authored and bonzini committed Nov 26, 2021
1 parent 6250b38 commit 682cc79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions x86/vmx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions x86/vmx_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 682cc79

Please sign in to comment.