From: akpm@linux-foundation.org
To: akpm@linux-foundation.org, hughd@google.com,
joel@joelfernandes.org, linux-mm@kvack.org,
mm-commits@vger.kernel.org, ngeoffray@google.com,
shuah@kernel.org, torvalds@linux-foundation.org
Subject: [patch 070/158] memfd: add test for COW on MAP_PRIVATE and F_SEAL_FUTURE_WRITE mappings
Date: Sat, 30 Nov 2019 17:53:31 -0800 [thread overview]
Message-ID: <20191201015331.lZ47gCN7K%akpm@linux-foundation.org> (raw)
From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
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@joelfernandes.org
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Nicolas Geoffray <ngeoffray@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
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);
_
reply other threads:[~2019-12-01 1:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191201015331.lZ47gCN7K%akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=joel@joelfernandes.org \
--cc=linux-mm@kvack.org \
--cc=mm-commits@vger.kernel.org \
--cc=ngeoffray@google.com \
--cc=shuah@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).