File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
tools/testing/selftests/kvm Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_caps_test
118
118
TEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test
119
119
TEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test
120
120
TEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests
121
+ TEST_GEN_PROGS_x86_64 += x86_64/sev_smoke_test
121
122
TEST_GEN_PROGS_x86_64 += x86_64/amx_test
122
123
TEST_GEN_PROGS_x86_64 += x86_64/max_vcpuid_cap_test
123
124
TEST_GEN_PROGS_x86_64 += x86_64/triple_fault_event_test
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0-only
2
+ #include <fcntl.h>
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+ #include <sys/ioctl.h>
7
+
8
+ #include "test_util.h"
9
+ #include "kvm_util.h"
10
+ #include "processor.h"
11
+ #include "svm_util.h"
12
+ #include "linux/psp-sev.h"
13
+ #include "sev.h"
14
+
15
+ static void guest_sev_code (void )
16
+ {
17
+ GUEST_ASSERT (this_cpu_has (X86_FEATURE_SEV ));
18
+ GUEST_ASSERT (rdmsr (MSR_AMD64_SEV ) & MSR_AMD64_SEV_ENABLED );
19
+
20
+ GUEST_DONE ();
21
+ }
22
+
23
+ static void test_sev (void * guest_code , uint64_t policy )
24
+ {
25
+ struct kvm_vcpu * vcpu ;
26
+ struct kvm_vm * vm ;
27
+ struct ucall uc ;
28
+
29
+ vm = vm_sev_create_with_one_vcpu (policy , guest_code , & vcpu );
30
+
31
+ for (;;) {
32
+ vcpu_run (vcpu );
33
+
34
+ switch (get_ucall (vcpu , & uc )) {
35
+ case UCALL_SYNC :
36
+ continue ;
37
+ case UCALL_DONE :
38
+ return ;
39
+ case UCALL_ABORT :
40
+ REPORT_GUEST_ASSERT (uc );
41
+ default :
42
+ TEST_FAIL ("Unexpected exit: %s" ,
43
+ exit_reason_str (vcpu -> run -> exit_reason ));
44
+ }
45
+ }
46
+
47
+ kvm_vm_free (vm );
48
+ }
49
+
50
+ int main (int argc , char * argv [])
51
+ {
52
+ TEST_REQUIRE (kvm_cpu_has (X86_FEATURE_SEV ));
53
+
54
+ test_sev (guest_sev_code , SEV_POLICY_NO_DBG );
55
+ test_sev (guest_sev_code , 0 );
56
+
57
+ return 0 ;
58
+ }
You can’t perform that action at this time.
0 commit comments