]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: selftests: Use kvm_cpu_has() for nested VMX checks
authorSean Christopherson <seanjc@google.com>
Tue, 14 Jun 2022 20:06:31 +0000 (20:06 +0000)
committerSean Christopherson <seanjc@google.com>
Thu, 14 Jul 2022 01:14:10 +0000 (18:14 -0700)
Use kvm_cpu_has() to check for nested VMX support, and drop the helpers
now that their functionality is trivial to implement.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/r/20220614200707.3315957-7-seanjc@google.com
16 files changed:
tools/testing/selftests/kvm/include/x86_64/vmx.h
tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c
tools/testing/selftests/kvm/lib/x86_64/vmx.c
tools/testing/selftests/kvm/x86_64/evmcs_test.c
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
tools/testing/selftests/kvm/x86_64/smm_test.c
tools/testing/selftests/kvm/x86_64/state_test.c
tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c
tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c
tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c
tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c
tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c
tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c

index cc3604f8f1d3c52c74ba0f307b69bf7bf7e78f0e..99fa1410964cac2d9d0bca6a05fbec1f279cbc8c 100644 (file)
@@ -607,8 +607,6 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx);
 void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp);
 bool load_vmcs(struct vmx_pages *vmx);
 
-bool nested_vmx_supported(void);
-void nested_vmx_check_supported(void);
 bool ept_1g_pages_supported(void);
 
 void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm,
index bfe85c8c2f6e88e0ebc317550d29ff53301b7fc4..0f344a7c89c4b9156881e3c70ae54a47aee6b5d7 100644 (file)
@@ -84,7 +84,7 @@ void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vc
        vm_vaddr_t vmx_gva;
        int vcpu_id;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
                vmx = vcpu_alloc_vmx(vm, &vmx_gva);
index 381432741df4b85e076bd2840e53493ac54ec85c..80a568c439b832ebc05cd77d7cec580b16687c5a 100644 (file)
@@ -382,18 +382,6 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp)
        init_vmcs_guest_state(guest_rip, guest_rsp);
 }
 
-bool nested_vmx_supported(void)
-{
-       struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
-
-       return entry->ecx & CPUID_VMX;
-}
-
-void nested_vmx_check_supported(void)
-{
-       TEST_REQUIRE(nested_vmx_supported());
-}
-
 static void nested_create_pte(struct kvm_vm *vm,
                              struct eptPageTableEntry *pte,
                              uint64_t nested_paddr,
index aacad86d90e139d80cdfc83362da7736e5e10d61..99bc202243d23c280cb7628b16ca0c65d6d9eba3 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, char *argv[])
 
        vm = vm_create_with_one_vcpu(&vcpu, guest_code);
 
-       TEST_REQUIRE(nested_vmx_supported());
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS));
 
index cbd4a7d36189e4f1601a3a84683ccc7ffb83c59e..c406b95cba9bc4bf12f899fe5006f3c479d9018e 100644 (file)
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
        test_hv_cpuid(hv_cpuid_entries, false);
        free(hv_cpuid_entries);
 
-       if (!nested_vmx_supported() ||
+       if (!kvm_cpu_has(X86_FEATURE_VMX) ||
            !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) {
                print_skip("Enlightened VMCS is unsupported");
                goto do_sys;
@@ -168,7 +168,7 @@ do_sys:
        test_hv_cpuid_e2big(vm, NULL);
 
        hv_cpuid_entries = kvm_get_supported_hv_cpuid();
-       test_hv_cpuid(hv_cpuid_entries, nested_vmx_supported());
+       test_hv_cpuid(hv_cpuid_entries, kvm_cpu_has(X86_FEATURE_VMX));
 
 out:
        kvm_vm_free(vm);
index fde3fe925686fbe0041e901ff4f3eac4fb2eefa5..17bb2397ea383355cf5ea384857e0abd16173d1a 100644 (file)
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
        if (kvm_has_cap(KVM_CAP_NESTED_STATE)) {
                if (kvm_cpu_has(X86_FEATURE_SVM))
                        vcpu_alloc_svm(vm, &nested_gva);
-               else if (nested_vmx_supported())
+               else if (kvm_cpu_has(X86_FEATURE_VMX))
                        vcpu_alloc_vmx(vm, &nested_gva);
        }
 
index ae01d32624ecfae14f1bb94adc3dcf3f3f8ed612..8ab81a3b561f58c708bc5737a8bd1bdd380b5ca0 100644 (file)
@@ -172,7 +172,7 @@ int main(int argc, char *argv[])
        if (kvm_has_cap(KVM_CAP_NESTED_STATE)) {
                if (kvm_cpu_has(X86_FEATURE_SVM))
                        vcpu_alloc_svm(vm, &nested_gva);
-               else if (nested_vmx_supported())
+               else if (kvm_cpu_has(X86_FEATURE_VMX))
                        vcpu_alloc_vmx(vm, &nested_gva);
        }
 
index d1274c097b36f974701d7696d8274954ea140b51..70b44f0b52fef2273c5dbb7d5a14858aa24dcf53 100644 (file)
@@ -46,7 +46,7 @@ int main(void)
        vm_vaddr_t vmx_pages_gva;
        struct ucall uc;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_TRIPLE_FAULT_EVENT));
 
index d3582cea1258a53ba231cbe57413fc007b1e96f4..5abecf06329eaccd2ac85e0fb6b57075d5628f15 100644 (file)
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])
        struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
 
index e69e8963ed08c81e7e44fbf440bac6a602d95066..d79651b027402d6f349eb594a03fdc425ce3843a 100644 (file)
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
        struct kvm_vcpu *vcpu;
        struct kvm_vm *vm;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
 
index f378960299c01d8fdc319861cda2458f4f43e585..2d8c23d639f77865a9c02bfdb124c10e0b541657 100644 (file)
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
        struct ucall uc;
        bool done = false;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        /* Create VM */
        vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
index 8c854738f2ccf1e3a2ad96b839a8199802b49448..6bfb4bb471ca2b68f7cdaeeece7b93ba4d6d33db 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
        struct kvm_run *run;
        struct ucall uc;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
 
index 6bfef77b87b717801bd608e82b5d577fd444d4aa..465a9434d61c2b9d7cc3611d719e32598365f00b 100644 (file)
@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
        uint64_t l1_tsc_freq = 0;
        uint64_t l2_tsc_freq = 0;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL));
        stable_tsc_check_supported();
 
index 8504c6ce0cada450cea0bf3fb5d2a7e12017e79c..0efdc05969a56395db7774821c9023fb93928d9c 100644 (file)
@@ -167,7 +167,7 @@ int main(int argc, char *argv[])
         * AMD currently does not implement any VMX features, so for now we
         * just early out.
         */
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE));
 
index b564b86dfc1d3168cd495ff9bab93fc90bd278d9..66cb2d0054e64c279b552f7f6caa40e97eb34291 100644 (file)
@@ -273,7 +273,7 @@ int main(int argc, char *argv[])
         * AMD currently does not implement set_nested_state, so for now we
         * just early out.
         */
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        vm = vm_create_with_one_vcpu(&vcpu, NULL);
 
index 2e75eef926ca9ee7e3c4a4c4a29182167b6140a3..5943187e859494301a332749c2c321ed0ba00962 100644 (file)
@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
        vm_vaddr_t vmx_pages_gva;
        struct kvm_vcpu *vcpu;
 
-       nested_vmx_check_supported();
+       TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
 
        vm = vm_create_with_one_vcpu(&vcpu, (void *) l1_guest_code);