aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kernel/traps.c
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2016-06-28 13:07:31 -0400
committerCatalin Marinas <catalin.marinas@arm.com>2016-07-01 06:43:30 -0400
commit390bf1773c7eba3b45df62ae82b3d2be911185b7 (patch)
tree7bbb8ee4425bdec0dbd5563952c68ab6c6e22ee5 /arch/arm64/kernel/traps.c
parent8e2318521bf5837dae093413f81292b59d49d030 (diff)
arm64: consolidate signal injection on emulation errors
The code for injecting a signal into userland if a trapped instruction fails emulation due to a _userland_ error (like an illegal address) will be used more often with the next patch. Factor out the core functionality into a separate function and use that both for the existing trap handler and for the deprecated instructions emulation. Signed-off-by: Andre Przywara <andre.przywara@arm.com> [catalin.marinas@arm.com: s/set_segfault/arm64_notify_segfault/] Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64/kernel/traps.c')
-rw-r--r--arch/arm64/kernel/traps.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index a4250a59f2b9..d8a5366dcc24 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -364,30 +364,67 @@ exit:
364 return fn ? fn(regs, instr) : 1; 364 return fn ? fn(regs, instr) : 1;
365} 365}
366 366
367asmlinkage void __exception do_undefinstr(struct pt_regs *regs) 367static void force_signal_inject(int signal, int code, struct pt_regs *regs,
368 unsigned long address)
368{ 369{
369 siginfo_t info; 370 siginfo_t info;
370 void __user *pc = (void __user *)instruction_pointer(regs); 371 void __user *pc = (void __user *)instruction_pointer(regs);
372 const char *desc;
371 373
372 /* check for AArch32 breakpoint instructions */ 374 switch (signal) {
373 if (!aarch32_break_handler(regs)) 375 case SIGILL:
374 return; 376 desc = "undefined instruction";
375 377 break;
376 if (call_undef_hook(regs) == 0) 378 case SIGSEGV:
377 return; 379 desc = "illegal memory access";
380 break;
381 default:
382 desc = "bad mode";
383 break;
384 }
378 385
379 if (unhandled_signal(current, SIGILL) && show_unhandled_signals_ratelimited()) { 386 if (unhandled_signal(current, signal) &&
380 pr_info("%s[%d]: undefined instruction: pc=%p\n", 387 show_unhandled_signals_ratelimited()) {
381 current->comm, task_pid_nr(current), pc); 388 pr_info("%s[%d]: %s: pc=%p\n",
389 current->comm, task_pid_nr(current), desc, pc);
382 dump_instr(KERN_INFO, regs); 390 dump_instr(KERN_INFO, regs);
383 } 391 }
384 392
385 info.si_signo = SIGILL; 393 info.si_signo = signal;
386 info.si_errno = 0; 394 info.si_errno = 0;
387 info.si_code = ILL_ILLOPC; 395 info.si_code = code;
388 info.si_addr = pc; 396 info.si_addr = pc;
389 397
390 arm64_notify_die("Oops - undefined instruction", regs, &info, 0); 398 arm64_notify_die(desc, regs, &info, 0);
399}
400
401/*
402 * Set up process info to signal segmentation fault - called on access error.
403 */
404void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr)
405{
406 int code;
407
408 down_read(&current->mm->mmap_sem);
409 if (find_vma(current->mm, addr) == NULL)
410 code = SEGV_MAPERR;
411 else
412 code = SEGV_ACCERR;
413 up_read(&current->mm->mmap_sem);
414
415 force_signal_inject(SIGSEGV, code, regs, addr);
416}
417
418asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
419{
420 /* check for AArch32 breakpoint instructions */
421 if (!aarch32_break_handler(regs))
422 return;
423
424 if (call_undef_hook(regs) == 0)
425 return;
426
427 force_signal_inject(SIGILL, ILL_ILLOPC, regs, 0);
391} 428}
392 429
393long compat_arm_syscall(struct pt_regs *regs); 430long compat_arm_syscall(struct pt_regs *regs);