[PATCH 27/32] KVM: selftests: Add test vmx_set_nested_state_test with EVMCS disabled

isaku.yamahata@intel.com posted 32 patches 5 days, 6 hours ago
[PATCH 27/32] KVM: selftests: Add test vmx_set_nested_state_test with EVMCS disabled
Posted by isaku.yamahata@intel.com 5 days, 6 hours ago
From: Isaku Yamahata <isaku.yamahata@intel.com>

Hyper-V EVMCS capability, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, is optional.
To increase test coverage, when Hyper-V EVMCS is supported, additionally
run tests with EVMCS disabled.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
 .../selftests/kvm/x86/vmx_set_nested_state_test.c    | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/selftests/kvm/x86/vmx_set_nested_state_test.c b/tools/testing/selftests/kvm/x86/vmx_set_nested_state_test.c
index 67a62a5a8895..cbf6a8ff626e 100644
--- a/tools/testing/selftests/kvm/x86/vmx_set_nested_state_test.c
+++ b/tools/testing/selftests/kvm/x86/vmx_set_nested_state_test.c
@@ -298,6 +298,18 @@ int main(int argc, char *argv[])
 	test_nested_state_expect_einval(vcpu, &state);
 
 	test_vmx_nested_state(vcpu);
+	if (have_evmcs) {
+		/*
+		 * KVM_CAP_HYPERV_ENLIGHTENED_VMCS can be only enabled.
+		 * Because There is no way to disable it, re-create vm and vcpu.
+		 */
+		have_evmcs = false;
+		kvm_vm_free(vm);
+		vm = vm_create_with_one_vcpu(&vcpu, NULL);
+		vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_VMX);
+
+		test_vmx_nested_state(vcpu);
+	}
 
 	kvm_vm_free(vm);
 	return 0;
-- 
2.45.2