hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/parisc/kernel/traps.c
....@@ -29,6 +29,7 @@
2929 #include <linux/bug.h>
3030 #include <linux/ratelimit.h>
3131 #include <linux/uaccess.h>
32
+#include <linux/kdebug.h>
3233
3334 #include <asm/assembly.h>
3435 #include <asm/io.h>
....@@ -42,11 +43,13 @@
4243 #include <asm/unwind.h>
4344 #include <asm/tlbflush.h>
4445 #include <asm/cacheflush.h>
46
+#include <linux/kgdb.h>
47
+#include <linux/kprobes.h>
4548
4649 #include "../math-emu/math-emu.h" /* for handle_fpe() */
4750
4851 static void parisc_show_stack(struct task_struct *task,
49
- struct pt_regs *regs);
52
+ struct pt_regs *regs, const char *loglvl);
5053
5154 static int printbinary(char *buf, unsigned long x, int nbits)
5255 {
....@@ -72,7 +75,7 @@
7275 lvl, f, (x), (x+3), (r)[(x)+0], (r)[(x)+1], \
7376 (r)[(x)+2], (r)[(x)+3])
7477
75
-static void print_gr(char *level, struct pt_regs *regs)
78
+static void print_gr(const char *level, struct pt_regs *regs)
7679 {
7780 int i;
7881 char buf[64];
....@@ -86,7 +89,7 @@
8689 PRINTREGS(level, regs->gr, "r", RFMT, i);
8790 }
8891
89
-static void print_fr(char *level, struct pt_regs *regs)
92
+static void print_fr(const char *level, struct pt_regs *regs)
9093 {
9194 int i;
9295 char buf[64];
....@@ -116,7 +119,7 @@
116119 void show_regs(struct pt_regs *regs)
117120 {
118121 int i, user;
119
- char *level;
122
+ const char *level;
120123 unsigned long cr30, cr31;
121124
122125 user = user_mode(regs);
....@@ -152,7 +155,7 @@
152155 printk("%s IAOQ[1]: %pS\n", level, (void *) regs->iaoq[1]);
153156 printk("%s RP(r2): %pS\n", level, (void *) regs->gr[2]);
154157
155
- parisc_show_stack(current, regs);
158
+ parisc_show_stack(current, regs, KERN_DEFAULT);
156159 }
157160 }
158161
....@@ -167,37 +170,37 @@
167170 }
168171
169172
170
-static void do_show_stack(struct unwind_frame_info *info)
173
+static void do_show_stack(struct unwind_frame_info *info, const char *loglvl)
171174 {
172175 int i = 1;
173176
174
- printk(KERN_CRIT "Backtrace:\n");
177
+ printk("%sBacktrace:\n", loglvl);
175178 while (i <= MAX_UNWIND_ENTRIES) {
176179 if (unwind_once(info) < 0 || info->ip == 0)
177180 break;
178181
179182 if (__kernel_text_address(info->ip)) {
180
- printk(KERN_CRIT " [<" RFMT ">] %pS\n",
181
- info->ip, (void *) info->ip);
183
+ printk("%s [<" RFMT ">] %pS\n",
184
+ loglvl, info->ip, (void *) info->ip);
182185 i++;
183186 }
184187 }
185
- printk(KERN_CRIT "\n");
188
+ printk("%s\n", loglvl);
186189 }
187190
188191 static void parisc_show_stack(struct task_struct *task,
189
- struct pt_regs *regs)
192
+ struct pt_regs *regs, const char *loglvl)
190193 {
191194 struct unwind_frame_info info;
192195
193196 unwind_frame_init_task(&info, task, regs);
194197
195
- do_show_stack(&info);
198
+ do_show_stack(&info, loglvl);
196199 }
197200
198
-void show_stack(struct task_struct *t, unsigned long *sp)
201
+void show_stack(struct task_struct *t, unsigned long *sp, const char *loglvl)
199202 {
200
- parisc_show_stack(t, NULL);
203
+ parisc_show_stack(t, NULL, loglvl);
201204 }
202205
203206 int is_valid_bugaddr(unsigned long iaoq)
....@@ -218,7 +221,7 @@
218221 return;
219222 }
220223
221
- oops_in_progress = 1;
224
+ bust_spinlocks(1);
222225
223226 oops_enter();
224227
....@@ -265,7 +268,7 @@
265268 panic("Fatal exception");
266269
267270 oops_exit();
268
- do_exit(SIGSEGV);
271
+ make_task_dead(SIGSEGV);
269272 }
270273
271274 /* gdb uses break 4,8 */
....@@ -273,7 +276,7 @@
273276 static void handle_gdb_break(struct pt_regs *regs, int wot)
274277 {
275278 force_sig_fault(SIGTRAP, wot,
276
- (void __user *) (regs->iaoq[0] & ~3), current);
279
+ (void __user *) (regs->iaoq[0] & ~3));
277280 }
278281
279282 static void handle_break(struct pt_regs *regs)
....@@ -292,6 +295,22 @@
292295 die_if_kernel("Unknown kernel breakpoint", regs,
293296 (tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);
294297 }
298
+
299
+#ifdef CONFIG_KPROBES
300
+ if (unlikely(iir == PARISC_KPROBES_BREAK_INSN)) {
301
+ parisc_kprobe_break_handler(regs);
302
+ return;
303
+ }
304
+
305
+#endif
306
+
307
+#ifdef CONFIG_KGDB
308
+ if (unlikely((iir == PARISC_KGDB_COMPILED_BREAK_INSN ||
309
+ iir == PARISC_KGDB_BREAK_INSN)) && !user_mode(regs)) {
310
+ kgdb_handle_exception(9, SIGTRAP, 0, regs);
311
+ return;
312
+ }
313
+#endif
295314
296315 if (unlikely(iir != GDB_BREAK_INSN))
297316 parisc_printk_ratelimited(0, regs,
....@@ -396,7 +415,8 @@
396415 {
397416 static DEFINE_SPINLOCK(terminate_lock);
398417
399
- oops_in_progress = 1;
418
+ (void)notify_die(DIE_OOPS, msg, regs, 0, code, SIGTRAP);
419
+ bust_spinlocks(1);
400420
401421 set_eiem(0);
402422 local_irq_disable();
....@@ -417,7 +437,6 @@
417437 break;
418438
419439 default:
420
- /* Fall through */
421440 break;
422441
423442 }
....@@ -426,12 +445,12 @@
426445 /* show_stack(NULL, (unsigned long *)regs->gr[30]); */
427446 struct unwind_frame_info info;
428447 unwind_frame_init(&info, current, regs);
429
- do_show_stack(&info);
448
+ do_show_stack(&info, KERN_CRIT);
430449 }
431450
432451 printk("\n");
433
- pr_crit("%s: Code=%d (%s) regs=%p (Addr=" RFMT ")\n",
434
- msg, code, trap_name(code), regs, offset);
452
+ pr_crit("%s: Code=%d (%s) at addr " RFMT "\n",
453
+ msg, code, trap_name(code), offset);
435454 show_regs(regs);
436455
437456 spin_unlock(&terminate_lock);
....@@ -518,6 +537,19 @@
518537 case 3:
519538 /* Recovery counter trap */
520539 regs->gr[0] &= ~PSW_R;
540
+
541
+#ifdef CONFIG_KPROBES
542
+ if (parisc_kprobe_ss_handler(regs))
543
+ return;
544
+#endif
545
+
546
+#ifdef CONFIG_KGDB
547
+ if (kgdb_single_step) {
548
+ kgdb_handle_exception(0, SIGTRAP, 0, regs);
549
+ return;
550
+ }
551
+#endif
552
+
521553 if (user_space(regs))
522554 handle_gdb_break(regs, TRAP_TRACE);
523555 /* else this must be the start of a syscall - just let it run */
....@@ -578,13 +610,13 @@
578610 si_code = ILL_PRVREG;
579611 give_sigill:
580612 force_sig_fault(SIGILL, si_code,
581
- (void __user *) regs->iaoq[0], current);
613
+ (void __user *) regs->iaoq[0]);
582614 return;
583615
584616 case 12:
585617 /* Overflow Trap, let the userland signal handler do the cleanup */
586618 force_sig_fault(SIGFPE, FPE_INTOVF,
587
- (void __user *) regs->iaoq[0], current);
619
+ (void __user *) regs->iaoq[0]);
588620 return;
589621
590622 case 13:
....@@ -596,7 +628,7 @@
596628 * to by si_addr.
597629 */
598630 force_sig_fault(SIGFPE, FPE_CONDTRAP,
599
- (void __user *) regs->iaoq[0], current);
631
+ (void __user *) regs->iaoq[0]);
600632 return;
601633 }
602634 /* The kernel doesn't want to handle condition codes */
....@@ -611,12 +643,12 @@
611643
612644 case 15:
613645 /* Data TLB miss fault/Data page fault */
614
- /* Fall through */
646
+ fallthrough;
615647 case 16:
616648 /* Non-access instruction TLB miss fault */
617649 /* The instruction TLB entry needed for the target address of the FIC
618650 is absent, and hardware can't find it, so we get to cleanup */
619
- /* Fall through */
651
+ fallthrough;
620652 case 17:
621653 /* Non-access data TLB miss fault/Non-access data page fault */
622654 /* FIXME:
....@@ -629,6 +661,8 @@
629661 by hand. Technically we need to emulate:
630662 fdc,fdce,pdc,"fic,4f",prober,probeir,probew, probeiw
631663 */
664
+ if (code == 17 && handle_nadtlb_fault(regs))
665
+ return;
632666 fault_address = regs->ior;
633667 fault_space = regs->isr;
634668 break;
....@@ -640,7 +674,7 @@
640674 handle_unaligned(regs);
641675 return;
642676 }
643
- /* Fall Through */
677
+ fallthrough;
644678 case 26:
645679 /* PCXL: Data memory access rights trap */
646680 fault_address = regs->ior;
....@@ -650,7 +684,7 @@
650684 case 19:
651685 /* Data memory break trap */
652686 regs->gr[0] |= PSW_X; /* So we can single-step over the trap */
653
- /* fall thru */
687
+ fallthrough;
654688 case 21:
655689 /* Page reference trap */
656690 handle_gdb_break(regs, TRAP_HWBKPT);
....@@ -684,7 +718,7 @@
684718 if (user_mode(regs)) {
685719 struct vm_area_struct *vma;
686720
687
- down_read(&current->mm->mmap_sem);
721
+ mmap_read_lock(current->mm);
688722 vma = find_vma(current->mm,regs->iaoq[0]);
689723 if (vma && (regs->iaoq[0] >= vma->vm_start)
690724 && (vma->vm_flags & VM_EXEC)) {
....@@ -692,12 +726,14 @@
692726 fault_address = regs->iaoq[0];
693727 fault_space = regs->iasq[0];
694728
695
- up_read(&current->mm->mmap_sem);
729
+ mmap_read_unlock(current->mm);
696730 break; /* call do_page_fault() */
697731 }
698
- up_read(&current->mm->mmap_sem);
732
+ mmap_read_unlock(current->mm);
699733 }
700
- /* Fall Through */
734
+ /* CPU could not fetch instruction, so clear stale IIR value. */
735
+ regs->iir = 0xbaadf00d;
736
+ fallthrough;
701737 case 27:
702738 /* Data memory protection ID trap */
703739 if (code == 27 && !user_mode(regs) &&
....@@ -708,7 +744,7 @@
708744 force_sig_fault(SIGSEGV, SEGV_MAPERR,
709745 (code == 7)?
710746 ((void __user *) regs->iaoq[0]) :
711
- ((void __user *) regs->ior), current);
747
+ ((void __user *) regs->ior));
712748 return;
713749
714750 case 28:
....@@ -723,7 +759,7 @@
723759 task_pid_nr(current), current->comm);
724760 /* SIGBUS, for lack of a better one. */
725761 force_sig_fault(SIGBUS, BUS_OBJERR,
726
- (void __user *)regs->ior, current);
762
+ (void __user *)regs->ior);
727763 return;
728764 }
729765 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
....@@ -739,7 +775,7 @@
739775 code, fault_space,
740776 task_pid_nr(current), current->comm);
741777 force_sig_fault(SIGSEGV, SEGV_MAPERR,
742
- (void __user *)regs->ior, current);
778
+ (void __user *)regs->ior);
743779 return;
744780 }
745781 }