Skip to content

Commit e7c600f

Browse files
caf-zjzhangwildea01
authored andcommitted
arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling
Add VM_FAULT_HWPOISON[_LARGE] handling to the arm64 page fault handler. Handling of VM_FAULT_HWPOISON[_LARGE] is very similar to VM_FAULT_OOM, the only difference is that a different si_code (BUS_MCEERR_AR) is passed to user space and si_addr_lsb field is initialized. Signed-off-by: Jonathan (Zhixiong) Zhang <zjzhang@codeaurora.org> Signed-off-by: Tyler Baicar <tbaicar@codeaurora.org> (fix new __do_user_fault call-site) Signed-off-by: Punit Agrawal <punit.agrawal@arm.com> Acked-by: Steve Capper <steve.capper@arm.com> Tested-by: Manoj Iyer <manoj.iyer@canonical.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent f02ab08 commit e7c600f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

arch/arm64/mm/fault.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/highmem.h>
3232
#include <linux/perf_event.h>
3333
#include <linux/preempt.h>
34+
#include <linux/hugetlb.h>
3435

3536
#include <asm/bug.h>
3637
#include <asm/cpufeature.h>
@@ -256,10 +257,11 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr,
256257
*/
257258
static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
258259
unsigned int esr, unsigned int sig, int code,
259-
struct pt_regs *regs)
260+
struct pt_regs *regs, int fault)
260261
{
261262
struct siginfo si;
262263
const struct fault_info *inf;
264+
unsigned int lsb = 0;
263265

264266
if (unhandled_signal(tsk, sig) && show_unhandled_signals_ratelimited()) {
265267
inf = esr_to_fault_info(esr);
@@ -277,6 +279,17 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
277279
si.si_errno = 0;
278280
si.si_code = code;
279281
si.si_addr = (void __user *)addr;
282+
/*
283+
* Either small page or large page may be poisoned.
284+
* In other words, VM_FAULT_HWPOISON_LARGE and
285+
* VM_FAULT_HWPOISON are mutually exclusive.
286+
*/
287+
if (fault & VM_FAULT_HWPOISON_LARGE)
288+
lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
289+
else if (fault & VM_FAULT_HWPOISON)
290+
lsb = PAGE_SHIFT;
291+
si.si_addr_lsb = lsb;
292+
280293
force_sig_info(sig, &si, tsk);
281294
}
282295

@@ -291,7 +304,7 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re
291304
*/
292305
if (user_mode(regs)) {
293306
inf = esr_to_fault_info(esr);
294-
__do_user_fault(tsk, addr, esr, inf->sig, inf->code, regs);
307+
__do_user_fault(tsk, addr, esr, inf->sig, inf->code, regs, 0);
295308
} else
296309
__do_kernel_fault(addr, esr, regs);
297310
}
@@ -478,6 +491,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
478491
*/
479492
sig = SIGBUS;
480493
code = BUS_ADRERR;
494+
} else if (fault & (VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE)) {
495+
sig = SIGBUS;
496+
code = BUS_MCEERR_AR;
481497
} else {
482498
/*
483499
* Something tried to access memory that isn't in our memory
@@ -488,7 +504,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
488504
SEGV_ACCERR : SEGV_MAPERR;
489505
}
490506

491-
__do_user_fault(tsk, addr, esr, sig, code, regs);
507+
__do_user_fault(tsk, addr, esr, sig, code, regs, fault);
492508
return 0;
493509

494510
no_context:

0 commit comments

Comments
 (0)