+ memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: memfd: add test for COW on MAP_PRIVATE and F_SEAL_FUTURE_WRITE mappings
has been added to the -mm tree.  Its filename is
     memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: "Joel Fernandes (Google)" <joel@xxxxxxxxxxxxxxxxx>
Subject: memfd: add test for COW on MAP_PRIVATE and F_SEAL_FUTURE_WRITE mappings

In this test, the parent and child both have writable private mappings. 
The test shows that without the patch in this series, the parent and child
shared the same memory which is incorrect.  In other words, COW needs to
be triggered so any writes to child's copy stays local to the child.

Link: http://lkml.kernel.org/r/20191107195355.80608-2-joel@xxxxxxxxxxxxxxxxx
Signed-off-by: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx>
Cc: Hugh Dickins <hughd@xxxxxxxxxx>
Cc: Nicolas Geoffray <ngeoffray@xxxxxxxxxx>
Cc: Shuah Khan <shuah@xxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 tools/testing/selftests/memfd/memfd_test.c |   36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

--- a/tools/testing/selftests/memfd/memfd_test.c~memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings
+++ a/tools/testing/selftests/memfd/memfd_test.c
@@ -290,6 +290,40 @@ static void mfd_assert_read_shared(int f
 	munmap(p, mfd_def_size);
 }
 
+static void mfd_assert_fork_private_write(int fd)
+{
+	int *p;
+	pid_t pid;
+
+	p = mmap(NULL,
+		 mfd_def_size,
+		 PROT_READ | PROT_WRITE,
+		 MAP_PRIVATE,
+		 fd,
+		 0);
+	if (p == MAP_FAILED) {
+		printf("mmap() failed: %m\n");
+		abort();
+	}
+
+	p[0] = 22;
+
+	pid = fork();
+	if (pid == 0) {
+		p[0] = 33;
+		exit(0);
+	} else {
+		waitpid(pid, NULL, 0);
+
+		if (p[0] != 22) {
+			printf("MAP_PRIVATE copy-on-write failed: %m\n");
+			abort();
+		}
+	}
+
+	munmap(p, mfd_def_size);
+}
+
 static void mfd_assert_write(int fd)
 {
 	ssize_t l;
@@ -760,6 +794,8 @@ static void test_seal_future_write(void)
 	mfd_assert_read_shared(fd2);
 	mfd_fail_write(fd2);
 
+	mfd_assert_fork_private_write(fd);
+
 	munmap(p, mfd_def_size);
 	close(fd2);
 	close(fd);
_

Patches currently in -mm which might be from joel@xxxxxxxxxxxxxxxxx are

mm-emit-tracepoint-when-rss-changes.patch
rss_stat-add-support-to-detect-rss-updates-of-external-mm.patch
memfd-add-test-for-cow-on-map_private-and-f_seal_future_write-mappings.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux