On Thu, May 02, 2019 at 11:31:41AM -0700, Aaron Lewis wrote: > Add tests for KVM_SET_NESTED_STATE and for various code paths in its implementation in vmx_set_nested_state(). > > Signed-off-by: Aaron Lewis <aaronlewis@xxxxxxxxxx> > Reviewed-by: Marc Orr <marcorr@xxxxxxxxxx> > Reviewed-by: Peter Shier <pshier@xxxxxxxxxx> > --- ... > +int main(int argc, char *argv[]) > +{ > + struct kvm_vm *vm; > + struct kvm_nested_state state; > + struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1); > + > + /* > + * AMD currently does not implement set_nested_state, so for now we > + * just early out. > + */ > + if (!(entry->ecx & CPUID_VMX)) { > + fprintf(stderr, "nested VMX not enabled, skipping test\n"); > + exit(KSFT_SKIP); > + } Hmm, probably better to check KVM_CAP_NESTED_STATE. If/when support for AMD is added it'd be good to automatically pick up whatever testing we can. As a bonus it'll test the cap code. > + > + vm = vm_create_default(VCPU_ID, 0, 0); > + > + /* Passing a NULL kvm_nested_state causes a EFAULT. */ > + test_nested_state_expect_efault(vm, NULL); > + > + /* 'size' cannot be smaller than sizeof(kvm_nested_state). */ > + set_default_state(&state); > + state.size = 0; > + test_nested_state_expect_einval(vm, &state); > + > + /* > + * Setting the flags 0xf fails the flags check. The only flags that > + * can be used are: > + * KVM_STATE_NESTED_GUEST_MODE > + * KVM_STATE_NESTED_RUN_PENDING > + * KVM_STATE_NESTED_EVMCS > + */ > + set_default_state(&state); > + state.flags = 0xf; > + test_nested_state_expect_einval(vm, &state); > + > + /* > + * If KVM_STATE_NESTED_RUN_PENDING is set then > + * KVM_STATE_NESTED_GUEST_MODE has to be set as well. > + */ > + set_default_state(&state); > + state.flags = KVM_STATE_NESTED_RUN_PENDING; > + test_nested_state_expect_einval(vm, &state); > + > + /* > + * TODO: When SVM support is added for KVM_SET_NESTED_STATE > + * add tests here to support it like VMX. > + */ > + if (entry->ecx & CPUID_VMX) > + test_vmx_nested_state(vm); > + > + kvm_vm_free(vm); > + return 0; > +} > -- > 2.21.0.593.g511ec345e18-goog >