From: Kiryl Shutsemau <kirill@shutemov.name>
To: Zenghui Yu <zenghui.yu@linux.dev>
Cc: akpm@linux-foundation.org, usama.anjum@collabora.com,
peterx@redhat.com, liam@infradead.org, ljs@kernel.org,
vbabka@kernel.org, jannh@google.com, pfalcato@suse.de,
david@kernel.org, rppt@kernel.org, surenb@google.com,
mhocko@suse.com, shuah@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kselftest@vger.kernel.org, stable@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH v3] fs/proc/task_mmu: fix PAGEMAP_SCAN written state for PMD holes
Date: Mon, 13 Jul 2026 10:16:07 +0100 [thread overview]
Message-ID: <alSqkTahOx9uc2Uc@thinkstation> (raw)
In-Reply-To: <88169a4d-157a-4307-8e21-554b122fb411@linux.dev>
On Sun, Jul 12, 2026 at 09:14:12AM +0800, Zenghui Yu wrote:
> Hi Kiryl,
>
> On 7/9/26 8:16 PM, Kiryl Shutsemau wrote:
> > From: "Kiryl Shutsemau (Meta)" <kas@kernel.org>
> >
> > PAGEMAP_SCAN reports an unpopulated PTE in a uffd-wp VMA as written, but
> > a range with no page table at all -- a PMD hole -- is skipped:
> > pagemap_scan_pte_hole() tests p->cur_vma_category, which never carries
> > PAGE_IS_WRITTEN, so the hole is neither reported nor (under
> > PM_SCAN_WP_MATCHING) armed.
> >
> > MADV_DONTNEED has fill-with-zeros semantics: it changes the contents of
> > the range to zeroes (a subsequent read maps the zero page), which write
> > tracking must report as written. An anonymous THP is write-protected in
> > place as a huge PMD, so a full-PMD MADV_DONTNEED clears it to pmd_none --
> > a hole -- and the zeroing goes unreported. A write-tracking
> > checkpoint/migration tool (e.g. CRIU) then treats the range as unchanged
> > and keeps its previous contents, so after restore or live migration the
> > process reads stale data instead of zeroes -- data corruption.
> >
> > Report a hole in a non-hugetlb uffd-wp VMA as written, matching the
> > pte_none handling in pagemap_page_category(); the existing
> > PM_SCAN_WP_MATCHING path then arms it via uffd_wp_range().
> >
> > hugetlb is excluded: pagemap_hugetlb_category() reports an empty hugetlb
> > entry (huge_pte_none) as not-written, unlike pagemap_page_category(),
> > which reports pte_none as written. pagemap_scan_pte_hole() fires for a
> > hugetlb slot only when it has no page table; keeping that not-written
> > matches how an allocated-but-empty hugetlb entry reads, so the hole and
> > the empty-entry cases agree within the VMA.
> >
> > Add a pagemap_ioctl selftest covering the anon-THP PMD-hole case.
> >
> > Reported-by: Sashiko AI review <sashiko-bot@kernel.org>
> > Closes: https://sashiko.dev/#/patchset/20260707151349.92143-1-kirill@shutemov.name
> > Fixes: 2bad466cc9d9 ("mm/uffd: UFFD_FEATURE_WP_UNPOPULATED")
> > Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
> > Cc: Peter Xu <peterx@redhat.com>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> > Assisted-by: Claude:claude-fable-5
> > ---
> >
> > Changes since v2 [1], addressing Andrew's review:
> > - Describe the user-visible effect: MADV_DONTNEED has fill-with-zeros
> > semantics, so the range must be reported written; otherwise a
> > checkpoint/migration tool (CRIU) keeps stale data and the process
> > reads corrupted contents after restore. Add Reported-by/Closes.
> > - Reword the hugetlb carve-out to rest on the category functions:
> > pagemap_hugetlb_category() reads an empty hugetlb entry as
> > not-written, unlike pagemap_page_category().
> > - Drop the redundant MADV_COLLAPSE fallback #define; it is in
> > <asm-generic/mman-common.h> and used directly by other mm selftests.
>
> I hit the following compilation error on mm-new:
>
> [root@localhost mm]# make
> CC pagemap_ioctl
> pagemap_ioctl.c: In function 'unpopulated_thp_hole_test':
> pagemap_ioctl.c:1130:31: error: 'MADV_COLLAPSE' undeclared (first use in this function); did you mean 'MADV_COLD'?
> 1130 | if (madvise(mem, hpage_size, MADV_COLLAPSE) ||
> | ^~~~~~~~~~~~~
> | MADV_COLD
> pagemap_ioctl.c:1130:31: note: each undeclared identifier is reported only once for each function it appears in
> make: *** [../lib.mk:225: /root/code/mm/tools/testing/selftests/mm/pagemap_ioctl] Error 1
>
> Could you consider addressing it like fd5295afae91 ("selftests/mm:
> hmm-tests: include linux/mman.h to access MADV_COLLAPSE")?
Yep, will send v4.
--
Kiryl Shutsemau / Kirill A. Shutemov
prev parent reply other threads:[~2026-07-13 9:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 12:16 [PATCH v3] fs/proc/task_mmu: fix PAGEMAP_SCAN written state for PMD holes Kiryl Shutsemau
2026-07-12 1:14 ` Zenghui Yu
2026-07-13 9:16 ` Kiryl Shutsemau [this message]
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=alSqkTahOx9uc2Uc@thinkstation \
--to=kirill@shutemov.name \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=kernel-team@meta.com \
--cc=liam@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=peterx@redhat.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=usama.anjum@collabora.com \
--cc=vbabka@kernel.org \
--cc=zenghui.yu@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.