All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: sashiko-reviews@lists.linux.dev, Jonathan Corbet <corbet@lwn.net>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	 Vlastimil Babka <vbabka@kernel.org>,
	Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
	 Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	 Michal Hocko <mhocko@suse.com>, Peter Xu <peterx@redhat.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Zi Yan <ziy@nvidia.com>,
	 Baolin Wang <baolin.wang@linux.alibaba.com>,
	Nico Pache <nico.pache@linux.dev>,
	 Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>,
	 Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	 Kiryl Shutsemau <kas@kernel.org>,
	Axel Rasmussen <axelrasmussen@google.com>,
	linux-mm@kvack.org,  linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm/khugepaged: check for empty PTE tables before retracting
Date: Tue, 10 Nov 2026 17:08:15 +0000	[thread overview]
Message-ID: <avNO1pvPuMYIdYTE@gremlin> (raw)
In-Reply-To: <28b818cb-f038-43ce-a2e2-a9c97befba09@kernel.org>

On Mon, Nov 09, 2026 at 04:08:23PM +0100, David Hildenbrand (Arm) wrote:
> On 11/8/26 00:51, sashiko-bot@kernel.org wrote:
> > [Severity: Medium]
> > Can removing the VM_COPY_ON_FORK flag checks here cause retract_page_tables()
> > to race with copy_page_range() during fork()?
> >
> > In dup_mmap(), the child VMA is linked into mapping->i_mmap and
> > i_mmap_unlock_write(mapping) is dropped before copy_page_range() runs.
> > vma_needs_copy() copies page tables not only when vma_has_anon_rmap() is set,
> > but also when VM_COPY_ON_FORK flags (VM_MAYBE_GUARD, VM_MAYBE_UFFD_POISON,
> > VM_UFFD_WP, or VM_UFFD_RWP) are set on a file or shmem VMA whose anon_vma is
> > still NULL.
>
> Ah, try_collapse_pte_mapped_thp() runs withe the mmap lock, whereby
> retract_page_tables() only holds the rmap lock.

[ ... ]

> > Once the PMD is pmd_none, the next fault in finish_fault() installs a huge
> > PMD before checking userfaultfd_armed(vma):
> >
> > mm/memory.c:finish_fault() {
> > 	if (pmd_none(*vmf->pmd)) {
> > 		if (!needs_fallback && folio_test_pmd_mappable(folio)) {
> > 			ret = do_set_pmd(vmf, folio, page);
> > 			if (ret != VM_FAULT_FALLBACK)
> > 				return ret;
> > 		}
> >     ...
> > 	/* Using per-page fault to maintain the uffd semantics */
> > 	if (unlikely(userfaultfd_armed(vma)) || unlikely(needs_fallback)) {
> > 		nr_pages = 1;
> > }
> >
> > When userspace later issues UFFDIO_RWPROTECT on that file or shmem VMA,
> > change_pmd_range() sees pgtable_split_needed() is true and calls
> > __split_huge_pmd(), which zaps the file huge PMD back to pmd_none without
> > populating a PTE table (since pgtable_populate_needed() is false for
> > MM_CP_UFFD_RWP), so RWP protection is lost and subsequent accesses fault the
> > unprotected huge PMD back in without delivering RWP faults.  Installing a
> > huge PMD also causes PAGEMAP_SCAN to report all 512 pages as accessed or
> > written after a single 4KB page fault.
>
> "Since pgtable_populate_needed() is false for MM_CP_UFFD_RWP" I think RWP also
> needs proper uffd marker support, independent of the change here.

Hey,

Wondered if you planned to do a respin on this? Want to know whether to delay
review for that or not, thanks!

--
Cheers, Lorenzo


  reply	other threads:[~2026-11-10 17:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 23:51 [PATCH 0/2] mm/userfaultfd: prevent poison marker loss David Hildenbrand (Arm)
2026-11-06 23:51 ` [PATCH 1/2] " David Hildenbrand (Arm)
2026-11-06 23:51 ` [PATCH 2/2] mm/khugepaged: check for empty PTE tables before retracting David Hildenbrand (Arm)
2026-11-07 23:51   ` sashiko-bot
2026-11-09 15:08     ` David Hildenbrand (Arm)
2026-11-10 17:08       ` Lorenzo Stoakes (ARM) [this message]
2026-11-11  8:17         ` David Hildenbrand (Arm)

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=avNO1pvPuMYIdYTE@gremlin \
    --to=ljs@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=ziy@nvidia.com \
    /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.