Skip to content

Commit 9319676

Browse files
committed
selftests: kvm: do not set guest mode flag
Setting KVM_STATE_NESTED_GUEST_MODE enables various consistency checks on VMCS12 and therefore causes KVM_SET_NESTED_STATE to fail spuriously with -EINVAL. Do not set the flag so that we're sure to cover the conditions included by the test, and cover the case where VMCS12 is set and KVM_SET_NESTED_STATE is called with invalid VMCS12 contents. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 3d9fdc2 commit 9319676

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ void set_default_state(struct kvm_nested_state *state)
7676
void set_default_vmx_state(struct kvm_nested_state *state, int size)
7777
{
7878
memset(state, 0, size);
79-
state->flags = KVM_STATE_NESTED_GUEST_MODE |
80-
KVM_STATE_NESTED_RUN_PENDING;
8179
if (have_evmcs)
82-
state->flags |= KVM_STATE_NESTED_EVMCS;
80+
state->flags = KVM_STATE_NESTED_EVMCS;
8381
state->format = 0;
8482
state->size = size;
8583
state->hdr.vmx.vmxon_pa = 0x1000;
@@ -190,17 +188,20 @@ void test_vmx_nested_state(struct kvm_vm *vm)
190188
state->size = sizeof(*state);
191189
test_nested_state(vm, state);
192190

191+
/*
192+
* KVM_SET_NESTED_STATE succeeds with invalid VMCS
193+
* contents but L2 not running.
194+
*/
195+
set_default_vmx_state(state, state_sz);
196+
state->flags = 0;
197+
test_nested_state(vm, state);
198+
193199
/* vmxon_pa cannot be the same address as vmcs_pa. */
194200
set_default_vmx_state(state, state_sz);
195201
state->hdr.vmx.vmxon_pa = 0;
196202
state->hdr.vmx.vmcs12_pa = 0;
197203
test_nested_state_expect_einval(vm, state);
198204

199-
/* The revision id for vmcs12 must be VMCS12_REVISION. */
200-
set_default_vmx_state(state, state_sz);
201-
set_revision_id_for_vmcs12(state, 0);
202-
test_nested_state_expect_einval(vm, state);
203-
204205
/*
205206
* Test that if we leave nesting the state reflects that when we get
206207
* it again.

0 commit comments

Comments
 (0)