]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/arm64/kernel/traps.c
2 * Based on arch/arm/kernel/traps.c
4 * Copyright (C) 1995-2009 Russell King
5 * Copyright (C) 2012 ARM Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/signal.h>
21 #include <linux/personality.h>
22 #include <linux/kallsyms.h>
23 #include <linux/spinlock.h>
24 #include <linux/uaccess.h>
25 #include <linux/hardirq.h>
26 #include <linux/kdebug.h>
27 #include <linux/module.h>
28 #include <linux/kexec.h>
29 #include <linux/delay.h>
30 #include <linux/init.h>
31 #include <linux/sched.h>
32 #include <linux/syscalls.h>
34 #include <asm/atomic.h>
35 #include <asm/debug-monitors.h>
37 #include <asm/traps.h>
38 #include <asm/stacktrace.h>
39 #include <asm/exception.h>
40 #include <asm/system_misc.h>
42 static const char *handler
[]= {
49 int show_unhandled_signals
= 1;
52 * Dump out the contents of some memory nicely...
54 static void dump_mem(const char *lvl
, const char *str
, unsigned long bottom
,
55 unsigned long top
, bool compat
)
60 unsigned int width
= compat
? 4 : 8;
63 * We need to switch to kernel mode so that we can use __get_user
64 * to safely read from kernel space. Note that we now dump the
65 * code first, just in case the backtrace kills us.
70 printk("%s%s(0x%016lx to 0x%016lx)\n", lvl
, str
, bottom
, top
);
72 for (first
= bottom
& ~31; first
< top
; first
+= 32) {
74 char str
[sizeof(" 12345678") * 8 + 1];
76 memset(str
, ' ', sizeof(str
));
77 str
[sizeof(str
) - 1] = '\0';
79 for (p
= first
, i
= 0; i
< (32 / width
)
80 && p
< top
; i
++, p
+= width
) {
81 if (p
>= bottom
&& p
< top
) {
85 if (__get_user(val
, (unsigned long *)p
) == 0)
86 sprintf(str
+ i
* 17, " %016lx", val
);
88 sprintf(str
+ i
* 17, " ????????????????");
90 if (__get_user(val
, (unsigned int *)p
) == 0)
91 sprintf(str
+ i
* 9, " %08lx", val
);
93 sprintf(str
+ i
* 9, " ????????");
97 printk("%s%04lx:%s\n", lvl
, first
& 0xffff, str
);
103 static void dump_backtrace_entry(unsigned long where
, unsigned long stack
)
106 if (in_exception_text(where
))
107 dump_mem("", "Exception stack", stack
,
108 stack
+ sizeof(struct pt_regs
), false);
111 static void dump_instr(const char *lvl
, struct pt_regs
*regs
)
113 unsigned long addr
= instruction_pointer(regs
);
115 char str
[sizeof("00000000 ") * 5 + 2 + 1], *p
= str
;
119 * We need to switch to kernel mode so that we can use __get_user
120 * to safely read from kernel space. Note that we now dump the
121 * code first, just in case the backtrace kills us.
126 for (i
= -4; i
< 1; i
++) {
127 unsigned int val
, bad
;
129 bad
= __get_user(val
, &((u32
*)addr
)[i
]);
132 p
+= sprintf(p
, i
== 0 ? "(%08x) " : "%08x ", val
);
134 p
+= sprintf(p
, "bad PC value");
138 printk("%sCode: %s\n", lvl
, str
);
143 static void dump_backtrace(struct pt_regs
*regs
, struct task_struct
*tsk
)
145 struct stackframe frame
;
147 pr_debug("%s(regs = %p tsk = %p)\n", __func__
, regs
, tsk
);
153 frame
.fp
= regs
->regs
[29];
156 } else if (tsk
== current
) {
157 frame
.fp
= (unsigned long)__builtin_frame_address(0);
158 frame
.sp
= current_stack_pointer
;
159 frame
.pc
= (unsigned long)dump_backtrace
;
162 * task blocked in __switch_to
164 frame
.fp
= thread_saved_fp(tsk
);
165 frame
.sp
= thread_saved_sp(tsk
);
166 frame
.pc
= thread_saved_pc(tsk
);
169 pr_emerg("Call trace:\n");
171 unsigned long where
= frame
.pc
;
174 ret
= unwind_frame(&frame
);
177 dump_backtrace_entry(where
, frame
.sp
);
181 void show_stack(struct task_struct
*tsk
, unsigned long *sp
)
183 dump_backtrace(NULL
, tsk
);
187 #ifdef CONFIG_PREEMPT
188 #define S_PREEMPT " PREEMPT"
194 static int __die(const char *str
, int err
, struct thread_info
*thread
,
195 struct pt_regs
*regs
)
197 struct task_struct
*tsk
= thread
->task
;
198 static int die_counter
;
201 pr_emerg("Internal error: %s: %x [#%d]" S_PREEMPT S_SMP
"\n",
202 str
, err
, ++die_counter
);
204 /* trap and error numbers are mostly meaningless on ARM */
205 ret
= notify_die(DIE_OOPS
, str
, regs
, err
, 0, SIGSEGV
);
206 if (ret
== NOTIFY_STOP
)
211 pr_emerg("Process %.*s (pid: %d, stack limit = 0x%p)\n",
212 TASK_COMM_LEN
, tsk
->comm
, task_pid_nr(tsk
), thread
+ 1);
214 if (!user_mode(regs
) || in_interrupt()) {
215 dump_mem(KERN_EMERG
, "Stack: ", regs
->sp
,
216 THREAD_SIZE
+ (unsigned long)task_stack_page(tsk
),
217 compat_user_mode(regs
));
218 dump_backtrace(regs
, tsk
);
219 dump_instr(KERN_EMERG
, regs
);
225 static DEFINE_RAW_SPINLOCK(die_lock
);
228 * This function is protected against re-entrancy.
230 void die(const char *str
, struct pt_regs
*regs
, int err
)
232 struct thread_info
*thread
= current_thread_info();
237 raw_spin_lock_irq(&die_lock
);
240 ret
= __die(str
, err
, thread
, regs
);
242 if (regs
&& kexec_should_crash(thread
->task
))
246 add_taint(TAINT_DIE
, LOCKDEP_NOW_UNRELIABLE
);
247 raw_spin_unlock_irq(&die_lock
);
251 panic("Fatal exception in interrupt");
253 panic("Fatal exception");
254 if (ret
!= NOTIFY_STOP
)
258 void arm64_notify_die(const char *str
, struct pt_regs
*regs
,
259 struct siginfo
*info
, int err
)
261 if (user_mode(regs
)) {
262 current
->thread
.fault_address
= 0;
263 current
->thread
.fault_code
= err
;
264 force_sig_info(info
->si_signo
, info
, current
);
270 static LIST_HEAD(undef_hook
);
271 static DEFINE_RAW_SPINLOCK(undef_lock
);
273 void register_undef_hook(struct undef_hook
*hook
)
277 raw_spin_lock_irqsave(&undef_lock
, flags
);
278 list_add(&hook
->node
, &undef_hook
);
279 raw_spin_unlock_irqrestore(&undef_lock
, flags
);
282 void unregister_undef_hook(struct undef_hook
*hook
)
286 raw_spin_lock_irqsave(&undef_lock
, flags
);
287 list_del(&hook
->node
);
288 raw_spin_unlock_irqrestore(&undef_lock
, flags
);
291 static int call_undef_hook(struct pt_regs
*regs
)
293 struct undef_hook
*hook
;
296 int (*fn
)(struct pt_regs
*regs
, u32 instr
) = NULL
;
297 void __user
*pc
= (void __user
*)instruction_pointer(regs
);
299 if (!user_mode(regs
))
302 if (compat_thumb_mode(regs
)) {
303 /* 16-bit Thumb instruction */
304 if (get_user(instr
, (u16 __user
*)pc
))
306 instr
= le16_to_cpu(instr
);
307 if (aarch32_insn_is_wide(instr
)) {
310 if (get_user(instr2
, (u16 __user
*)(pc
+ 2)))
312 instr2
= le16_to_cpu(instr2
);
313 instr
= (instr
<< 16) | instr2
;
316 /* 32-bit ARM instruction */
317 if (get_user(instr
, (u32 __user
*)pc
))
319 instr
= le32_to_cpu(instr
);
322 raw_spin_lock_irqsave(&undef_lock
, flags
);
323 list_for_each_entry(hook
, &undef_hook
, node
)
324 if ((instr
& hook
->instr_mask
) == hook
->instr_val
&&
325 (regs
->pstate
& hook
->pstate_mask
) == hook
->pstate_val
)
328 raw_spin_unlock_irqrestore(&undef_lock
, flags
);
330 return fn
? fn(regs
, instr
) : 1;
333 asmlinkage
void __exception
do_undefinstr(struct pt_regs
*regs
)
336 void __user
*pc
= (void __user
*)instruction_pointer(regs
);
338 /* check for AArch32 breakpoint instructions */
339 if (!aarch32_break_handler(regs
))
342 if (call_undef_hook(regs
) == 0)
345 if (unhandled_signal(current
, SIGILL
) && show_unhandled_signals_ratelimited()) {
346 pr_info("%s[%d]: undefined instruction: pc=%p\n",
347 current
->comm
, task_pid_nr(current
), pc
);
348 dump_instr(KERN_INFO
, regs
);
351 info
.si_signo
= SIGILL
;
353 info
.si_code
= ILL_ILLOPC
;
356 arm64_notify_die("Oops - undefined instruction", regs
, &info
, 0);
359 long compat_arm_syscall(struct pt_regs
*regs
);
361 asmlinkage
long do_ni_syscall(struct pt_regs
*regs
)
365 if (is_compat_task()) {
366 ret
= compat_arm_syscall(regs
);
372 if (show_unhandled_signals_ratelimited()) {
373 pr_info("%s[%d]: syscall %d\n", current
->comm
,
374 task_pid_nr(current
), (int)regs
->syscallno
);
375 dump_instr("", regs
);
380 return sys_ni_syscall();
383 static const char *esr_class_str
[] = {
384 [0 ... ESR_ELx_EC_MAX
] = "UNRECOGNIZED EC",
385 [ESR_ELx_EC_UNKNOWN
] = "Unknown/Uncategorized",
386 [ESR_ELx_EC_WFx
] = "WFI/WFE",
387 [ESR_ELx_EC_CP15_32
] = "CP15 MCR/MRC",
388 [ESR_ELx_EC_CP15_64
] = "CP15 MCRR/MRRC",
389 [ESR_ELx_EC_CP14_MR
] = "CP14 MCR/MRC",
390 [ESR_ELx_EC_CP14_LS
] = "CP14 LDC/STC",
391 [ESR_ELx_EC_FP_ASIMD
] = "ASIMD",
392 [ESR_ELx_EC_CP10_ID
] = "CP10 MRC/VMRS",
393 [ESR_ELx_EC_CP14_64
] = "CP14 MCRR/MRRC",
394 [ESR_ELx_EC_ILL
] = "PSTATE.IL",
395 [ESR_ELx_EC_SVC32
] = "SVC (AArch32)",
396 [ESR_ELx_EC_HVC32
] = "HVC (AArch32)",
397 [ESR_ELx_EC_SMC32
] = "SMC (AArch32)",
398 [ESR_ELx_EC_SVC64
] = "SVC (AArch64)",
399 [ESR_ELx_EC_HVC64
] = "HVC (AArch64)",
400 [ESR_ELx_EC_SMC64
] = "SMC (AArch64)",
401 [ESR_ELx_EC_SYS64
] = "MSR/MRS (AArch64)",
402 [ESR_ELx_EC_IMP_DEF
] = "EL3 IMP DEF",
403 [ESR_ELx_EC_IABT_LOW
] = "IABT (lower EL)",
404 [ESR_ELx_EC_IABT_CUR
] = "IABT (current EL)",
405 [ESR_ELx_EC_PC_ALIGN
] = "PC Alignment",
406 [ESR_ELx_EC_DABT_LOW
] = "DABT (lower EL)",
407 [ESR_ELx_EC_DABT_CUR
] = "DABT (current EL)",
408 [ESR_ELx_EC_SP_ALIGN
] = "SP Alignment",
409 [ESR_ELx_EC_FP_EXC32
] = "FP (AArch32)",
410 [ESR_ELx_EC_FP_EXC64
] = "FP (AArch64)",
411 [ESR_ELx_EC_SERROR
] = "SError",
412 [ESR_ELx_EC_BREAKPT_LOW
] = "Breakpoint (lower EL)",
413 [ESR_ELx_EC_BREAKPT_CUR
] = "Breakpoint (current EL)",
414 [ESR_ELx_EC_SOFTSTP_LOW
] = "Software Step (lower EL)",
415 [ESR_ELx_EC_SOFTSTP_CUR
] = "Software Step (current EL)",
416 [ESR_ELx_EC_WATCHPT_LOW
] = "Watchpoint (lower EL)",
417 [ESR_ELx_EC_WATCHPT_CUR
] = "Watchpoint (current EL)",
418 [ESR_ELx_EC_BKPT32
] = "BKPT (AArch32)",
419 [ESR_ELx_EC_VECTOR32
] = "Vector catch (AArch32)",
420 [ESR_ELx_EC_BRK64
] = "BRK (AArch64)",
423 const char *esr_get_class_string(u32 esr
)
425 return esr_class_str
[esr
>> ESR_ELx_EC_SHIFT
];
429 * bad_mode handles the impossible case in the exception vector.
431 asmlinkage
void bad_mode(struct pt_regs
*regs
, int reason
, unsigned int esr
)
434 void __user
*pc
= (void __user
*)instruction_pointer(regs
);
437 pr_crit("Bad mode in %s handler detected, code 0x%08x -- %s\n",
438 handler
[reason
], esr
, esr_get_class_string(esr
));
441 info
.si_signo
= SIGILL
;
443 info
.si_code
= ILL_ILLOPC
;
446 arm64_notify_die("Oops - bad mode", regs
, &info
, 0);
449 void __pte_error(const char *file
, int line
, unsigned long val
)
451 pr_crit("%s:%d: bad pte %016lx.\n", file
, line
, val
);
454 void __pmd_error(const char *file
, int line
, unsigned long val
)
456 pr_crit("%s:%d: bad pmd %016lx.\n", file
, line
, val
);
459 void __pud_error(const char *file
, int line
, unsigned long val
)
461 pr_crit("%s:%d: bad pud %016lx.\n", file
, line
, val
);
464 void __pgd_error(const char *file
, int line
, unsigned long val
)
466 pr_crit("%s:%d: bad pgd %016lx.\n", file
, line
, val
);
469 void __init
trap_init(void)