Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 3 | * Copyright 2007-2010 Freescale Semiconductor, Inc. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 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. |
| 9 | * |
| 10 | * Modified by Cort Dougan (cort@cs.nmt.edu) |
| 11 | * and Paul Mackerras (paulus@samba.org) |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * This file handles the architecture-dependent parts of hardware exceptions |
| 16 | */ |
| 17 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 18 | #include <linux/errno.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/stddef.h> |
| 23 | #include <linux/unistd.h> |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 24 | #include <linux/ptrace.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 25 | #include <linux/user.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 27 | #include <linux/init.h> |
Paul Gortmaker | 8a39b05 | 2016-08-16 10:57:34 -0400 | [diff] [blame] | 28 | #include <linux/extable.h> |
| 29 | #include <linux/module.h> /* print_modules */ |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 30 | #include <linux/prctl.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 31 | #include <linux/delay.h> |
| 32 | #include <linux/kprobes.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 33 | #include <linux/kexec.h> |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 34 | #include <linux/backlight.h> |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 35 | #include <linux/bug.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 36 | #include <linux/kdebug.h> |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 37 | #include <linux/debugfs.h> |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 38 | #include <linux/ratelimit.h> |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 39 | #include <linux/context_tracking.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 40 | |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 41 | #include <asm/emulated_ops.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 42 | #include <asm/pgtable.h> |
| 43 | #include <asm/uaccess.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 44 | #include <asm/io.h> |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 45 | #include <asm/machdep.h> |
| 46 | #include <asm/rtas.h> |
David Gibson | f7f6f4f | 2005-10-19 14:53:32 +1000 | [diff] [blame] | 47 | #include <asm/pmc.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 48 | #include <asm/reg.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 49 | #ifdef CONFIG_PMAC_BACKLIGHT |
| 50 | #include <asm/backlight.h> |
| 51 | #endif |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 52 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 53 | #include <asm/firmware.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 54 | #include <asm/processor.h> |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 55 | #include <asm/tm.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 56 | #endif |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 57 | #include <asm/kexec.h> |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 58 | #include <asm/ppc-opcode.h> |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 59 | #include <asm/rio.h> |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 60 | #include <asm/fadump.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 61 | #include <asm/switch_to.h> |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 62 | #include <asm/tm.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 63 | #include <asm/debug.h> |
Daniel Axtens | 42f5b4c | 2016-05-18 11:16:50 +1000 | [diff] [blame] | 64 | #include <asm/asm-prototypes.h> |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 65 | #include <asm/hmi.h> |
Hongtao Jia | 4e0e343 | 2013-04-28 13:20:08 +0800 | [diff] [blame] | 66 | #include <sysdev/fsl_pci.h> |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 67 | |
Olof Johansson | 7dbb922 | 2008-01-31 14:34:47 +1100 | [diff] [blame] | 68 | #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) |
Anton Blanchard | 5be3492 | 2010-01-12 00:50:14 +0000 | [diff] [blame] | 69 | int (*__debugger)(struct pt_regs *regs) __read_mostly; |
| 70 | int (*__debugger_ipi)(struct pt_regs *regs) __read_mostly; |
| 71 | int (*__debugger_bpt)(struct pt_regs *regs) __read_mostly; |
| 72 | int (*__debugger_sstep)(struct pt_regs *regs) __read_mostly; |
| 73 | int (*__debugger_iabr_match)(struct pt_regs *regs) __read_mostly; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 74 | int (*__debugger_break_match)(struct pt_regs *regs) __read_mostly; |
Anton Blanchard | 5be3492 | 2010-01-12 00:50:14 +0000 | [diff] [blame] | 75 | int (*__debugger_fault_handler)(struct pt_regs *regs) __read_mostly; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 76 | |
| 77 | EXPORT_SYMBOL(__debugger); |
| 78 | EXPORT_SYMBOL(__debugger_ipi); |
| 79 | EXPORT_SYMBOL(__debugger_bpt); |
| 80 | EXPORT_SYMBOL(__debugger_sstep); |
| 81 | EXPORT_SYMBOL(__debugger_iabr_match); |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 82 | EXPORT_SYMBOL(__debugger_break_match); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 83 | EXPORT_SYMBOL(__debugger_fault_handler); |
| 84 | #endif |
| 85 | |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 86 | /* Transactional Memory trap debug */ |
| 87 | #ifdef TM_DEBUG_SW |
| 88 | #define TM_DEBUG(x...) printk(KERN_INFO x) |
| 89 | #else |
| 90 | #define TM_DEBUG(x...) do { } while(0) |
| 91 | #endif |
| 92 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 93 | /* |
| 94 | * Trap & Exception support |
| 95 | */ |
| 96 | |
anton@samba.org | 6031d9d | 2007-03-20 20:38:12 -0500 | [diff] [blame] | 97 | #ifdef CONFIG_PMAC_BACKLIGHT |
| 98 | static void pmac_backlight_unblank(void) |
| 99 | { |
| 100 | mutex_lock(&pmac_backlight_mutex); |
| 101 | if (pmac_backlight) { |
| 102 | struct backlight_properties *props; |
| 103 | |
| 104 | props = &pmac_backlight->props; |
| 105 | props->brightness = props->max_brightness; |
| 106 | props->power = FB_BLANK_UNBLANK; |
| 107 | backlight_update_status(pmac_backlight); |
| 108 | } |
| 109 | mutex_unlock(&pmac_backlight_mutex); |
| 110 | } |
| 111 | #else |
| 112 | static inline void pmac_backlight_unblank(void) { } |
| 113 | #endif |
| 114 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 115 | static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
| 116 | static int die_owner = -1; |
| 117 | static unsigned int die_nest_count; |
| 118 | static int die_counter; |
| 119 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 120 | static unsigned long oops_begin(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 121 | { |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 122 | int cpu; |
anton@samba.org | 34c2a14 | 2007-03-20 20:38:13 -0500 | [diff] [blame] | 123 | unsigned long flags; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 124 | |
| 125 | if (debugger(regs)) |
| 126 | return 1; |
| 127 | |
anton@samba.org | 293e468 | 2007-03-20 20:38:11 -0500 | [diff] [blame] | 128 | oops_enter(); |
| 129 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 130 | /* racy, but better than risking deadlock. */ |
| 131 | raw_local_irq_save(flags); |
| 132 | cpu = smp_processor_id(); |
| 133 | if (!arch_spin_trylock(&die_lock)) { |
| 134 | if (cpu == die_owner) |
| 135 | /* nested oops. should stop eventually */; |
| 136 | else |
| 137 | arch_spin_lock(&die_lock); |
anton@samba.org | 34c2a14 | 2007-03-20 20:38:13 -0500 | [diff] [blame] | 138 | } |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 139 | die_nest_count++; |
| 140 | die_owner = cpu; |
| 141 | console_verbose(); |
| 142 | bust_spinlocks(1); |
| 143 | if (machine_is(powermac)) |
| 144 | pmac_backlight_unblank(); |
| 145 | return flags; |
| 146 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 147 | NOKPROBE_SYMBOL(oops_begin); |
Michael Hanselmann | 5474c12 | 2006-06-25 05:47:08 -0700 | [diff] [blame] | 148 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 149 | static void oops_end(unsigned long flags, struct pt_regs *regs, |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 150 | int signr) |
| 151 | { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 152 | bust_spinlocks(0); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 153 | die_owner = -1; |
Rusty Russell | 373d4d0 | 2013-01-21 17:17:39 +1030 | [diff] [blame] | 154 | add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 155 | die_nest_count--; |
Anton Blanchard | 58154c8 | 2011-11-30 00:23:09 +0000 | [diff] [blame] | 156 | oops_exit(); |
| 157 | printk("\n"); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 158 | if (!die_nest_count) |
| 159 | /* Nest count reaches zero, release the lock. */ |
| 160 | arch_spin_unlock(&die_lock); |
| 161 | raw_local_irq_restore(flags); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 162 | |
Mahesh Salgaonkar | ebaeb5a | 2012-02-16 01:14:45 +0000 | [diff] [blame] | 163 | crash_fadump(regs, "die oops"); |
| 164 | |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 165 | /* |
| 166 | * A system reset (0x100) is a request to dump, so we always send |
| 167 | * it through the crashdump code. |
| 168 | */ |
| 169 | if (kexec_should_crash(current) || (TRAP(regs) == 0x100)) { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 170 | crash_kexec(regs); |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 171 | |
| 172 | /* |
| 173 | * We aren't the primary crash CPU. We need to send it |
| 174 | * to a holding pattern to avoid it ending up in the panic |
| 175 | * code. |
| 176 | */ |
| 177 | crash_kexec_secondary(regs); |
| 178 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 179 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 180 | if (!signr) |
| 181 | return; |
| 182 | |
Anton Blanchard | 58154c8 | 2011-11-30 00:23:09 +0000 | [diff] [blame] | 183 | /* |
| 184 | * While our oops output is serialised by a spinlock, output |
| 185 | * from panic() called below can race and corrupt it. If we |
| 186 | * know we are going to panic, delay for 1 second so we have a |
| 187 | * chance to get clean backtraces from all CPUs that are oopsing. |
| 188 | */ |
| 189 | if (in_interrupt() || panic_on_oops || !current->pid || |
| 190 | is_global_init(current)) { |
| 191 | mdelay(MSEC_PER_SEC); |
| 192 | } |
| 193 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 194 | if (in_interrupt()) |
| 195 | panic("Fatal exception in interrupt"); |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 196 | if (panic_on_oops) |
Horms | 012c437 | 2006-08-13 23:24:22 -0700 | [diff] [blame] | 197 | panic("Fatal exception"); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 198 | do_exit(signr); |
| 199 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 200 | NOKPROBE_SYMBOL(oops_end); |
Horms | cea6a4b | 2006-07-30 03:03:34 -0700 | [diff] [blame] | 201 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 202 | static int __die(const char *str, struct pt_regs *regs, long err) |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 203 | { |
| 204 | printk("Oops: %s, sig: %ld [#%d]\n", str, err, ++die_counter); |
| 205 | #ifdef CONFIG_PREEMPT |
| 206 | printk("PREEMPT "); |
| 207 | #endif |
| 208 | #ifdef CONFIG_SMP |
| 209 | printk("SMP NR_CPUS=%d ", NR_CPUS); |
| 210 | #endif |
Joonsoo Kim | e7df0d8 | 2016-03-17 14:17:59 -0700 | [diff] [blame] | 211 | if (debug_pagealloc_enabled()) |
| 212 | printk("DEBUG_PAGEALLOC "); |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 213 | #ifdef CONFIG_NUMA |
| 214 | printk("NUMA "); |
| 215 | #endif |
| 216 | printk("%s\n", ppc_md.name ? ppc_md.name : ""); |
| 217 | |
| 218 | if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV) == NOTIFY_STOP) |
| 219 | return 1; |
| 220 | |
| 221 | print_modules(); |
| 222 | show_regs(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 226 | NOKPROBE_SYMBOL(__die); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 227 | |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 228 | void die(const char *str, struct pt_regs *regs, long err) |
| 229 | { |
| 230 | unsigned long flags = oops_begin(regs); |
| 231 | |
| 232 | if (__die(str, regs, err)) |
| 233 | err = 0; |
| 234 | oops_end(flags, regs, err); |
| 235 | } |
| 236 | |
Oleg Nesterov | 25baa35 | 2009-12-15 16:47:18 -0800 | [diff] [blame] | 237 | void user_single_step_siginfo(struct task_struct *tsk, |
| 238 | struct pt_regs *regs, siginfo_t *info) |
| 239 | { |
| 240 | memset(info, 0, sizeof(*info)); |
| 241 | info->si_signo = SIGTRAP; |
| 242 | info->si_code = TRAP_TRACE; |
| 243 | info->si_addr = (void __user *)regs->nip; |
| 244 | } |
| 245 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 246 | void _exception(int signr, struct pt_regs *regs, int code, unsigned long addr) |
| 247 | { |
| 248 | siginfo_t info; |
Olof Johansson | d0c3d53 | 2007-10-12 10:20:07 +1000 | [diff] [blame] | 249 | const char fmt32[] = KERN_INFO "%s[%d]: unhandled signal %d " \ |
| 250 | "at %08lx nip %08lx lr %08lx code %x\n"; |
| 251 | const char fmt64[] = KERN_INFO "%s[%d]: unhandled signal %d " \ |
| 252 | "at %016lx nip %016lx lr %016lx code %x\n"; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 253 | |
| 254 | if (!user_mode(regs)) { |
Anton Blanchard | 760ca4d | 2011-11-30 00:23:13 +0000 | [diff] [blame] | 255 | die("Exception in kernel mode", regs, signr); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | if (show_unhandled_signals && unhandled_signal(current, signr)) { |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 260 | printk_ratelimited(regs->msr & MSR_64BIT ? fmt64 : fmt32, |
| 261 | current->comm, current->pid, signr, |
| 262 | addr, regs->nip, regs->link, code); |
| 263 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 264 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 265 | if (arch_irqs_disabled() && !arch_irq_disabled_regs(regs)) |
Benjamin Herrenschmidt | 9f2f79e | 2012-03-01 15:47:44 +1100 | [diff] [blame] | 266 | local_irq_enable(); |
| 267 | |
Ananth N Mavinakayanahalli | 41ab526 | 2012-08-23 21:27:09 +0000 | [diff] [blame] | 268 | current->thread.trap_nr = code; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 269 | memset(&info, 0, sizeof(info)); |
| 270 | info.si_signo = signr; |
| 271 | info.si_code = code; |
| 272 | info.si_addr = (void __user *) addr; |
| 273 | force_sig_info(signr, &info, current); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 274 | } |
| 275 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 276 | void system_reset_exception(struct pt_regs *regs) |
| 277 | { |
| 278 | /* See if any machine dependent calls */ |
Arnd Bergmann | c902be7 | 2006-01-04 19:55:53 +0000 | [diff] [blame] | 279 | if (ppc_md.system_reset_exception) { |
| 280 | if (ppc_md.system_reset_exception(regs)) |
| 281 | return; |
| 282 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 283 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 284 | die("System Reset", regs, SIGABRT); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 285 | |
| 286 | /* Must die if the interrupt is not recoverable */ |
| 287 | if (!(regs->msr & MSR_RI)) |
| 288 | panic("Unrecoverable System Reset"); |
| 289 | |
| 290 | /* What should we do here? We could issue a shutdown or hard reset. */ |
| 291 | } |
Mahesh Salgaonkar | 1e9b450 | 2013-10-30 20:04:08 +0530 | [diff] [blame] | 292 | |
Christophe Leroy | f307939 | 2016-09-05 08:42:31 +0200 | [diff] [blame^] | 293 | #ifdef CONFIG_PPC64 |
Mahesh Salgaonkar | 1e9b450 | 2013-10-30 20:04:08 +0530 | [diff] [blame] | 294 | /* |
| 295 | * This function is called in real mode. Strictly no printk's please. |
| 296 | * |
| 297 | * regs->nip and regs->msr contains srr0 and ssr1. |
| 298 | */ |
| 299 | long machine_check_early(struct pt_regs *regs) |
| 300 | { |
Mahesh Salgaonkar | 4c70341 | 2013-10-30 20:04:40 +0530 | [diff] [blame] | 301 | long handled = 0; |
| 302 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 303 | __this_cpu_inc(irq_stat.mce_exceptions); |
Mahesh Salgaonkar | e6654d5 | 2014-06-11 14:18:07 +0530 | [diff] [blame] | 304 | |
Daniel Axtens | 27ea2c4 | 2015-06-15 13:25:19 +1000 | [diff] [blame] | 305 | add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE); |
| 306 | |
Mahesh Salgaonkar | 4c70341 | 2013-10-30 20:04:40 +0530 | [diff] [blame] | 307 | if (cur_cpu_spec && cur_cpu_spec->machine_check_early) |
| 308 | handled = cur_cpu_spec->machine_check_early(regs); |
| 309 | return handled; |
Mahesh Salgaonkar | 1e9b450 | 2013-10-30 20:04:08 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 312 | long hmi_exception_realmode(struct pt_regs *regs) |
| 313 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 314 | __this_cpu_inc(irq_stat.hmi_exceptions); |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 315 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 316 | wait_for_subcore_guest_exit(); |
| 317 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 318 | if (ppc_md.hmi_exception_early) |
| 319 | ppc_md.hmi_exception_early(regs); |
| 320 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 321 | wait_for_tb_resync(); |
| 322 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 323 | return 0; |
| 324 | } |
| 325 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 326 | #endif |
| 327 | |
| 328 | /* |
| 329 | * I/O accesses can cause machine checks on powermacs. |
| 330 | * Check if the NIP corresponds to the address of a sync |
| 331 | * instruction for which there is an entry in the exception |
| 332 | * table. |
| 333 | * Note that the 601 only takes a machine check on TEA |
| 334 | * (transfer error ack) signal assertion, and does not |
| 335 | * set any of the top 16 bits of SRR1. |
| 336 | * -- paulus. |
| 337 | */ |
| 338 | static inline int check_io_access(struct pt_regs *regs) |
| 339 | { |
Benjamin Herrenschmidt | 68a6435 | 2006-11-13 09:27:39 +1100 | [diff] [blame] | 340 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 341 | unsigned long msr = regs->msr; |
| 342 | const struct exception_table_entry *entry; |
| 343 | unsigned int *nip = (unsigned int *)regs->nip; |
| 344 | |
| 345 | if (((msr & 0xffff0000) == 0 || (msr & (0x80000 | 0x40000))) |
| 346 | && (entry = search_exception_tables(regs->nip)) != NULL) { |
| 347 | /* |
| 348 | * Check that it's a sync instruction, or somewhere |
| 349 | * in the twi; isync; nop sequence that inb/inw/inl uses. |
| 350 | * As the address is in the exception table |
| 351 | * we should be able to read the instr there. |
| 352 | * For the debug message, we look at the preceding |
| 353 | * load or store. |
| 354 | */ |
Christophe Leroy | ddc6cd0 | 2016-05-17 14:01:39 +0200 | [diff] [blame] | 355 | if (*nip == PPC_INST_NOP) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 356 | nip -= 2; |
Christophe Leroy | ddc6cd0 | 2016-05-17 14:01:39 +0200 | [diff] [blame] | 357 | else if (*nip == PPC_INST_ISYNC) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 358 | --nip; |
Christophe Leroy | ddc6cd0 | 2016-05-17 14:01:39 +0200 | [diff] [blame] | 359 | if (*nip == PPC_INST_SYNC || (*nip >> 26) == OP_TRAP) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 360 | unsigned int rb; |
| 361 | |
| 362 | --nip; |
| 363 | rb = (*nip >> 11) & 0x1f; |
| 364 | printk(KERN_DEBUG "%s bad port %lx at %p\n", |
| 365 | (*nip & 0x100)? "OUT to": "IN from", |
| 366 | regs->gpr[rb] - _IO_BASE, nip); |
| 367 | regs->msr |= MSR_RI; |
| 368 | regs->nip = entry->fixup; |
| 369 | return 1; |
| 370 | } |
| 371 | } |
Benjamin Herrenschmidt | 68a6435 | 2006-11-13 09:27:39 +1100 | [diff] [blame] | 372 | #endif /* CONFIG_PPC32 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 376 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 377 | /* On 4xx, the reason for the machine check or program exception |
| 378 | is in the ESR. */ |
| 379 | #define get_reason(regs) ((regs)->dsisr) |
| 380 | #ifndef CONFIG_FSL_BOOKE |
| 381 | #define get_mc_reason(regs) ((regs)->dsisr) |
| 382 | #else |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 383 | #define get_mc_reason(regs) (mfspr(SPRN_MCSR)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 384 | #endif |
| 385 | #define REASON_FP ESR_FP |
| 386 | #define REASON_ILLEGAL (ESR_PIL | ESR_PUO) |
| 387 | #define REASON_PRIVILEGED ESR_PPR |
| 388 | #define REASON_TRAP ESR_PTR |
| 389 | |
| 390 | /* single-step stuff */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 391 | #define single_stepping(regs) (current->thread.debug.dbcr0 & DBCR0_IC) |
| 392 | #define clear_single_step(regs) (current->thread.debug.dbcr0 &= ~DBCR0_IC) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 393 | |
| 394 | #else |
| 395 | /* On non-4xx, the reason for the machine check or program |
| 396 | exception is in the MSR. */ |
| 397 | #define get_reason(regs) ((regs)->msr) |
| 398 | #define get_mc_reason(regs) ((regs)->msr) |
Michael Neuling | 8b3c34c | 2013-02-13 16:21:32 +0000 | [diff] [blame] | 399 | #define REASON_TM 0x200000 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 400 | #define REASON_FP 0x100000 |
| 401 | #define REASON_ILLEGAL 0x80000 |
| 402 | #define REASON_PRIVILEGED 0x40000 |
| 403 | #define REASON_TRAP 0x20000 |
| 404 | |
| 405 | #define single_stepping(regs) ((regs)->msr & MSR_SE) |
| 406 | #define clear_single_step(regs) ((regs)->msr &= ~MSR_SE) |
| 407 | #endif |
| 408 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 409 | #if defined(CONFIG_4xx) |
| 410 | int machine_check_4xx(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 411 | { |
Kumar Gala | 1a6a4ff | 2006-03-30 21:11:15 -0600 | [diff] [blame] | 412 | unsigned long reason = get_mc_reason(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 413 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 414 | if (reason & ESR_IMCP) { |
| 415 | printk("Instruction"); |
| 416 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 417 | } else |
| 418 | printk("Data"); |
| 419 | printk(" machine check in kernel mode.\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | int machine_check_440A(struct pt_regs *regs) |
| 425 | { |
| 426 | unsigned long reason = get_mc_reason(regs); |
| 427 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 428 | printk("Machine check in kernel mode.\n"); |
| 429 | if (reason & ESR_IMCP){ |
| 430 | printk("Instruction Synchronous Machine Check exception\n"); |
| 431 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 432 | } |
| 433 | else { |
| 434 | u32 mcsr = mfspr(SPRN_MCSR); |
| 435 | if (mcsr & MCSR_IB) |
| 436 | printk("Instruction Read PLB Error\n"); |
| 437 | if (mcsr & MCSR_DRB) |
| 438 | printk("Data Read PLB Error\n"); |
| 439 | if (mcsr & MCSR_DWB) |
| 440 | printk("Data Write PLB Error\n"); |
| 441 | if (mcsr & MCSR_TLBP) |
| 442 | printk("TLB Parity Error\n"); |
| 443 | if (mcsr & MCSR_ICP){ |
| 444 | flush_instruction_cache(); |
| 445 | printk("I-Cache Parity Error\n"); |
| 446 | } |
| 447 | if (mcsr & MCSR_DCSP) |
| 448 | printk("D-Cache Search Parity Error\n"); |
| 449 | if (mcsr & MCSR_DCFP) |
| 450 | printk("D-Cache Flush Parity Error\n"); |
| 451 | if (mcsr & MCSR_IMPE) |
| 452 | printk("Machine Check exception is imprecise\n"); |
| 453 | |
| 454 | /* Clear MCSR */ |
| 455 | mtspr(SPRN_MCSR, mcsr); |
| 456 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 457 | return 0; |
| 458 | } |
Dave Kleikamp | fc5e709 | 2010-03-05 03:43:18 +0000 | [diff] [blame] | 459 | |
| 460 | int machine_check_47x(struct pt_regs *regs) |
| 461 | { |
| 462 | unsigned long reason = get_mc_reason(regs); |
| 463 | u32 mcsr; |
| 464 | |
| 465 | printk(KERN_ERR "Machine check in kernel mode.\n"); |
| 466 | if (reason & ESR_IMCP) { |
| 467 | printk(KERN_ERR |
| 468 | "Instruction Synchronous Machine Check exception\n"); |
| 469 | mtspr(SPRN_ESR, reason & ~ESR_IMCP); |
| 470 | return 0; |
| 471 | } |
| 472 | mcsr = mfspr(SPRN_MCSR); |
| 473 | if (mcsr & MCSR_IB) |
| 474 | printk(KERN_ERR "Instruction Read PLB Error\n"); |
| 475 | if (mcsr & MCSR_DRB) |
| 476 | printk(KERN_ERR "Data Read PLB Error\n"); |
| 477 | if (mcsr & MCSR_DWB) |
| 478 | printk(KERN_ERR "Data Write PLB Error\n"); |
| 479 | if (mcsr & MCSR_TLBP) |
| 480 | printk(KERN_ERR "TLB Parity Error\n"); |
| 481 | if (mcsr & MCSR_ICP) { |
| 482 | flush_instruction_cache(); |
| 483 | printk(KERN_ERR "I-Cache Parity Error\n"); |
| 484 | } |
| 485 | if (mcsr & MCSR_DCSP) |
| 486 | printk(KERN_ERR "D-Cache Search Parity Error\n"); |
| 487 | if (mcsr & PPC47x_MCSR_GPR) |
| 488 | printk(KERN_ERR "GPR Parity Error\n"); |
| 489 | if (mcsr & PPC47x_MCSR_FPR) |
| 490 | printk(KERN_ERR "FPR Parity Error\n"); |
| 491 | if (mcsr & PPC47x_MCSR_IPR) |
| 492 | printk(KERN_ERR "Machine Check exception is imprecise\n"); |
| 493 | |
| 494 | /* Clear MCSR */ |
| 495 | mtspr(SPRN_MCSR, mcsr); |
| 496 | |
| 497 | return 0; |
| 498 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 499 | #elif defined(CONFIG_E500) |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 500 | int machine_check_e500mc(struct pt_regs *regs) |
| 501 | { |
| 502 | unsigned long mcsr = mfspr(SPRN_MCSR); |
| 503 | unsigned long reason = mcsr; |
| 504 | int recoverable = 1; |
| 505 | |
Scott Wood | 82a9a48 | 2011-06-16 14:09:17 -0500 | [diff] [blame] | 506 | if (reason & MCSR_LD) { |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 507 | recoverable = fsl_rio_mcheck_exception(regs); |
| 508 | if (recoverable == 1) |
| 509 | goto silent_out; |
| 510 | } |
| 511 | |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 512 | printk("Machine check in kernel mode.\n"); |
| 513 | printk("Caused by (from MCSR=%lx): ", reason); |
| 514 | |
| 515 | if (reason & MCSR_MCP) |
| 516 | printk("Machine Check Signal\n"); |
| 517 | |
| 518 | if (reason & MCSR_ICPERR) { |
| 519 | printk("Instruction Cache Parity Error\n"); |
| 520 | |
| 521 | /* |
| 522 | * This is recoverable by invalidating the i-cache. |
| 523 | */ |
| 524 | mtspr(SPRN_L1CSR1, mfspr(SPRN_L1CSR1) | L1CSR1_ICFI); |
| 525 | while (mfspr(SPRN_L1CSR1) & L1CSR1_ICFI) |
| 526 | ; |
| 527 | |
| 528 | /* |
| 529 | * This will generally be accompanied by an instruction |
| 530 | * fetch error report -- only treat MCSR_IF as fatal |
| 531 | * if it wasn't due to an L1 parity error. |
| 532 | */ |
| 533 | reason &= ~MCSR_IF; |
| 534 | } |
| 535 | |
| 536 | if (reason & MCSR_DCPERR_MC) { |
| 537 | printk("Data Cache Parity Error\n"); |
Kumar Gala | 37caf9f | 2011-08-27 06:14:23 -0500 | [diff] [blame] | 538 | |
| 539 | /* |
| 540 | * In write shadow mode we auto-recover from the error, but it |
| 541 | * may still get logged and cause a machine check. We should |
| 542 | * only treat the non-write shadow case as non-recoverable. |
| 543 | */ |
| 544 | if (!(mfspr(SPRN_L1CSR2) & L1CSR2_DCWS)) |
| 545 | recoverable = 0; |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | if (reason & MCSR_L2MMU_MHIT) { |
| 549 | printk("Hit on multiple TLB entries\n"); |
| 550 | recoverable = 0; |
| 551 | } |
| 552 | |
| 553 | if (reason & MCSR_NMI) |
| 554 | printk("Non-maskable interrupt\n"); |
| 555 | |
| 556 | if (reason & MCSR_IF) { |
| 557 | printk("Instruction Fetch Error Report\n"); |
| 558 | recoverable = 0; |
| 559 | } |
| 560 | |
| 561 | if (reason & MCSR_LD) { |
| 562 | printk("Load Error Report\n"); |
| 563 | recoverable = 0; |
| 564 | } |
| 565 | |
| 566 | if (reason & MCSR_ST) { |
| 567 | printk("Store Error Report\n"); |
| 568 | recoverable = 0; |
| 569 | } |
| 570 | |
| 571 | if (reason & MCSR_LDG) { |
| 572 | printk("Guarded Load Error Report\n"); |
| 573 | recoverable = 0; |
| 574 | } |
| 575 | |
| 576 | if (reason & MCSR_TLBSYNC) |
| 577 | printk("Simultaneous tlbsync operations\n"); |
| 578 | |
| 579 | if (reason & MCSR_BSL2_ERR) { |
| 580 | printk("Level 2 Cache Error\n"); |
| 581 | recoverable = 0; |
| 582 | } |
| 583 | |
| 584 | if (reason & MCSR_MAV) { |
| 585 | u64 addr; |
| 586 | |
| 587 | addr = mfspr(SPRN_MCAR); |
| 588 | addr |= (u64)mfspr(SPRN_MCARU) << 32; |
| 589 | |
| 590 | printk("Machine Check %s Address: %#llx\n", |
| 591 | reason & MCSR_MEA ? "Effective" : "Physical", addr); |
| 592 | } |
| 593 | |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 594 | silent_out: |
Scott Wood | fe04b11 | 2010-04-08 00:38:22 -0500 | [diff] [blame] | 595 | mtspr(SPRN_MCSR, mcsr); |
| 596 | return mfspr(SPRN_MCSR) == 0 && recoverable; |
| 597 | } |
| 598 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 599 | int machine_check_e500(struct pt_regs *regs) |
| 600 | { |
| 601 | unsigned long reason = get_mc_reason(regs); |
| 602 | |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 603 | if (reason & MCSR_BUS_RBERR) { |
| 604 | if (fsl_rio_mcheck_exception(regs)) |
| 605 | return 1; |
Hongtao Jia | 4e0e343 | 2013-04-28 13:20:08 +0800 | [diff] [blame] | 606 | if (fsl_pci_mcheck_exception(regs)) |
| 607 | return 1; |
Shaohui Xie | cce1f10 | 2010-11-18 14:57:32 +0800 | [diff] [blame] | 608 | } |
| 609 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 610 | printk("Machine check in kernel mode.\n"); |
| 611 | printk("Caused by (from MCSR=%lx): ", reason); |
| 612 | |
| 613 | if (reason & MCSR_MCP) |
| 614 | printk("Machine Check Signal\n"); |
| 615 | if (reason & MCSR_ICPERR) |
| 616 | printk("Instruction Cache Parity Error\n"); |
| 617 | if (reason & MCSR_DCP_PERR) |
| 618 | printk("Data Cache Push Parity Error\n"); |
| 619 | if (reason & MCSR_DCPERR) |
| 620 | printk("Data Cache Parity Error\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 621 | if (reason & MCSR_BUS_IAERR) |
| 622 | printk("Bus - Instruction Address Error\n"); |
| 623 | if (reason & MCSR_BUS_RAERR) |
| 624 | printk("Bus - Read Address Error\n"); |
| 625 | if (reason & MCSR_BUS_WAERR) |
| 626 | printk("Bus - Write Address Error\n"); |
| 627 | if (reason & MCSR_BUS_IBERR) |
| 628 | printk("Bus - Instruction Data Error\n"); |
| 629 | if (reason & MCSR_BUS_RBERR) |
| 630 | printk("Bus - Read Data Bus Error\n"); |
| 631 | if (reason & MCSR_BUS_WBERR) |
Wladislav Wiebe | c152833 | 2014-06-17 15:30:53 +0200 | [diff] [blame] | 632 | printk("Bus - Write Data Bus Error\n"); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 633 | if (reason & MCSR_BUS_IPERR) |
| 634 | printk("Bus - Instruction Parity Error\n"); |
| 635 | if (reason & MCSR_BUS_RPERR) |
| 636 | printk("Bus - Read Parity Error\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 637 | |
| 638 | return 0; |
| 639 | } |
Kumar Gala | 4490c06 | 2010-10-08 08:32:11 -0500 | [diff] [blame] | 640 | |
| 641 | int machine_check_generic(struct pt_regs *regs) |
| 642 | { |
| 643 | return 0; |
| 644 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 645 | #elif defined(CONFIG_E200) |
| 646 | int machine_check_e200(struct pt_regs *regs) |
| 647 | { |
| 648 | unsigned long reason = get_mc_reason(regs); |
| 649 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 650 | printk("Machine check in kernel mode.\n"); |
| 651 | printk("Caused by (from MCSR=%lx): ", reason); |
| 652 | |
| 653 | if (reason & MCSR_MCP) |
| 654 | printk("Machine Check Signal\n"); |
| 655 | if (reason & MCSR_CP_PERR) |
| 656 | printk("Cache Push Parity Error\n"); |
| 657 | if (reason & MCSR_CPERR) |
| 658 | printk("Cache Parity Error\n"); |
| 659 | if (reason & MCSR_EXCP_ERR) |
| 660 | printk("ISI, ITLB, or Bus Error on first instruction fetch for an exception handler\n"); |
| 661 | if (reason & MCSR_BUS_IRERR) |
| 662 | printk("Bus - Read Bus Error on instruction fetch\n"); |
| 663 | if (reason & MCSR_BUS_DRERR) |
| 664 | printk("Bus - Read Bus Error on data load\n"); |
| 665 | if (reason & MCSR_BUS_WRERR) |
| 666 | printk("Bus - Write Bus Error on buffered store or cache line push\n"); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | #else |
| 671 | int machine_check_generic(struct pt_regs *regs) |
| 672 | { |
| 673 | unsigned long reason = get_mc_reason(regs); |
| 674 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 675 | printk("Machine check in kernel mode.\n"); |
| 676 | printk("Caused by (from SRR1=%lx): ", reason); |
| 677 | switch (reason & 0x601F0000) { |
| 678 | case 0x80000: |
| 679 | printk("Machine check signal\n"); |
| 680 | break; |
| 681 | case 0: /* for 601 */ |
| 682 | case 0x40000: |
| 683 | case 0x140000: /* 7450 MSS error and TEA */ |
| 684 | printk("Transfer error ack signal\n"); |
| 685 | break; |
| 686 | case 0x20000: |
| 687 | printk("Data parity error signal\n"); |
| 688 | break; |
| 689 | case 0x10000: |
| 690 | printk("Address parity error signal\n"); |
| 691 | break; |
| 692 | case 0x20000000: |
| 693 | printk("L1 Data Cache error\n"); |
| 694 | break; |
| 695 | case 0x40000000: |
| 696 | printk("L1 Instruction Cache error\n"); |
| 697 | break; |
| 698 | case 0x00100000: |
| 699 | printk("L2 data cache parity error\n"); |
| 700 | break; |
| 701 | default: |
| 702 | printk("Unknown values in msr\n"); |
| 703 | } |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 704 | return 0; |
| 705 | } |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 706 | #endif /* everything else */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 707 | |
| 708 | void machine_check_exception(struct pt_regs *regs) |
| 709 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 710 | enum ctx_state prev_state = exception_enter(); |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 711 | int recover = 0; |
| 712 | |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 713 | __this_cpu_inc(irq_stat.mce_exceptions); |
Anton Blanchard | 89713ed | 2010-01-31 20:34:06 +0000 | [diff] [blame] | 714 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 715 | /* See if any machine dependent calls. In theory, we would want |
| 716 | * to call the CPU first, and call the ppc_md. one if the CPU |
| 717 | * one returns a positive number. However there is existing code |
| 718 | * that assumes the board gets a first chance, so let's keep it |
| 719 | * that way for now and fix things later. --BenH. |
| 720 | */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 721 | if (ppc_md.machine_check_exception) |
| 722 | recover = ppc_md.machine_check_exception(regs); |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 723 | else if (cur_cpu_spec->machine_check) |
| 724 | recover = cur_cpu_spec->machine_check(regs); |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 725 | |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 726 | if (recover > 0) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 727 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 728 | |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 729 | #if defined(CONFIG_8xx) && defined(CONFIG_PCI) |
Benjamin Herrenschmidt | 47c0bd1 | 2007-12-21 15:39:21 +1100 | [diff] [blame] | 730 | /* the qspan pci read routines can cause machine checks -- Cort |
| 731 | * |
| 732 | * yuck !!! that totally needs to go away ! There are better ways |
| 733 | * to deal with that than having a wart in the mcheck handler. |
| 734 | * -- BenH |
| 735 | */ |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 736 | bad_page_fault(regs, regs->dar, SIGBUS); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 737 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 738 | #endif |
| 739 | |
Anton Blanchard | a443506 | 2011-01-11 19:45:31 +0000 | [diff] [blame] | 740 | if (debugger_fault_handler(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 741 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 742 | |
| 743 | if (check_io_access(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 744 | goto bail; |
Olof Johansson | 75918a4 | 2007-09-21 05:11:20 +1000 | [diff] [blame] | 745 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 746 | die("Machine check", regs, SIGBUS); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 747 | |
| 748 | /* Must die if the interrupt is not recoverable */ |
| 749 | if (!(regs->msr & MSR_RI)) |
| 750 | panic("Unrecoverable Machine check"); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 751 | |
| 752 | bail: |
| 753 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | void SMIException(struct pt_regs *regs) |
| 757 | { |
| 758 | die("System Management Interrupt", regs, SIGABRT); |
| 759 | } |
| 760 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 761 | void handle_hmi_exception(struct pt_regs *regs) |
| 762 | { |
| 763 | struct pt_regs *old_regs; |
| 764 | |
| 765 | old_regs = set_irq_regs(regs); |
| 766 | irq_enter(); |
| 767 | |
| 768 | if (ppc_md.handle_hmi_exception) |
| 769 | ppc_md.handle_hmi_exception(regs); |
| 770 | |
| 771 | irq_exit(); |
| 772 | set_irq_regs(old_regs); |
| 773 | } |
| 774 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 775 | void unknown_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 776 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 777 | enum ctx_state prev_state = exception_enter(); |
| 778 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 779 | printk("Bad trap at PC: %lx, SR: %lx, vector=%lx\n", |
| 780 | regs->nip, regs->msr, regs->trap); |
| 781 | |
| 782 | _exception(SIGTRAP, regs, 0, 0); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 783 | |
| 784 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 785 | } |
| 786 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 787 | void instruction_breakpoint_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 788 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 789 | enum ctx_state prev_state = exception_enter(); |
| 790 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 791 | if (notify_die(DIE_IABR_MATCH, "iabr_match", regs, 5, |
| 792 | 5, SIGTRAP) == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 793 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 794 | if (debugger_iabr_match(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 795 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 796 | _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 797 | |
| 798 | bail: |
| 799 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void RunModeException(struct pt_regs *regs) |
| 803 | { |
| 804 | _exception(SIGTRAP, regs, 0, 0); |
| 805 | } |
| 806 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 807 | void single_step_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 808 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 809 | enum ctx_state prev_state = exception_enter(); |
| 810 | |
K.Prasad | 2538c2d | 2010-06-15 11:35:31 +0530 | [diff] [blame] | 811 | clear_single_step(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 812 | |
| 813 | if (notify_die(DIE_SSTEP, "single_step", regs, 5, |
| 814 | 5, SIGTRAP) == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 815 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 816 | if (debugger_sstep(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 817 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 818 | |
| 819 | _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 820 | |
| 821 | bail: |
| 822 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 823 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 824 | NOKPROBE_SYMBOL(single_step_exception); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 825 | |
| 826 | /* |
| 827 | * After we have successfully emulated an instruction, we have to |
| 828 | * check if the instruction was being single-stepped, and if so, |
| 829 | * pretend we got a single-step exception. This was pointed out |
| 830 | * by Kumar Gala. -- paulus |
| 831 | */ |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 832 | static void emulate_single_step(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 833 | { |
K.Prasad | 2538c2d | 2010-06-15 11:35:31 +0530 | [diff] [blame] | 834 | if (single_stepping(regs)) |
| 835 | single_step_exception(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 836 | } |
| 837 | |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 838 | static inline int __parse_fpscr(unsigned long fpscr) |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 839 | { |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 840 | int ret = 0; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 841 | |
| 842 | /* Invalid operation */ |
| 843 | if ((fpscr & FPSCR_VE) && (fpscr & FPSCR_VX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 844 | ret = FPE_FLTINV; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 845 | |
| 846 | /* Overflow */ |
| 847 | else if ((fpscr & FPSCR_OE) && (fpscr & FPSCR_OX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 848 | ret = FPE_FLTOVF; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 849 | |
| 850 | /* Underflow */ |
| 851 | else if ((fpscr & FPSCR_UE) && (fpscr & FPSCR_UX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 852 | ret = FPE_FLTUND; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 853 | |
| 854 | /* Divide by zero */ |
| 855 | else if ((fpscr & FPSCR_ZE) && (fpscr & FPSCR_ZX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 856 | ret = FPE_FLTDIV; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 857 | |
| 858 | /* Inexact result */ |
| 859 | else if ((fpscr & FPSCR_XE) && (fpscr & FPSCR_XX)) |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 860 | ret = FPE_FLTRES; |
| 861 | |
| 862 | return ret; |
| 863 | } |
| 864 | |
| 865 | static void parse_fpe(struct pt_regs *regs) |
| 866 | { |
| 867 | int code = 0; |
| 868 | |
| 869 | flush_fp_to_thread(current); |
| 870 | |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 871 | code = __parse_fpscr(current->thread.fp_state.fpscr); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 872 | |
| 873 | _exception(SIGFPE, regs, code, regs->nip); |
| 874 | } |
| 875 | |
| 876 | /* |
| 877 | * Illegal instruction emulation support. Originally written to |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 878 | * provide the PVR to user applications using the mfspr rd, PVR. |
| 879 | * Return non-zero if we can't emulate, or -EFAULT if the associated |
| 880 | * memory access caused an access fault. Return zero on success. |
| 881 | * |
| 882 | * There are a couple of ways to do this, either "decode" the instruction |
| 883 | * or directly match lots of bits. In this case, matching lots of |
| 884 | * bits is faster and easier. |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 885 | * |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 886 | */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 887 | static int emulate_string_inst(struct pt_regs *regs, u32 instword) |
| 888 | { |
| 889 | u8 rT = (instword >> 21) & 0x1f; |
| 890 | u8 rA = (instword >> 16) & 0x1f; |
| 891 | u8 NB_RB = (instword >> 11) & 0x1f; |
| 892 | u32 num_bytes; |
| 893 | unsigned long EA; |
| 894 | int pos = 0; |
| 895 | |
| 896 | /* Early out if we are an invalid form of lswx */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 897 | if ((instword & PPC_INST_STRING_MASK) == PPC_INST_LSWX) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 898 | if ((rT == rA) || (rT == NB_RB)) |
| 899 | return -EINVAL; |
| 900 | |
| 901 | EA = (rA == 0) ? 0 : regs->gpr[rA]; |
| 902 | |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 903 | switch (instword & PPC_INST_STRING_MASK) { |
| 904 | case PPC_INST_LSWX: |
| 905 | case PPC_INST_STSWX: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 906 | EA += NB_RB; |
| 907 | num_bytes = regs->xer & 0x7f; |
| 908 | break; |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 909 | case PPC_INST_LSWI: |
| 910 | case PPC_INST_STSWI: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 911 | num_bytes = (NB_RB == 0) ? 32 : NB_RB; |
| 912 | break; |
| 913 | default: |
| 914 | return -EINVAL; |
| 915 | } |
| 916 | |
| 917 | while (num_bytes != 0) |
| 918 | { |
| 919 | u8 val; |
| 920 | u32 shift = 8 * (3 - (pos & 0x3)); |
| 921 | |
James Yang | 80aa0fb | 2013-06-25 11:41:05 -0500 | [diff] [blame] | 922 | /* if process is 32-bit, clear upper 32 bits of EA */ |
| 923 | if ((regs->msr & MSR_64BIT) == 0) |
| 924 | EA &= 0xFFFFFFFF; |
| 925 | |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 926 | switch ((instword & PPC_INST_STRING_MASK)) { |
| 927 | case PPC_INST_LSWX: |
| 928 | case PPC_INST_LSWI: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 929 | if (get_user(val, (u8 __user *)EA)) |
| 930 | return -EFAULT; |
| 931 | /* first time updating this reg, |
| 932 | * zero it out */ |
| 933 | if (pos == 0) |
| 934 | regs->gpr[rT] = 0; |
| 935 | regs->gpr[rT] |= val << shift; |
| 936 | break; |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 937 | case PPC_INST_STSWI: |
| 938 | case PPC_INST_STSWX: |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 939 | val = regs->gpr[rT] >> shift; |
| 940 | if (put_user(val, (u8 __user *)EA)) |
| 941 | return -EFAULT; |
| 942 | break; |
| 943 | } |
| 944 | /* move EA to next address */ |
| 945 | EA += 1; |
| 946 | num_bytes--; |
| 947 | |
| 948 | /* manage our position within the register */ |
| 949 | if (++pos == 4) { |
| 950 | pos = 0; |
| 951 | if (++rT == 32) |
| 952 | rT = 0; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 959 | static int emulate_popcntb_inst(struct pt_regs *regs, u32 instword) |
| 960 | { |
| 961 | u32 ra,rs; |
| 962 | unsigned long tmp; |
| 963 | |
| 964 | ra = (instword >> 16) & 0x1f; |
| 965 | rs = (instword >> 21) & 0x1f; |
| 966 | |
| 967 | tmp = regs->gpr[rs]; |
| 968 | tmp = tmp - ((tmp >> 1) & 0x5555555555555555ULL); |
| 969 | tmp = (tmp & 0x3333333333333333ULL) + ((tmp >> 2) & 0x3333333333333333ULL); |
| 970 | tmp = (tmp + (tmp >> 4)) & 0x0f0f0f0f0f0f0f0fULL; |
| 971 | regs->gpr[ra] = tmp; |
| 972 | |
| 973 | return 0; |
| 974 | } |
| 975 | |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 976 | static int emulate_isel(struct pt_regs *regs, u32 instword) |
| 977 | { |
| 978 | u8 rT = (instword >> 21) & 0x1f; |
| 979 | u8 rA = (instword >> 16) & 0x1f; |
| 980 | u8 rB = (instword >> 11) & 0x1f; |
| 981 | u8 BC = (instword >> 6) & 0x1f; |
| 982 | u8 bit; |
| 983 | unsigned long tmp; |
| 984 | |
| 985 | tmp = (rA == 0) ? 0 : regs->gpr[rA]; |
| 986 | bit = (regs->ccr >> (31 - BC)) & 0x1; |
| 987 | |
| 988 | regs->gpr[rT] = bit ? tmp : regs->gpr[rB]; |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 993 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 994 | static inline bool tm_abort_check(struct pt_regs *regs, int cause) |
| 995 | { |
| 996 | /* If we're emulating a load/store in an active transaction, we cannot |
| 997 | * emulate it as the kernel operates in transaction suspended context. |
| 998 | * We need to abort the transaction. This creates a persistent TM |
| 999 | * abort so tell the user what caused it with a new code. |
| 1000 | */ |
| 1001 | if (MSR_TM_TRANSACTIONAL(regs->msr)) { |
| 1002 | tm_enable(); |
| 1003 | tm_abort(cause); |
| 1004 | return true; |
| 1005 | } |
| 1006 | return false; |
| 1007 | } |
| 1008 | #else |
| 1009 | static inline bool tm_abort_check(struct pt_regs *regs, int reason) |
| 1010 | { |
| 1011 | return false; |
| 1012 | } |
| 1013 | #endif |
| 1014 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1015 | static int emulate_instruction(struct pt_regs *regs) |
| 1016 | { |
| 1017 | u32 instword; |
| 1018 | u32 rd; |
| 1019 | |
Anton Blanchard | 4288e34 | 2013-08-07 02:01:47 +1000 | [diff] [blame] | 1020 | if (!user_mode(regs)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1021 | return -EINVAL; |
| 1022 | CHECK_FULL_REGS(regs); |
| 1023 | |
| 1024 | if (get_user(instword, (u32 __user *)(regs->nip))) |
| 1025 | return -EFAULT; |
| 1026 | |
| 1027 | /* Emulate the mfspr rD, PVR. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1028 | if ((instword & PPC_INST_MFSPR_PVR_MASK) == PPC_INST_MFSPR_PVR) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1029 | PPC_WARN_EMULATED(mfpvr, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1030 | rd = (instword >> 21) & 0x1f; |
| 1031 | regs->gpr[rd] = mfspr(SPRN_PVR); |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | /* Emulating the dcba insn is just a no-op. */ |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1036 | if ((instword & PPC_INST_DCBA_MASK) == PPC_INST_DCBA) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1037 | PPC_WARN_EMULATED(dcba, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1038 | return 0; |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1039 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1040 | |
| 1041 | /* Emulate the mcrxr insn. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1042 | if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { |
Paul Mackerras | 8641778 | 2005-10-10 22:37:57 +1000 | [diff] [blame] | 1043 | int shift = (instword >> 21) & 0x1c; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1044 | unsigned long msk = 0xf0000000UL >> shift; |
| 1045 | |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1046 | PPC_WARN_EMULATED(mcrxr, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1047 | regs->ccr = (regs->ccr & ~msk) | ((regs->xer >> shift) & msk); |
| 1048 | regs->xer &= ~0xf0000000UL; |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | /* Emulate load/store string insn. */ |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1053 | if ((instword & PPC_INST_STRING_GEN_MASK) == PPC_INST_STRING) { |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 1054 | if (tm_abort_check(regs, |
| 1055 | TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) |
| 1056 | return -EINVAL; |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1057 | PPC_WARN_EMULATED(string, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1058 | return emulate_string_inst(regs, instword); |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1059 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1060 | |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 1061 | /* Emulate the popcntb (Population Count Bytes) instruction. */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1062 | if ((instword & PPC_INST_POPCNTB_MASK) == PPC_INST_POPCNTB) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1063 | PPC_WARN_EMULATED(popcntb, regs); |
Will Schmidt | c3412dc | 2006-08-30 13:11:38 -0500 | [diff] [blame] | 1064 | return emulate_popcntb_inst(regs, instword); |
| 1065 | } |
| 1066 | |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 1067 | /* Emulate isel (Integer Select) instruction */ |
Kumar Gala | 16c57b3 | 2009-02-10 20:10:44 +0000 | [diff] [blame] | 1068 | if ((instword & PPC_INST_ISEL_MASK) == PPC_INST_ISEL) { |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1069 | PPC_WARN_EMULATED(isel, regs); |
Kumar Gala | c1469f1 | 2007-11-19 21:35:29 -0600 | [diff] [blame] | 1070 | return emulate_isel(regs, instword); |
| 1071 | } |
| 1072 | |
James Yang | 9863c28 | 2013-07-03 16:26:47 -0500 | [diff] [blame] | 1073 | /* Emulate sync instruction variants */ |
| 1074 | if ((instword & PPC_INST_SYNC_MASK) == PPC_INST_SYNC) { |
| 1075 | PPC_WARN_EMULATED(sync, regs); |
| 1076 | asm volatile("sync"); |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1080 | #ifdef CONFIG_PPC64 |
| 1081 | /* Emulate the mfspr rD, DSCR. */ |
Anton Blanchard | 73d2fb7 | 2013-05-01 20:06:33 +0000 | [diff] [blame] | 1082 | if ((((instword & PPC_INST_MFSPR_DSCR_USER_MASK) == |
| 1083 | PPC_INST_MFSPR_DSCR_USER) || |
| 1084 | ((instword & PPC_INST_MFSPR_DSCR_MASK) == |
| 1085 | PPC_INST_MFSPR_DSCR)) && |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1086 | cpu_has_feature(CPU_FTR_DSCR)) { |
| 1087 | PPC_WARN_EMULATED(mfdscr, regs); |
| 1088 | rd = (instword >> 21) & 0x1f; |
| 1089 | regs->gpr[rd] = mfspr(SPRN_DSCR); |
| 1090 | return 0; |
| 1091 | } |
| 1092 | /* Emulate the mtspr DSCR, rD. */ |
Anton Blanchard | 73d2fb7 | 2013-05-01 20:06:33 +0000 | [diff] [blame] | 1093 | if ((((instword & PPC_INST_MTSPR_DSCR_USER_MASK) == |
| 1094 | PPC_INST_MTSPR_DSCR_USER) || |
| 1095 | ((instword & PPC_INST_MTSPR_DSCR_MASK) == |
| 1096 | PPC_INST_MTSPR_DSCR)) && |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1097 | cpu_has_feature(CPU_FTR_DSCR)) { |
| 1098 | PPC_WARN_EMULATED(mtdscr, regs); |
| 1099 | rd = (instword >> 21) & 0x1f; |
Anton Blanchard | 00ca0de | 2012-09-03 16:48:46 +0000 | [diff] [blame] | 1100 | current->thread.dscr = regs->gpr[rd]; |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1101 | current->thread.dscr_inherit = 1; |
Anton Blanchard | 00ca0de | 2012-09-03 16:48:46 +0000 | [diff] [blame] | 1102 | mtspr(SPRN_DSCR, current->thread.dscr); |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1103 | return 0; |
| 1104 | } |
| 1105 | #endif |
| 1106 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1107 | return -EINVAL; |
| 1108 | } |
| 1109 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1110 | int is_valid_bugaddr(unsigned long addr) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1111 | { |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1112 | return is_kernel_addr(addr); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1113 | } |
| 1114 | |
Kevin Hao | 3a3b5aa | 2013-07-14 16:40:07 +0800 | [diff] [blame] | 1115 | #ifdef CONFIG_MATH_EMULATION |
| 1116 | static int emulate_math(struct pt_regs *regs) |
| 1117 | { |
| 1118 | int ret; |
| 1119 | extern int do_mathemu(struct pt_regs *regs); |
| 1120 | |
| 1121 | ret = do_mathemu(regs); |
| 1122 | if (ret >= 0) |
| 1123 | PPC_WARN_EMULATED(math, regs); |
| 1124 | |
| 1125 | switch (ret) { |
| 1126 | case 0: |
| 1127 | emulate_single_step(regs); |
| 1128 | return 0; |
| 1129 | case 1: { |
| 1130 | int code = 0; |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 1131 | code = __parse_fpscr(current->thread.fp_state.fpscr); |
Kevin Hao | 3a3b5aa | 2013-07-14 16:40:07 +0800 | [diff] [blame] | 1132 | _exception(SIGFPE, regs, code, regs->nip); |
| 1133 | return 0; |
| 1134 | } |
| 1135 | case -EFAULT: |
| 1136 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | return -1; |
| 1141 | } |
| 1142 | #else |
| 1143 | static inline int emulate_math(struct pt_regs *regs) { return -1; } |
| 1144 | #endif |
| 1145 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1146 | void program_check_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1147 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1148 | enum ctx_state prev_state = exception_enter(); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1149 | unsigned int reason = get_reason(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1150 | |
Kim Phillips | aa42c69 | 2006-12-08 02:43:30 -0600 | [diff] [blame] | 1151 | /* We can now get here via a FP Unavailable exception if the core |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1152 | * has no FPU, in that case the reason flags will be 0 */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1153 | |
| 1154 | if (reason & REASON_FP) { |
| 1155 | /* IEEE FP exception */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1156 | parse_fpe(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1157 | goto bail; |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1158 | } |
| 1159 | if (reason & REASON_TRAP) { |
Balbir Singh | a4c3f90 | 2016-02-18 13:48:01 +1100 | [diff] [blame] | 1160 | unsigned long bugaddr; |
Jason Wessel | ba797b2 | 2010-05-20 21:04:25 -0500 | [diff] [blame] | 1161 | /* Debugger is first in line to stop recursive faults in |
| 1162 | * rcu_lock, notify_die, or atomic_notifier_call_chain */ |
| 1163 | if (debugger_bpt(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1164 | goto bail; |
Jason Wessel | ba797b2 | 2010-05-20 21:04:25 -0500 | [diff] [blame] | 1165 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1166 | /* trap exception */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1167 | if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) |
| 1168 | == NOTIFY_STOP) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1169 | goto bail; |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1170 | |
Balbir Singh | a4c3f90 | 2016-02-18 13:48:01 +1100 | [diff] [blame] | 1171 | bugaddr = regs->nip; |
| 1172 | /* |
| 1173 | * Fixup bugaddr for BUG_ON() in real mode |
| 1174 | */ |
| 1175 | if (!is_kernel_addr(bugaddr) && !(regs->msr & MSR_IR)) |
| 1176 | bugaddr += PAGE_OFFSET; |
| 1177 | |
Jeremy Fitzhardinge | 73c9cea | 2006-12-08 03:30:41 -0800 | [diff] [blame] | 1178 | if (!(regs->msr & MSR_PR) && /* not user-mode */ |
Balbir Singh | a4c3f90 | 2016-02-18 13:48:01 +1100 | [diff] [blame] | 1179 | report_bug(bugaddr, regs) == BUG_TRAP_TYPE_WARN) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1180 | regs->nip += 4; |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1181 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1182 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1183 | _exception(SIGTRAP, regs, TRAP_BRKPT, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1184 | goto bail; |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1185 | } |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1186 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1187 | if (reason & REASON_TM) { |
| 1188 | /* This is a TM "Bad Thing Exception" program check. |
| 1189 | * This occurs when: |
| 1190 | * - An rfid/hrfid/mtmsrd attempts to cause an illegal |
| 1191 | * transition in TM states. |
| 1192 | * - A trechkpt is attempted when transactional. |
| 1193 | * - A treclaim is attempted when non transactional. |
| 1194 | * - A tend is illegally attempted. |
| 1195 | * - writing a TM SPR when transactional. |
| 1196 | */ |
| 1197 | if (!user_mode(regs) && |
| 1198 | report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) { |
| 1199 | regs->nip += 4; |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1200 | goto bail; |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1201 | } |
| 1202 | /* If usermode caused this, it's done something illegal and |
| 1203 | * gets a SIGILL slap on the wrist. We call it an illegal |
| 1204 | * operand to distinguish from the instruction just being bad |
| 1205 | * (e.g. executing a 'tend' on a CPU without TM!); it's an |
| 1206 | * illegal /placement/ of a valid instruction. |
| 1207 | */ |
| 1208 | if (user_mode(regs)) { |
| 1209 | _exception(SIGILL, regs, ILL_ILLOPN, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1210 | goto bail; |
Michael Neuling | bc2a940 | 2013-02-13 16:21:40 +0000 | [diff] [blame] | 1211 | } else { |
| 1212 | printk(KERN_EMERG "Unexpected TM Bad Thing exception " |
| 1213 | "at %lx (msr 0x%x)\n", regs->nip, reason); |
| 1214 | die("Unrecoverable exception", regs, SIGABRT); |
| 1215 | } |
| 1216 | } |
| 1217 | #endif |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1218 | |
Michael Ellerman | b3f6a45 | 2013-08-15 15:22:19 +1000 | [diff] [blame] | 1219 | /* |
| 1220 | * If we took the program check in the kernel skip down to sending a |
| 1221 | * SIGILL. The subsequent cases all relate to emulating instructions |
| 1222 | * which we should only do for userspace. We also do not want to enable |
| 1223 | * interrupts for kernel faults because that might lead to further |
| 1224 | * faults, and loose the context of the original exception. |
| 1225 | */ |
| 1226 | if (!user_mode(regs)) |
| 1227 | goto sigill; |
| 1228 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 1229 | /* We restore the interrupt state now */ |
| 1230 | if (!arch_irq_disabled_regs(regs)) |
| 1231 | local_irq_enable(); |
Paul Mackerras | cd8a567 | 2006-03-03 17:11:40 +1100 | [diff] [blame] | 1232 | |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1233 | /* (reason & REASON_ILLEGAL) would be the obvious thing here, |
| 1234 | * but there seems to be a hardware bug on the 405GP (RevD) |
| 1235 | * that means ESR is sometimes set incorrectly - either to |
| 1236 | * ESR_DST (!?) or 0. In the process of chasing this with the |
| 1237 | * hardware people - not sure if it can happen on any illegal |
| 1238 | * instruction or only on FP instructions, whether there is a |
Benjamin Herrenschmidt | 4e63f8e | 2013-06-09 17:01:24 +1000 | [diff] [blame] | 1239 | * pattern to occurrences etc. -dgibson 31/Mar/2003 |
| 1240 | */ |
Kevin Hao | 3a3b5aa | 2013-07-14 16:40:07 +0800 | [diff] [blame] | 1241 | if (!emulate_math(regs)) |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1242 | goto bail; |
Kumar Gala | 04903a3 | 2007-02-07 01:13:32 -0600 | [diff] [blame] | 1243 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1244 | /* Try to emulate it if we should. */ |
| 1245 | if (reason & (REASON_ILLEGAL | REASON_PRIVILEGED)) { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1246 | switch (emulate_instruction(regs)) { |
| 1247 | case 0: |
| 1248 | regs->nip += 4; |
| 1249 | emulate_single_step(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1250 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1251 | case -EFAULT: |
| 1252 | _exception(SIGSEGV, regs, SEGV_MAPERR, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1253 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1254 | } |
| 1255 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1256 | |
Michael Ellerman | b3f6a45 | 2013-08-15 15:22:19 +1000 | [diff] [blame] | 1257 | sigill: |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1258 | if (reason & REASON_PRIVILEGED) |
| 1259 | _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); |
| 1260 | else |
| 1261 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1262 | |
| 1263 | bail: |
| 1264 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1265 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1266 | NOKPROBE_SYMBOL(program_check_exception); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1267 | |
Paul Mackerras | bf59390 | 2013-06-14 20:07:41 +1000 | [diff] [blame] | 1268 | /* |
| 1269 | * This occurs when running in hypervisor mode on POWER6 or later |
| 1270 | * and an illegal instruction is encountered. |
| 1271 | */ |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1272 | void emulation_assist_interrupt(struct pt_regs *regs) |
Paul Mackerras | bf59390 | 2013-06-14 20:07:41 +1000 | [diff] [blame] | 1273 | { |
| 1274 | regs->msr |= REASON_ILLEGAL; |
| 1275 | program_check_exception(regs); |
| 1276 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1277 | NOKPROBE_SYMBOL(emulation_assist_interrupt); |
Paul Mackerras | bf59390 | 2013-06-14 20:07:41 +1000 | [diff] [blame] | 1278 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1279 | void alignment_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1280 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1281 | enum ctx_state prev_state = exception_enter(); |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1282 | int sig, code, fixed = 0; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1283 | |
Benjamin Herrenschmidt | a3512b2 | 2012-05-08 13:38:50 +1000 | [diff] [blame] | 1284 | /* We restore the interrupt state now */ |
| 1285 | if (!arch_irq_disabled_regs(regs)) |
| 1286 | local_irq_enable(); |
| 1287 | |
Michael Neuling | 6ce6c62 | 2013-05-26 18:09:39 +0000 | [diff] [blame] | 1288 | if (tm_abort_check(regs, TM_CAUSE_ALIGNMENT | TM_CAUSE_PERSISTENT)) |
| 1289 | goto bail; |
| 1290 | |
Paul Mackerras | e9370ae | 2006-06-07 16:15:39 +1000 | [diff] [blame] | 1291 | /* we don't implement logging of alignment exceptions */ |
| 1292 | if (!(current->thread.align_ctl & PR_UNALIGN_SIGBUS)) |
| 1293 | fixed = fix_alignment(regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1294 | |
| 1295 | if (fixed == 1) { |
| 1296 | regs->nip += 4; /* skip over emulated instruction */ |
| 1297 | emulate_single_step(regs); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1298 | goto bail; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1299 | } |
| 1300 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1301 | /* Operand address was bad */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1302 | if (fixed == -EFAULT) { |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1303 | sig = SIGSEGV; |
| 1304 | code = SEGV_ACCERR; |
| 1305 | } else { |
| 1306 | sig = SIGBUS; |
| 1307 | code = BUS_ADRALN; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1308 | } |
Benjamin Herrenschmidt | 4393c4f | 2006-11-01 15:11:39 +1100 | [diff] [blame] | 1309 | if (user_mode(regs)) |
| 1310 | _exception(sig, regs, code, regs->dar); |
| 1311 | else |
| 1312 | bad_page_fault(regs, regs->dar, sig); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1313 | |
| 1314 | bail: |
| 1315 | exception_exit(prev_state); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1316 | } |
| 1317 | |
Paul Mackerras | f0f558b | 2016-09-02 21:49:21 +1000 | [diff] [blame] | 1318 | void slb_miss_bad_addr(struct pt_regs *regs) |
| 1319 | { |
| 1320 | enum ctx_state prev_state = exception_enter(); |
| 1321 | |
| 1322 | if (user_mode(regs)) |
| 1323 | _exception(SIGSEGV, regs, SEGV_BNDERR, regs->dar); |
| 1324 | else |
| 1325 | bad_page_fault(regs, regs->dar, SIGSEGV); |
| 1326 | |
| 1327 | exception_exit(prev_state); |
| 1328 | } |
| 1329 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1330 | void StackOverflow(struct pt_regs *regs) |
| 1331 | { |
| 1332 | printk(KERN_CRIT "Kernel stack overflow in process %p, r1=%lx\n", |
| 1333 | current, regs->gpr[1]); |
| 1334 | debugger(regs); |
| 1335 | show_regs(regs); |
| 1336 | panic("kernel stack overflow"); |
| 1337 | } |
| 1338 | |
| 1339 | void nonrecoverable_exception(struct pt_regs *regs) |
| 1340 | { |
| 1341 | printk(KERN_ERR "Non-recoverable exception at PC=%lx MSR=%lx\n", |
| 1342 | regs->nip, regs->msr); |
| 1343 | debugger(regs); |
| 1344 | die("nonrecoverable exception", regs, SIGKILL); |
| 1345 | } |
| 1346 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1347 | void kernel_fp_unavailable_exception(struct pt_regs *regs) |
| 1348 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1349 | enum ctx_state prev_state = exception_enter(); |
| 1350 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1351 | printk(KERN_EMERG "Unrecoverable FP Unavailable Exception " |
| 1352 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1353 | die("Unrecoverable FP Unavailable Exception", regs, SIGABRT); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1354 | |
| 1355 | exception_exit(prev_state); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1356 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1357 | |
| 1358 | void altivec_unavailable_exception(struct pt_regs *regs) |
| 1359 | { |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1360 | enum ctx_state prev_state = exception_enter(); |
| 1361 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1362 | if (user_mode(regs)) { |
| 1363 | /* A user program has executed an altivec instruction, |
| 1364 | but this kernel doesn't support altivec. */ |
| 1365 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1366 | goto bail; |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1367 | } |
Anton Blanchard | 6c4841c | 2006-10-13 11:41:00 +1000 | [diff] [blame] | 1368 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1369 | printk(KERN_EMERG "Unrecoverable VMX/Altivec Unavailable Exception " |
| 1370 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1371 | die("Unrecoverable VMX/Altivec Unavailable Exception", regs, SIGABRT); |
Li Zhong | ba12eed | 2013-05-13 16:16:41 +0000 | [diff] [blame] | 1372 | |
| 1373 | bail: |
| 1374 | exception_exit(prev_state); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1375 | } |
| 1376 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1377 | void vsx_unavailable_exception(struct pt_regs *regs) |
| 1378 | { |
| 1379 | if (user_mode(regs)) { |
| 1380 | /* A user program has executed an vsx instruction, |
| 1381 | but this kernel doesn't support vsx. */ |
| 1382 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | printk(KERN_EMERG "Unrecoverable VSX Unavailable Exception " |
| 1387 | "%lx at %lx\n", regs->trap, regs->nip); |
| 1388 | die("Unrecoverable VSX Unavailable Exception", regs, SIGABRT); |
| 1389 | } |
| 1390 | |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1391 | #ifdef CONFIG_PPC64 |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1392 | void facility_unavailable_exception(struct pt_regs *regs) |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1393 | { |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1394 | static char *facility_strings[] = { |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1395 | [FSCR_FP_LG] = "FPU", |
| 1396 | [FSCR_VECVSX_LG] = "VMX/VSX", |
| 1397 | [FSCR_DSCR_LG] = "DSCR", |
| 1398 | [FSCR_PM_LG] = "PMU SPRs", |
| 1399 | [FSCR_BHRB_LG] = "BHRB", |
| 1400 | [FSCR_TM_LG] = "TM", |
| 1401 | [FSCR_EBB_LG] = "EBB", |
| 1402 | [FSCR_TAR_LG] = "TAR", |
Jack Miller | bd3ea31 | 2016-06-09 12:31:09 +1000 | [diff] [blame] | 1403 | [FSCR_LM_LG] = "LM", |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1404 | }; |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1405 | char *facility = "unknown"; |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1406 | u64 value; |
Anshuman Khandual | c952c1c | 2015-05-21 12:13:01 +0530 | [diff] [blame] | 1407 | u32 instword, rd; |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1408 | u8 status; |
| 1409 | bool hv; |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1410 | |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1411 | hv = (regs->trap == 0xf80); |
| 1412 | if (hv) |
Michael Ellerman | b14b626 | 2013-06-25 17:47:57 +1000 | [diff] [blame] | 1413 | value = mfspr(SPRN_HFSCR); |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1414 | else |
| 1415 | value = mfspr(SPRN_FSCR); |
| 1416 | |
| 1417 | status = value >> 56; |
| 1418 | if (status == FSCR_DSCR_LG) { |
Anshuman Khandual | c952c1c | 2015-05-21 12:13:01 +0530 | [diff] [blame] | 1419 | /* |
| 1420 | * User is accessing the DSCR register using the problem |
| 1421 | * state only SPR number (0x03) either through a mfspr or |
| 1422 | * a mtspr instruction. If it is a write attempt through |
| 1423 | * a mtspr, then we set the inherit bit. This also allows |
| 1424 | * the user to write or read the register directly in the |
| 1425 | * future by setting via the FSCR DSCR bit. But in case it |
| 1426 | * is a read DSCR attempt through a mfspr instruction, we |
| 1427 | * just emulate the instruction instead. This code path will |
| 1428 | * always emulate all the mfspr instructions till the user |
Adam Buchbinder | 446957b | 2016-02-24 10:51:11 -0800 | [diff] [blame] | 1429 | * has attempted at least one mtspr instruction. This way it |
Anshuman Khandual | c952c1c | 2015-05-21 12:13:01 +0530 | [diff] [blame] | 1430 | * preserves the same behaviour when the user is accessing |
| 1431 | * the DSCR through privilege level only SPR number (0x11) |
| 1432 | * which is emulated through illegal instruction exception. |
| 1433 | * We always leave HFSCR DSCR set. |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1434 | */ |
Anshuman Khandual | c952c1c | 2015-05-21 12:13:01 +0530 | [diff] [blame] | 1435 | if (get_user(instword, (u32 __user *)(regs->nip))) { |
| 1436 | pr_err("Failed to fetch the user instruction\n"); |
| 1437 | return; |
| 1438 | } |
| 1439 | |
| 1440 | /* Write into DSCR (mtspr 0x03, RS) */ |
| 1441 | if ((instword & PPC_INST_MTSPR_DSCR_USER_MASK) |
| 1442 | == PPC_INST_MTSPR_DSCR_USER) { |
| 1443 | rd = (instword >> 21) & 0x1f; |
| 1444 | current->thread.dscr = regs->gpr[rd]; |
| 1445 | current->thread.dscr_inherit = 1; |
Michael Neuling | b57bd2d | 2016-06-09 12:31:08 +1000 | [diff] [blame] | 1446 | current->thread.fscr |= FSCR_DSCR; |
| 1447 | mtspr(SPRN_FSCR, current->thread.fscr); |
Anshuman Khandual | c952c1c | 2015-05-21 12:13:01 +0530 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /* Read from DSCR (mfspr RT, 0x03) */ |
| 1451 | if ((instword & PPC_INST_MFSPR_DSCR_USER_MASK) |
| 1452 | == PPC_INST_MFSPR_DSCR_USER) { |
| 1453 | if (emulate_instruction(regs)) { |
| 1454 | pr_err("DSCR based mfspr emulation failed\n"); |
| 1455 | return; |
| 1456 | } |
| 1457 | regs->nip += 4; |
| 1458 | emulate_single_step(regs); |
| 1459 | } |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1460 | return; |
Jack Miller | bd3ea31 | 2016-06-09 12:31:09 +1000 | [diff] [blame] | 1461 | } else if ((status == FSCR_LM_LG) && cpu_has_feature(CPU_FTR_ARCH_300)) { |
| 1462 | /* |
| 1463 | * This process has touched LM, so turn it on forever |
| 1464 | * for this process |
| 1465 | */ |
| 1466 | current->thread.fscr |= FSCR_LM; |
| 1467 | mtspr(SPRN_FSCR, current->thread.fscr); |
| 1468 | return; |
Michael Ellerman | b14b626 | 2013-06-25 17:47:57 +1000 | [diff] [blame] | 1469 | } |
| 1470 | |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1471 | if ((status < ARRAY_SIZE(facility_strings)) && |
| 1472 | facility_strings[status]) |
| 1473 | facility = facility_strings[status]; |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1474 | |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1475 | /* We restore the interrupt state now */ |
| 1476 | if (!arch_irq_disabled_regs(regs)) |
| 1477 | local_irq_enable(); |
| 1478 | |
Michael Neuling | ee4ed6f | 2014-03-14 17:03:58 +1100 | [diff] [blame] | 1479 | pr_err_ratelimited( |
| 1480 | "%sFacility '%s' unavailable, exception at 0x%lx, MSR=%lx\n", |
| 1481 | hv ? "Hypervisor " : "", facility, regs->nip, regs->msr); |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1482 | |
| 1483 | if (user_mode(regs)) { |
| 1484 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
| 1485 | return; |
| 1486 | } |
| 1487 | |
Michael Ellerman | 021424a | 2013-06-25 17:47:56 +1000 | [diff] [blame] | 1488 | die("Unexpected facility unavailable exception", regs, SIGABRT); |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1489 | } |
Michael Neuling | 2517617 | 2013-08-09 17:29:29 +1000 | [diff] [blame] | 1490 | #endif |
Michael Neuling | d0c0c9a | 2013-02-13 16:21:38 +0000 | [diff] [blame] | 1491 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1492 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1493 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1494 | void fp_unavailable_tm(struct pt_regs *regs) |
| 1495 | { |
| 1496 | /* Note: This does not handle any kind of FP laziness. */ |
| 1497 | |
| 1498 | TM_DEBUG("FP Unavailable trap whilst transactional at 0x%lx, MSR=%lx\n", |
| 1499 | regs->nip, regs->msr); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1500 | |
| 1501 | /* We can only have got here if the task started using FP after |
| 1502 | * beginning the transaction. So, the transactional regs are just a |
| 1503 | * copy of the checkpointed ones. But, we still need to recheckpoint |
| 1504 | * as we're enabling FP for the process; it will return, abort the |
| 1505 | * transaction, and probably retry but now with FP enabled. So the |
| 1506 | * checkpointed FP registers need to be loaded. |
| 1507 | */ |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 1508 | tm_reclaim_current(TM_CAUSE_FAC_UNAV); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1509 | /* Reclaim didn't save out any FPRs to transact_fprs. */ |
| 1510 | |
| 1511 | /* Enable FP for the task: */ |
| 1512 | regs->msr |= (MSR_FP | current->thread.fpexc_mode); |
| 1513 | |
| 1514 | /* This loads and recheckpoints the FP registers from |
| 1515 | * thread.fpr[]. They will remain in registers after the |
| 1516 | * checkpoint so we don't need to reload them after. |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1517 | * If VMX is in use, the VRs now hold checkpointed values, |
| 1518 | * so we don't want to load the VRs from the thread_struct. |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1519 | */ |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1520 | tm_recheckpoint(¤t->thread, MSR_FP); |
| 1521 | |
| 1522 | /* If VMX is in use, get the transactional values back */ |
| 1523 | if (regs->msr & MSR_VEC) { |
| 1524 | do_load_up_transact_altivec(¤t->thread); |
| 1525 | /* At this point all the VSX state is loaded, so enable it */ |
| 1526 | regs->msr |= MSR_VSX; |
| 1527 | } |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1530 | void altivec_unavailable_tm(struct pt_regs *regs) |
| 1531 | { |
| 1532 | /* See the comments in fp_unavailable_tm(). This function operates |
| 1533 | * the same way. |
| 1534 | */ |
| 1535 | |
| 1536 | TM_DEBUG("Vector Unavailable trap whilst transactional at 0x%lx," |
| 1537 | "MSR=%lx\n", |
| 1538 | regs->nip, regs->msr); |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 1539 | tm_reclaim_current(TM_CAUSE_FAC_UNAV); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1540 | regs->msr |= MSR_VEC; |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1541 | tm_recheckpoint(¤t->thread, MSR_VEC); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1542 | current->thread.used_vr = 1; |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1543 | |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1544 | if (regs->msr & MSR_FP) { |
| 1545 | do_load_up_transact_fpu(¤t->thread); |
| 1546 | regs->msr |= MSR_VSX; |
| 1547 | } |
| 1548 | } |
| 1549 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1550 | void vsx_unavailable_tm(struct pt_regs *regs) |
| 1551 | { |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1552 | unsigned long orig_msr = regs->msr; |
| 1553 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1554 | /* See the comments in fp_unavailable_tm(). This works similarly, |
| 1555 | * though we're loading both FP and VEC registers in here. |
| 1556 | * |
| 1557 | * If FP isn't in use, load FP regs. If VEC isn't in use, load VEC |
| 1558 | * regs. Either way, set MSR_VSX. |
| 1559 | */ |
| 1560 | |
| 1561 | TM_DEBUG("VSX Unavailable trap whilst transactional at 0x%lx," |
| 1562 | "MSR=%lx\n", |
| 1563 | regs->nip, regs->msr); |
| 1564 | |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1565 | current->thread.used_vsr = 1; |
| 1566 | |
| 1567 | /* If FP and VMX are already loaded, we have all the state we need */ |
| 1568 | if ((orig_msr & (MSR_FP | MSR_VEC)) == (MSR_FP | MSR_VEC)) { |
| 1569 | regs->msr |= MSR_VSX; |
| 1570 | return; |
| 1571 | } |
| 1572 | |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1573 | /* This reclaims FP and/or VR regs if they're already enabled */ |
Paul Mackerras | d31626f | 2014-01-13 15:56:29 +1100 | [diff] [blame] | 1574 | tm_reclaim_current(TM_CAUSE_FAC_UNAV); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1575 | |
| 1576 | regs->msr |= MSR_VEC | MSR_FP | current->thread.fpexc_mode | |
| 1577 | MSR_VSX; |
Paul Mackerras | 3ac8ff1 | 2014-01-13 15:56:30 +1100 | [diff] [blame] | 1578 | |
| 1579 | /* This loads & recheckpoints FP and VRs; but we have |
| 1580 | * to be sure not to overwrite previously-valid state. |
| 1581 | */ |
| 1582 | tm_recheckpoint(¤t->thread, regs->msr & ~orig_msr); |
| 1583 | |
| 1584 | if (orig_msr & MSR_FP) |
| 1585 | do_load_up_transact_fpu(¤t->thread); |
| 1586 | if (orig_msr & MSR_VEC) |
| 1587 | do_load_up_transact_altivec(¤t->thread); |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1588 | } |
Michael Neuling | f54db64 | 2013-02-13 16:21:39 +0000 | [diff] [blame] | 1589 | #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ |
| 1590 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1591 | void performance_monitor_exception(struct pt_regs *regs) |
| 1592 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 1593 | __this_cpu_inc(irq_stat.pmu_irqs); |
Anton Blanchard | 89713ed | 2010-01-31 20:34:06 +0000 | [diff] [blame] | 1594 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1595 | perf_irq(regs); |
| 1596 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1597 | |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1598 | #ifdef CONFIG_8xx |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1599 | void SoftwareEmulation(struct pt_regs *regs) |
| 1600 | { |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1601 | CHECK_FULL_REGS(regs); |
| 1602 | |
| 1603 | if (!user_mode(regs)) { |
| 1604 | debugger(regs); |
LEROY Christophe | 1eb2819 | 2013-08-28 16:19:17 +0200 | [diff] [blame] | 1605 | die("Kernel Mode Unimplemented Instruction or SW FPU Emulation", |
| 1606 | regs, SIGFPE); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1607 | } |
| 1608 | |
Kevin Hao | 3a3b5aa | 2013-07-14 16:40:07 +0800 | [diff] [blame] | 1609 | if (!emulate_math(regs)) |
| 1610 | return; |
Kumar Gala | 5fad293 | 2007-02-07 01:47:59 -0600 | [diff] [blame] | 1611 | |
Scott Wood | 5dd57a1 | 2007-09-18 15:29:35 -0500 | [diff] [blame] | 1612 | _exception(SIGILL, regs, ILL_ILLOPC, regs->nip); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1613 | } |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1614 | #endif /* CONFIG_8xx */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1615 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1616 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1617 | static void handle_debug(struct pt_regs *regs, unsigned long debug_status) |
| 1618 | { |
| 1619 | int changed = 0; |
| 1620 | /* |
| 1621 | * Determine the cause of the debug event, clear the |
| 1622 | * event flags and send a trap to the handler. Torez |
| 1623 | */ |
| 1624 | if (debug_status & (DBSR_DAC1R | DBSR_DAC1W)) { |
| 1625 | dbcr_dac(current) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
| 1626 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1627 | current->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1628 | #endif |
| 1629 | do_send_trap(regs, mfspr(SPRN_DAC1), debug_status, TRAP_HWBKPT, |
| 1630 | 5); |
| 1631 | changed |= 0x01; |
| 1632 | } else if (debug_status & (DBSR_DAC2R | DBSR_DAC2W)) { |
| 1633 | dbcr_dac(current) &= ~(DBCR_DAC2R | DBCR_DAC2W); |
| 1634 | do_send_trap(regs, mfspr(SPRN_DAC2), debug_status, TRAP_HWBKPT, |
| 1635 | 6); |
| 1636 | changed |= 0x01; |
| 1637 | } else if (debug_status & DBSR_IAC1) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1638 | current->thread.debug.dbcr0 &= ~DBCR0_IAC1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1639 | dbcr_iac_range(current) &= ~DBCR_IAC12MODE; |
| 1640 | do_send_trap(regs, mfspr(SPRN_IAC1), debug_status, TRAP_HWBKPT, |
| 1641 | 1); |
| 1642 | changed |= 0x01; |
| 1643 | } else if (debug_status & DBSR_IAC2) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1644 | current->thread.debug.dbcr0 &= ~DBCR0_IAC2; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1645 | do_send_trap(regs, mfspr(SPRN_IAC2), debug_status, TRAP_HWBKPT, |
| 1646 | 2); |
| 1647 | changed |= 0x01; |
| 1648 | } else if (debug_status & DBSR_IAC3) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1649 | current->thread.debug.dbcr0 &= ~DBCR0_IAC3; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1650 | dbcr_iac_range(current) &= ~DBCR_IAC34MODE; |
| 1651 | do_send_trap(regs, mfspr(SPRN_IAC3), debug_status, TRAP_HWBKPT, |
| 1652 | 3); |
| 1653 | changed |= 0x01; |
| 1654 | } else if (debug_status & DBSR_IAC4) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1655 | current->thread.debug.dbcr0 &= ~DBCR0_IAC4; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1656 | do_send_trap(regs, mfspr(SPRN_IAC4), debug_status, TRAP_HWBKPT, |
| 1657 | 4); |
| 1658 | changed |= 0x01; |
| 1659 | } |
| 1660 | /* |
| 1661 | * At the point this routine was called, the MSR(DE) was turned off. |
| 1662 | * Check all other debug flags and see if that bit needs to be turned |
| 1663 | * back on or not. |
| 1664 | */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1665 | if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, |
Bharat Bhushan | 9579198 | 2013-06-26 11:12:22 +0530 | [diff] [blame] | 1666 | current->thread.debug.dbcr1)) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1667 | regs->msr |= MSR_DE; |
| 1668 | else |
| 1669 | /* Make sure the IDM flag is off */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1670 | current->thread.debug.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1671 | |
| 1672 | if (changed & 0x01) |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1673 | mtspr(SPRN_DBCR0, current->thread.debug.dbcr0); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1674 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1675 | |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1676 | void DebugException(struct pt_regs *regs, unsigned long debug_status) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1677 | { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1678 | current->thread.debug.dbsr = debug_status; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1679 | |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 1680 | /* Hack alert: On BookE, Branch Taken stops on the branch itself, while |
| 1681 | * on server, it stops on the target of the branch. In order to simulate |
| 1682 | * the server behaviour, we thus restart right away with a single step |
| 1683 | * instead of stopping here when hitting a BT |
| 1684 | */ |
| 1685 | if (debug_status & DBSR_BT) { |
| 1686 | regs->msr &= ~MSR_DE; |
| 1687 | |
| 1688 | /* Disable BT */ |
| 1689 | mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_BT); |
| 1690 | /* Clear the BT event */ |
| 1691 | mtspr(SPRN_DBSR, DBSR_BT); |
| 1692 | |
| 1693 | /* Do the single step trick only when coming from userspace */ |
| 1694 | if (user_mode(regs)) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1695 | current->thread.debug.dbcr0 &= ~DBCR0_BT; |
| 1696 | current->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 1697 | regs->msr |= MSR_DE; |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | if (notify_die(DIE_SSTEP, "block_step", regs, 5, |
| 1702 | 5, SIGTRAP) == NOTIFY_STOP) { |
| 1703 | return; |
| 1704 | } |
| 1705 | if (debugger_sstep(regs)) |
| 1706 | return; |
| 1707 | } else if (debug_status & DBSR_IC) { /* Instruction complete */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1708 | regs->msr &= ~MSR_DE; |
Kumar Gala | f827962 | 2008-06-26 02:01:37 -0500 | [diff] [blame] | 1709 | |
| 1710 | /* Disable instruction completion */ |
| 1711 | mtspr(SPRN_DBCR0, mfspr(SPRN_DBCR0) & ~DBCR0_IC); |
| 1712 | /* Clear the instruction completion event */ |
| 1713 | mtspr(SPRN_DBSR, DBSR_IC); |
| 1714 | |
| 1715 | if (notify_die(DIE_SSTEP, "single_step", regs, 5, |
| 1716 | 5, SIGTRAP) == NOTIFY_STOP) { |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | if (debugger_sstep(regs)) |
| 1721 | return; |
| 1722 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1723 | if (user_mode(regs)) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1724 | current->thread.debug.dbcr0 &= ~DBCR0_IC; |
| 1725 | if (DBCR_ACTIVE_EVENTS(current->thread.debug.dbcr0, |
| 1726 | current->thread.debug.dbcr1)) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1727 | regs->msr |= MSR_DE; |
| 1728 | else |
| 1729 | /* Make sure the IDM bit is off */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1730 | current->thread.debug.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1731 | } |
Kumar Gala | f827962 | 2008-06-26 02:01:37 -0500 | [diff] [blame] | 1732 | |
| 1733 | _exception(SIGTRAP, regs, TRAP_TRACE, regs->nip); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1734 | } else |
| 1735 | handle_debug(regs, debug_status); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1736 | } |
Nicholas Piggin | 03465f8 | 2016-09-16 20:48:08 +1000 | [diff] [blame] | 1737 | NOKPROBE_SYMBOL(DebugException); |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1738 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1739 | |
| 1740 | #if !defined(CONFIG_TAU_INT) |
| 1741 | void TAUException(struct pt_regs *regs) |
| 1742 | { |
| 1743 | printk("TAU trap at PC: %lx, MSR: %lx, vector=%lx %s\n", |
| 1744 | regs->nip, regs->msr, regs->trap, print_tainted()); |
| 1745 | } |
| 1746 | #endif /* CONFIG_INT_TAU */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1747 | |
| 1748 | #ifdef CONFIG_ALTIVEC |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1749 | void altivec_assist_exception(struct pt_regs *regs) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1750 | { |
| 1751 | int err; |
| 1752 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1753 | if (!user_mode(regs)) { |
| 1754 | printk(KERN_EMERG "VMX/Altivec assist exception in kernel mode" |
| 1755 | " at %lx\n", regs->nip); |
Paul Mackerras | 8dad3f9 | 2005-10-06 13:27:05 +1000 | [diff] [blame] | 1756 | die("Kernel VMX/Altivec assist exception", regs, SIGILL); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1757 | } |
| 1758 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1759 | flush_altivec_to_thread(current); |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1760 | |
Anton Blanchard | eecff81 | 2009-10-27 18:46:55 +0000 | [diff] [blame] | 1761 | PPC_WARN_EMULATED(altivec, regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1762 | err = emulate_altivec(regs); |
| 1763 | if (err == 0) { |
| 1764 | regs->nip += 4; /* skip emulated instruction */ |
| 1765 | emulate_single_step(regs); |
| 1766 | return; |
| 1767 | } |
| 1768 | |
| 1769 | if (err == -EFAULT) { |
| 1770 | /* got an error reading the instruction */ |
| 1771 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1772 | } else { |
| 1773 | /* didn't recognize the instruction */ |
| 1774 | /* XXX quick hack for now: set the non-Java bit in the VSCR */ |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 1775 | printk_ratelimited(KERN_ERR "Unrecognized altivec instruction " |
| 1776 | "in %s at %lx\n", current->comm, regs->nip); |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 1777 | current->thread.vr_state.vscr.u[3] |= 0x10000; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | #endif /* CONFIG_ALTIVEC */ |
| 1781 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1782 | #ifdef CONFIG_FSL_BOOKE |
| 1783 | void CacheLockingException(struct pt_regs *regs, unsigned long address, |
| 1784 | unsigned long error_code) |
| 1785 | { |
| 1786 | /* We treat cache locking instructions from the user |
| 1787 | * as priv ops, in the future we could try to do |
| 1788 | * something smarter |
| 1789 | */ |
| 1790 | if (error_code & (ESR_DLK|ESR_ILK)) |
| 1791 | _exception(SIGILL, regs, ILL_PRVOPC, regs->nip); |
| 1792 | return; |
| 1793 | } |
| 1794 | #endif /* CONFIG_FSL_BOOKE */ |
| 1795 | |
| 1796 | #ifdef CONFIG_SPE |
| 1797 | void SPEFloatingPointException(struct pt_regs *regs) |
| 1798 | { |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1799 | extern int do_spe_mathemu(struct pt_regs *regs); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1800 | unsigned long spefscr; |
| 1801 | int fpexc_mode; |
| 1802 | int code = 0; |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1803 | int err; |
| 1804 | |
yu liu | 685659e | 2011-06-14 18:34:25 -0500 | [diff] [blame] | 1805 | flush_spe_to_thread(current); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1806 | |
| 1807 | spefscr = current->thread.spefscr; |
| 1808 | fpexc_mode = current->thread.fpexc_mode; |
| 1809 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1810 | if ((spefscr & SPEFSCR_FOVF) && (fpexc_mode & PR_FP_EXC_OVF)) { |
| 1811 | code = FPE_FLTOVF; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1812 | } |
| 1813 | else if ((spefscr & SPEFSCR_FUNF) && (fpexc_mode & PR_FP_EXC_UND)) { |
| 1814 | code = FPE_FLTUND; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1815 | } |
| 1816 | else if ((spefscr & SPEFSCR_FDBZ) && (fpexc_mode & PR_FP_EXC_DIV)) |
| 1817 | code = FPE_FLTDIV; |
| 1818 | else if ((spefscr & SPEFSCR_FINV) && (fpexc_mode & PR_FP_EXC_INV)) { |
| 1819 | code = FPE_FLTINV; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1820 | } |
| 1821 | else if ((spefscr & (SPEFSCR_FG | SPEFSCR_FX)) && (fpexc_mode & PR_FP_EXC_RES)) |
| 1822 | code = FPE_FLTRES; |
| 1823 | |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1824 | err = do_spe_mathemu(regs); |
| 1825 | if (err == 0) { |
| 1826 | regs->nip += 4; /* skip emulated instruction */ |
| 1827 | emulate_single_step(regs); |
| 1828 | return; |
| 1829 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1830 | |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1831 | if (err == -EFAULT) { |
| 1832 | /* got an error reading the instruction */ |
| 1833 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1834 | } else if (err == -EINVAL) { |
| 1835 | /* didn't recognize the instruction */ |
| 1836 | printk(KERN_ERR "unrecognized spe instruction " |
| 1837 | "in %s at %lx\n", current->comm, regs->nip); |
| 1838 | } else { |
| 1839 | _exception(SIGFPE, regs, code, regs->nip); |
| 1840 | } |
| 1841 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1842 | return; |
| 1843 | } |
Liu Yu | 6a800f3 | 2008-10-28 11:50:21 +0800 | [diff] [blame] | 1844 | |
| 1845 | void SPEFloatingPointRoundException(struct pt_regs *regs) |
| 1846 | { |
| 1847 | extern int speround_handler(struct pt_regs *regs); |
| 1848 | int err; |
| 1849 | |
| 1850 | preempt_disable(); |
| 1851 | if (regs->msr & MSR_SPE) |
| 1852 | giveup_spe(current); |
| 1853 | preempt_enable(); |
| 1854 | |
| 1855 | regs->nip -= 4; |
| 1856 | err = speround_handler(regs); |
| 1857 | if (err == 0) { |
| 1858 | regs->nip += 4; /* skip emulated instruction */ |
| 1859 | emulate_single_step(regs); |
| 1860 | return; |
| 1861 | } |
| 1862 | |
| 1863 | if (err == -EFAULT) { |
| 1864 | /* got an error reading the instruction */ |
| 1865 | _exception(SIGSEGV, regs, SEGV_ACCERR, regs->nip); |
| 1866 | } else if (err == -EINVAL) { |
| 1867 | /* didn't recognize the instruction */ |
| 1868 | printk(KERN_ERR "unrecognized spe instruction " |
| 1869 | "in %s at %lx\n", current->comm, regs->nip); |
| 1870 | } else { |
| 1871 | _exception(SIGFPE, regs, 0, regs->nip); |
| 1872 | return; |
| 1873 | } |
| 1874 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1875 | #endif |
| 1876 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1877 | /* |
| 1878 | * We enter here if we get an unrecoverable exception, that is, one |
| 1879 | * that happened at a point where the RI (recoverable interrupt) bit |
| 1880 | * in the MSR is 0. This indicates that SRR0/1 are live, and that |
| 1881 | * we therefore lost state by taking this exception. |
| 1882 | */ |
| 1883 | void unrecoverable_exception(struct pt_regs *regs) |
| 1884 | { |
| 1885 | printk(KERN_EMERG "Unrecoverable exception %lx at %lx\n", |
| 1886 | regs->trap, regs->nip); |
| 1887 | die("Unrecoverable exception", regs, SIGABRT); |
| 1888 | } |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1889 | |
Jason Gunthorpe | 1e18c17 | 2012-10-05 08:07:15 +0000 | [diff] [blame] | 1890 | #if defined(CONFIG_BOOKE_WDT) || defined(CONFIG_40x) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1891 | /* |
| 1892 | * Default handler for a Watchdog exception, |
| 1893 | * spins until a reboot occurs |
| 1894 | */ |
| 1895 | void __attribute__ ((weak)) WatchdogHandler(struct pt_regs *regs) |
| 1896 | { |
| 1897 | /* Generic WatchdogHandler, implement your own */ |
| 1898 | mtspr(SPRN_TCR, mfspr(SPRN_TCR)&(~TCR_WIE)); |
| 1899 | return; |
| 1900 | } |
| 1901 | |
| 1902 | void WatchdogException(struct pt_regs *regs) |
| 1903 | { |
| 1904 | printk (KERN_EMERG "PowerPC Book-E Watchdog Exception\n"); |
| 1905 | WatchdogHandler(regs); |
| 1906 | } |
| 1907 | #endif |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1908 | |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 1909 | /* |
| 1910 | * We enter here if we discover during exception entry that we are |
| 1911 | * running in supervisor mode with a userspace value in the stack pointer. |
| 1912 | */ |
| 1913 | void kernel_bad_stack(struct pt_regs *regs) |
| 1914 | { |
| 1915 | printk(KERN_EMERG "Bad kernel stack pointer %lx at %lx\n", |
| 1916 | regs->gpr[1], regs->nip); |
| 1917 | die("Bad kernel stack pointer", regs, SIGABRT); |
| 1918 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1919 | |
| 1920 | void __init trap_init(void) |
| 1921 | { |
| 1922 | } |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1923 | |
| 1924 | |
| 1925 | #ifdef CONFIG_PPC_EMULATED_STATS |
| 1926 | |
| 1927 | #define WARN_EMULATED_SETUP(type) .type = { .name = #type } |
| 1928 | |
| 1929 | struct ppc_emulated ppc_emulated = { |
| 1930 | #ifdef CONFIG_ALTIVEC |
| 1931 | WARN_EMULATED_SETUP(altivec), |
| 1932 | #endif |
| 1933 | WARN_EMULATED_SETUP(dcba), |
| 1934 | WARN_EMULATED_SETUP(dcbz), |
| 1935 | WARN_EMULATED_SETUP(fp_pair), |
| 1936 | WARN_EMULATED_SETUP(isel), |
| 1937 | WARN_EMULATED_SETUP(mcrxr), |
| 1938 | WARN_EMULATED_SETUP(mfpvr), |
| 1939 | WARN_EMULATED_SETUP(multiple), |
| 1940 | WARN_EMULATED_SETUP(popcntb), |
| 1941 | WARN_EMULATED_SETUP(spe), |
| 1942 | WARN_EMULATED_SETUP(string), |
Scott Wood | a3821b2 | 2013-10-28 22:07:59 -0500 | [diff] [blame] | 1943 | WARN_EMULATED_SETUP(sync), |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1944 | WARN_EMULATED_SETUP(unaligned), |
| 1945 | #ifdef CONFIG_MATH_EMULATION |
| 1946 | WARN_EMULATED_SETUP(math), |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1947 | #endif |
| 1948 | #ifdef CONFIG_VSX |
| 1949 | WARN_EMULATED_SETUP(vsx), |
| 1950 | #endif |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1951 | #ifdef CONFIG_PPC64 |
| 1952 | WARN_EMULATED_SETUP(mfdscr), |
| 1953 | WARN_EMULATED_SETUP(mtdscr), |
Anton Blanchard | f83319d | 2014-03-28 17:01:23 +1100 | [diff] [blame] | 1954 | WARN_EMULATED_SETUP(lq_stq), |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 1955 | #endif |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1956 | }; |
| 1957 | |
| 1958 | u32 ppc_warn_emulated; |
| 1959 | |
| 1960 | void ppc_warn_emulated_print(const char *type) |
| 1961 | { |
Christian Dietrich | 7646223 | 2011-06-04 05:36:54 +0000 | [diff] [blame] | 1962 | pr_warn_ratelimited("%s used emulated %s instruction\n", current->comm, |
| 1963 | type); |
Geert Uytterhoeven | 80947e7 | 2009-05-18 02:10:05 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | static int __init ppc_warn_emulated_init(void) |
| 1967 | { |
| 1968 | struct dentry *dir, *d; |
| 1969 | unsigned int i; |
| 1970 | struct ppc_emulated_entry *entries = (void *)&ppc_emulated; |
| 1971 | |
| 1972 | if (!powerpc_debugfs_root) |
| 1973 | return -ENODEV; |
| 1974 | |
| 1975 | dir = debugfs_create_dir("emulated_instructions", |
| 1976 | powerpc_debugfs_root); |
| 1977 | if (!dir) |
| 1978 | return -ENOMEM; |
| 1979 | |
| 1980 | d = debugfs_create_u32("do_warn", S_IRUGO | S_IWUSR, dir, |
| 1981 | &ppc_warn_emulated); |
| 1982 | if (!d) |
| 1983 | goto fail; |
| 1984 | |
| 1985 | for (i = 0; i < sizeof(ppc_emulated)/sizeof(*entries); i++) { |
| 1986 | d = debugfs_create_u32(entries[i].name, S_IRUGO | S_IWUSR, dir, |
| 1987 | (u32 *)&entries[i].val.counter); |
| 1988 | if (!d) |
| 1989 | goto fail; |
| 1990 | } |
| 1991 | |
| 1992 | return 0; |
| 1993 | |
| 1994 | fail: |
| 1995 | debugfs_remove_recursive(dir); |
| 1996 | return -ENOMEM; |
| 1997 | } |
| 1998 | |
| 1999 | device_initcall(ppc_warn_emulated_init); |
| 2000 | |
| 2001 | #endif /* CONFIG_PPC_EMULATED_STATS */ |