Signed-off-by: Itamar-Dalal dalalitamar@gmail.com --- tools/testing/selftests/mm/rmap.c | 45 ++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/rmap.c b/tools/testing/selftests/mm/rmap.c index 13f7bccfd0a9..2ba3361fecf0 100644 --- a/tools/testing/selftests/mm/rmap.c +++ b/tools/testing/selftests/mm/rmap.c @@ -430,4 +430,47 @@ TEST_F(migrate, ksm) propagate_children(_metadata, data); }
-TEST_HARNESS_MAIN +TEST_F(migrate, cow_after_fork) +{ + struct global_data *data = &self->data; + int status; + pid_t pid; + unsigned long parent_pfn, child_pfn; + int pagemap_fd; + char *region; + + /* Map private anonymous memory and fault it in */ + region = mmap(NULL, data->mapsize, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + ASSERT_NE(region, MAP_FAILED); + memset(region, 0xaa, data->mapsize); + + pagemap_fd = open("/proc/self/pagemap", O_RDONLY); + ASSERT_NE(pagemap_fd, -1); + parent_pfn = pagemap_get_pfn(pagemap_fd, region); + close(pagemap_fd); + + pid = fork(); + ASSERT_NE(pid, -1); + + if (pid == 0) { + /* Child: write to trigger COW */ + region[0] = 0xbb; + + pagemap_fd = open("/proc/self/pagemap", O_RDONLY); + ASSERT_NE(pagemap_fd, -1); + child_pfn = pagemap_get_pfn(pagemap_fd, region); + close(pagemap_fd); + + /* Expect PFN to differ after write (COW happened) */ + if (child_pfn == parent_pfn) + _exit(FAIL_ON_CHECK); + _exit(0); + } + + waitpid(pid, &status, 0); + ASSERT_EQ(WEXITSTATUS(status), 0); + munmap(region, data->mapsize); +} + +TEST_HARNESS_MAIN \ No newline at end of file
On Tue, 14 Oct 2025 22:49:44 +0300 Itamar-Dalal dalalitamar@gmail.com wrote:
Subject: [PATCH] Add a new test 'migrate.cow_after_fork' that verifies correct RMAP handling of Copy-On-Write pages after fork(). Before a write, parent and child share the same PFN; after a write, the child’s PFN differs, confirming proper COW duplication. Date: Tue, 14 Oct 2025 22:49:44 +0300 X-Mailer: git-send-email 2.34.1
Signed-off-by: Itamar-Dalal dalalitamar@gmail.com
tools/testing/selftests/mm/rmap.c | 45 ++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
OK, somehow your changelog was pasted into the email Subject, so please resend.
Please prefix the Subject: with something which tells readers what part of the kernel is affected. eg,
: : Subject: selfstests/mm/rmap: verify correct RMAP handling of COW pages after fork() :
Then enter the details in the changelog body, eg:
: : Before a write, parent and child share the same PFN. After a write, the : child’s PFN differs. Check this to confirm proper COW duplication. :
linux-kselftest-mirror@lists.linaro.org