File tree Expand file tree Collapse file tree 4 files changed +33
-4
lines changed
tools/testing/selftests/kvm Expand file tree Collapse file tree 4 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -484,8 +484,10 @@ int main(int argc, char *argv[])
484
484
}
485
485
}
486
486
487
- TEST_ASSERT (p .uffd_mode != UFFDIO_REGISTER_MODE_MINOR || p .src_type == VM_MEM_SRC_SHMEM ,
488
- "userfaultfd MINOR mode requires shared memory; pick a different -t" );
487
+ if (p .uffd_mode == UFFDIO_REGISTER_MODE_MINOR &&
488
+ !backing_src_is_shared (p .src_type )) {
489
+ TEST_FAIL ("userfaultfd MINOR mode requires shared memory; pick a different -t" );
490
+ }
489
491
490
492
for_each_guest_mode (run_test , & p );
491
493
Original file line number Diff line number Diff line change 17
17
#include <errno.h>
18
18
#include <unistd.h>
19
19
#include <fcntl.h>
20
+ #include <sys/mman.h>
20
21
#include "kselftest.h"
21
22
22
23
static inline int _no_printf (const char * format , ...) { return 0 ; }
@@ -85,6 +86,7 @@ enum vm_mem_backing_src_type {
85
86
VM_MEM_SRC_ANONYMOUS_HUGETLB_2GB ,
86
87
VM_MEM_SRC_ANONYMOUS_HUGETLB_16GB ,
87
88
VM_MEM_SRC_SHMEM ,
89
+ VM_MEM_SRC_SHARED_HUGETLB ,
88
90
NUM_SRC_TYPES ,
89
91
};
90
92
@@ -101,4 +103,13 @@ size_t get_backing_src_pagesz(uint32_t i);
101
103
void backing_src_help (void );
102
104
enum vm_mem_backing_src_type parse_backing_src_type (const char * type_name );
103
105
106
+ /*
107
+ * Whether or not the given source type is shared memory (as opposed to
108
+ * anonymous).
109
+ */
110
+ static inline bool backing_src_is_shared (enum vm_mem_backing_src_type t )
111
+ {
112
+ return vm_mem_backing_src_alias (t )-> flag & MAP_SHARED ;
113
+ }
114
+
104
115
#endif /* SELFTEST_KVM_TEST_UTIL_H */
Original file line number Diff line number Diff line change @@ -848,8 +848,13 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
848
848
region -> mmap_size += alignment ;
849
849
850
850
region -> fd = -1 ;
851
- if (src_type == VM_MEM_SRC_SHMEM ) {
852
- region -> fd = memfd_create ("kvm_selftest" , MFD_CLOEXEC );
851
+ if (backing_src_is_shared (src_type )) {
852
+ int memfd_flags = MFD_CLOEXEC ;
853
+
854
+ if (src_type == VM_MEM_SRC_SHARED_HUGETLB )
855
+ memfd_flags |= MFD_HUGETLB ;
856
+
857
+ region -> fd = memfd_create ("kvm_selftest" , memfd_flags );
853
858
TEST_ASSERT (region -> fd != -1 ,
854
859
"memfd_create failed, errno: %i" , errno );
855
860
Original file line number Diff line number Diff line change @@ -240,6 +240,16 @@ const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i)
240
240
.name = "shmem" ,
241
241
.flag = MAP_SHARED ,
242
242
},
243
+ [VM_MEM_SRC_SHARED_HUGETLB ] = {
244
+ .name = "shared_hugetlb" ,
245
+ /*
246
+ * No MAP_HUGETLB, we use MFD_HUGETLB instead. Since
247
+ * we're using "file backed" memory, we need to specify
248
+ * this when the FD is created, not when the area is
249
+ * mapped.
250
+ */
251
+ .flag = MAP_SHARED ,
252
+ },
243
253
};
244
254
_Static_assert (ARRAY_SIZE (aliases ) == NUM_SRC_TYPES ,
245
255
"Missing new backing src types?" );
@@ -262,6 +272,7 @@ size_t get_backing_src_pagesz(uint32_t i)
262
272
case VM_MEM_SRC_ANONYMOUS_THP :
263
273
return get_trans_hugepagesz ();
264
274
case VM_MEM_SRC_ANONYMOUS_HUGETLB :
275
+ case VM_MEM_SRC_SHARED_HUGETLB :
265
276
return get_def_hugetlb_pagesz ();
266
277
default :
267
278
return MAP_HUGE_PAGE_SIZE (flag );
You can’t perform that action at this time.
0 commit comments