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