From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: david@kernel.org, willy@infradead.org, ljs@kernel.org,
liam@infradead.org, vbabka@kernel.org, rppt@kernel.org,
jannh@google.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com,
nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com,
baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev,
kas@kernel.org, muchun.song@linux.dev, osalvador@suse.de,
dave.hansen@linux.intel.com, luto@kernel.org,
peterz@infradead.org, linux@armlinux.org.uk,
catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
chenhuacai@kernel.org, kernel@xen0n.name, maddy@linux.ibm.com,
mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org,
ritesh.list@gmail.com, sshegde@linux.ibm.com, pjw@kernel.org,
palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
agordeev@linux.ibm.com, gerald.schaefer@linux.ibm.com,
corbet@lwn.net, skhan@linuxfoundation.org,
rdunlap@infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org,
linux-s390@vger.kernel.org, linux-doc@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>
Subject: [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY
Date: Sun, 29 Nov 2026 12:22:03 -0800 [thread overview]
Message-ID: <20261129202203.1183277-3-surenb@google.com> (raw)
In-Reply-To: <20261129202203.1183277-1-surenb@google.com>
VM_FAULT_RETRY is returned for two different reasons. It tells the
caller that the fault handler had to drop its lock, usually to wait for
something, so the fault has to be handled again. With per-VMA locks it
is also returned when the fault can not be handled under the per-VMA
lock at all and has to be handled under mmap_lock. The caller can not
tell these two cases apart.
Introduce VM_FAULT_RETRY_LOCK_MM for the second case and return it where
the fault handler falls back from the per-VMA lock to mmap_lock. Those
cases are:
- vmf_can_call_fault(), when the VMA has ->fault but no ->map_pages;
- __vmf_anon_prepare(), when the VMA has no anon_vma yet and mmap_lock
can not be taken without blocking;
- do_swap_page() and do_huge_pmd_device_private(), because
migrate_to_ram() is not ready to operate under the per-VMA lock.
VM_FAULT_RETRY keeps being returned in all the other cases.
vmf_anon_prepare() and hugetlb release the per-VMA lock based on the
result of __vmf_anon_prepare(), so make them check the new code.
should_retry_mm_fault() accepts both codes, so page fault handlers keep
retrying under mmap_lock in both cases. VM_FAULT_RETRY_LOCK_MM is never
returned for a fault that is handled under mmap_lock, so the checks done
after such a fault are left unchanged.
No functional change intended.
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
Documentation/filesystems/porting.rst | 4 ++--
include/linux/mm_types.h | 13 +++++++++++--
mm/huge_memory.c | 2 +-
mm/hugetlb.c | 9 +++++----
mm/internal.h | 2 +-
mm/memory.c | 18 ++++++++++--------
6 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index e41466904501..94db82f2195f 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -944,8 +944,8 @@ Calling convention for ->huge_fault has changed. It now takes a page
order instead of an enum page_entry_size, and it may be called without the
mmap_lock held. All in-tree users have been audited and do not seem to
depend on the mmap_lock being held, but out of tree users should verify
-for themselves. If they do need it, they can return VM_FAULT_RETRY to
-be called with the mmap_lock held.
+for themselves. If they do need it, they can drop the per-VMA lock and
+return VM_FAULT_RETRY_LOCK_MM to be called with the mmap_lock held.
---
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 7a80c904eab9..b46a9dbfe2c8 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1711,6 +1711,8 @@ typedef __bitwise unsigned int vm_fault_t;
* fsync() to complete (for synchronous page faults
* in DAX)
* @VM_FAULT_COMPLETED: ->fault completed, meanwhile mmap lock released
+ * @VM_FAULT_RETRY_LOCK_MM: fault can not be handled under per-VMA lock,
+ * must retry under mmap_lock
* @VM_FAULT_HINDEX_MASK: mask HINDEX value
*
*/
@@ -1728,6 +1730,7 @@ enum vm_fault_reason {
VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000,
VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000,
VM_FAULT_COMPLETED = (__force vm_fault_t)0x004000,
+ VM_FAULT_RETRY_LOCK_MM = (__force vm_fault_t)0x008000,
VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000,
};
@@ -1743,12 +1746,17 @@ enum vm_fault_reason {
* should_retry_mm_fault - Check whether a page fault has to be retried.
* @fault: The fault result returned by handle_mm_fault().
*
+ * A fault handled under the per-VMA lock can fail with either
+ * VM_FAULT_RETRY_LOCK_MM, when it has to be handled under mmap_lock, or with
+ * VM_FAULT_RETRY for all the other reasons to retry. A fault handled under
+ * mmap_lock can only fail with the latter.
+ *
* Return: true if the fault was not handled and the caller has to retry it,
* false otherwise.
*/
static inline bool should_retry_mm_fault(vm_fault_t fault)
{
- return !!(fault & VM_FAULT_RETRY);
+ return !!(fault & (VM_FAULT_RETRY | VM_FAULT_RETRY_LOCK_MM));
}
#define VM_FAULT_RESULT_TRACE \
@@ -1764,7 +1772,8 @@ static inline bool should_retry_mm_fault(vm_fault_t fault)
{ (__force u32)VM_FAULT_FALLBACK, "FALLBACK" }, \
{ (__force u32)VM_FAULT_DONE_COW, "DONE_COW" }, \
{ (__force u32)VM_FAULT_NEEDDSYNC, "NEEDDSYNC" }, \
- { (__force u32)VM_FAULT_COMPLETED, "COMPLETED" }
+ { (__force u32)VM_FAULT_COMPLETED, "COMPLETED" }, \
+ { (__force u32)VM_FAULT_RETRY_LOCK_MM, "RETRY_LOCK_MM" }
struct vm_special_mapping {
const char *name; /* The name, e.g. "[vdso]". */
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 4fc888ddfb69..23a5dfe05824 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1479,7 +1479,7 @@ vm_fault_t do_huge_pmd_device_private(struct vm_fault *vmf)
if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
vma_end_read(vma);
- return VM_FAULT_RETRY;
+ return VM_FAULT_RETRY_LOCK_MM;
}
ptl = pmd_lock(vma->vm_mm, vmf->pmd);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 4386425b5ce5..4f3eea0b1e67 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6130,9 +6130,9 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping,
/*
* We must check to release the per-VMA lock. __vmf_anon_prepare() is
- * the only way ret can be set to VM_FAULT_RETRY.
+ * the only way ret can be set to VM_FAULT_RETRY_LOCK_MM.
*/
- if (unlikely(ret & VM_FAULT_RETRY))
+ if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM))
vma_end_read(vma);
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
@@ -6391,9 +6391,10 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
/*
* We must check to release the per-VMA lock. __vmf_anon_prepare() in
- * hugetlb_wp() is the only way ret can be set to VM_FAULT_RETRY.
+ * hugetlb_wp() is the only way ret can be set to
+ * VM_FAULT_RETRY_LOCK_MM.
*/
- if (unlikely(ret & VM_FAULT_RETRY))
+ if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM))
vma_end_read(vma);
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
diff --git a/mm/internal.h b/mm/internal.h
index f865d7b0c94b..a65192d8358d 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -574,7 +574,7 @@ static inline vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
{
vm_fault_t ret = __vmf_anon_prepare(vmf);
- if (unlikely(ret & VM_FAULT_RETRY))
+ if (unlikely(ret & VM_FAULT_RETRY_LOCK_MM))
vma_end_read(vmf->vma);
return ret;
}
diff --git a/mm/memory.c b/mm/memory.c
index e0f1aeed713c..682d1167eb49 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4021,7 +4021,7 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf)
if (vma->vm_ops->map_pages || !(vmf->flags & FAULT_FLAG_VMA_LOCK))
return 0;
vma_end_read(vma);
- return VM_FAULT_RETRY;
+ return VM_FAULT_RETRY_LOCK_MM;
}
/**
@@ -4037,7 +4037,8 @@ static inline vm_fault_t vmf_can_call_fault(const struct vm_fault *vmf)
* do with only the per-VMA lock held for this VMA.
*
* Return: 0 if fault handling can proceed. Any other value should be
- * returned to the caller.
+ * returned to the caller. VM_FAULT_RETRY_LOCK_MM is returned with the
+ * per-VMA lock still held if the fault has to be retried under mmap_lock.
*/
vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf)
{
@@ -4048,7 +4049,7 @@ vm_fault_t __vmf_anon_prepare(struct vm_fault *vmf)
return 0;
if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
if (!mmap_read_trylock(vma->vm_mm))
- return VM_FAULT_RETRY;
+ return VM_FAULT_RETRY_LOCK_MM;
}
if (__anon_vma_prepare(vma))
ret = VM_FAULT_OOM;
@@ -5046,7 +5047,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
* under VMA lock.
*/
vma_end_read(vma);
- ret = VM_FAULT_RETRY;
+ ret = VM_FAULT_RETRY_LOCK_MM;
goto out;
}
@@ -6744,9 +6745,9 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
/*
* On entry, we hold either the VMA lock or the mmap_lock
- * (see FAULT_FLAG_VMA_LOCK). If VM_FAULT_RETRY is set in
- * the result, the lock is not held on exit. See filemap_fault()
- * and __folio_lock_or_retry().
+ * (see FAULT_FLAG_VMA_LOCK). If VM_FAULT_RETRY or
+ * VM_FAULT_RETRY_LOCK_MM is set in the result, the lock is not held
+ * on exit. See filemap_fault() and __folio_lock_or_retry().
*/
static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
unsigned long address, unsigned int flags)
@@ -6966,7 +6967,8 @@ static vm_fault_t sanitize_fault_flags(struct vm_area_struct *vma,
}
/*
* Per-VMA locks can't be used with FAULT_FLAG_RETRY_NOWAIT because of
- * the assumption that lock is dropped on VM_FAULT_RETRY.
+ * the assumption that lock is dropped on VM_FAULT_RETRY and
+ * VM_FAULT_RETRY_LOCK_MM.
*/
if (WARN_ON_ONCE((*flags &
(FAULT_FLAG_VMA_LOCK | FAULT_FLAG_RETRY_NOWAIT)) ==
--
2.56.1.839.g22a8290db9-goog
prev parent reply other threads:[~2026-11-29 20:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 20:22 [RFC PATCH 0/2] mm: separate the fallback to mmap_lock from VM_FAULT_RETRY Suren Baghdasaryan
2026-11-29 20:22 ` [RFC PATCH 1/2] mm: introduce should_retry_mm_fault() helper Suren Baghdasaryan
2026-11-29 20:22 ` Suren Baghdasaryan [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=20261129202203.1183277-3-surenb@google.com \
--to=surenb@google.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=catalin.marinas@arm.com \
--cc=chenhuacai@kernel.org \
--cc=chleroy@kernel.org \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=jannh@google.com \
--cc=kas@kernel.org \
--cc=kernel@xen0n.name \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ljs@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=maddy@linux.ibm.com \
--cc=mark.rutland@arm.com \
--cc=mpe@ellerman.id.au \
--cc=muchun.song@linux.dev \
--cc=nico.pache@linux.dev \
--cc=npiggin@gmail.com \
--cc=osalvador@suse.de \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=rdunlap@infradead.org \
--cc=ritesh.list@gmail.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=skhan@linuxfoundation.org \
--cc=sshegde@linux.ibm.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=will@kernel.org \
--cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®