Skip to content

Commit 101743c

Browse files
bonzinigregkh
authored andcommitted
selftests: kvm: fix vmx_set_nested_state_test
[ Upstream commit c930e19 ] 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: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5aac82a commit 101743c

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define VMCS12_REVISION 0x11e57ed0
2626
#define VCPU_ID 5
2727

28+
bool have_evmcs;
29+
2830
void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state)
2931
{
3032
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)
7577
{
7678
memset(state, 0, size);
7779
state->flags = KVM_STATE_NESTED_GUEST_MODE |
78-
KVM_STATE_NESTED_RUN_PENDING |
79-
KVM_STATE_NESTED_EVMCS;
80+
KVM_STATE_NESTED_RUN_PENDING;
81+
if (have_evmcs)
82+
state->flags |= KVM_STATE_NESTED_EVMCS;
8083
state->format = 0;
8184
state->size = size;
8285
state->hdr.vmx.vmxon_pa = 0x1000;
@@ -126,13 +129,19 @@ void test_vmx_nested_state(struct kvm_vm *vm)
126129
/*
127130
* Setting vmxon_pa == -1ull and vmcs_pa == -1ull exits early without
128131
* setting the nested state but flags other than eVMCS must be clear.
132+
* The eVMCS flag can be set if the enlightened VMCS capability has
133+
* been enabled.
129134
*/
130135
set_default_vmx_state(state, state_sz);
131136
state->hdr.vmx.vmxon_pa = -1ull;
132137
state->hdr.vmx.vmcs12_pa = -1ull;
133138
test_nested_state_expect_einval(vm, state);
134139

135-
state->flags = KVM_STATE_NESTED_EVMCS;
140+
state->flags &= KVM_STATE_NESTED_EVMCS;
141+
if (have_evmcs) {
142+
test_nested_state_expect_einval(vm, state);
143+
vcpu_enable_evmcs(vm, VCPU_ID);
144+
}
136145
test_nested_state(vm, state);
137146

138147
/* It is invalid to have vmxon_pa == -1ull and SMM flags non-zero. */
@@ -217,6 +226,8 @@ int main(int argc, char *argv[])
217226
struct kvm_nested_state state;
218227
struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
219228

229+
have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS);
230+
220231
if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) {
221232
printf("KVM_CAP_NESTED_STATE not available, skipping test\n");
222233
exit(KSFT_SKIP);

0 commit comments

Comments
 (0)