Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Itamar Dalal <dalalitamar@gmail.com>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	lorenzo.stoakes@oracle.com, riel@surriel.com,
	Liam.Howlett@oracle.com, vbabka@suse.cz, harry.yoo@oracle.com,
	jannh@google.com, rppt@kernel.org, surenb@google.com,
	mhocko@suse.com, shuah@kernel.org
Subject: Re: selftests/mm/rmap: verify correct RMAP handling of COW pages after fork()
Date: Wed, 15 Oct 2025 10:47:21 +0200	[thread overview]
Message-ID: <9c323deb-ded8-480a-ab96-34ea47194a16@redhat.com> (raw)
In-Reply-To: <CAJoePDqCd6F0ai1itmVATawqMQzB+JRi4NUtMJtxyeOVOT56VQ@mail.gmail.com>

On 15.10.25 10:33, Itamar Dalal wrote:
> Add a new test `migrate.cow_after_fork` that verifies correct RMAP handling
> of Copy-On-Write (COW) pages after fork().
> 
> Before a write, the parent and child share the same PFN. After a write, the
> child’s PFN differs. This confirms that proper COW duplication occurred and
> that RMAP correctly tracks page ownership transitions during COW events.
> 
> Signed-off-by: Itamar-Dalal <dalalitamar@gmail.com 
> <mailto: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);
> +}

We have excessive cow tests in cow.c, that are independent of any PFN 
checks.

So I don't think we need this.

BTW, I never received a mail that shows up right-aligned in my mail client.

Seems to be because of

Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"rtl"

The whole attachment should be dropped. Did you send this with 
git-send-email? :)

-- 
Cheers

David / dhildenb


       reply	other threads:[~2025-10-15  8:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAJoePDqCd6F0ai1itmVATawqMQzB+JRi4NUtMJtxyeOVOT56VQ@mail.gmail.com>
2025-10-15  8:47 ` David Hildenbrand [this message]
2025-10-15  8:43 selftests/mm/rmap: verify correct RMAP handling of COW pages after fork() Itamar Dalal
2025-10-15  8:49 ` David Hildenbrand
2025-10-15  9:02   ` Mike Rapoport

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=9c323deb-ded8-480a-ab96-34ea47194a16@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dalalitamar@gmail.com \
    --cc=harry.yoo@oracle.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /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