All of 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 2/3] mm/memory: replace uffd-wp markers in insert_page_into_pte_locked()
Date: Wed, 18 Nov 2026 15:59:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-221396@kernel.org> (raw)
In-Reply-To: <20261117-uffd-dax-async-wp-fix-v1-2-c9a30f27f452@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm: uffd-wp bit not checked on mkwrite in
  insert_page_into_pte_locked()
--

commit 6bd6838d9e7f98f448f46bdb05cc4400045f49f7
Author: Mike Rapoport (Microsoft) <rppt@kernel.org>

mm/memory: replace uffd-wp markers in insert_page_into_pte_locked()

This commit updates insert_page_into_pte_locked() to replace uffd-wp PTE
markers with a new PTE that preserves the uffd-wp bit when handling faults
on DAX mappings.

> diff --git a/mm/memory.c b/mm/memory.c
> index f927f2241e404..66ad58429967e 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -2452,8 +2452,9 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte,
>  {
>  	struct folio *folio = page_folio(page);
>  	pte_t pteval = ptep_get(pte);
> +	bool uffd_wp_marker = pte_is_uffd_wp_marker(pteval);
>  
> -	if (pte_none(pteval)) {
> +	if (pte_none(pteval) || uffd_wp_marker) {
>  		pteval = mk_pte(page, prot);
>  		if (unlikely(is_zero_folio(folio))) {
>  			pteval = pte_mkspecial(pteval);
> @@ -2467,6 +2468,8 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte,
>  			inc_mm_counter(vma->vm_mm, mm_counter_file(folio));
>  			folio_add_file_rmap_pte(folio, page, vma);
>  		}
> +		if (uffd_wp_marker && userfaultfd_wp(vma))
> +			pteval = pte_mkuffd(pteval);
>  		set_pte_at(vma->vm_mm, addr, pte, pteval);
>  		return 0;
>  	}

[Severity: Medium]
Can a concurrent write fault in insert_page_into_pte_locked() mark a
present uffd-wp PTE writable without clearing the uffd-wp bit?

DAX fault handlers serialize on the DAX mapping entry lock in
grab_mapping_entry() and only acquire the page table lock inside
vmf_insert_page_mkwrite() -> insert_page() ->
insert_page_into_pte_locked().  If a read fault and a write fault race on
the same uffd-wp PTE marker:

CPU0 (read fault)                 CPU1 (write fault, mkwrite = true)
dax_iomap_pte_fault()             dax_iomap_pte_fault()
  grab_mapping_entry()
  dax_fault_iter()
    vmf_insert_page()
      insert_page_into_pte_locked()
        /* replaces marker with
         * present RO uffd-wp PTE
         */
        pteval = pte_mkuffd(pteval)
        set_pte_at(..., pteval)
  dax_unlock_entry()
                                    grab_mapping_entry()
                                    dax_fault_iter()
                                      vmf_insert_page_mkwrite()
                                        insert_page_into_pte_locked()
                                          /* pte_none() and uffd_wp_marker
                                           * are both false
                                           */
                                          pteval = maybe_mkwrite(pteval, vma)
                                          ptep_set_access_flags(..., pteval, 1)
                                            <-- pte_write() && pte_uffd()

In the existing-PTE path of insert_page_into_pte_locked(), maybe_mkwrite()
sets the writable bit without checking userfaultfd_pte_wp(vma, pteval):

mm/memory.c:insert_page_into_pte_locked() {
    ...
	if (pte_pfn(pteval) != page_to_pfn(page)) {
		WARN_ON_ONCE(!is_zero_pfn(pte_pfn(pteval)));
		return -EFAULT;
	}
	pteval = maybe_mkwrite(pteval, vma);
	pteval = pte_mkyoung(pteval);
	if (ptep_set_access_flags(vma, addr, pte, pteval, 1))
		update_mmu_cache(vma, addr, pte);
}

This leaves the present PTE with both pte_write() and pte_uffd() set,
which triggers WARN_ON_ONCE(pte_uffd(pte) && pte_write(pte)) in
page_table_check_pte_flags() when CONFIG_PAGE_TABLE_CHECK is enabled and
breaks UFFD_FEATURE_WP_ASYNC write tracking because hardware writes no
longer trap into do_wp_page() while pagemap_scan sees pte_uffd() still
set.

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


  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 [this message]
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
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-221396@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 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.