mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ARM: mm: handle VM_FAULT_HWPOISON and VM_FAULT_HWPOISON_LARGE
@ 2026-12-01 23:59 Wei-chung Hsu
  0 siblings, 0 replies; only message in thread
From: Wei-chung Hsu @ 2026-12-01 23:59 UTC (permalink / raw)
  To: Russell King; +Cc: linux-arm-kernel, linux-kernel, Wei-chung Hsu, stable

On 32-bit ARM, do_page_fault() only handles VM_FAULT_OOM and
VM_FAULT_SIGBUS, falling through to SIGSEGV (SEGV_MAPERR) for any other
VM_FAULT_ERROR bit.

Although ARM does not select ARCH_SUPPORTS_MEMORY_FAILURE, core mm returns
VM_FAULT_HWPOISON (and VM_FAULT_HWPOISON_LARGE for hugetlb with ARM_LPAE)
when userspace accesses a page poisoned via userfaultfd UFFDIO_POISON. As
a result, faulting on a UFFDIO_POISON page delivers SIGSEGV instead of
SIGBUS, breaking both the mm kselftest uffd-unit-tests ("poison" /
uffd_poison_test) and LTP userfaultfd06.

Factor out the common setup in __do_user_fault() and add a
__do_user_fault_mceerr() helper mirroring arm64's handling to deliver
SIGBUS (BUS_MCEERR_AR) via force_sig_mceerr() with the appropriate page
shift (PAGE_SHIFT or hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault))).

Fixes: fc71884a5f59 ("mm: userfaultfd: add new UFFDIO_POISON ioctl")
Cc: stable@vger.kernel.org
Signed-off-by: Wei-chung Hsu <weihsu@google.com>
---
 arch/arm/mm/fault.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 0a09d4ff7..a31c40eec 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -16,6 +16,7 @@
 #include <linux/sched/signal.h>
 #include <linux/sched/debug.h>
 #include <linux/highmem.h>
+#include <linux/hugetlb.h>
 #include <linux/perf_event.h>
 #include <linux/kfence.h>
 
@@ -168,8 +169,8 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
  * for preempt RT.
  */
 static void
-__do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
-		int code, struct pt_regs *regs)
+__do_user_fault_prepare(unsigned long addr, unsigned int fsr, unsigned int sig,
+			struct pt_regs *regs)
 {
 	struct task_struct *tsk = current;
 
@@ -199,9 +200,24 @@ __do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
 	tsk->thread.address = addr;
 	tsk->thread.error_code = fsr;
 	tsk->thread.trap_no = 14;
+}
+
+static void
+__do_user_fault(unsigned long addr, unsigned int fsr, unsigned int sig,
+		int code, struct pt_regs *regs)
+{
+	__do_user_fault_prepare(addr, fsr, sig, regs);
 	force_sig_fault(sig, code, (void __user *)addr);
 }
 
+static void
+__do_user_fault_mceerr(unsigned long addr, unsigned int fsr, int code,
+		       short lsb, struct pt_regs *regs)
+{
+	__do_user_fault_prepare(addr, fsr, SIGBUS, regs);
+	force_sig_mceerr(code, (void __user *)addr, lsb);
+}
+
 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 {
 	struct task_struct *tsk = current;
@@ -501,6 +517,14 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 		 */
 		sig = SIGBUS;
 		code = BUS_ADRERR;
+	} else if (fault & (VM_FAULT_HWPOISON_LARGE | VM_FAULT_HWPOISON)) {
+		unsigned int lsb = PAGE_SHIFT;
+
+		if (fault & VM_FAULT_HWPOISON_LARGE)
+			lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
+
+		__do_user_fault_mceerr(addr, fsr, BUS_MCEERR_AR, lsb, regs);
+		return 0;
 	} else {
 		/*
 		 * Something tried to access memory that
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-01 23:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 23:59 [PATCH] ARM: mm: handle VM_FAULT_HWPOISON and VM_FAULT_HWPOISON_LARGE Wei-chung Hsu

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®