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 1/2] mm: introduce should_retry_mm_fault() helper
Date: Sun, 29 Nov 2026 12:22:02 -0800 [thread overview]
Message-ID: <20261129202203.1183277-2-surenb@google.com> (raw)
In-Reply-To: <20261129202203.1183277-1-surenb@google.com>
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
next 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 ` Suren Baghdasaryan [this message]
2026-11-29 20:22 ` [RFC PATCH 2/2] mm: split VM_FAULT_RETRY_LOCK_MM out of VM_FAULT_RETRY Suren Baghdasaryan
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-2-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®