Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"David Hildenbrand" <david@kernel.org>
Cc: "Jan Kara" <jack@suse.cz>, "Jingyi Sun" <1045704958@qq.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Michal Hocko" <mhocko@suse.com>,
	"Muhammad Usama Anjum" <usama.anjum@arm.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	linux-mm@kvack.org, nvdimm@lists.linux.dev
Subject: Re: [PATCH 3/3] mm/memory: don't upgrade non-present PTEs in insert_page_into_pte_locked()
Date: Wed, 18 Nov 2026 15:59:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-221397@kernel.org> (raw)
In-Reply-To: <20261117-uffd-dax-async-wp-fix-v1-3-c9a30f27f452@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/memory: insert_page_into_pte_locked() upgrades uffd-wp
  PTEs to writable
--

commit 62002bc33a7233bf10217f5cd96cf7d78e384960
Author: Mike Rapoport (Microsoft) <rppt@kernel.org>

mm/memory: don't upgrade non-present PTEs in insert_page_into_pte_locked()

This commit changes insert_page_into_pte_locked() to return -EBUSY when
encountering a non-present PTE on a write fault so that PTE markers are
retried through handle_pte_marker() instead of being upgraded in place.

> diff --git a/mm/memory.c b/mm/memory.c
> index 66ad58429967e..a80925c61706d 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2474,7 +2474,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte,
>  		return 0;
>  	}
>  
> -	if (!mkwrite)
> +	if (!mkwrite || !pte_present(pteval))
>  		return -EBUSY;

[Severity: Medium]
Can this still upgrade a present PTE that is write-protected by
userfaultfd-wp in place?

When two threads fault concurrently on a PTE_MARKER_UFFD_WP entry in a
shared DAX mapping, the first fault installs a present read-only PTE with
pte_mkuffd() set, and the second write fault then sees a present PTE and
upgrades it with maybe_mkwrite():

CPU0 (read fault)                 CPU1 (write fault, mkwrite = true)
dax_iomap_pte_fault()             dax_iomap_pte_fault()
  vmf_insert_page()                 vmf_insert_page_mkwrite()
    insert_page_into_pte_locked()
      /* uffd_wp_marker is true */
      pteval = pte_mkuffd(pteval)
      set_pte_at(..., pteval)
                                      insert_page_into_pte_locked()
                                        /* pte_present(pteval) is true */
                                        pteval = maybe_mkwrite(pteval, vma)
                                        ptep_set_access_flags(..., pteval, 1)
                                          <-- pte_uffd() && pte_write()

Because maybe_mkwrite() sets the writable bit without clearing the uffd-wp
bit, this installs a present PTE with both pte_uffd() and pte_write() set.
That triggers the WARN_ON_ONCE(pte_uffd(pte) && pte_write(pte)) in
page_table_check_pte_flags() and allows subsequent writes to bypass
do_wp_page(), losing userfaultfd-wp write tracking.

Should this check also return -EBUSY when userfaultfd_pte_wp(vma, pteval)
is true so the fault retries through do_wp_page()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-uffd-dax-async-wp-fix-v1-0-c9a30f27f452@kernel.org?part=3


  parent reply	other threads:[~2026-11-18 15:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:58 [PATCH 0/3] mm/memory: fix handling of PTE markers in insert_page_into_pte_locked() Mike Rapoport (Microsoft)
2026-11-17 15:58 ` [PATCH 1/3] mm/memory: install new PTEs first " Mike Rapoport (Microsoft)
2026-11-17 15:58 ` [PATCH 2/3] mm/memory: replace uffd-wp markers " Mike Rapoport (Microsoft)
2026-11-18 15:59   ` sashiko-bot
2026-11-17 15:58 ` [PATCH 3/3] mm/memory: don't upgrade non-present PTEs " Mike Rapoport (Microsoft)
2026-11-18 10:05   ` David Hildenbrand (Arm)
2026-11-18 14:27   ` Lorenzo Stoakes (ARM)
2026-11-18 14:47   ` David Hildenbrand (Arm)
2026-11-18 15:59   ` sashiko-bot [this message]
2026-11-17 16:22 ` [PATCH 0/3] mm/memory: fix handling of PTE markers " David Hildenbrand (Arm)
2026-11-17 19:31   ` Mike Rapoport
2026-11-17 20:19     ` David Hildenbrand (Arm)
2026-11-18 14:56 ` (subset) " David Hildenbrand

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=sashiko-outbox-221397@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=1045704958@qq.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jack@suse.cz \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=peterx@redhat.com \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=usama.anjum@arm.com \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.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