From: Wei-chung Hsu <weihsu@google.com>
To: Russell King <linux@armlinux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Wei-chung Hsu <weihsu@google.com>,
stable@vger.kernel.org
Subject: [PATCH] ARM: mm: handle VM_FAULT_HWPOISON and VM_FAULT_HWPOISON_LARGE
Date: Tue, 1 Dec 2026 23:59:54 +0000 [thread overview]
Message-ID: <20261201235954.1732864-1-weihsu@google.com> (raw)
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
reply other threads:[~2026-12-01 23:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261201235954.1732864-1-weihsu@google.com \
--to=weihsu@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=stable@vger.kernel.org \
/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®