8
8
#define _GNU_SOURCE /* for program_invocation_short_name */
9
9
#include <sys/ioctl.h>
10
10
11
+ #include "kvm_test_harness.h"
11
12
#include "test_util.h"
12
13
#include "kvm_util.h"
13
14
#include "vmx.h"
@@ -527,14 +528,13 @@ static void run_guest_then_process_ucall_done(struct kvm_vcpu *vcpu)
527
528
process_ucall_done (vcpu );
528
529
}
529
530
530
- static void test_msr_filter_allow (void )
531
+ KVM_ONE_VCPU_TEST_SUITE (user_msr );
532
+
533
+ KVM_ONE_VCPU_TEST (user_msr , msr_filter_allow , guest_code_filter_allow )
531
534
{
532
- struct kvm_vcpu * vcpu ;
533
- struct kvm_vm * vm ;
535
+ struct kvm_vm * vm = vcpu -> vm ;
534
536
int rc ;
535
537
536
- vm = vm_create_with_one_vcpu (& vcpu , guest_code_filter_allow );
537
-
538
538
rc = kvm_check_cap (KVM_CAP_X86_USER_SPACE_MSR );
539
539
TEST_ASSERT (rc , "KVM_CAP_X86_USER_SPACE_MSR is available" );
540
540
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
585
} else {
586
586
printf ("To run the instruction emulated tests set the module parameter 'kvm.force_emulation_prefix=1'\n" );
587
587
}
588
-
589
- kvm_vm_free (vm );
590
588
}
591
589
592
590
static int handle_ucall (struct kvm_vcpu * vcpu )
@@ -646,16 +644,12 @@ static void handle_wrmsr(struct kvm_run *run)
646
644
}
647
645
}
648
646
649
- static void test_msr_filter_deny ( void )
647
+ KVM_ONE_VCPU_TEST ( user_msr , msr_filter_deny , guest_code_filter_deny )
650
648
{
651
- struct kvm_vcpu * vcpu ;
652
- struct kvm_vm * vm ;
653
- struct kvm_run * run ;
649
+ struct kvm_vm * vm = vcpu -> vm ;
650
+ struct kvm_run * run = vcpu -> run ;
654
651
int rc ;
655
652
656
- vm = vm_create_with_one_vcpu (& vcpu , guest_code_filter_deny );
657
- run = vcpu -> run ;
658
-
659
653
rc = kvm_check_cap (KVM_CAP_X86_USER_SPACE_MSR );
660
654
TEST_ASSERT (rc , "KVM_CAP_X86_USER_SPACE_MSR is available" );
661
655
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
683
done :
690
684
TEST_ASSERT (msr_reads == 4 , "Handled 4 rdmsr in user space" );
691
685
TEST_ASSERT (msr_writes == 3 , "Handled 3 wrmsr in user space" );
692
-
693
- kvm_vm_free (vm );
694
686
}
695
687
696
- static void test_msr_permission_bitmap ( void )
688
+ KVM_ONE_VCPU_TEST ( user_msr , msr_permission_bitmap , guest_code_permission_bitmap )
697
689
{
698
- struct kvm_vcpu * vcpu ;
699
- struct kvm_vm * vm ;
690
+ struct kvm_vm * vm = vcpu -> vm ;
700
691
int rc ;
701
692
702
- vm = vm_create_with_one_vcpu (& vcpu , guest_code_permission_bitmap );
703
-
704
693
rc = kvm_check_cap (KVM_CAP_X86_USER_SPACE_MSR );
705
694
TEST_ASSERT (rc , "KVM_CAP_X86_USER_SPACE_MSR is available" );
706
695
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
704
vm_ioctl (vm , KVM_X86_SET_MSR_FILTER , & filter_gs );
716
705
run_guest_then_process_rdmsr (vcpu , MSR_GS_BASE );
717
706
run_guest_then_process_ucall_done (vcpu );
718
-
719
- kvm_vm_free (vm );
720
707
}
721
708
722
709
#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
773
}
787
774
788
775
/* Test that attempts to write to the unused bits in a flag fails. */
789
- static void test_user_exit_msr_flags ( void )
776
+ KVM_ONE_VCPU_TEST ( user_msr , user_exit_msr_flags , NULL )
790
777
{
791
- struct kvm_vcpu * vcpu ;
792
- struct kvm_vm * vm ;
793
-
794
- vm = vm_create_with_one_vcpu (& vcpu , NULL );
778
+ struct kvm_vm * vm = vcpu -> vm ;
795
779
796
780
/* Test flags for KVM_CAP_X86_USER_SPACE_MSR. */
797
781
run_user_space_msr_flag_test (vm );
798
782
799
783
/* Test flags and range flags for KVM_X86_SET_MSR_FILTER. */
800
784
run_msr_filter_flag_test (vm );
801
-
802
- kvm_vm_free (vm );
803
785
}
804
786
805
787
int main (int argc , char * argv [])
806
788
{
807
- test_msr_filter_allow ();
808
-
809
- test_msr_filter_deny ();
810
-
811
- test_msr_permission_bitmap ();
812
-
813
- test_user_exit_msr_flags ();
814
-
815
- return 0 ;
789
+ return test_harness_run (argc , argv );
816
790
}
0 commit comments