Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] mm: separate the fallback to mmap_lock from VM_FAULT_RETRY
@ 2026-11-29 20:22 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 ` [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY Suren Baghdasaryan
  0 siblings, 2 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2026-11-29 20:22 UTC (permalink / raw)
  To: akpm
  Cc: david, willy, ljs, liam, vbabka, rppt, jannh, ziy, baolin.wang,
	nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
	usama.arif, kas, muchun.song, osalvador, dave.hansen, luto,
	peterz, linux, catalin.marinas, will, mark.rutland, chenhuacai,
	kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
	palmer, aou, alex, agordeev, gerald.schaefer, corbet, skhan,
	rdunlap, linux-mm, linux-kernel, linux-arm-kernel, loongarch,
	linuxppc-dev, linux-riscv, linux-s390, linux-doc,
	Suren Baghdasaryan

VM_FAULT_RETRY is returned from the page fault path for two different
reasons.  Usually it means that the fault handler had to drop its lock,
typically to wait for something, and 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
architecture fault handlers can not tell these two cases apart, so every
VM_FAULT_RETRY from a fault handled under the per-VMA lock results in a
retry under mmap_lock.

This series separates the two cases:

Patch 1 introduces should_retry_mm_fault() and uses it in the per-VMA lock
path of the architecture fault handlers, in fault_signal_pending() and in
mm_account_fault() instead of testing VM_FAULT_RETRY directly.

Patch 2 introduces VM_FAULT_RETRY_LOCK_MM and returns it from the places
that fall back from the per-VMA lock to mmap_lock: vmf_can_call_fault(),
__vmf_anon_prepare() and the device private paths in do_swap_page() and
do_huge_pmd_device_private(). VM_FAULT_RETRY keeps being returned in all
the other cases.

should_retry_mm_fault() accepts both codes and the architecture fault
handlers keep retrying under mmap_lock in both cases, so no functional
change is intended.  The series only makes the reason for the retry
visible to the callers of handle_mm_fault().

Only the checks in the per-VMA lock path are converted.  The checks done
after handling a fault under mmap_lock still test VM_FAULT_RETRY, since
VM_FAULT_RETRY_LOCK_MM is never returned there.

Drivers and filesystems that return VM_FAULT_RETRY are left unchanged.
panthor_gem_any_fault() might return it after dropping the per-VMA lock
and waiting, which is treated as a generic retry.

The series is based on mm-unstable.

Suren Baghdasaryan (2):
  mm: introduce should_retry_mm_fault() helper
  mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY

 Documentation/filesystems/porting.rst |  4 ++--
 arch/arm/mm/fault.c                   |  4 ++--
 arch/arm64/mm/fault.c                 |  4 ++--
 arch/loongarch/mm/fault.c             |  4 ++--
 arch/powerpc/mm/fault.c               |  4 ++--
 arch/riscv/mm/fault.c                 |  4 ++--
 arch/s390/mm/fault.c                  |  4 ++--
 arch/x86/mm/fault.c                   |  4 ++--
 include/linux/mm_types.h              | 23 ++++++++++++++++++++++-
 include/linux/sched/signal.h          |  2 +-
 mm/huge_memory.c                      |  2 +-
 mm/hugetlb.c                          |  9 +++++----
 mm/internal.h                         |  2 +-
 mm/memory.c                           | 20 +++++++++++---------
 14 files changed, 57 insertions(+), 33 deletions(-)


base-commit: 890dc639d8a33e674caa7ea9993dbd2416660447
-- 
2.56.1.839.g22a8290db9-goog



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 1/2] mm: introduce should_retry_mm_fault() helper
  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 ` Suren Baghdasaryan
  2026-11-29 20:22 ` [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY Suren Baghdasaryan
  1 sibling, 0 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2026-11-29 20:22 UTC (permalink / raw)
  To: akpm
  Cc: david, willy, ljs, liam, vbabka, rppt, jannh, ziy, baolin.wang,
	nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
	usama.arif, kas, muchun.song, osalvador, dave.hansen, luto,
	peterz, linux, catalin.marinas, will, mark.rutland, chenhuacai,
	kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
	palmer, aou, alex, agordeev, gerald.schaefer, corbet, skhan,
	rdunlap, linux-mm, linux-kernel, linux-arm-kernel, loongarch,
	linuxppc-dev, linux-riscv, linux-s390, linux-doc,
	Suren Baghdasaryan

Page fault handlers test VM_FAULT_RETRY in the result of handle_mm_fault()
to decide whether the fault has to be retried.  For a fault that was
handled under the per-VMA lock, this means falling back to handling it
under mmap_lock.

Introduce should_retry_mm_fault() and use it for these checks in the
per-VMA lock path of the architecture fault handlers, in
fault_signal_pending() and in mm_account_fault().  This keeps the set of
fault codes that request a retry in one place, in preparation for
splitting VM_FAULT_RETRY into separate codes.

The checks done after handling the fault under mmap_lock are left
unchanged.

No functional change intended.

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
 arch/arm/mm/fault.c          |  4 ++--
 arch/arm64/mm/fault.c        |  4 ++--
 arch/loongarch/mm/fault.c    |  4 ++--
 arch/powerpc/mm/fault.c      |  4 ++--
 arch/riscv/mm/fault.c        |  4 ++--
 arch/s390/mm/fault.c         |  4 ++--
 arch/x86/mm/fault.c          |  4 ++--
 include/linux/mm_types.h     | 12 ++++++++++++
 include/linux/sched/signal.h |  2 +-
 mm/memory.c                  |  2 +-
 10 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 0a09d4ff7718..48e2aa4dbb63 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -407,10 +407,10 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 		goto bad_area;
 	}
 	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index b22736853fcd..41165beccab0 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -718,10 +718,10 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr,
 	}
 
 	fault = handle_mm_fault(vma, addr, mm_flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index 2c93d33356e5..edbf700af18e 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -247,10 +247,10 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
 	}
 
 	fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 806c74e0d5ab..eaadb8023eb2 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -503,10 +503,10 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address,
 	}
 
 	fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 04ed6f8acae4..742b2cc3b495 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -360,10 +360,10 @@ void handle_page_fault(struct pt_regs *regs)
 	}
 
 	fault = handle_mm_fault(vma, addr, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 46d828926009..3056b33496ec 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -303,9 +303,9 @@ static void do_exception(struct pt_regs *regs, int access)
 		return handle_fault_error_nolock(regs, SEGV_ACCERR);
 	}
 	fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index aa88370ce739..23edca8f0555 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1341,10 +1341,10 @@ void do_user_addr_fault(struct pt_regs *regs,
 		return;
 	}
 	fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs);
-	if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED)))
+	if (!should_retry_mm_fault(fault) && !(fault & VM_FAULT_COMPLETED))
 		vma_end_read(vma);
 
-	if (!(fault & VM_FAULT_RETRY)) {
+	if (!should_retry_mm_fault(fault)) {
 		count_vm_vma_lock_event(VMA_LOCK_SUCCESS);
 		goto done;
 	}
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 4c576e24ce42..7a80c904eab9 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1739,6 +1739,18 @@ enum vm_fault_reason {
 			VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON |	\
 			VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK)
 
+/**
+ * should_retry_mm_fault - Check whether a page fault has to be retried.
+ * @fault: The fault result returned by handle_mm_fault().
+ *
+ * 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);
+}
+
 #define VM_FAULT_RESULT_TRACE						\
 	{ (__force u32)VM_FAULT_OOM,                 "OOM" },		\
 	{ (__force u32)VM_FAULT_SIGBUS,              "SIGBUS" },	\
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 0adb51ab1542..9e1334379296 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -448,7 +448,7 @@ static inline int signal_pending_state(unsigned int state, struct task_struct *p
 static inline bool fault_signal_pending(vm_fault_t fault_flags,
 					struct pt_regs *regs)
 {
-	return unlikely((fault_flags & VM_FAULT_RETRY) &&
+	return unlikely(should_retry_mm_fault(fault_flags) &&
 			(fatal_signal_pending(current) ||
 			 (user_mode(regs) && signal_pending(current))));
 }
diff --git a/mm/memory.c b/mm/memory.c
index 90fc7c395124..e0f1aeed713c 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6876,7 +6876,7 @@ static inline void mm_account_fault(struct mm_struct *mm, struct pt_regs *regs,
 	bool major;
 
 	/* Incomplete faults will be accounted upon completion. */
-	if (ret & VM_FAULT_RETRY)
+	if (should_retry_mm_fault(ret))
 		return;
 
 	/*
-- 
2.56.1.839.g22a8290db9-goog



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2026-11-29 20:22 UTC (permalink / raw)
  To: akpm
  Cc: david, willy, ljs, liam, vbabka, rppt, jannh, ziy, baolin.wang,
	nico.pache, ryan.roberts, dev.jain, baohua, lance.yang,
	usama.arif, kas, muchun.song, osalvador, dave.hansen, luto,
	peterz, linux, catalin.marinas, will, mark.rutland, chenhuacai,
	kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
	palmer, aou, alex, agordeev, gerald.schaefer, corbet, skhan,
	rdunlap, linux-mm, linux-kernel, linux-arm-kernel, loongarch,
	linuxppc-dev, linux-riscv, linux-s390, linux-doc,
	Suren Baghdasaryan

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29 20:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox