Skip to contentSkip to conversation

userfaultfd-selftests-use-memfd_create-for-shmem-test-type.patch removed from -mm tree

merged [email protected] 1 participant 1 message Jul 6, 2021

lore
Share & tools
lore

[email protected]

author tree notice Applied
#0 lore raw

The patch titled
Subject: userfaultfd/selftests: use memfd_create for shmem test type
has been removed from the -mm tree. Its filename was
userfaultfd-selftests-use-memfd_create-for-shmem-test-type.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Axel Rasmussen <[email protected]>
Subject: userfaultfd/selftests: use memfd_create for shmem test type

This is a preparatory commit. In the future, we want to be able to setup alias mappings for area_src and area_dst in the shmem test, like we do in the hugetlb_shared test. With a VMA obtained via mmap(MAP_ANONYMOUS | MAP_SHARED), it isn't clear how to do this.

So, mmap() with an fd, so we can create alias mappings. Use memfd_create instead of actually passing in a tmpfs path like hugetlb does, since it's more convenient / simpler to run, and works just as well.

Future commits will:

1. Setup the alias mappings.
2. Extend our tests to actually take advantage of this, to test new userfaultfd behavior being introduced in this series.

Also, a small fix in the area we're changing: when the hugetlb setup fails in main(), pass in the right argv[] so we actually print out the hugetlb file path.

Cc Alexander Viro <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Brian Geffon <[email protected]>
Cc "Dr . David Alan Gilbert" <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Jerome Glisse <[email protected]>
Cc Joe Perches <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Lokesh Gidra <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Mina Almasry <[email protected]>
Cc Oliver Upton <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Stephen Rothwell <[email protected]>
Cc Wang Qing <[email protected]>

---

 tools/testing/selftests/vm/userfaultfd.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-use-memfd_create-for-shmem-test-type +15 -1
@@ -85,6 +85,7 @@ static bool test_uffdio_wp = false;
 static bool test_uffdio_minor = false;
 
 static bool map_shared;
+static int shm_fd;
 static int huge_fd;
 static char *huge_fd_off0;
 static unsigned long long *count_verify;
@@ -277,8 +278,11 @@ static void shmem_release_pages(char *re
 
 static void shmem_allocate_area(void **alloc_area)
 {
+	unsigned long offset =
+		alloc_area == (void **)&area_src ? 0 : nr_pages * page_size;
+
 	*alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
-			   MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+			   MAP_SHARED, shm_fd, offset);
 	if (*alloc_area == MAP_FAILED)
 		err("mmap of memfd failed");
 }
@@ -1602,6 +1606,16 @@ int main(int argc, char **argv)
 			err("Open of %s failed", argv[4]);
 		if (ftruncate(huge_fd, 0))
 			err("ftruncate %s to size 0 failed", argv[4]);
+	} else if (test_type == TEST_SHMEM) {
+		shm_fd = memfd_create(argv[0], 0);
+		if (shm_fd < 0)
+			err("memfd_create");
+		if (ftruncate(shm_fd, nr_pages * page_size * 2))
+			err("ftruncate");
+		if (fallocate(shm_fd,
+			      FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0,
+			      nr_pages * page_size * 2))
+			err("fallocate");
 	}
 	printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n",
 	       nr_pages, nr_pages_per_cpu);

_

Patches currently in -mm which might be from [email protected] are