KVM: selftests: Use vcpu_{set,clear}_cpuid_feature() in nVMX state test
authorSean Christopherson <seanjc@google.com>
Tue, 14 Jun 2022 20:06:53 +0000 (20:06 +0000)
committerSean Christopherson <seanjc@google.com>
Thu, 14 Jul 2022 01:14:19 +0000 (18:14 -0700)
Use vcpu_{set,clear}_cpuid_feature() to toggle nested VMX support in the
vCPU CPUID module in the nVMX state test.  Drop CPUID_VMX as there are
no longer any users.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20220614200707.3315957-29-seanjc@google.com
tools/testing/selftests/kvm/include/x86_64/processor.h
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c

index 50d6811..7c03967 100644 (file)
@@ -160,7 +160,6 @@ struct kvm_x86_cpu_feature {
 #define X86_FEATURE_KVM_MIGRATION_CONTROL      KVM_X86_CPU_FEATURE(0x40000001, 0, EAX, 17)
 
 /* CPUID.1.ECX */
-#define CPUID_VMX              (1ul << 5)
 #define CPUID_XSAVE            (1ul << 26)
 #define CPUID_OSXSAVE          (1ul << 27)
 
index 1cf78ec..41ea702 100644 (file)
@@ -121,7 +121,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu)
        test_nested_state(vcpu, state);
 
        /* Enable VMX in the guest CPUID. */
-       vcpu_set_cpuid(vcpu);
+       vcpu_set_cpuid_feature(vcpu, X86_FEATURE_VMX);
 
        /*
         * Setting vmxon_pa == -1ull and vmcs_pa == -1ull exits early without
@@ -243,22 +243,6 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu)
        free(state);
 }
 
-void disable_vmx(struct kvm_vcpu *vcpu)
-{
-       struct kvm_cpuid2 *cpuid = vcpu->cpuid;
-       int i;
-
-       for (i = 0; i < cpuid->nent; ++i)
-               if (cpuid->entries[i].function == 1 &&
-                   cpuid->entries[i].index == 0)
-                       break;
-       TEST_ASSERT(i != cpuid->nent, "CPUID function 1 not found");
-
-       cpuid->entries[i].ecx &= ~CPUID_VMX;
-       vcpu_set_cpuid(vcpu);
-       cpuid->entries[i].ecx |= CPUID_VMX;
-}
-
 int main(int argc, char *argv[])
 {
        struct kvm_vm *vm;
@@ -280,7 +264,7 @@ int main(int argc, char *argv[])
        /*
         * First run tests with VMX disabled to check error handling.
         */
-       disable_vmx(vcpu);
+       vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_VMX);
 
        /* Passing a NULL kvm_nested_state causes a EFAULT. */
        test_nested_state_expect_efault(vcpu, NULL);