[PATCH v2 28/36] KVM: selftests: Add test vmx_set_nested_state_test with EVMCS disabled

isaku.yamahata@intel.com posted 36 patches 3 weeks, 6 days ago
[PATCH v2 28/36] KVM: selftests: Add test vmx_set_nested_state_test with EVMCS disabled
Posted by isaku.yamahata@intel.com 3 weeks, 6 days 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/nested_set_state_test.c       | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/testing/selftests/kvm/x86/nested_set_state_test.c b/tools/testing/selftests/kvm/x86/nested_set_state_test.c
index 0f2102b43629..9651282df4d3 100644
--- a/tools/testing/selftests/kvm/x86/nested_set_state_test.c
+++ b/tools/testing/selftests/kvm/x86/nested_set_state_test.c
@@ -401,6 +401,19 @@ int main(int argc, char *argv[])
 	else
 		test_svm_nested_state(vcpu);
 
+	if (kvm_cpu_has(X86_FEATURE_VMX) && 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