selftests: kvm: improvements to VMX support check
cover selftests: kvm: improvements to VMX support check
vmx_dirty_log_test fails on AMD and this is no surprise as it is VMX specific. Consolidate checks from other VMX tests into a library routine and add a check to skip the test when !VMX.
Vitaly Kuznetsov (3):
selftests: kvm: vmx_set_nested_state_test: don't check for VMX support
twice
selftests: kvm: consolidate VMX support checks
selftests: kvm: vmx_dirty_log_test: skip the test when VMX is not
supported
tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 10 ++++++++++ .../kvm/x86_64/vmx_close_while_nested_test.c | 6 +----- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 ++ .../kvm/x86_64/vmx_set_nested_state_test.c | 13 ++----------- .../selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 6 +----- 6 files changed, 18 insertions(+), 21 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/3 selftests: kvm: vmx_set_nested_state_test: don't check for VMX support twice
vmx_set_nested_state_test() checks if VMX is supported twice: in the very beginning (and skips the whole test if it's not) and before doing test_vmx_nested_state(). One should be enough.
--- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +1 -6
@@ -271,12 +271,7 @@ int main(int argc, char *argv[]) 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); +test_vmx_nested_state (vm);kvm_vm_free (vm);return 0 ;
Signature · 1 line
2.20.1
PATCH 2/3 selftests: kvm: consolidate VMX support checks
In reply to Vitaly Kuznetsovvmx_* tests require VMX and three of them implement the same check. Move it to vmx library.
--- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 10 ++++++++++ .../selftests/kvm/x86_64/vmx_close_while_nested_test.c | 6 +----- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 6 +----- .../testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 6 +----- 5 files changed, 15 insertions(+), 15 deletions(-)
tools/testing/selftests/kvm/include/x86_64/vmx.h +2 -0
@@ -580,6 +580,8 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx);void prepare_vmcs (struct vmx_pages *vmx,void *guest_rip,void *guest_rsp);bool load_vmcs (struct vmx_pages *vmx); +void nested_vmx_check_supported (void ); +void nested_pg_map (struct vmx_pages *vmx,struct kvm_vm *vm,uint64_t nested_paddr,uint64_t paddr,uint32_t eptp_memslot); void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm,
tools/testing/selftests/kvm/lib/x86_64/vmx.c +10 -0
@@ -376,6 +376,16 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp)init_vmcs_guest_state (guest_rip, guest_rsp); } +void nested_vmx_check_supported (void ) +{ +struct kvm_cpuid_entry2 *entry =kvm_get_supported_cpuid_entry (1 ); + +if (!(entry->ecx &CPUID_VMX )) { +fprintf (stderr,"nested VMX not enabled, skipping test\n" ); +exit (KSFT_SKIP ); + } +} +void nested_pg_map (struct vmx_pages *vmx,struct kvm_vm *vm,uint64_t nested_paddr,uint64_t paddr,uint32_t eptp_memslot) {
tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c +1 -5
@@ -53,12 +53,8 @@ static void l1_guest_code(struct vmx_pages *vmx_pages)int main (int argc,char *argv[]) {vm_vaddr_t vmx_pages_gva; -struct kvm_cpuid_entry2 *entry =kvm_get_supported_cpuid_entry (1 ); -if (!(entry->ecx &CPUID_VMX )) { -fprintf (stderr,"nested VMX not enabled, skipping test\n" ); -exit (KSFT_SKIP ); - } +nested_vmx_check_supported (); vm =vm_create_default (VCPU_ID ,0 , (void *) l1_guest_code);vcpu_set_cpuid (vm,VCPU_ID ,kvm_get_supported_cpuid ());
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +1 -5
@@ -224,7 +224,6 @@ 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 ); have_evmcs =kvm_check_cap (KVM_CAP_HYPERV_ENLIGHTENED_VMCS );
@@ -237,10 +236,7 @@ int main(int argc, char *argv[])* 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 ); - } +nested_vmx_check_supported (); vm =vm_create_default (VCPU_ID ,0 ,0 );
tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +1 -5
@@ -128,12 +128,8 @@ static void report(int64_t val)int main (int argc,char *argv[]) {vm_vaddr_t vmx_pages_gva; -struct kvm_cpuid_entry2 *entry =kvm_get_supported_cpuid_entry (1 ); -if (!(entry->ecx &CPUID_VMX )) { -fprintf (stderr,"nested VMX not enabled, skipping test\n" ); -exit (KSFT_SKIP ); - } +nested_vmx_check_supported (); vm =vm_create_default (VCPU_ID ,0 , (void *) l1_guest_code);vcpu_set_cpuid (vm,VCPU_ID ,kvm_get_supported_cpuid ());
Signature · 1 line
2.20.1
PATCH 3/3 selftests: kvm: vmx_dirty_log_test: skip the test when VMX is not supported
In reply to Vitaly Kuznetsovvmx_dirty_log_test fails on AMD and this is no surprise as it is VMX specific. Bail early when nested VMX is unsupported.
--- tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +2 -0
@@ -78,6 +78,8 @@ int main(int argc, char *argv[])struct ucall uc;bool done = false; +nested_vmx_check_supported (); +/* Create VM */ vm =vm_create_default (VCPU_ID ,0 , l1_guest_code);vcpu_set_cpuid (vm,VCPU_ID ,kvm_get_supported_cpuid ());
Signature · 1 line
2.20.1
Quoted 11 lines · Vitaly Kuznetsov
vmx_dirty_log_testfails on AMD and this is no surprise as it is VMX specific. Consolidate checks from other VMX tests into a library routine and add a check to skip the test when !VMX.Vitaly Kuznetsov (3):
selftests: kvm:vmx_set_nested_state_test: don't check for VMX support
twice
selftests: kvm: consolidate VMX support checks
selftests: kvm:vmx_dirty_log_test: skip the test when VMX is not
supported
Quoted 8 lines
tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 10 ++++++++++ .../kvm/x86_64/vmx_close_while_nested_test.c | 6 +----- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 ++ .../kvm/x86_64/vmx_set_nested_state_test.c | 13 ++----------- .../selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 6 +----- 6 files changed, 18 insertions(+), 21 deletions(-)
Queued, thanks.
Paolo