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