File tree Expand file tree Collapse file tree 4 files changed +30
-10
lines changed
tools/testing/selftests/kvm Expand file tree Collapse file tree 4 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ struct vm_guest_mode_params {
82
82
};
83
83
extern const struct vm_guest_mode_params vm_guest_mode_params [];
84
84
85
+ int open_path_or_exit (const char * path , int flags );
85
86
int open_kvm_dev_path_or_exit (void );
86
87
int kvm_check_cap (long cap );
87
88
int vm_enable_cap (struct kvm_vm * vm , struct kvm_enable_cap * cap );
Original file line number Diff line number Diff line change @@ -46,4 +46,6 @@ static inline bool cpu_has_svm(void)
46
46
return ecx & CPUID_SVM ;
47
47
}
48
48
49
+ int open_sev_dev_path_or_exit (void );
50
+
49
51
#endif /* SELFTEST_KVM_SVM_UTILS_H */
Original file line number Diff line number Diff line change @@ -31,6 +31,19 @@ static void *align(void *x, size_t size)
31
31
return (void * ) (((size_t ) x + mask ) & ~mask );
32
32
}
33
33
34
+ int open_path_or_exit (const char * path , int flags )
35
+ {
36
+ int fd ;
37
+
38
+ fd = open (path , flags );
39
+ if (fd < 0 ) {
40
+ print_skip ("%s not available (errno: %d)" , path , errno );
41
+ exit (KSFT_SKIP );
42
+ }
43
+
44
+ return fd ;
45
+ }
46
+
34
47
/*
35
48
* Open KVM_DEV_PATH if available, otherwise exit the entire program.
36
49
*
@@ -42,16 +55,7 @@ static void *align(void *x, size_t size)
42
55
*/
43
56
static int _open_kvm_dev_path_or_exit (int flags )
44
57
{
45
- int fd ;
46
-
47
- fd = open (KVM_DEV_PATH , flags );
48
- if (fd < 0 ) {
49
- print_skip ("%s not available, is KVM loaded? (errno: %d)" ,
50
- KVM_DEV_PATH , errno );
51
- exit (KSFT_SKIP );
52
- }
53
-
54
- return fd ;
58
+ return open_path_or_exit (KVM_DEV_PATH , flags );
55
59
}
56
60
57
61
int open_kvm_dev_path_or_exit (void )
Original file line number Diff line number Diff line change 13
13
#include "processor.h"
14
14
#include "svm_util.h"
15
15
16
+ #define SEV_DEV_PATH "/dev/sev"
17
+
16
18
struct gpr64_regs guest_regs ;
17
19
u64 rflags ;
18
20
@@ -172,3 +174,14 @@ void nested_svm_check_supported(void)
172
174
exit (KSFT_SKIP );
173
175
}
174
176
}
177
+
178
+ /*
179
+ * Open SEV_DEV_PATH if available, otherwise exit the entire program.
180
+ *
181
+ * Return:
182
+ * The opened file descriptor of /dev/sev.
183
+ */
184
+ int open_sev_dev_path_or_exit (void )
185
+ {
186
+ return open_path_or_exit (SEV_DEV_PATH , 0 );
187
+ }
You can’t perform that action at this time.
0 commit comments