Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	 Jan Kara <jack@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Ying Huang <huang.ying.caritas@gmail.com>,
	 Kefeng Wang <wangkefeng.wang@huawei.com>,
	 ZhangPeng <zhangpeng362@huawei.com>,
	Hannes Reinecke <hare@suse.de>,
	 Christian Brauner <brauner@kernel.org>,
	 Luis Chamberlain <mcgrof@kernel.org>,
	John Garry <john.garry@linux.dev>,
	 Zhang Yi <yi.zhang@huawei.com>, Baokun Li <libaokun1@huawei.com>,
	 Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	Theodore Ts'o <tytso@mit.edu>
Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	 "David Hildenbrand (Arm)" <david@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] mm/filemap: avoid retrying faults on uffd-wp markers
Date: Sun, 29 Nov 2026 10:05:09 +0100	[thread overview]
Message-ID: <20261129-filemap_fixes-v1-1-1546675e3c97@kernel.org> (raw)
In-Reply-To: <20261129-filemap_fixes-v1-0-1546675e3c97@kernel.org>

filemap_fault_recheck_pte_none() avoids unnecessary major faults in
mlocked mappings by checking whether an apparently empty PTE was only
temporarily cleared. If the PTE is no longer empty, it returns
VM_FAULT_NOPAGE to retry the fault before populating the page cache.

However, filemap_fault() can also be reached with an uffd-wp marker in
vmf->orig_pte. If the page is absent from the page cache, the recheck
treats the nonempty marker as a reason to retry, but the marker remains
unchanged.

Consequently, the fault repeats indefinitely.

This can be reproduced by mapping a fresh sparse regular file, applying
mlock2(MLOCK_ONFAULT), registering for async uffd-wp and write-protecting
the unpopulated mapping. A read from the mapping then fails to complete.

Let's fix it by checking pte_present() instead, allowing marker faults to
populate the page cache while still detecting temporarily cleared
mappings, including NUMA hinting PTEs, and by renaming the helper
accordingly.

This has low urgency, as it requires the unusual combination of
MLOCK_ONFAULT and async uffd-wp.

Fixes: 58f327f2ce80 ("filemap: avoid unnecessary major faults in filemap_fault()")
Cc: stable@vger.kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
 mm/filemap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 5f8c180d6124d..cc547063695ec 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3513,7 +3513,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf,
 	return fpin;
 }
 
-static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf)
+static vm_fault_t filemap_fault_recheck_pte_present(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	vm_fault_t ret = 0;
@@ -3544,11 +3544,11 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf)
 	if (unlikely(!ptep))
 		return VM_FAULT_NOPAGE;
 
-	if (unlikely(!pte_none(ptep_get_lockless(ptep)))) {
+	if (unlikely(pte_present(ptep_get_lockless(ptep)))) {
 		ret = VM_FAULT_NOPAGE;
 	} else {
 		spin_lock(vmf->ptl);
-		if (unlikely(!pte_none(ptep_get(ptep))))
+		if (unlikely(pte_present(ptep_get(ptep))))
 			ret = VM_FAULT_NOPAGE;
 		spin_unlock(vmf->ptl);
 	}
@@ -3613,7 +3613,7 @@ vm_fault_t filemap_fault(struct vm_fault *vmf)
 			mapping_locked = true;
 		}
 	} else {
-		ret = filemap_fault_recheck_pte_none(vmf);
+		ret = filemap_fault_recheck_pte_present(vmf);
 		if (unlikely(ret))
 			return ret;
 

-- 
2.56.1



  reply	other threads:[~2026-11-29  9:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:05 [PATCH 0/2] mm/filemap: two smaller fixes David Hildenbrand (Arm)
2026-11-29  9:05 ` David Hildenbrand (Arm) [this message]
2026-11-29  9:05 ` [PATCH 2/2] mm/filemap: update the folio order range atomically 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=20261129-filemap_fixes-v1-1-1546675e3c97@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=hare@suse.de \
    --cc=huang.ying.caritas@gmail.com \
    --cc=jack@suse.cz \
    --cc=john.garry@linux.dev \
    --cc=libaokun1@huawei.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=wangkefeng.wang@huawei.com \
    --cc=willy@infradead.org \
    --cc=yi.zhang@huawei.com \
    --cc=zhangpeng362@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox