hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/xtensa/kernel/traps.c
....@@ -34,12 +34,12 @@
3434 #include <linux/delay.h>
3535 #include <linux/hardirq.h>
3636 #include <linux/ratelimit.h>
37
+#include <linux/pgtable.h>
3738
3839 #include <asm/stacktrace.h>
3940 #include <asm/ptrace.h>
4041 #include <asm/timex.h>
4142 #include <linux/uaccess.h>
42
-#include <asm/pgtable.h>
4343 #include <asm/processor.h>
4444 #include <asm/traps.h>
4545 #include <asm/hw_breakpoint.h>
....@@ -51,7 +51,7 @@
5151 extern void kernel_exception(void);
5252 extern void user_exception(void);
5353
54
-extern void fast_syscall_kernel(void);
54
+extern void fast_illegal_instruction_user(void);
5555 extern void fast_syscall_user(void);
5656 extern void fast_alloca(void);
5757 extern void fast_unaligned(void);
....@@ -88,8 +88,10 @@
8888
8989 static dispatch_init_table_t __initdata dispatch_init_table[] = {
9090
91
+#ifdef CONFIG_USER_ABI_CALL0_PROBE
92
+{ EXCCAUSE_ILLEGAL_INSTRUCTION, USER, fast_illegal_instruction_user },
93
+#endif
9194 { EXCCAUSE_ILLEGAL_INSTRUCTION, 0, do_illegal_instruction},
92
-{ EXCCAUSE_SYSTEM_CALL, KRNL, fast_syscall_kernel },
9395 { EXCCAUSE_SYSTEM_CALL, USER, fast_syscall_user },
9496 { EXCCAUSE_SYSTEM_CALL, 0, system_call },
9597 /* EXCCAUSE_INSTRUCTION_FETCH unhandled */
....@@ -186,7 +188,7 @@
186188 "\tEXCCAUSE is %ld\n",
187189 current->comm, task_pid_nr(current), regs->pc,
188190 exccause);
189
- force_sig(SIGILL, current);
191
+ force_sig(SIGILL);
190192 }
191193
192194 /*
....@@ -215,8 +217,8 @@
215217
216218 static inline void check_valid_nmi(void)
217219 {
218
- unsigned intread = get_sr(interrupt);
219
- unsigned intenable = get_sr(intenable);
220
+ unsigned intread = xtensa_get_sr(interrupt);
221
+ unsigned intenable = xtensa_get_sr(intenable);
220222
221223 BUG_ON(intread & intenable &
222224 ~(XTENSA_INTLEVEL_ANDBELOW_MASK(PROFILING_INTLEVEL) ^
....@@ -273,8 +275,8 @@
273275 irq_enter();
274276
275277 for (;;) {
276
- unsigned intread = get_sr(interrupt);
277
- unsigned intenable = get_sr(intenable);
278
+ unsigned intread = xtensa_get_sr(interrupt);
279
+ unsigned intenable = xtensa_get_sr(intenable);
278280 unsigned int_at_level = intread & intenable;
279281 unsigned level;
280282
....@@ -308,7 +310,7 @@
308310
309311 pr_info_ratelimited("Illegal Instruction in '%s' (pid = %d, pc = %#010lx)\n",
310312 current->comm, task_pid_nr(current), regs->pc);
311
- force_sig(SIGILL, current);
313
+ force_sig(SIGILL);
312314 }
313315
314316
....@@ -332,7 +334,7 @@
332334 "(pid = %d, pc = %#010lx)\n",
333335 regs->excvaddr, current->comm,
334336 task_pid_nr(current), regs->pc);
335
- force_sig_fault(SIGBUS, BUS_ADRALN, (void *) regs->excvaddr, current);
337
+ force_sig_fault(SIGBUS, BUS_ADRALN, (void *) regs->excvaddr);
336338 }
337339 #endif
338340
....@@ -356,7 +358,7 @@
356358
357359 /* If in user mode, send SIGTRAP signal to current process */
358360
359
- force_sig(SIGTRAP, current);
361
+ force_sig(SIGTRAP);
360362 }
361363
362364
....@@ -422,16 +424,15 @@
422424 /* Setup specific handlers. */
423425
424426 for(i = 0; dispatch_init_table[i].cause >= 0; i++) {
425
-
426427 int fast = dispatch_init_table[i].fast;
427428 int cause = dispatch_init_table[i].cause;
428429 void *handler = dispatch_init_table[i].handler;
429430
430431 if (fast == 0)
431432 set_handler(default_handler, cause, handler);
432
- if (fast && fast & USER)
433
+ if ((fast & USER) != 0)
433434 set_handler(fast_user_handler, cause, handler);
434
- if (fast && fast & KRNL)
435
+ if ((fast & KRNL) != 0)
435436 set_handler(fast_kernel_handler, cause, handler);
436437 }
437438
....@@ -478,44 +479,51 @@
478479
479480 static int show_trace_cb(struct stackframe *frame, void *data)
480481 {
482
+ const char *loglvl = data;
483
+
481484 if (kernel_text_address(frame->pc))
482
- pr_cont(" [<%08lx>] %pB\n", frame->pc, (void *)frame->pc);
485
+ printk("%s [<%08lx>] %pB\n",
486
+ loglvl, frame->pc, (void *)frame->pc);
483487 return 0;
484488 }
485489
486
-void show_trace(struct task_struct *task, unsigned long *sp)
490
+static void show_trace(struct task_struct *task, unsigned long *sp,
491
+ const char *loglvl)
487492 {
488493 if (!sp)
489494 sp = stack_pointer(task);
490495
491
- pr_info("Call Trace:\n");
492
- walk_stackframe(sp, show_trace_cb, NULL);
493
-#ifndef CONFIG_KALLSYMS
494
- pr_cont("\n");
495
-#endif
496
+ printk("%sCall Trace:\n", loglvl);
497
+ walk_stackframe(sp, show_trace_cb, (void *)loglvl);
496498 }
497499
498
-static int kstack_depth_to_print = 24;
500
+#define STACK_DUMP_ENTRY_SIZE 4
501
+#define STACK_DUMP_LINE_SIZE 32
502
+static size_t kstack_depth_to_print = CONFIG_PRINT_STACK_DEPTH;
499503
500
-void show_stack(struct task_struct *task, unsigned long *sp)
504
+void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
501505 {
502
- int i = 0;
503
- unsigned long *stack;
506
+ size_t len, off = 0;
504507
505508 if (!sp)
506509 sp = stack_pointer(task);
507
- stack = sp;
508510
509
- pr_info("Stack:\n");
511
+ len = min((-(size_t)sp) & (THREAD_SIZE - STACK_DUMP_ENTRY_SIZE),
512
+ kstack_depth_to_print * STACK_DUMP_ENTRY_SIZE);
510513
511
- for (i = 0; i < kstack_depth_to_print; i++) {
512
- if (kstack_end(sp))
513
- break;
514
- pr_cont(" %08lx", *sp++);
515
- if (i % 8 == 7)
516
- pr_cont("\n");
514
+ printk("%sStack:\n", loglvl);
515
+ while (off < len) {
516
+ u8 line[STACK_DUMP_LINE_SIZE];
517
+ size_t line_len = len - off > STACK_DUMP_LINE_SIZE ?
518
+ STACK_DUMP_LINE_SIZE : len - off;
519
+
520
+ __memcpy(line, (u8 *)sp + off, line_len);
521
+ print_hex_dump(loglvl, " ", DUMP_PREFIX_NONE,
522
+ STACK_DUMP_LINE_SIZE, STACK_DUMP_ENTRY_SIZE,
523
+ line, line_len, false);
524
+ off += STACK_DUMP_LINE_SIZE;
517525 }
518
- show_trace(task, stack);
526
+ show_trace(task, sp, loglvl);
519527 }
520528
521529 DEFINE_SPINLOCK(die_lock);
....@@ -523,15 +531,18 @@
523531 void die(const char * str, struct pt_regs * regs, long err)
524532 {
525533 static int die_counter;
534
+ const char *pr = "";
535
+
536
+ if (IS_ENABLED(CONFIG_PREEMPTION))
537
+ pr = IS_ENABLED(CONFIG_PREEMPT_RT) ? " PREEMPT_RT" : " PREEMPT";
526538
527539 console_verbose();
528540 spin_lock_irq(&die_lock);
529541
530
- pr_info("%s: sig: %ld [#%d]%s\n", str, err, ++die_counter,
531
- IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "");
542
+ pr_info("%s: sig: %ld [#%d]%s\n", str, err, ++die_counter, pr);
532543 show_regs(regs);
533544 if (!user_mode(regs))
534
- show_stack(NULL, (unsigned long*)regs->areg[1]);
545
+ show_stack(NULL, (unsigned long *)regs->areg[1], KERN_INFO);
535546
536547 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
537548 spin_unlock_irq(&die_lock);
....@@ -542,5 +553,5 @@
542553 if (panic_on_oops)
543554 panic("Fatal exception");
544555
545
- do_exit(err);
556
+ make_task_dead(err);
546557 }