hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/powerpc/kernel/traps.c
....@@ -1,11 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
34 * Copyright 2007-2010 Freescale Semiconductor, Inc.
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License
7
- * as published by the Free Software Foundation; either version
8
- * 2 of the License, or (at your option) any later version.
95 *
106 * Modified by Cort Dougan (cort@cs.nmt.edu)
117 * and Paul Mackerras (paulus@samba.org)
....@@ -43,7 +39,6 @@
4339 #include <linux/kmsg_dump.h>
4440
4541 #include <asm/emulated_ops.h>
46
-#include <asm/pgtable.h>
4742 #include <linux/uaccess.h>
4843 #include <asm/debugfs.h>
4944 #include <asm/io.h>
....@@ -71,6 +66,7 @@
7166 #include <sysdev/fsl_pci.h>
7267 #include <asm/kprobes.h>
7368 #include <asm/stacktrace.h>
69
+#include <asm/nmi.h>
7470
7571 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC_CORE)
7672 int (*__debugger)(struct pt_regs *regs) __read_mostly;
....@@ -178,7 +174,7 @@
178174 kmsg_dump(KMSG_DUMP_PANIC);
179175 bust_spinlocks(0);
180176 debug_locks_off();
181
- console_flush_on_panic();
177
+ console_flush_on_panic(CONSOLE_FLUSH_PENDING);
182178 }
183179
184180 static unsigned long oops_begin(struct pt_regs *regs)
....@@ -247,36 +243,34 @@
247243 mdelay(MSEC_PER_SEC);
248244 }
249245
250
- if (in_interrupt())
251
- panic("Fatal exception in interrupt");
252246 if (panic_on_oops)
253247 panic("Fatal exception");
254
- do_exit(signr);
248
+ make_task_dead(signr);
255249 }
256250 NOKPROBE_SYMBOL(oops_end);
251
+
252
+static char *get_mmu_str(void)
253
+{
254
+ if (early_radix_enabled())
255
+ return " MMU=Radix";
256
+ if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE))
257
+ return " MMU=Hash";
258
+ return "";
259
+}
257260
258261 static int __die(const char *str, struct pt_regs *regs, long err)
259262 {
260263 printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter);
261264
262
- if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
263
- printk("LE ");
264
- else
265
- printk("BE ");
266
-
267
- if (IS_ENABLED(CONFIG_PREEMPT))
268
- pr_cont("PREEMPT ");
269
-
270
- if (IS_ENABLED(CONFIG_SMP))
271
- pr_cont("SMP NR_CPUS=%d ", NR_CPUS);
272
-
273
- if (debug_pagealloc_enabled())
274
- pr_cont("DEBUG_PAGEALLOC ");
275
-
276
- if (IS_ENABLED(CONFIG_NUMA))
277
- pr_cont("NUMA ");
278
-
279
- pr_cont("%s\n", ppc_md.name ? ppc_md.name : "");
265
+ printk("%s PAGE_SIZE=%luK%s%s%s%s%s%s %s\n",
266
+ IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN) ? "LE" : "BE",
267
+ PAGE_SIZE / 1024, get_mmu_str(),
268
+ IS_ENABLED(CONFIG_PREEMPT) ? " PREEMPT" : "",
269
+ IS_ENABLED(CONFIG_SMP) ? " SMP" : "",
270
+ IS_ENABLED(CONFIG_SMP) ? (" NR_CPUS=" __stringify(NR_CPUS)) : "",
271
+ debug_pagealloc_enabled() ? " DEBUG_PAGEALLOC" : "",
272
+ IS_ENABLED(CONFIG_NUMA) ? " NUMA" : "",
273
+ ppc_md.name ? ppc_md.name : "");
280274
281275 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP)
282276 return 1;
....@@ -307,12 +301,9 @@
307301 }
308302 NOKPROBE_SYMBOL(die);
309303
310
-void user_single_step_siginfo(struct task_struct *tsk,
311
- struct pt_regs *regs, siginfo_t *info)
304
+void user_single_step_report(struct pt_regs *regs)
312305 {
313
- info->si_signo = SIGTRAP;
314
- info->si_code = TRAP_TRACE;
315
- info->si_addr = (void __user *)regs->nip;
306
+ force_sig_fault(SIGTRAP, TRAP_TRACE, (void __user *)regs->nip);
316307 }
317308
318309 static void show_signal_msg(int signr, struct pt_regs *regs, int code,
....@@ -341,14 +332,12 @@
341332 show_user_instructions(regs);
342333 }
343334
344
-void _exception_pkey(int signr, struct pt_regs *regs, int code,
345
- unsigned long addr, int key)
335
+static bool exception_common(int signr, struct pt_regs *regs, int code,
336
+ unsigned long addr)
346337 {
347
- siginfo_t info;
348
-
349338 if (!user_mode(regs)) {
350339 die("Exception in kernel mode", regs, signr);
351
- return;
340
+ return false;
352341 }
353342
354343 show_signal_msg(signr, regs, code, addr);
....@@ -364,29 +353,116 @@
364353 */
365354 thread_pkey_regs_save(&current->thread);
366355
367
- clear_siginfo(&info);
368
- info.si_signo = signr;
369
- info.si_code = code;
370
- info.si_addr = (void __user *) addr;
371
- info.si_pkey = key;
356
+ return true;
357
+}
372358
373
- force_sig_info(signr, &info, current);
359
+void _exception_pkey(struct pt_regs *regs, unsigned long addr, int key)
360
+{
361
+ if (!exception_common(SIGSEGV, regs, SEGV_PKUERR, addr))
362
+ return;
363
+
364
+ force_sig_pkuerr((void __user *) addr, key);
374365 }
375366
376367 void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr)
377368 {
378
- _exception_pkey(signr, regs, code, addr, 0);
369
+ if (!exception_common(signr, regs, code, addr))
370
+ return;
371
+
372
+ force_sig_fault(signr, code, (void __user *)addr);
373
+}
374
+
375
+/*
376
+ * The interrupt architecture has a quirk in that the HV interrupts excluding
377
+ * the NMIs (0x100 and 0x200) do not clear MSR[RI] at entry. The first thing
378
+ * that an interrupt handler must do is save off a GPR into a scratch register,
379
+ * and all interrupts on POWERNV (HV=1) use the HSPRG1 register as scratch.
380
+ * Therefore an NMI can clobber an HV interrupt's live HSPRG1 without noticing
381
+ * that it is non-reentrant, which leads to random data corruption.
382
+ *
383
+ * The solution is for NMI interrupts in HV mode to check if they originated
384
+ * from these critical HV interrupt regions. If so, then mark them not
385
+ * recoverable.
386
+ *
387
+ * An alternative would be for HV NMIs to use SPRG for scratch to avoid the
388
+ * HSPRG1 clobber, however this would cause guest SPRG to be clobbered. Linux
389
+ * guests should always have MSR[RI]=0 when its scratch SPRG is in use, so
390
+ * that would work. However any other guest OS that may have the SPRG live
391
+ * and MSR[RI]=1 could encounter silent corruption.
392
+ *
393
+ * Builds that do not support KVM could take this second option to increase
394
+ * the recoverability of NMIs.
395
+ */
396
+void hv_nmi_check_nonrecoverable(struct pt_regs *regs)
397
+{
398
+#ifdef CONFIG_PPC_POWERNV
399
+ unsigned long kbase = (unsigned long)_stext;
400
+ unsigned long nip = regs->nip;
401
+
402
+ if (!(regs->msr & MSR_RI))
403
+ return;
404
+ if (!(regs->msr & MSR_HV))
405
+ return;
406
+ if (regs->msr & MSR_PR)
407
+ return;
408
+
409
+ /*
410
+ * Now test if the interrupt has hit a range that may be using
411
+ * HSPRG1 without having RI=0 (i.e., an HSRR interrupt). The
412
+ * problem ranges all run un-relocated. Test real and virt modes
413
+ * at the same time by droping the high bit of the nip (virt mode
414
+ * entry points still have the +0x4000 offset).
415
+ */
416
+ nip &= ~0xc000000000000000ULL;
417
+ if ((nip >= 0x500 && nip < 0x600) || (nip >= 0x4500 && nip < 0x4600))
418
+ goto nonrecoverable;
419
+ if ((nip >= 0x980 && nip < 0xa00) || (nip >= 0x4980 && nip < 0x4a00))
420
+ goto nonrecoverable;
421
+ if ((nip >= 0xe00 && nip < 0xec0) || (nip >= 0x4e00 && nip < 0x4ec0))
422
+ goto nonrecoverable;
423
+ if ((nip >= 0xf80 && nip < 0xfa0) || (nip >= 0x4f80 && nip < 0x4fa0))
424
+ goto nonrecoverable;
425
+
426
+ /* Trampoline code runs un-relocated so subtract kbase. */
427
+ if (nip >= (unsigned long)(start_real_trampolines - kbase) &&
428
+ nip < (unsigned long)(end_real_trampolines - kbase))
429
+ goto nonrecoverable;
430
+ if (nip >= (unsigned long)(start_virt_trampolines - kbase) &&
431
+ nip < (unsigned long)(end_virt_trampolines - kbase))
432
+ goto nonrecoverable;
433
+ return;
434
+
435
+nonrecoverable:
436
+ regs->msr &= ~MSR_RI;
437
+#endif
379438 }
380439
381440 void system_reset_exception(struct pt_regs *regs)
382441 {
442
+ unsigned long hsrr0, hsrr1;
443
+ bool saved_hsrrs = false;
444
+ u8 ftrace_enabled = this_cpu_get_ftrace_enabled();
445
+
446
+ this_cpu_set_ftrace_enabled(0);
447
+
448
+ nmi_enter();
449
+
383450 /*
384
- * Avoid crashes in case of nested NMI exceptions. Recoverability
385
- * is determined by RI and in_nmi
451
+ * System reset can interrupt code where HSRRs are live and MSR[RI]=1.
452
+ * The system reset interrupt itself may clobber HSRRs (e.g., to call
453
+ * OPAL), so save them here and restore them before returning.
454
+ *
455
+ * Machine checks don't need to save HSRRs, as the real mode handler
456
+ * is careful to avoid them, and the regular handler is not delivered
457
+ * as an NMI.
386458 */
387
- bool nested = in_nmi();
388
- if (!nested)
389
- nmi_enter();
459
+ if (cpu_has_feature(CPU_FTR_HVMODE)) {
460
+ hsrr0 = mfspr(SPRN_HSRR0);
461
+ hsrr1 = mfspr(SPRN_HSRR1);
462
+ saved_hsrrs = true;
463
+ }
464
+
465
+ hv_nmi_check_nonrecoverable(regs);
390466
391467 __this_cpu_inc(irq_stat.sreset_irqs);
392468
....@@ -439,8 +515,14 @@
439515 die("Unrecoverable System Reset", regs, SIGABRT);
440516 }
441517
442
- if (!nested)
443
- nmi_exit();
518
+ if (saved_hsrrs) {
519
+ mtspr(SPRN_HSRR0, hsrr0);
520
+ mtspr(SPRN_HSRR1, hsrr1);
521
+ }
522
+
523
+ nmi_exit();
524
+
525
+ this_cpu_set_ftrace_enabled(ftrace_enabled);
444526
445527 /* What should we do here? We could issue a shutdown or hard reset. */
446528 }
....@@ -450,9 +532,6 @@
450532 * Check if the NIP corresponds to the address of a sync
451533 * instruction for which there is an entry in the exception
452534 * table.
453
- * Note that the 601 only takes a machine check on TEA
454
- * (transfer error ack) signal assertion, and does not
455
- * set any of the top 16 bits of SRR1.
456535 * -- paulus.
457536 */
458537 static inline int check_io_access(struct pt_regs *regs)
....@@ -501,6 +580,8 @@
501580 #define REASON_ILLEGAL (ESR_PIL | ESR_PUO)
502581 #define REASON_PRIVILEGED ESR_PPR
503582 #define REASON_TRAP ESR_PTR
583
+#define REASON_PREFIXED 0
584
+#define REASON_BOUNDARY 0
504585
505586 /* single-step stuff */
506587 #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC)
....@@ -515,11 +596,15 @@
515596 #define REASON_ILLEGAL SRR1_PROGILL
516597 #define REASON_PRIVILEGED SRR1_PROGPRIV
517598 #define REASON_TRAP SRR1_PROGTRAP
599
+#define REASON_PREFIXED SRR1_PREFIXED
600
+#define REASON_BOUNDARY SRR1_BOUNDARY
518601
519602 #define single_stepping(regs) ((regs)->msr & MSR_SE)
520603 #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE)
521604 #define clear_br_trace(regs) ((regs)->msr &= ~MSR_BE)
522605 #endif
606
+
607
+#define inst_length(reason) (((reason) & REASON_PREFIXED) ? 8 : 4)
523608
524609 #if defined(CONFIG_E500)
525610 int machine_check_e500mc(struct pt_regs *regs)
....@@ -539,10 +624,10 @@
539624 printk("Caused by (from MCSR=%lx): ", reason);
540625
541626 if (reason & MCSR_MCP)
542
- printk("Machine Check Signal\n");
627
+ pr_cont("Machine Check Signal\n");
543628
544629 if (reason & MCSR_ICPERR) {
545
- printk("Instruction Cache Parity Error\n");
630
+ pr_cont("Instruction Cache Parity Error\n");
546631
547632 /*
548633 * This is recoverable by invalidating the i-cache.
....@@ -560,7 +645,7 @@
560645 }
561646
562647 if (reason & MCSR_DCPERR_MC) {
563
- printk("Data Cache Parity Error\n");
648
+ pr_cont("Data Cache Parity Error\n");
564649
565650 /*
566651 * In write shadow mode we auto-recover from the error, but it
....@@ -579,38 +664,38 @@
579664 }
580665
581666 if (reason & MCSR_L2MMU_MHIT) {
582
- printk("Hit on multiple TLB entries\n");
667
+ pr_cont("Hit on multiple TLB entries\n");
583668 recoverable = 0;
584669 }
585670
586671 if (reason & MCSR_NMI)
587
- printk("Non-maskable interrupt\n");
672
+ pr_cont("Non-maskable interrupt\n");
588673
589674 if (reason & MCSR_IF) {
590
- printk("Instruction Fetch Error Report\n");
675
+ pr_cont("Instruction Fetch Error Report\n");
591676 recoverable = 0;
592677 }
593678
594679 if (reason & MCSR_LD) {
595
- printk("Load Error Report\n");
680
+ pr_cont("Load Error Report\n");
596681 recoverable = 0;
597682 }
598683
599684 if (reason & MCSR_ST) {
600
- printk("Store Error Report\n");
685
+ pr_cont("Store Error Report\n");
601686 recoverable = 0;
602687 }
603688
604689 if (reason & MCSR_LDG) {
605
- printk("Guarded Load Error Report\n");
690
+ pr_cont("Guarded Load Error Report\n");
606691 recoverable = 0;
607692 }
608693
609694 if (reason & MCSR_TLBSYNC)
610
- printk("Simultaneous tlbsync operations\n");
695
+ pr_cont("Simultaneous tlbsync operations\n");
611696
612697 if (reason & MCSR_BSL2_ERR) {
613
- printk("Level 2 Cache Error\n");
698
+ pr_cont("Level 2 Cache Error\n");
614699 recoverable = 0;
615700 }
616701
....@@ -620,7 +705,7 @@
620705 addr = mfspr(SPRN_MCAR);
621706 addr |= (u64)mfspr(SPRN_MCARU) << 32;
622707
623
- printk("Machine Check %s Address: %#llx\n",
708
+ pr_cont("Machine Check %s Address: %#llx\n",
624709 reason & MCSR_MEA ? "Effective" : "Physical", addr);
625710 }
626711
....@@ -644,29 +729,29 @@
644729 printk("Caused by (from MCSR=%lx): ", reason);
645730
646731 if (reason & MCSR_MCP)
647
- printk("Machine Check Signal\n");
732
+ pr_cont("Machine Check Signal\n");
648733 if (reason & MCSR_ICPERR)
649
- printk("Instruction Cache Parity Error\n");
734
+ pr_cont("Instruction Cache Parity Error\n");
650735 if (reason & MCSR_DCP_PERR)
651
- printk("Data Cache Push Parity Error\n");
736
+ pr_cont("Data Cache Push Parity Error\n");
652737 if (reason & MCSR_DCPERR)
653
- printk("Data Cache Parity Error\n");
738
+ pr_cont("Data Cache Parity Error\n");
654739 if (reason & MCSR_BUS_IAERR)
655
- printk("Bus - Instruction Address Error\n");
740
+ pr_cont("Bus - Instruction Address Error\n");
656741 if (reason & MCSR_BUS_RAERR)
657
- printk("Bus - Read Address Error\n");
742
+ pr_cont("Bus - Read Address Error\n");
658743 if (reason & MCSR_BUS_WAERR)
659
- printk("Bus - Write Address Error\n");
744
+ pr_cont("Bus - Write Address Error\n");
660745 if (reason & MCSR_BUS_IBERR)
661
- printk("Bus - Instruction Data Error\n");
746
+ pr_cont("Bus - Instruction Data Error\n");
662747 if (reason & MCSR_BUS_RBERR)
663
- printk("Bus - Read Data Bus Error\n");
748
+ pr_cont("Bus - Read Data Bus Error\n");
664749 if (reason & MCSR_BUS_WBERR)
665
- printk("Bus - Write Data Bus Error\n");
750
+ pr_cont("Bus - Write Data Bus Error\n");
666751 if (reason & MCSR_BUS_IPERR)
667
- printk("Bus - Instruction Parity Error\n");
752
+ pr_cont("Bus - Instruction Parity Error\n");
668753 if (reason & MCSR_BUS_RPERR)
669
- printk("Bus - Read Parity Error\n");
754
+ pr_cont("Bus - Read Parity Error\n");
670755
671756 return 0;
672757 }
....@@ -684,19 +769,19 @@
684769 printk("Caused by (from MCSR=%lx): ", reason);
685770
686771 if (reason & MCSR_MCP)
687
- printk("Machine Check Signal\n");
772
+ pr_cont("Machine Check Signal\n");
688773 if (reason & MCSR_CP_PERR)
689
- printk("Cache Push Parity Error\n");
774
+ pr_cont("Cache Push Parity Error\n");
690775 if (reason & MCSR_CPERR)
691
- printk("Cache Parity Error\n");
776
+ pr_cont("Cache Parity Error\n");
692777 if (reason & MCSR_EXCP_ERR)
693
- printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
778
+ pr_cont("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n");
694779 if (reason & MCSR_BUS_IRERR)
695
- printk("Bus - Read Bus Error on instruction fetch\n");
780
+ pr_cont("Bus - Read Bus Error on instruction fetch\n");
696781 if (reason & MCSR_BUS_DRERR)
697
- printk("Bus - Read Bus Error on data load\n");
782
+ pr_cont("Bus - Read Bus Error on data load\n");
698783 if (reason & MCSR_BUS_WRERR)
699
- printk("Bus - Write Bus Error on buffered store or cache line push\n");
784
+ pr_cont("Bus - Write Bus Error on buffered store or cache line push\n");
700785
701786 return 0;
702787 }
....@@ -709,30 +794,29 @@
709794 printk("Caused by (from SRR1=%lx): ", reason);
710795 switch (reason & 0x601F0000) {
711796 case 0x80000:
712
- printk("Machine check signal\n");
797
+ pr_cont("Machine check signal\n");
713798 break;
714
- case 0: /* for 601 */
715799 case 0x40000:
716800 case 0x140000: /* 7450 MSS error and TEA */
717
- printk("Transfer error ack signal\n");
801
+ pr_cont("Transfer error ack signal\n");
718802 break;
719803 case 0x20000:
720
- printk("Data parity error signal\n");
804
+ pr_cont("Data parity error signal\n");
721805 break;
722806 case 0x10000:
723
- printk("Address parity error signal\n");
807
+ pr_cont("Address parity error signal\n");
724808 break;
725809 case 0x20000000:
726
- printk("L1 Data Cache error\n");
810
+ pr_cont("L1 Data Cache error\n");
727811 break;
728812 case 0x40000000:
729
- printk("L1 Instruction Cache error\n");
813
+ pr_cont("L1 Instruction Cache error\n");
730814 break;
731815 case 0x00100000:
732
- printk("L2 data cache parity error\n");
816
+ pr_cont("L2 data cache parity error\n");
733817 break;
734818 default:
735
- printk("Unknown values in msr\n");
819
+ pr_cont("Unknown values in msr\n");
736820 }
737821 return 0;
738822 }
....@@ -741,13 +825,22 @@
741825 void machine_check_exception(struct pt_regs *regs)
742826 {
743827 int recover = 0;
744
- bool nested = in_nmi();
745
- if (!nested)
746
- nmi_enter();
747828
748
- /* 64s accounts the mce in machine_check_early when in HVMODE */
749
- if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) || !cpu_has_feature(CPU_FTR_HVMODE))
750
- __this_cpu_inc(irq_stat.mce_exceptions);
829
+ /*
830
+ * BOOK3S_64 does not call this handler as a non-maskable interrupt
831
+ * (it uses its own early real-mode handler to handle the MCE proper
832
+ * and then raises irq_work to call this handler when interrupts are
833
+ * enabled).
834
+ *
835
+ * This is silly. The BOOK3S_64 should just call a different function
836
+ * rather than expecting semantics to magically change. Something
837
+ * like 'non_nmi_machine_check_exception()', perhaps?
838
+ */
839
+ const bool nmi = !IS_ENABLED(CONFIG_PPC_BOOK3S_64);
840
+
841
+ if (nmi) nmi_enter();
842
+
843
+ __this_cpu_inc(irq_stat.mce_exceptions);
751844
752845 add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
753846
....@@ -771,8 +864,7 @@
771864 if (check_io_access(regs))
772865 goto bail;
773866
774
- if (!nested)
775
- nmi_exit();
867
+ if (nmi) nmi_exit();
776868
777869 die("Machine check", regs, SIGBUS);
778870
....@@ -783,8 +875,7 @@
783875 return;
784876
785877 bail:
786
- if (!nested)
787
- nmi_exit();
878
+ if (nmi) nmi_exit();
788879 }
789880
790881 void SMIException(struct pt_regs *regs)
....@@ -845,7 +936,7 @@
845936 addr = (__force const void __user *)ea;
846937
847938 /* Check it */
848
- if (!access_ok(VERIFY_READ, addr, 16)) {
939
+ if (!access_ok(addr, 16)) {
849940 pr_devel("HMI vec emu: bad access %i:%s[%d] nip=%016lx"
850941 " instr=%08x addr=%016lx\n",
851942 smp_processor_id(), current->comm, current->pid,
....@@ -1442,7 +1533,8 @@
14421533 goto bail;
14431534 } else {
14441535 printk(KERN_EMERG "Unexpected TM Bad Thing exception "
1445
- "at %lx (msr 0x%x)\n", regs->nip, reason);
1536
+ "at %lx (msr 0x%lx) tm_scratch=%llx\n",
1537
+ regs->nip, regs->msr, get_paca()->tm_scratch);
14461538 die("Unrecoverable exception", regs, SIGABRT);
14471539 }
14481540 }
....@@ -1512,10 +1604,19 @@
15121604 {
15131605 enum ctx_state prev_state = exception_enter();
15141606 int sig, code, fixed = 0;
1607
+ unsigned long reason;
15151608
15161609 /* We restore the interrupt state now */
15171610 if (!arch_irq_disabled_regs(regs))
15181611 local_irq_enable();
1612
+
1613
+ reason = get_reason(regs);
1614
+
1615
+ if (reason & REASON_BOUNDARY) {
1616
+ sig = SIGBUS;
1617
+ code = BUS_ADRALN;
1618
+ goto bad;
1619
+ }
15191620
15201621 if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT))
15211622 goto bail;
....@@ -1525,7 +1626,8 @@
15251626 fixed = fix_alignment(regs);
15261627
15271628 if (fixed == 1) {
1528
- regs->nip += 4; /* skip over emulated instruction */
1629
+ /* skip over emulated instruction */
1630
+ regs->nip += inst_length(reason);
15291631 emulate_single_step(regs);
15301632 goto bail;
15311633 }
....@@ -1538,6 +1640,7 @@
15381640 sig = SIGBUS;
15391641 code = BUS_ADRALN;
15401642 }
1643
+bad:
15411644 if (user_mode(regs))
15421645 _exception(sig, regs, code, regs->dar);
15431646 else
....@@ -1556,12 +1659,13 @@
15561659 panic("kernel stack overflow");
15571660 }
15581661
1559
-void nonrecoverable_exception(struct pt_regs *regs)
1662
+void stack_overflow_exception(struct pt_regs *regs)
15601663 {
1561
- printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n",
1562
- regs->nip, regs->msr);
1563
- debugger(regs);
1564
- die("nonrecoverable exception", regs, SIGKILL);
1664
+ enum ctx_state prev_state = exception_enter();
1665
+
1666
+ die("Kernel stack overflow", regs, SIGSEGV);
1667
+
1668
+ exception_exit(prev_state);
15651669 }
15661670
15671671 void kernel_fp_unavailable_exception(struct pt_regs *regs)
....@@ -1638,6 +1742,7 @@
16381742 [FSCR_TAR_LG] = "TAR",
16391743 [FSCR_MSGP_LG] = "MSGP",
16401744 [FSCR_SCV_LG] = "SCV",
1745
+ [FSCR_PREFIX_LG] = "PREFIX",
16411746 };
16421747 char *facility = "unknown";
16431748 u64 value;
....@@ -1759,16 +1864,20 @@
17591864 * checkpointed FP registers need to be loaded.
17601865 */
17611866 tm_reclaim_current(TM_CAUSE_FAC_UNAV);
1762
- /* Reclaim didn't save out any FPRs to transact_fprs. */
1867
+
1868
+ /*
1869
+ * Reclaim initially saved out bogus (lazy) FPRs to ckfp_state, and
1870
+ * then it was overwrite by the thr->fp_state by tm_reclaim_thread().
1871
+ *
1872
+ * At this point, ck{fp,vr}_state contains the exact values we want to
1873
+ * recheckpoint.
1874
+ */
17631875
17641876 /* Enable FP for the task: */
17651877 current->thread.load_fp = 1;
17661878
1767
- /* This loads and recheckpoints the FP registers from
1768
- * thread.fpr[]. They will remain in registers after the
1769
- * checkpoint so we don't need to reload them after.
1770
- * If VMX is in use, the VRs now hold checkpointed values,
1771
- * so we don't want to load the VRs from the thread_struct.
1879
+ /*
1880
+ * Recheckpoint all the checkpointed ckpt, ck{fp, vr}_state registers.
17721881 */
17731882 tm_recheckpoint(&current->thread);
17741883 }
....@@ -1813,11 +1922,40 @@
18131922 }
18141923 #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
18151924
1816
-void performance_monitor_exception(struct pt_regs *regs)
1925
+static void performance_monitor_exception_nmi(struct pt_regs *regs)
18171926 {
1927
+ nmi_enter();
1928
+
18181929 __this_cpu_inc(irq_stat.pmu_irqs);
18191930
18201931 perf_irq(regs);
1932
+
1933
+ nmi_exit();
1934
+}
1935
+
1936
+static void performance_monitor_exception_async(struct pt_regs *regs)
1937
+{
1938
+ irq_enter();
1939
+
1940
+ __this_cpu_inc(irq_stat.pmu_irqs);
1941
+
1942
+ perf_irq(regs);
1943
+
1944
+ irq_exit();
1945
+}
1946
+
1947
+void performance_monitor_exception(struct pt_regs *regs)
1948
+{
1949
+ /*
1950
+ * On 64-bit, if perf interrupts hit in a local_irq_disable
1951
+ * (soft-masked) region, we consider them as NMIs. This is required to
1952
+ * prevent hash faults on user addresses when reading callchains (and
1953
+ * looks better from an irq tracing perspective).
1954
+ */
1955
+ if (IS_ENABLED(CONFIG_PPC64) && unlikely(arch_irq_disabled_regs(regs)))
1956
+ performance_monitor_exception_nmi(regs);
1957
+ else
1958
+ performance_monitor_exception_async(regs);
18211959 }
18221960
18231961 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
....@@ -1950,14 +2088,6 @@
19502088 NOKPROBE_SYMBOL(DebugException);
19512089 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
19522090
1953
-#if !defined(CONFIG_TAU_INT)
1954
-void TAUException(struct pt_regs *regs)
1955
-{
1956
- printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n",
1957
- regs->nip, regs->msr, regs->trap, print_tainted());
1958
-}
1959
-#endif /* CONFIG_INT_TAU */
1960
-
19612091 #ifdef CONFIG_ALTIVEC
19622092 void altivec_assist_exception(struct pt_regs *regs)
19632093 {
....@@ -2015,6 +2145,10 @@
20152145 int code = FPE_FLTUNK;
20162146 int err;
20172147
2148
+ /* We restore the interrupt state now */
2149
+ if (!arch_irq_disabled_regs(regs))
2150
+ local_irq_enable();
2151
+
20182152 flush_spe_to_thread(current);
20192153
20202154 spefscr = current->thread.spefscr;
....@@ -2060,6 +2194,10 @@
20602194 extern int speround_handler(struct pt_regs *regs);
20612195 int err;
20622196
2197
+ /* We restore the interrupt state now */
2198
+ if (!arch_irq_disabled_regs(regs))
2199
+ local_irq_enable();
2200
+
20632201 preempt_disable();
20642202 if (regs->msr & MSR_SPE)
20652203 giveup_spe(current);
....@@ -2095,8 +2233,8 @@
20952233 */
20962234 void unrecoverable_exception(struct pt_regs *regs)
20972235 {
2098
- printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n",
2099
- regs->trap, regs->nip);
2236
+ pr_emerg("Unrecoverable exception %lx at %lx (msr=%lx)\n",
2237
+ regs->trap, regs->nip, regs->msr);
21002238 die("Unrecoverable exception", regs, SIGABRT);
21012239 }
21022240 NOKPROBE_SYMBOL(unrecoverable_exception);
....@@ -2184,35 +2322,20 @@
21842322
21852323 static int __init ppc_warn_emulated_init(void)
21862324 {
2187
- struct dentry *dir, *d;
2325
+ struct dentry *dir;
21882326 unsigned int i;
21892327 struct ppc_emulated_entry *entries = (void *)&ppc_emulated;
21902328
2191
- if (!powerpc_debugfs_root)
2192
- return -ENODEV;
2193
-
21942329 dir = debugfs_create_dir("emulated_instructions",
21952330 powerpc_debugfs_root);
2196
- if (!dir)
2197
- return -ENOMEM;
21982331
2199
- d = debugfs_create_u32("do_warn", 0644, dir,
2200
- &ppc_warn_emulated);
2201
- if (!d)
2202
- goto fail;
2332
+ debugfs_create_u32("do_warn", 0644, dir, &ppc_warn_emulated);
22032333
2204
- for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) {
2205
- d = debugfs_create_u32(entries[i].name, 0644, dir,
2206
- (u32 *)&entries[i].val.counter);
2207
- if (!d)
2208
- goto fail;
2209
- }
2334
+ for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++)
2335
+ debugfs_create_u32(entries[i].name, 0644, dir,
2336
+ (u32 *)&entries[i].val.counter);
22102337
22112338 return 0;
2212
-
2213
-fail:
2214
- debugfs_remove_recursive(dir);
2215
- return -ENOMEM;
22162339 }
22172340
22182341 device_initcall(ppc_warn_emulated_init);