21 #include <linux/module.h>
22 #include <linux/signal.h>
29 #include <linux/sched.h>
31 #include <linux/perf_event.h>
33 #include <asm/exception.h>
35 #include <asm/system_misc.h>
36 #include <asm/pgtable.h>
37 #include <asm/tlbflush.h>
58 if (pgd_none_or_clear_bad(pgd))
62 if (pud_none_or_clear_bad(pud))
67 if (pmd_none_or_clear_bad(pmd))
81 static void __do_kernel_fault(
struct mm_struct *mm,
unsigned long addr,
94 pr_alert(
"Unable to handle kernel %s at virtual address %08lx\n",
95 (addr <
PAGE_SIZE) ?
"NULL pointer dereference" :
96 "paging request", addr);
99 die(
"Oops", regs, esr);
108 static void __do_user_fault(
struct task_struct *tsk,
unsigned long addr,
109 unsigned int esr,
unsigned int sig,
int code,
115 pr_info(
"%s[%d]: unhandled page fault (%d) at 0x%08lx, code 0x%03x\n",
116 tsk->
comm, task_pid_nr(tsk), sig, addr, esr);
125 si.si_addr = (
void __user *)addr;
141 __do_kernel_fault(mm, addr, esr, regs);
144 #define VM_FAULT_BADMAP 0x010000
145 #define VM_FAULT_BADACCESS 0x020000
147 #define ESR_WRITE (1 << 6)
148 #define ESR_LNX_EXEC (1 << 24)
155 static inline bool access_error(
unsigned int esr,
struct vm_area_struct *vma)
157 unsigned int mask = VM_READ | VM_WRITE | VM_EXEC;
164 return vma->
vm_flags & mask ?
false :
true;
167 static int __do_page_fault(
struct mm_struct *mm,
unsigned long addr,
168 unsigned int esr,
unsigned int flags,
186 if (access_error(esr, vma)) {
207 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
208 (write ? FAULT_FLAG_WRITE : 0);
240 #ifdef CONFIG_DEBUG_VM
246 fault = __do_page_fault(mm, addr, esr, flags, tsk);
253 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(
current))
263 if (flags & FAULT_FLAG_ALLOW_RETRY) {
264 if (fault & VM_FAULT_MAJOR) {
273 if (fault & VM_FAULT_RETRY) {
278 flags &= ~FAULT_FLAG_ALLOW_RETRY;
292 if (fault & VM_FAULT_OOM) {
309 if (fault & VM_FAULT_SIGBUS) {
326 __do_user_fault(tsk, addr, esr, sig, code, regs);
330 __do_kernel_fault(mm, addr, esr, regs);
351 static int __kprobes do_translation_fault(
unsigned long addr,
366 static int do_sect_fault(
unsigned long addr,
unsigned int esr,
376 static int do_bad(
unsigned long addr,
unsigned int esr,
struct pt_regs *regs)
387 { do_bad,
SIGBUS, 0,
"ttbr address size fault" },
388 { do_bad,
SIGBUS, 0,
"level 1 address size fault" },
389 { do_bad,
SIGBUS, 0,
"level 2 address size fault" },
390 { do_bad,
SIGBUS, 0,
"level 3 address size fault" },
395 { do_bad,
SIGBUS, 0,
"reserved access flag fault" },
399 { do_bad,
SIGBUS, 0,
"reserved permission fault" },
403 { do_bad,
SIGBUS, 0,
"synchronous external abort" },
404 { do_bad,
SIGBUS, 0,
"asynchronous external abort" },
405 { do_bad,
SIGBUS, 0,
"unknown 18" },
406 { do_bad,
SIGBUS, 0,
"unknown 19" },
407 { do_bad,
SIGBUS, 0,
"synchronous abort (translation table walk)" },
408 { do_bad,
SIGBUS, 0,
"synchronous abort (translation table walk)" },
409 { do_bad,
SIGBUS, 0,
"synchronous abort (translation table walk)" },
410 { do_bad,
SIGBUS, 0,
"synchronous abort (translation table walk)" },
411 { do_bad,
SIGBUS, 0,
"synchronous parity error" },
412 { do_bad,
SIGBUS, 0,
"asynchronous parity error" },
413 { do_bad,
SIGBUS, 0,
"unknown 26" },
414 { do_bad,
SIGBUS, 0,
"unknown 27" },
415 { do_bad,
SIGBUS, 0,
"synchronous parity error (translation table walk" },
416 { do_bad,
SIGBUS, 0,
"synchronous parity error (translation table walk" },
417 { do_bad,
SIGBUS, 0,
"synchronous parity error (translation table walk" },
418 { do_bad,
SIGBUS, 0,
"synchronous parity error (translation table walk" },
419 { do_bad,
SIGBUS, 0,
"unknown 32" },
421 { do_bad,
SIGBUS, 0,
"debug event" },
422 { do_bad,
SIGBUS, 0,
"unknown 35" },
423 { do_bad,
SIGBUS, 0,
"unknown 36" },
424 { do_bad,
SIGBUS, 0,
"unknown 37" },
425 { do_bad,
SIGBUS, 0,
"unknown 38" },
426 { do_bad,
SIGBUS, 0,
"unknown 39" },
427 { do_bad,
SIGBUS, 0,
"unknown 40" },
428 { do_bad,
SIGBUS, 0,
"unknown 41" },
429 { do_bad,
SIGBUS, 0,
"unknown 42" },
430 { do_bad,
SIGBUS, 0,
"unknown 43" },
431 { do_bad,
SIGBUS, 0,
"unknown 44" },
432 { do_bad,
SIGBUS, 0,
"unknown 45" },
433 { do_bad,
SIGBUS, 0,
"unknown 46" },
434 { do_bad,
SIGBUS, 0,
"unknown 47" },
435 { do_bad,
SIGBUS, 0,
"unknown 48" },
436 { do_bad,
SIGBUS, 0,
"unknown 49" },
437 { do_bad,
SIGBUS, 0,
"unknown 50" },
438 { do_bad,
SIGBUS, 0,
"unknown 51" },
439 { do_bad,
SIGBUS, 0,
"implementation fault (lockdown abort)" },
440 { do_bad,
SIGBUS, 0,
"unknown 53" },
441 { do_bad,
SIGBUS, 0,
"unknown 54" },
442 { do_bad,
SIGBUS, 0,
"unknown 55" },
443 { do_bad,
SIGBUS, 0,
"unknown 56" },
444 { do_bad,
SIGBUS, 0,
"unknown 57" },
445 { do_bad,
SIGBUS, 0,
"implementation fault (coprocessor abort)" },
446 { do_bad,
SIGBUS, 0,
"unknown 59" },
447 { do_bad,
SIGBUS, 0,
"unknown 60" },
448 { do_bad,
SIGBUS, 0,
"unknown 61" },
449 { do_bad,
SIGBUS, 0,
"unknown 62" },
450 { do_bad,
SIGBUS, 0,
"unknown 63" },
462 if (!inf->fn(addr, esr, regs))
465 pr_alert(
"Unhandled fault: %s (0x%08x) at 0x%016lx\n",
466 inf->name, esr, addr);
471 info.si_addr = (
void __user *)addr;
487 info.si_addr = (
void __user *)addr;
491 static struct fault_info debug_fault_info[] = {
495 { do_bad,
SIGBUS, 0,
"unknown 3" },
497 { do_bad,
SIGTRAP, 0,
"aarch32 vector catch" },
499 { do_bad,
SIGBUS, 0,
"unknown 7" },
503 int (*
fn)(
unsigned long,
unsigned int,
struct pt_regs *),
504 int sig,
int code,
const char *
name)
508 debug_fault_info[
nr].fn =
fn;
509 debug_fault_info[
nr].sig =
sig;
510 debug_fault_info[
nr].code =
code;
511 debug_fault_info[
nr].name =
name;
518 const struct fault_info *inf = debug_fault_info + DBG_ESR_EVT(esr);
521 if (!inf->fn(addr, esr, regs))
524 pr_alert(
"Unhandled debug exception: %s (0x%08x) at 0x%016lx\n",
525 inf->name, esr, addr);
530 info.si_addr = (
void __user *)addr;