Commit c930e197 authored by Paolo Bonzini's avatar Paolo Bonzini

selftests: kvm: fix vmx_set_nested_state_test

vmx_set_nested_state_test is trying to use the KVM_STATE_NESTED_EVMCS without
enabling enlightened VMCS first.  Correct the outcome of the test, and actually
test that it succeeds after the capability is enabled.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 65efa61d
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#define VMCS12_REVISION 0x11e57ed0 #define VMCS12_REVISION 0x11e57ed0
#define VCPU_ID 5 #define VCPU_ID 5
bool have_evmcs;
void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state) void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state)
{ {
vcpu_nested_state_set(vm, VCPU_ID, state, false); vcpu_nested_state_set(vm, VCPU_ID, state, false);
...@@ -75,8 +77,9 @@ void set_default_vmx_state(struct kvm_nested_state *state, int size) ...@@ -75,8 +77,9 @@ void set_default_vmx_state(struct kvm_nested_state *state, int size)
{ {
memset(state, 0, size); memset(state, 0, size);
state->flags = KVM_STATE_NESTED_GUEST_MODE | state->flags = KVM_STATE_NESTED_GUEST_MODE |
KVM_STATE_NESTED_RUN_PENDING | KVM_STATE_NESTED_RUN_PENDING;
KVM_STATE_NESTED_EVMCS; if (have_evmcs)
state->flags |= KVM_STATE_NESTED_EVMCS;
state->format = 0; state->format = 0;
state->size = size; state->size = size;
state->hdr.vmx.vmxon_pa = 0x1000; state->hdr.vmx.vmxon_pa = 0x1000;
...@@ -126,13 +129,19 @@ void test_vmx_nested_state(struct kvm_vm *vm) ...@@ -126,13 +129,19 @@ void test_vmx_nested_state(struct kvm_vm *vm)
/* /*
* Setting vmxon_pa == -1ull and vmcs_pa == -1ull exits early without * Setting vmxon_pa == -1ull and vmcs_pa == -1ull exits early without
* setting the nested state but flags other than eVMCS must be clear. * setting the nested state but flags other than eVMCS must be clear.
* The eVMCS flag can be set if the enlightened VMCS capability has
* been enabled.
*/ */
set_default_vmx_state(state, state_sz); set_default_vmx_state(state, state_sz);
state->hdr.vmx.vmxon_pa = -1ull; state->hdr.vmx.vmxon_pa = -1ull;
state->hdr.vmx.vmcs12_pa = -1ull; state->hdr.vmx.vmcs12_pa = -1ull;
test_nested_state_expect_einval(vm, state); test_nested_state_expect_einval(vm, state);
state->flags = KVM_STATE_NESTED_EVMCS; state->flags &= KVM_STATE_NESTED_EVMCS;
if (have_evmcs) {
test_nested_state_expect_einval(vm, state);
vcpu_enable_evmcs(vm, VCPU_ID);
}
test_nested_state(vm, state); test_nested_state(vm, state);
/* It is invalid to have vmxon_pa == -1ull and SMM flags non-zero. */ /* It is invalid to have vmxon_pa == -1ull and SMM flags non-zero. */
...@@ -217,6 +226,8 @@ int main(int argc, char *argv[]) ...@@ -217,6 +226,8 @@ int main(int argc, char *argv[])
struct kvm_nested_state state; struct kvm_nested_state state;
struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS);
if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) { if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) {
printf("KVM_CAP_NESTED_STATE not available, skipping test\n"); printf("KVM_CAP_NESTED_STATE not available, skipping test\n");
exit(KSFT_SKIP); exit(KSFT_SKIP);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment