Skip to content

Commit c5c6383

Browse files
elmarcotorvalds
authored andcommitted
memfd-test: run fuse test on hugetlb backend memory
Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Marc-André Lureau <[email protected]> Suggested-by: Mike Kravetz <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Michal Hocko <[email protected]> Cc: David Herrmann <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 29f34d1 commit c5c6383

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

tools/testing/selftests/memfd/fuse_test.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define MFD_DEF_SIZE 8192
3939
#define STACK_SIZE 65536
4040

41+
static size_t mfd_def_size = MFD_DEF_SIZE;
42+
4143
static int mfd_assert_new(const char *name, loff_t sz, unsigned int flags)
4244
{
4345
int r, fd;
@@ -123,7 +125,7 @@ static void *mfd_assert_mmap_shared(int fd)
123125
void *p;
124126

125127
p = mmap(NULL,
126-
MFD_DEF_SIZE,
128+
mfd_def_size,
127129
PROT_READ | PROT_WRITE,
128130
MAP_SHARED,
129131
fd,
@@ -141,7 +143,7 @@ static void *mfd_assert_mmap_private(int fd)
141143
void *p;
142144

143145
p = mmap(NULL,
144-
MFD_DEF_SIZE,
146+
mfd_def_size,
145147
PROT_READ | PROT_WRITE,
146148
MAP_PRIVATE,
147149
fd,
@@ -174,7 +176,7 @@ static int sealing_thread_fn(void *arg)
174176
usleep(200000);
175177

176178
/* unmount mapping before sealing to avoid i_mmap_writable failures */
177-
munmap(global_p, MFD_DEF_SIZE);
179+
munmap(global_p, mfd_def_size);
178180

179181
/* Try sealing the global file; expect EBUSY or success. Current
180182
* kernels will never succeed, but in the future, kernels might
@@ -224,7 +226,7 @@ static void join_sealing_thread(pid_t pid)
224226

225227
int main(int argc, char **argv)
226228
{
227-
static const char zero[MFD_DEF_SIZE];
229+
char *zero;
228230
int fd, mfd, r;
229231
void *p;
230232
int was_sealed;
@@ -235,6 +237,25 @@ int main(int argc, char **argv)
235237
abort();
236238
}
237239

240+
if (argc >= 3) {
241+
if (!strcmp(argv[2], "hugetlbfs")) {
242+
unsigned long hpage_size = default_huge_page_size();
243+
244+
if (!hpage_size) {
245+
printf("Unable to determine huge page size\n");
246+
abort();
247+
}
248+
249+
hugetlbfs_test = 1;
250+
mfd_def_size = hpage_size * 2;
251+
} else {
252+
printf("Unknown option: %s\n", argv[2]);
253+
abort();
254+
}
255+
}
256+
257+
zero = calloc(sizeof(*zero), mfd_def_size);
258+
238259
/* open FUSE memfd file for GUP testing */
239260
printf("opening: %s\n", argv[1]);
240261
fd = open(argv[1], O_RDONLY | O_CLOEXEC);
@@ -245,7 +266,7 @@ int main(int argc, char **argv)
245266

246267
/* create new memfd-object */
247268
mfd = mfd_assert_new("kern_memfd_fuse",
248-
MFD_DEF_SIZE,
269+
mfd_def_size,
249270
MFD_CLOEXEC | MFD_ALLOW_SEALING);
250271

251272
/* mmap memfd-object for writing */
@@ -264,7 +285,7 @@ int main(int argc, char **argv)
264285
* This guarantees that the receive-buffer is pinned for 1s until the
265286
* data is written into it. The racing ADD_SEALS should thus fail as
266287
* the pages are still pinned. */
267-
r = read(fd, p, MFD_DEF_SIZE);
288+
r = read(fd, p, mfd_def_size);
268289
if (r < 0) {
269290
printf("read() failed: %m\n");
270291
abort();
@@ -291,10 +312,10 @@ int main(int argc, char **argv)
291312
* enough to avoid any in-flight writes. */
292313

293314
p = mfd_assert_mmap_private(mfd);
294-
if (was_sealed && memcmp(p, zero, MFD_DEF_SIZE)) {
315+
if (was_sealed && memcmp(p, zero, mfd_def_size)) {
295316
printf("memfd sealed during read() but data not discarded\n");
296317
abort();
297-
} else if (!was_sealed && !memcmp(p, zero, MFD_DEF_SIZE)) {
318+
} else if (!was_sealed && !memcmp(p, zero, mfd_def_size)) {
298319
printf("memfd sealed after read() but data discarded\n");
299320
abort();
300321
}
@@ -303,6 +324,7 @@ int main(int argc, char **argv)
303324
close(fd);
304325

305326
printf("fuse: DONE\n");
327+
free(zero);
306328

307329
return 0;
308330
}

tools/testing/selftests/memfd/run_fuse_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ set -e
1010

1111
mkdir mnt
1212
./fuse_mnt ./mnt
13-
./fuse_test ./mnt/memfd
13+
./fuse_test ./mnt/memfd $@
1414
fusermount -u ./mnt
1515
rmdir ./mnt

tools/testing/selftests/memfd/run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fi
6060
# Run the hugetlbfs test
6161
#
6262
./memfd_test hugetlbfs
63+
./run_fuse_test.sh hugetlbfs
6364

6465
#
6566
# Give back any huge pages allocated for the test

0 commit comments

Comments
 (0)