Commit 8d251856 authored by Thomas Huth's avatar Thomas Huth Committed by Sean Christopherson

KVM: selftests: x86: Use TAP interface in the userspace_msr_exit test

Use the kselftest_harness.h interface in this test to get TAP
output, so that it is easier for the user to see what the test
is doing.
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
Link: https://lore.kernel.org/r/20240208204844.119326-9-thuth@redhat.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent de1b03f2
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define _GNU_SOURCE /* for program_invocation_short_name */ #define _GNU_SOURCE /* for program_invocation_short_name */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include "kvm_test_harness.h"
#include "test_util.h" #include "test_util.h"
#include "kvm_util.h" #include "kvm_util.h"
#include "vmx.h" #include "vmx.h"
...@@ -527,14 +528,13 @@ static void run_guest_then_process_ucall_done(struct kvm_vcpu *vcpu) ...@@ -527,14 +528,13 @@ static void run_guest_then_process_ucall_done(struct kvm_vcpu *vcpu)
process_ucall_done(vcpu); process_ucall_done(vcpu);
} }
static void test_msr_filter_allow(void) KVM_ONE_VCPU_TEST_SUITE(user_msr);
KVM_ONE_VCPU_TEST(user_msr, msr_filter_allow, guest_code_filter_allow)
{ {
struct kvm_vcpu *vcpu; struct kvm_vm *vm = vcpu->vm;
struct kvm_vm *vm;
int rc; int rc;
vm = vm_create_with_one_vcpu(&vcpu, guest_code_filter_allow);
rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR); rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR);
TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available"); TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available");
vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER); vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER);
...@@ -585,8 +585,6 @@ static void test_msr_filter_allow(void) ...@@ -585,8 +585,6 @@ static void test_msr_filter_allow(void)
} else { } else {
printf("To run the instruction emulated tests set the module parameter 'kvm.force_emulation_prefix=1'\n"); printf("To run the instruction emulated tests set the module parameter 'kvm.force_emulation_prefix=1'\n");
} }
kvm_vm_free(vm);
} }
static int handle_ucall(struct kvm_vcpu *vcpu) static int handle_ucall(struct kvm_vcpu *vcpu)
...@@ -646,16 +644,12 @@ static void handle_wrmsr(struct kvm_run *run) ...@@ -646,16 +644,12 @@ static void handle_wrmsr(struct kvm_run *run)
} }
} }
static void test_msr_filter_deny(void) KVM_ONE_VCPU_TEST(user_msr, msr_filter_deny, guest_code_filter_deny)
{ {
struct kvm_vcpu *vcpu; struct kvm_vm *vm = vcpu->vm;
struct kvm_vm *vm; struct kvm_run *run = vcpu->run;
struct kvm_run *run;
int rc; int rc;
vm = vm_create_with_one_vcpu(&vcpu, guest_code_filter_deny);
run = vcpu->run;
rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR); rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR);
TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available"); TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available");
vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_INVAL | vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_INVAL |
...@@ -689,18 +683,13 @@ static void test_msr_filter_deny(void) ...@@ -689,18 +683,13 @@ static void test_msr_filter_deny(void)
done: done:
TEST_ASSERT(msr_reads == 4, "Handled 4 rdmsr in user space"); TEST_ASSERT(msr_reads == 4, "Handled 4 rdmsr in user space");
TEST_ASSERT(msr_writes == 3, "Handled 3 wrmsr in user space"); TEST_ASSERT(msr_writes == 3, "Handled 3 wrmsr in user space");
kvm_vm_free(vm);
} }
static void test_msr_permission_bitmap(void) KVM_ONE_VCPU_TEST(user_msr, msr_permission_bitmap, guest_code_permission_bitmap)
{ {
struct kvm_vcpu *vcpu; struct kvm_vm *vm = vcpu->vm;
struct kvm_vm *vm;
int rc; int rc;
vm = vm_create_with_one_vcpu(&vcpu, guest_code_permission_bitmap);
rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR); rc = kvm_check_cap(KVM_CAP_X86_USER_SPACE_MSR);
TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available"); TEST_ASSERT(rc, "KVM_CAP_X86_USER_SPACE_MSR is available");
vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER); vm_enable_cap(vm, KVM_CAP_X86_USER_SPACE_MSR, KVM_MSR_EXIT_REASON_FILTER);
...@@ -715,8 +704,6 @@ static void test_msr_permission_bitmap(void) ...@@ -715,8 +704,6 @@ static void test_msr_permission_bitmap(void)
vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_gs); vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_gs);
run_guest_then_process_rdmsr(vcpu, MSR_GS_BASE); run_guest_then_process_rdmsr(vcpu, MSR_GS_BASE);
run_guest_then_process_ucall_done(vcpu); run_guest_then_process_ucall_done(vcpu);
kvm_vm_free(vm);
} }
#define test_user_exit_msr_ioctl(vm, cmd, arg, flag, valid_mask) \ #define test_user_exit_msr_ioctl(vm, cmd, arg, flag, valid_mask) \
...@@ -786,31 +773,18 @@ static void run_msr_filter_flag_test(struct kvm_vm *vm) ...@@ -786,31 +773,18 @@ static void run_msr_filter_flag_test(struct kvm_vm *vm)
} }
/* Test that attempts to write to the unused bits in a flag fails. */ /* Test that attempts to write to the unused bits in a flag fails. */
static void test_user_exit_msr_flags(void) KVM_ONE_VCPU_TEST(user_msr, user_exit_msr_flags, NULL)
{ {
struct kvm_vcpu *vcpu; struct kvm_vm *vm = vcpu->vm;
struct kvm_vm *vm;
vm = vm_create_with_one_vcpu(&vcpu, NULL);
/* Test flags for KVM_CAP_X86_USER_SPACE_MSR. */ /* Test flags for KVM_CAP_X86_USER_SPACE_MSR. */
run_user_space_msr_flag_test(vm); run_user_space_msr_flag_test(vm);
/* Test flags and range flags for KVM_X86_SET_MSR_FILTER. */ /* Test flags and range flags for KVM_X86_SET_MSR_FILTER. */
run_msr_filter_flag_test(vm); run_msr_filter_flag_test(vm);
kvm_vm_free(vm);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
test_msr_filter_allow(); return test_harness_run(argc, argv);
test_msr_filter_deny();
test_msr_permission_bitmap();
test_user_exit_msr_flags();
return 0;
} }
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