Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * PowerPC version |
| 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * |
| 5 | * Derived from "arch/m68k/kernel/ptrace.c" |
| 6 | * Copyright (C) 1994 by Hamish Macdonald |
| 7 | * Taken from linux/kernel/ptrace.c and modified for M680x0. |
| 8 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds |
| 9 | * |
| 10 | * Modified by Cort Dougan (cort@hq.fsmlabs.com) |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 11 | * and Paul Mackerras (paulus@samba.org). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 13 | * This file is subject to the terms and conditions of the GNU General |
| 14 | * Public License. See the file README.legal in the main directory of |
| 15 | * this archive for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/errno.h> |
| 23 | #include <linux/ptrace.h> |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 24 | #include <linux/regset.h> |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 25 | #include <linux/tracehook.h> |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 26 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/user.h> |
| 28 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 29 | #include <linux/signal.h> |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 30 | #include <linux/seccomp.h> |
| 31 | #include <linux/audit.h> |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 32 | #include <trace/syscall.h> |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 33 | #include <linux/hw_breakpoint.h> |
| 34 | #include <linux/perf_event.h> |
Li Zhong | 22ecbe8 | 2013-05-13 16:16:40 +0000 | [diff] [blame] | 35 | #include <linux/context_tracking.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/uaccess.h> |
| 38 | #include <asm/page.h> |
| 39 | #include <asm/pgtable.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 40 | #include <asm/switch_to.h> |
Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 41 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 42 | #define CREATE_TRACE_POINTS |
| 43 | #include <trace/events/syscalls.h> |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
Mahesh Salgaonkar | 359e428 | 2010-04-07 18:10:20 +1000 | [diff] [blame] | 46 | * The parameter save area on the stack is used to store arguments being passed |
| 47 | * to callee function and is located at fixed offset from stack pointer. |
| 48 | */ |
| 49 | #ifdef CONFIG_PPC32 |
| 50 | #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */ |
| 51 | #else /* CONFIG_PPC32 */ |
| 52 | #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */ |
| 53 | #endif |
| 54 | |
| 55 | struct pt_regs_offset { |
| 56 | const char *name; |
| 57 | int offset; |
| 58 | }; |
| 59 | |
| 60 | #define STR(s) #s /* convert to string */ |
| 61 | #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)} |
| 62 | #define GPR_OFFSET_NAME(num) \ |
Rashmica Gupta | 343c332 | 2015-11-21 17:08:16 +1100 | [diff] [blame] | 63 | {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \ |
Mahesh Salgaonkar | 359e428 | 2010-04-07 18:10:20 +1000 | [diff] [blame] | 64 | {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])} |
| 65 | #define REG_OFFSET_END {.name = NULL, .offset = 0} |
| 66 | |
| 67 | static const struct pt_regs_offset regoffset_table[] = { |
| 68 | GPR_OFFSET_NAME(0), |
| 69 | GPR_OFFSET_NAME(1), |
| 70 | GPR_OFFSET_NAME(2), |
| 71 | GPR_OFFSET_NAME(3), |
| 72 | GPR_OFFSET_NAME(4), |
| 73 | GPR_OFFSET_NAME(5), |
| 74 | GPR_OFFSET_NAME(6), |
| 75 | GPR_OFFSET_NAME(7), |
| 76 | GPR_OFFSET_NAME(8), |
| 77 | GPR_OFFSET_NAME(9), |
| 78 | GPR_OFFSET_NAME(10), |
| 79 | GPR_OFFSET_NAME(11), |
| 80 | GPR_OFFSET_NAME(12), |
| 81 | GPR_OFFSET_NAME(13), |
| 82 | GPR_OFFSET_NAME(14), |
| 83 | GPR_OFFSET_NAME(15), |
| 84 | GPR_OFFSET_NAME(16), |
| 85 | GPR_OFFSET_NAME(17), |
| 86 | GPR_OFFSET_NAME(18), |
| 87 | GPR_OFFSET_NAME(19), |
| 88 | GPR_OFFSET_NAME(20), |
| 89 | GPR_OFFSET_NAME(21), |
| 90 | GPR_OFFSET_NAME(22), |
| 91 | GPR_OFFSET_NAME(23), |
| 92 | GPR_OFFSET_NAME(24), |
| 93 | GPR_OFFSET_NAME(25), |
| 94 | GPR_OFFSET_NAME(26), |
| 95 | GPR_OFFSET_NAME(27), |
| 96 | GPR_OFFSET_NAME(28), |
| 97 | GPR_OFFSET_NAME(29), |
| 98 | GPR_OFFSET_NAME(30), |
| 99 | GPR_OFFSET_NAME(31), |
| 100 | REG_OFFSET_NAME(nip), |
| 101 | REG_OFFSET_NAME(msr), |
| 102 | REG_OFFSET_NAME(ctr), |
| 103 | REG_OFFSET_NAME(link), |
| 104 | REG_OFFSET_NAME(xer), |
| 105 | REG_OFFSET_NAME(ccr), |
| 106 | #ifdef CONFIG_PPC64 |
| 107 | REG_OFFSET_NAME(softe), |
| 108 | #else |
| 109 | REG_OFFSET_NAME(mq), |
| 110 | #endif |
| 111 | REG_OFFSET_NAME(trap), |
| 112 | REG_OFFSET_NAME(dar), |
| 113 | REG_OFFSET_NAME(dsisr), |
| 114 | REG_OFFSET_END, |
| 115 | }; |
| 116 | |
| 117 | /** |
| 118 | * regs_query_register_offset() - query register offset from its name |
| 119 | * @name: the name of a register |
| 120 | * |
| 121 | * regs_query_register_offset() returns the offset of a register in struct |
| 122 | * pt_regs from its name. If the name is invalid, this returns -EINVAL; |
| 123 | */ |
| 124 | int regs_query_register_offset(const char *name) |
| 125 | { |
| 126 | const struct pt_regs_offset *roff; |
| 127 | for (roff = regoffset_table; roff->name != NULL; roff++) |
| 128 | if (!strcmp(roff->name, name)) |
| 129 | return roff->offset; |
| 130 | return -EINVAL; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * regs_query_register_name() - query register name from its offset |
| 135 | * @offset: the offset of a register in struct pt_regs. |
| 136 | * |
| 137 | * regs_query_register_name() returns the name of a register from its |
| 138 | * offset in struct pt_regs. If the @offset is invalid, this returns NULL; |
| 139 | */ |
| 140 | const char *regs_query_register_name(unsigned int offset) |
| 141 | { |
| 142 | const struct pt_regs_offset *roff; |
| 143 | for (roff = regoffset_table; roff->name != NULL; roff++) |
| 144 | if (roff->offset == offset) |
| 145 | return roff->name; |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * does not yet catch signals sent when the child dies. |
| 151 | * in exit.c or in signal.c. |
| 152 | */ |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | /* |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 155 | * Set of msr bits that gdb can change on behalf of a process. |
| 156 | */ |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 157 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 158 | #define MSR_DEBUGCHANGE 0 |
| 159 | #else |
| 160 | #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE) |
| 161 | #endif |
| 162 | |
| 163 | /* |
| 164 | * Max register writeable via put_reg |
| 165 | */ |
| 166 | #ifdef CONFIG_PPC32 |
| 167 | #define PT_MAX_PUT_REG PT_MQ |
| 168 | #else |
| 169 | #define PT_MAX_PUT_REG PT_CCR |
| 170 | #endif |
| 171 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 172 | static unsigned long get_user_msr(struct task_struct *task) |
| 173 | { |
| 174 | return task->thread.regs->msr | task->thread.fpexc_mode; |
| 175 | } |
| 176 | |
| 177 | static int set_user_msr(struct task_struct *task, unsigned long msr) |
| 178 | { |
| 179 | task->thread.regs->msr &= ~MSR_DEBUGCHANGE; |
| 180 | task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; |
| 181 | return 0; |
| 182 | } |
| 183 | |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 184 | #ifdef CONFIG_PPC64 |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 185 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 186 | { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 187 | *data = task->thread.dscr; |
| 188 | return 0; |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) |
| 192 | { |
| 193 | task->thread.dscr = dscr; |
| 194 | task->thread.dscr_inherit = 1; |
| 195 | return 0; |
| 196 | } |
| 197 | #else |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 198 | static int get_user_dscr(struct task_struct *task, unsigned long *data) |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 199 | { |
| 200 | return -EIO; |
| 201 | } |
| 202 | |
| 203 | static int set_user_dscr(struct task_struct *task, unsigned long dscr) |
| 204 | { |
| 205 | return -EIO; |
| 206 | } |
| 207 | #endif |
| 208 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 209 | /* |
| 210 | * We prevent mucking around with the reserved area of trap |
| 211 | * which are used internally by the kernel. |
| 212 | */ |
| 213 | static int set_user_trap(struct task_struct *task, unsigned long trap) |
| 214 | { |
| 215 | task->thread.regs->trap = trap & 0xfff0; |
| 216 | return 0; |
| 217 | } |
| 218 | |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 219 | /* |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 220 | * Get contents of register REGNO in task TASK. |
| 221 | */ |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 222 | int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 223 | { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 224 | if ((task->thread.regs == NULL) || !data) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 225 | return -EIO; |
| 226 | |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 227 | if (regno == PT_MSR) { |
| 228 | *data = get_user_msr(task); |
| 229 | return 0; |
| 230 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 231 | |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 232 | if (regno == PT_DSCR) |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 233 | return get_user_dscr(task, data); |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 234 | |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 235 | if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { |
| 236 | *data = ((unsigned long *)task->thread.regs)[regno]; |
| 237 | return 0; |
| 238 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 239 | |
| 240 | return -EIO; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Write contents of register REGNO in task TASK. |
| 245 | */ |
| 246 | int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) |
| 247 | { |
| 248 | if (task->thread.regs == NULL) |
| 249 | return -EIO; |
| 250 | |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 251 | if (regno == PT_MSR) |
| 252 | return set_user_msr(task, data); |
| 253 | if (regno == PT_TRAP) |
| 254 | return set_user_trap(task, data); |
Alexey Kardashevskiy | 1715a82 | 2013-01-10 20:29:09 +0000 | [diff] [blame] | 255 | if (regno == PT_DSCR) |
| 256 | return set_user_dscr(task, data); |
Roland McGrath | 26f7713 | 2007-12-20 03:57:51 -0800 | [diff] [blame] | 257 | |
| 258 | if (regno <= PT_MAX_PUT_REG) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 259 | ((unsigned long *)task->thread.regs)[regno] = data; |
| 260 | return 0; |
| 261 | } |
| 262 | return -EIO; |
| 263 | } |
| 264 | |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 265 | static int gpr_get(struct task_struct *target, const struct user_regset *regset, |
| 266 | unsigned int pos, unsigned int count, |
| 267 | void *kbuf, void __user *ubuf) |
| 268 | { |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 269 | int i, ret; |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 270 | |
| 271 | if (target->thread.regs == NULL) |
| 272 | return -EIO; |
| 273 | |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 274 | if (!FULL_REGS(target->thread.regs)) { |
| 275 | /* We have a partial register set. Fill 14-31 with bogus values */ |
| 276 | for (i = 14; i < 32; i++) |
| 277 | target->thread.regs->gpr[i] = NV_REG_POISON; |
| 278 | } |
Roland McGrath | 44dd3f5 | 2007-12-20 03:57:55 -0800 | [diff] [blame] | 279 | |
| 280 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 281 | target->thread.regs, |
| 282 | 0, offsetof(struct pt_regs, msr)); |
| 283 | if (!ret) { |
| 284 | unsigned long msr = get_user_msr(target); |
| 285 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr, |
| 286 | offsetof(struct pt_regs, msr), |
| 287 | offsetof(struct pt_regs, msr) + |
| 288 | sizeof(msr)); |
| 289 | } |
| 290 | |
| 291 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != |
| 292 | offsetof(struct pt_regs, msr) + sizeof(long)); |
| 293 | |
| 294 | if (!ret) |
| 295 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 296 | &target->thread.regs->orig_gpr3, |
| 297 | offsetof(struct pt_regs, orig_gpr3), |
| 298 | sizeof(struct pt_regs)); |
| 299 | if (!ret) |
| 300 | ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 301 | sizeof(struct pt_regs), -1); |
| 302 | |
| 303 | return ret; |
| 304 | } |
| 305 | |
| 306 | static int gpr_set(struct task_struct *target, const struct user_regset *regset, |
| 307 | unsigned int pos, unsigned int count, |
| 308 | const void *kbuf, const void __user *ubuf) |
| 309 | { |
| 310 | unsigned long reg; |
| 311 | int ret; |
| 312 | |
| 313 | if (target->thread.regs == NULL) |
| 314 | return -EIO; |
| 315 | |
| 316 | CHECK_FULL_REGS(target->thread.regs); |
| 317 | |
| 318 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 319 | target->thread.regs, |
| 320 | 0, PT_MSR * sizeof(reg)); |
| 321 | |
| 322 | if (!ret && count > 0) { |
| 323 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, |
| 324 | PT_MSR * sizeof(reg), |
| 325 | (PT_MSR + 1) * sizeof(reg)); |
| 326 | if (!ret) |
| 327 | ret = set_user_msr(target, reg); |
| 328 | } |
| 329 | |
| 330 | BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) != |
| 331 | offsetof(struct pt_regs, msr) + sizeof(long)); |
| 332 | |
| 333 | if (!ret) |
| 334 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 335 | &target->thread.regs->orig_gpr3, |
| 336 | PT_ORIG_R3 * sizeof(reg), |
| 337 | (PT_MAX_PUT_REG + 1) * sizeof(reg)); |
| 338 | |
| 339 | if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret) |
| 340 | ret = user_regset_copyin_ignore( |
| 341 | &pos, &count, &kbuf, &ubuf, |
| 342 | (PT_MAX_PUT_REG + 1) * sizeof(reg), |
| 343 | PT_TRAP * sizeof(reg)); |
| 344 | |
| 345 | if (!ret && count > 0) { |
| 346 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®, |
| 347 | PT_TRAP * sizeof(reg), |
| 348 | (PT_TRAP + 1) * sizeof(reg)); |
| 349 | if (!ret) |
| 350 | ret = set_user_trap(target, reg); |
| 351 | } |
| 352 | |
| 353 | if (!ret) |
| 354 | ret = user_regset_copyin_ignore( |
| 355 | &pos, &count, &kbuf, &ubuf, |
| 356 | (PT_TRAP + 1) * sizeof(reg), -1); |
| 357 | |
| 358 | return ret; |
| 359 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 360 | |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 361 | /* |
| 362 | * When the transaction is active, 'transact_fp' holds the current running |
| 363 | * value of all FPR registers and 'fp_state' holds the last checkpointed |
| 364 | * value of all FPR registers for the current transaction. When transaction |
| 365 | * is not active 'fp_state' holds the current running state of all the FPR |
| 366 | * registers. So this function which returns the current running values of |
| 367 | * all the FPR registers, needs to know whether any transaction is active |
| 368 | * or not. |
| 369 | * |
| 370 | * Userspace interface buffer layout: |
| 371 | * |
| 372 | * struct data { |
| 373 | * u64 fpr[32]; |
| 374 | * u64 fpscr; |
| 375 | * }; |
| 376 | * |
| 377 | * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM |
| 378 | * which determines the final code in this function. All the combinations of |
| 379 | * these two config options are possible except the one below as transactional |
| 380 | * memory config pulls in CONFIG_VSX automatically. |
| 381 | * |
| 382 | * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
| 383 | */ |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 384 | static int fpr_get(struct task_struct *target, const struct user_regset *regset, |
| 385 | unsigned int pos, unsigned int count, |
| 386 | void *kbuf, void __user *ubuf) |
| 387 | { |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 388 | #ifdef CONFIG_VSX |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 389 | u64 buf[33]; |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 390 | int i; |
| 391 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 392 | flush_fp_to_thread(target); |
| 393 | |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 394 | #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
| 395 | /* copy to local buffer then write that out */ |
| 396 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { |
| 397 | flush_altivec_to_thread(target); |
| 398 | flush_tmregs_to_thread(target); |
| 399 | for (i = 0; i < 32 ; i++) |
| 400 | buf[i] = target->thread.TS_TRANS_FPR(i); |
| 401 | buf[32] = target->thread.transact_fp.fpscr; |
| 402 | } else { |
| 403 | for (i = 0; i < 32 ; i++) |
| 404 | buf[i] = target->thread.TS_FPR(i); |
| 405 | buf[32] = target->thread.fp_state.fpscr; |
| 406 | } |
| 407 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
| 408 | #endif |
| 409 | |
| 410 | #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 411 | /* copy to local buffer then write that out */ |
| 412 | for (i = 0; i < 32 ; i++) |
| 413 | buf[i] = target->thread.TS_FPR(i); |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 414 | buf[32] = target->thread.fp_state.fpscr; |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 415 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 416 | #endif |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 417 | |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 418 | #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 419 | BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != |
Khem Raj | 1e407ee | 2016-04-25 09:19:17 -0700 | [diff] [blame] | 420 | offsetof(struct thread_fp_state, fpr[32])); |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 421 | |
| 422 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 423 | &target->thread.fp_state, 0, -1); |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 424 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 427 | /* |
| 428 | * When the transaction is active, 'transact_fp' holds the current running |
| 429 | * value of all FPR registers and 'fp_state' holds the last checkpointed |
| 430 | * value of all FPR registers for the current transaction. When transaction |
| 431 | * is not active 'fp_state' holds the current running state of all the FPR |
| 432 | * registers. So this function which setss the current running values of |
| 433 | * all the FPR registers, needs to know whether any transaction is active |
| 434 | * or not. |
| 435 | * |
| 436 | * Userspace interface buffer layout: |
| 437 | * |
| 438 | * struct data { |
| 439 | * u64 fpr[32]; |
| 440 | * u64 fpscr; |
| 441 | * }; |
| 442 | * |
| 443 | * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM |
| 444 | * which determines the final code in this function. All the combinations of |
| 445 | * these two config options are possible except the one below as transactional |
| 446 | * memory config pulls in CONFIG_VSX automatically. |
| 447 | * |
| 448 | * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
| 449 | */ |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 450 | static int fpr_set(struct task_struct *target, const struct user_regset *regset, |
| 451 | unsigned int pos, unsigned int count, |
| 452 | const void *kbuf, const void __user *ubuf) |
| 453 | { |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 454 | #ifdef CONFIG_VSX |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 455 | u64 buf[33]; |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 456 | int i; |
| 457 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 458 | flush_fp_to_thread(target); |
| 459 | |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 460 | #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
| 461 | /* copy to local buffer then write that out */ |
| 462 | i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
| 463 | if (i) |
| 464 | return i; |
| 465 | |
| 466 | if (MSR_TM_ACTIVE(target->thread.regs->msr)) { |
| 467 | flush_altivec_to_thread(target); |
| 468 | flush_tmregs_to_thread(target); |
| 469 | for (i = 0; i < 32 ; i++) |
| 470 | target->thread.TS_TRANS_FPR(i) = buf[i]; |
| 471 | target->thread.transact_fp.fpscr = buf[32]; |
| 472 | } else { |
| 473 | for (i = 0; i < 32 ; i++) |
| 474 | target->thread.TS_FPR(i) = buf[i]; |
| 475 | target->thread.fp_state.fpscr = buf[32]; |
| 476 | } |
| 477 | return 0; |
| 478 | #endif |
| 479 | |
| 480 | #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 481 | /* copy to local buffer then write that out */ |
| 482 | i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1); |
| 483 | if (i) |
| 484 | return i; |
| 485 | for (i = 0; i < 32 ; i++) |
| 486 | target->thread.TS_FPR(i) = buf[i]; |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 487 | target->thread.fp_state.fpscr = buf[32]; |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 488 | return 0; |
Anshuman Khandual | 1ec8549 | 2016-07-28 10:57:32 +0800 | [diff] [blame^] | 489 | #endif |
| 490 | |
| 491 | #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM) |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 492 | BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) != |
Khem Raj | 1e407ee | 2016-04-25 09:19:17 -0700 | [diff] [blame] | 493 | offsetof(struct thread_fp_state, fpr[32])); |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 494 | |
| 495 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 496 | &target->thread.fp_state, 0, -1); |
Michael Neuling | c6e6771 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 497 | #endif |
Roland McGrath | f65255e | 2007-12-20 03:57:34 -0800 | [diff] [blame] | 498 | } |
| 499 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 500 | #ifdef CONFIG_ALTIVEC |
| 501 | /* |
| 502 | * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go. |
| 503 | * The transfer totals 34 quadword. Quadwords 0-31 contain the |
| 504 | * corresponding vector registers. Quadword 32 contains the vscr as the |
| 505 | * last word (offset 12) within that quadword. Quadword 33 contains the |
| 506 | * vrsave as the first word (offset 0) within the quadword. |
| 507 | * |
| 508 | * This definition of the VMX state is compatible with the current PPC32 |
| 509 | * ptrace interface. This allows signal handling and ptrace to use the |
| 510 | * same structures. This also simplifies the implementation of a bi-arch |
| 511 | * (combined (32- and 64-bit) gdb. |
| 512 | */ |
| 513 | |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 514 | static int vr_active(struct task_struct *target, |
| 515 | const struct user_regset *regset) |
| 516 | { |
| 517 | flush_altivec_to_thread(target); |
| 518 | return target->thread.used_vr ? regset->n : 0; |
| 519 | } |
| 520 | |
| 521 | static int vr_get(struct task_struct *target, const struct user_regset *regset, |
| 522 | unsigned int pos, unsigned int count, |
| 523 | void *kbuf, void __user *ubuf) |
| 524 | { |
| 525 | int ret; |
| 526 | |
| 527 | flush_altivec_to_thread(target); |
| 528 | |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 529 | BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != |
| 530 | offsetof(struct thread_vr_state, vr[32])); |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 531 | |
| 532 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 533 | &target->thread.vr_state, 0, |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 534 | 33 * sizeof(vector128)); |
| 535 | if (!ret) { |
| 536 | /* |
| 537 | * Copy out only the low-order word of vrsave. |
| 538 | */ |
| 539 | union { |
| 540 | elf_vrreg_t reg; |
| 541 | u32 word; |
| 542 | } vrsave; |
| 543 | memset(&vrsave, 0, sizeof(vrsave)); |
| 544 | vrsave.word = target->thread.vrsave; |
| 545 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 546 | 33 * sizeof(vector128), -1); |
| 547 | } |
| 548 | |
| 549 | return ret; |
| 550 | } |
| 551 | |
| 552 | static int vr_set(struct task_struct *target, const struct user_regset *regset, |
| 553 | unsigned int pos, unsigned int count, |
| 554 | const void *kbuf, const void __user *ubuf) |
| 555 | { |
| 556 | int ret; |
| 557 | |
| 558 | flush_altivec_to_thread(target); |
| 559 | |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 560 | BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) != |
| 561 | offsetof(struct thread_vr_state, vr[32])); |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 562 | |
| 563 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 564 | &target->thread.vr_state, 0, |
| 565 | 33 * sizeof(vector128)); |
Roland McGrath | 3caf06c | 2007-12-20 03:57:39 -0800 | [diff] [blame] | 566 | if (!ret && count > 0) { |
| 567 | /* |
| 568 | * We use only the first word of vrsave. |
| 569 | */ |
| 570 | union { |
| 571 | elf_vrreg_t reg; |
| 572 | u32 word; |
| 573 | } vrsave; |
| 574 | memset(&vrsave, 0, sizeof(vrsave)); |
| 575 | vrsave.word = target->thread.vrsave; |
| 576 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, |
| 577 | 33 * sizeof(vector128), -1); |
| 578 | if (!ret) |
| 579 | target->thread.vrsave = vrsave.word; |
| 580 | } |
| 581 | |
| 582 | return ret; |
| 583 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 584 | #endif /* CONFIG_ALTIVEC */ |
| 585 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 586 | #ifdef CONFIG_VSX |
| 587 | /* |
| 588 | * Currently to set and and get all the vsx state, you need to call |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 589 | * the fp and VMX calls as well. This only get/sets the lower 32 |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 590 | * 128bit VSX registers. |
| 591 | */ |
| 592 | |
| 593 | static int vsr_active(struct task_struct *target, |
| 594 | const struct user_regset *regset) |
| 595 | { |
| 596 | flush_vsx_to_thread(target); |
| 597 | return target->thread.used_vsr ? regset->n : 0; |
| 598 | } |
| 599 | |
| 600 | static int vsr_get(struct task_struct *target, const struct user_regset *regset, |
| 601 | unsigned int pos, unsigned int count, |
| 602 | void *kbuf, void __user *ubuf) |
| 603 | { |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 604 | u64 buf[32]; |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 605 | int ret, i; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 606 | |
| 607 | flush_vsx_to_thread(target); |
| 608 | |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 609 | for (i = 0; i < 32 ; i++) |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 610 | buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET]; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 611 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 612 | buf, 0, 32 * sizeof(double)); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 613 | |
| 614 | return ret; |
| 615 | } |
| 616 | |
| 617 | static int vsr_set(struct task_struct *target, const struct user_regset *regset, |
| 618 | unsigned int pos, unsigned int count, |
| 619 | const void *kbuf, const void __user *ubuf) |
| 620 | { |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 621 | u64 buf[32]; |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 622 | int ret,i; |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 623 | |
| 624 | flush_vsx_to_thread(target); |
| 625 | |
| 626 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 627 | buf, 0, 32 * sizeof(double)); |
| 628 | for (i = 0; i < 32 ; i++) |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 629 | target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i]; |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 630 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | #endif /* CONFIG_VSX */ |
| 635 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 636 | #ifdef CONFIG_SPE |
| 637 | |
| 638 | /* |
| 639 | * For get_evrregs/set_evrregs functions 'data' has the following layout: |
| 640 | * |
| 641 | * struct { |
| 642 | * u32 evr[32]; |
| 643 | * u64 acc; |
| 644 | * u32 spefscr; |
| 645 | * } |
| 646 | */ |
| 647 | |
Roland McGrath | a4e4b17 | 2007-12-20 03:57:48 -0800 | [diff] [blame] | 648 | static int evr_active(struct task_struct *target, |
| 649 | const struct user_regset *regset) |
| 650 | { |
| 651 | flush_spe_to_thread(target); |
| 652 | return target->thread.used_spe ? regset->n : 0; |
| 653 | } |
| 654 | |
| 655 | static int evr_get(struct task_struct *target, const struct user_regset *regset, |
| 656 | unsigned int pos, unsigned int count, |
| 657 | void *kbuf, void __user *ubuf) |
| 658 | { |
| 659 | int ret; |
| 660 | |
| 661 | flush_spe_to_thread(target); |
| 662 | |
| 663 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 664 | &target->thread.evr, |
| 665 | 0, sizeof(target->thread.evr)); |
| 666 | |
| 667 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
| 668 | offsetof(struct thread_struct, spefscr)); |
| 669 | |
| 670 | if (!ret) |
| 671 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 672 | &target->thread.acc, |
| 673 | sizeof(target->thread.evr), -1); |
| 674 | |
| 675 | return ret; |
| 676 | } |
| 677 | |
| 678 | static int evr_set(struct task_struct *target, const struct user_regset *regset, |
| 679 | unsigned int pos, unsigned int count, |
| 680 | const void *kbuf, const void __user *ubuf) |
| 681 | { |
| 682 | int ret; |
| 683 | |
| 684 | flush_spe_to_thread(target); |
| 685 | |
| 686 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 687 | &target->thread.evr, |
| 688 | 0, sizeof(target->thread.evr)); |
| 689 | |
| 690 | BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) != |
| 691 | offsetof(struct thread_struct, spefscr)); |
| 692 | |
| 693 | if (!ret) |
| 694 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 695 | &target->thread.acc, |
| 696 | sizeof(target->thread.evr), -1); |
| 697 | |
| 698 | return ret; |
| 699 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 700 | #endif /* CONFIG_SPE */ |
| 701 | |
| 702 | |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 703 | /* |
| 704 | * These are our native regset flavors. |
| 705 | */ |
| 706 | enum powerpc_regset { |
| 707 | REGSET_GPR, |
| 708 | REGSET_FPR, |
| 709 | #ifdef CONFIG_ALTIVEC |
| 710 | REGSET_VMX, |
| 711 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 712 | #ifdef CONFIG_VSX |
| 713 | REGSET_VSX, |
| 714 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 715 | #ifdef CONFIG_SPE |
| 716 | REGSET_SPE, |
| 717 | #endif |
| 718 | }; |
| 719 | |
| 720 | static const struct user_regset native_regsets[] = { |
| 721 | [REGSET_GPR] = { |
| 722 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, |
| 723 | .size = sizeof(long), .align = sizeof(long), |
| 724 | .get = gpr_get, .set = gpr_set |
| 725 | }, |
| 726 | [REGSET_FPR] = { |
| 727 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, |
| 728 | .size = sizeof(double), .align = sizeof(double), |
| 729 | .get = fpr_get, .set = fpr_set |
| 730 | }, |
| 731 | #ifdef CONFIG_ALTIVEC |
| 732 | [REGSET_VMX] = { |
| 733 | .core_note_type = NT_PPC_VMX, .n = 34, |
| 734 | .size = sizeof(vector128), .align = sizeof(vector128), |
| 735 | .active = vr_active, .get = vr_get, .set = vr_set |
| 736 | }, |
| 737 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 738 | #ifdef CONFIG_VSX |
| 739 | [REGSET_VSX] = { |
Michael Neuling | f3e909c | 2008-07-01 14:01:39 +1000 | [diff] [blame] | 740 | .core_note_type = NT_PPC_VSX, .n = 32, |
| 741 | .size = sizeof(double), .align = sizeof(double), |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 742 | .active = vsr_active, .get = vsr_get, .set = vsr_set |
| 743 | }, |
| 744 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 745 | #ifdef CONFIG_SPE |
| 746 | [REGSET_SPE] = { |
Suzuki Poulose | a0b38b4 | 2013-08-27 13:22:14 +0530 | [diff] [blame] | 747 | .core_note_type = NT_PPC_SPE, .n = 35, |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 748 | .size = sizeof(u32), .align = sizeof(u32), |
| 749 | .active = evr_active, .get = evr_get, .set = evr_set |
| 750 | }, |
| 751 | #endif |
| 752 | }; |
| 753 | |
| 754 | static const struct user_regset_view user_ppc_native_view = { |
| 755 | .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI, |
| 756 | .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets) |
| 757 | }; |
| 758 | |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 759 | #ifdef CONFIG_PPC64 |
| 760 | #include <linux/compat.h> |
| 761 | |
| 762 | static int gpr32_get(struct task_struct *target, |
| 763 | const struct user_regset *regset, |
| 764 | unsigned int pos, unsigned int count, |
| 765 | void *kbuf, void __user *ubuf) |
| 766 | { |
| 767 | const unsigned long *regs = &target->thread.regs->gpr[0]; |
| 768 | compat_ulong_t *k = kbuf; |
| 769 | compat_ulong_t __user *u = ubuf; |
| 770 | compat_ulong_t reg; |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 771 | int i; |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 772 | |
| 773 | if (target->thread.regs == NULL) |
| 774 | return -EIO; |
| 775 | |
Mike Wolf | a71f5d5 | 2011-03-21 11:14:53 +1100 | [diff] [blame] | 776 | if (!FULL_REGS(target->thread.regs)) { |
| 777 | /* We have a partial register set. Fill 14-31 with bogus values */ |
| 778 | for (i = 14; i < 32; i++) |
| 779 | target->thread.regs->gpr[i] = NV_REG_POISON; |
| 780 | } |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 781 | |
| 782 | pos /= sizeof(reg); |
| 783 | count /= sizeof(reg); |
| 784 | |
| 785 | if (kbuf) |
| 786 | for (; count > 0 && pos < PT_MSR; --count) |
| 787 | *k++ = regs[pos++]; |
| 788 | else |
| 789 | for (; count > 0 && pos < PT_MSR; --count) |
| 790 | if (__put_user((compat_ulong_t) regs[pos++], u++)) |
| 791 | return -EFAULT; |
| 792 | |
| 793 | if (count > 0 && pos == PT_MSR) { |
| 794 | reg = get_user_msr(target); |
| 795 | if (kbuf) |
| 796 | *k++ = reg; |
| 797 | else if (__put_user(reg, u++)) |
| 798 | return -EFAULT; |
| 799 | ++pos; |
| 800 | --count; |
| 801 | } |
| 802 | |
| 803 | if (kbuf) |
| 804 | for (; count > 0 && pos < PT_REGS_COUNT; --count) |
| 805 | *k++ = regs[pos++]; |
| 806 | else |
| 807 | for (; count > 0 && pos < PT_REGS_COUNT; --count) |
| 808 | if (__put_user((compat_ulong_t) regs[pos++], u++)) |
| 809 | return -EFAULT; |
| 810 | |
| 811 | kbuf = k; |
| 812 | ubuf = u; |
| 813 | pos *= sizeof(reg); |
| 814 | count *= sizeof(reg); |
| 815 | return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 816 | PT_REGS_COUNT * sizeof(reg), -1); |
| 817 | } |
| 818 | |
| 819 | static int gpr32_set(struct task_struct *target, |
| 820 | const struct user_regset *regset, |
| 821 | unsigned int pos, unsigned int count, |
| 822 | const void *kbuf, const void __user *ubuf) |
| 823 | { |
| 824 | unsigned long *regs = &target->thread.regs->gpr[0]; |
| 825 | const compat_ulong_t *k = kbuf; |
| 826 | const compat_ulong_t __user *u = ubuf; |
| 827 | compat_ulong_t reg; |
| 828 | |
| 829 | if (target->thread.regs == NULL) |
| 830 | return -EIO; |
| 831 | |
| 832 | CHECK_FULL_REGS(target->thread.regs); |
| 833 | |
| 834 | pos /= sizeof(reg); |
| 835 | count /= sizeof(reg); |
| 836 | |
| 837 | if (kbuf) |
| 838 | for (; count > 0 && pos < PT_MSR; --count) |
| 839 | regs[pos++] = *k++; |
| 840 | else |
| 841 | for (; count > 0 && pos < PT_MSR; --count) { |
| 842 | if (__get_user(reg, u++)) |
| 843 | return -EFAULT; |
| 844 | regs[pos++] = reg; |
| 845 | } |
| 846 | |
| 847 | |
| 848 | if (count > 0 && pos == PT_MSR) { |
| 849 | if (kbuf) |
| 850 | reg = *k++; |
| 851 | else if (__get_user(reg, u++)) |
| 852 | return -EFAULT; |
| 853 | set_user_msr(target, reg); |
| 854 | ++pos; |
| 855 | --count; |
| 856 | } |
| 857 | |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 858 | if (kbuf) { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 859 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) |
| 860 | regs[pos++] = *k++; |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 861 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
| 862 | ++k; |
| 863 | } else { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 864 | for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { |
| 865 | if (__get_user(reg, u++)) |
| 866 | return -EFAULT; |
| 867 | regs[pos++] = reg; |
| 868 | } |
Roland McGrath | c2372eb | 2008-03-13 19:25:35 +1100 | [diff] [blame] | 869 | for (; count > 0 && pos < PT_TRAP; --count, ++pos) |
| 870 | if (__get_user(reg, u++)) |
| 871 | return -EFAULT; |
| 872 | } |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 873 | |
| 874 | if (count > 0 && pos == PT_TRAP) { |
| 875 | if (kbuf) |
| 876 | reg = *k++; |
| 877 | else if (__get_user(reg, u++)) |
| 878 | return -EFAULT; |
| 879 | set_user_trap(target, reg); |
| 880 | ++pos; |
| 881 | --count; |
| 882 | } |
| 883 | |
| 884 | kbuf = k; |
| 885 | ubuf = u; |
| 886 | pos *= sizeof(reg); |
| 887 | count *= sizeof(reg); |
| 888 | return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, |
| 889 | (PT_TRAP + 1) * sizeof(reg), -1); |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * These are the regset flavors matching the CONFIG_PPC32 native set. |
| 894 | */ |
| 895 | static const struct user_regset compat_regsets[] = { |
| 896 | [REGSET_GPR] = { |
| 897 | .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, |
| 898 | .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), |
| 899 | .get = gpr32_get, .set = gpr32_set |
| 900 | }, |
| 901 | [REGSET_FPR] = { |
| 902 | .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, |
| 903 | .size = sizeof(double), .align = sizeof(double), |
| 904 | .get = fpr_get, .set = fpr_set |
| 905 | }, |
| 906 | #ifdef CONFIG_ALTIVEC |
| 907 | [REGSET_VMX] = { |
| 908 | .core_note_type = NT_PPC_VMX, .n = 34, |
| 909 | .size = sizeof(vector128), .align = sizeof(vector128), |
| 910 | .active = vr_active, .get = vr_get, .set = vr_set |
| 911 | }, |
| 912 | #endif |
| 913 | #ifdef CONFIG_SPE |
| 914 | [REGSET_SPE] = { |
Roland McGrath | 24f1a84 | 2008-01-02 17:05:48 -0800 | [diff] [blame] | 915 | .core_note_type = NT_PPC_SPE, .n = 35, |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 916 | .size = sizeof(u32), .align = sizeof(u32), |
| 917 | .active = evr_active, .get = evr_get, .set = evr_set |
| 918 | }, |
| 919 | #endif |
| 920 | }; |
| 921 | |
| 922 | static const struct user_regset_view user_ppc_compat_view = { |
| 923 | .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI, |
| 924 | .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets) |
| 925 | }; |
| 926 | #endif /* CONFIG_PPC64 */ |
| 927 | |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 928 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 929 | { |
Roland McGrath | fa8f5cb | 2007-12-20 03:58:08 -0800 | [diff] [blame] | 930 | #ifdef CONFIG_PPC64 |
| 931 | if (test_tsk_thread_flag(task, TIF_32BIT)) |
| 932 | return &user_ppc_compat_view; |
| 933 | #endif |
Roland McGrath | 80fdf47 | 2007-12-20 03:58:00 -0800 | [diff] [blame] | 934 | return &user_ppc_native_view; |
| 935 | } |
| 936 | |
| 937 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 938 | void user_enable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 939 | { |
| 940 | struct pt_regs *regs = task->thread.regs; |
| 941 | |
| 942 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 943 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 944 | task->thread.debug.dbcr0 &= ~DBCR0_BT; |
| 945 | task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 946 | regs->msr |= MSR_DE; |
| 947 | #else |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 948 | regs->msr &= ~MSR_BE; |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 949 | regs->msr |= MSR_SE; |
| 950 | #endif |
| 951 | } |
| 952 | set_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 953 | } |
| 954 | |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 955 | void user_enable_block_step(struct task_struct *task) |
| 956 | { |
| 957 | struct pt_regs *regs = task->thread.regs; |
| 958 | |
| 959 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 960 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 961 | task->thread.debug.dbcr0 &= ~DBCR0_IC; |
| 962 | task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT; |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 963 | regs->msr |= MSR_DE; |
| 964 | #else |
| 965 | regs->msr &= ~MSR_SE; |
| 966 | regs->msr |= MSR_BE; |
| 967 | #endif |
| 968 | } |
| 969 | set_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 970 | } |
| 971 | |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 972 | void user_disable_single_step(struct task_struct *task) |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 973 | { |
| 974 | struct pt_regs *regs = task->thread.regs; |
| 975 | |
| 976 | if (regs != NULL) { |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 977 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 978 | /* |
| 979 | * The logic to disable single stepping should be as |
| 980 | * simple as turning off the Instruction Complete flag. |
| 981 | * And, after doing so, if all debug flags are off, turn |
| 982 | * off DBCR0(IDM) and MSR(DE) .... Torez |
| 983 | */ |
James Yang | 682775b | 2013-07-05 14:49:43 -0500 | [diff] [blame] | 984 | task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 985 | /* |
| 986 | * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set. |
| 987 | */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 988 | if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, |
| 989 | task->thread.debug.dbcr1)) { |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 990 | /* |
| 991 | * All debug events were off..... |
| 992 | */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 993 | task->thread.debug.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 28477fb | 2009-07-08 13:46:18 +0000 | [diff] [blame] | 994 | regs->msr &= ~MSR_DE; |
| 995 | } |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 996 | #else |
Roland McGrath | ec097c8 | 2009-05-28 21:26:38 +0000 | [diff] [blame] | 997 | regs->msr &= ~(MSR_SE | MSR_BE); |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 998 | #endif |
| 999 | } |
| 1000 | clear_tsk_thread_flag(task, TIF_SINGLESTEP); |
| 1001 | } |
| 1002 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1003 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
Peter Zijlstra | a8b0ca1 | 2011-06-27 14:41:57 +0200 | [diff] [blame] | 1004 | void ptrace_triggered(struct perf_event *bp, |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1005 | struct perf_sample_data *data, struct pt_regs *regs) |
| 1006 | { |
| 1007 | struct perf_event_attr attr; |
| 1008 | |
| 1009 | /* |
| 1010 | * Disable the breakpoint request here since ptrace has defined a |
| 1011 | * one-shot behaviour for breakpoint exceptions in PPC64. |
| 1012 | * The SIGTRAP signal is generated automatically for us in do_dabr(). |
| 1013 | * We don't have to do anything about that here |
| 1014 | */ |
| 1015 | attr = bp->attr; |
| 1016 | attr.disabled = true; |
| 1017 | modify_user_hw_breakpoint(bp, &attr); |
| 1018 | } |
| 1019 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
| 1020 | |
Anton Blanchard | e51df2c | 2014-08-20 08:55:18 +1000 | [diff] [blame] | 1021 | static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr, |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1022 | unsigned long data) |
| 1023 | { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1024 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1025 | int ret; |
| 1026 | struct thread_struct *thread = &(task->thread); |
| 1027 | struct perf_event *bp; |
| 1028 | struct perf_event_attr attr; |
| 1029 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1030 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
| 1031 | struct arch_hw_breakpoint hw_brk; |
| 1032 | #endif |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1033 | |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1034 | /* For ppc64 we support one DABR and no IABR's at the moment (ppc64). |
| 1035 | * For embedded processors we support one DAC and no IAC's at the |
| 1036 | * moment. |
| 1037 | */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1038 | if (addr > 0) |
| 1039 | return -EINVAL; |
| 1040 | |
Kumar Gala | 2325f0a | 2008-07-26 05:27:33 +1000 | [diff] [blame] | 1041 | /* The bottom 3 bits in dabr are flags */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1042 | if ((data & ~0x7UL) >= TASK_SIZE) |
| 1043 | return -EIO; |
| 1044 | |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1045 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1046 | /* For processors using DABR (i.e. 970), the bottom 3 bits are flags. |
| 1047 | * It was assumed, on previous implementations, that 3 bits were |
| 1048 | * passed together with the data address, fitting the design of the |
| 1049 | * DABR register, as follows: |
| 1050 | * |
| 1051 | * bit 0: Read flag |
| 1052 | * bit 1: Write flag |
| 1053 | * bit 2: Breakpoint translation |
| 1054 | * |
| 1055 | * Thus, we use them here as so. |
| 1056 | */ |
| 1057 | |
| 1058 | /* Ensure breakpoint translation bit is set */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1059 | if (data && !(data & HW_BRK_TYPE_TRANSLATE)) |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1060 | return -EIO; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1061 | hw_brk.address = data & (~HW_BRK_TYPE_DABR); |
| 1062 | hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL; |
| 1063 | hw_brk.len = 8; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1064 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1065 | bp = thread->ptrace_bps[0]; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1066 | if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1067 | if (bp) { |
| 1068 | unregister_hw_breakpoint(bp); |
| 1069 | thread->ptrace_bps[0] = NULL; |
| 1070 | } |
| 1071 | return 0; |
| 1072 | } |
| 1073 | if (bp) { |
| 1074 | attr = bp->attr; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1075 | attr.bp_addr = hw_brk.address; |
| 1076 | arch_bp_generic_fields(hw_brk.type, &attr.bp_type); |
Aravinda Prasad | a53fd61 | 2012-11-04 22:15:28 +0000 | [diff] [blame] | 1077 | |
| 1078 | /* Enable breakpoint */ |
| 1079 | attr.disabled = false; |
| 1080 | |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1081 | ret = modify_user_hw_breakpoint(bp, &attr); |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1082 | if (ret) { |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1083 | return ret; |
Frederic Weisbecker | 925f83c | 2011-05-06 01:53:18 +0200 | [diff] [blame] | 1084 | } |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1085 | thread->ptrace_bps[0] = bp; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1086 | thread->hw_brk = hw_brk; |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | /* Create a new breakpoint request if one doesn't exist already */ |
| 1091 | hw_breakpoint_init(&attr); |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1092 | attr.bp_addr = hw_brk.address; |
| 1093 | arch_bp_generic_fields(hw_brk.type, |
| 1094 | &attr.bp_type); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1095 | |
| 1096 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, |
Avi Kivity | 4dc0da8 | 2011-06-29 18:42:35 +0300 | [diff] [blame] | 1097 | ptrace_triggered, NULL, task); |
K.Prasad | 5aae8a5 | 2010-06-15 11:35:19 +0530 | [diff] [blame] | 1098 | if (IS_ERR(bp)) { |
| 1099 | thread->ptrace_bps[0] = NULL; |
| 1100 | return PTR_ERR(bp); |
| 1101 | } |
| 1102 | |
| 1103 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1104 | task->thread.hw_brk = hw_brk; |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1105 | #else /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1106 | /* As described above, it was assumed 3 bits were passed with the data |
| 1107 | * address, but we will assume only the mode bits will be passed |
| 1108 | * as to not cause alignment restrictions for DAC-based processors. |
| 1109 | */ |
| 1110 | |
| 1111 | /* DAC's hold the whole address without any mode flags */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1112 | task->thread.debug.dac1 = data & ~0x3UL; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1113 | |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1114 | if (task->thread.debug.dac1 == 0) { |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1115 | dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1116 | if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0, |
| 1117 | task->thread.debug.dbcr1)) { |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1118 | task->thread.regs->msr &= ~MSR_DE; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1119 | task->thread.debug.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1120 | } |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | /* Read or Write bits must be set */ |
| 1125 | |
| 1126 | if (!(data & 0x3UL)) |
| 1127 | return -EINVAL; |
| 1128 | |
| 1129 | /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0 |
| 1130 | register */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1131 | task->thread.debug.dbcr0 |= DBCR0_IDM; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1132 | |
| 1133 | /* Check for write and read flags and set DBCR0 |
| 1134 | accordingly */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1135 | dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W); |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1136 | if (data & 0x1UL) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1137 | dbcr_dac(task) |= DBCR_DAC1R; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1138 | if (data & 0x2UL) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1139 | dbcr_dac(task) |= DBCR_DAC1W; |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 1140 | task->thread.regs->msr |= MSR_DE; |
Dave Kleikamp | 172ae2e | 2010-02-08 11:50:57 +0000 | [diff] [blame] | 1141 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1142 | return 0; |
| 1143 | } |
Benjamin Herrenschmidt | abd0650 | 2007-06-04 15:15:47 +1000 | [diff] [blame] | 1144 | |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 1145 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | * Called by kernel/ptrace.c when detaching.. |
| 1147 | * |
| 1148 | * Make sure single step bits etc are not set. |
| 1149 | */ |
| 1150 | void ptrace_disable(struct task_struct *child) |
| 1151 | { |
| 1152 | /* make sure the single step bit is not set. */ |
Roland McGrath | 2a84b0d | 2008-01-30 13:30:51 +0100 | [diff] [blame] | 1153 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1156 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Michael Neuling | 84295df | 2012-10-28 15:13:16 +0000 | [diff] [blame] | 1157 | static long set_instruction_bp(struct task_struct *child, |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1158 | struct ppc_hw_breakpoint *bp_info) |
| 1159 | { |
| 1160 | int slot; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1161 | int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0); |
| 1162 | int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0); |
| 1163 | int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0); |
| 1164 | int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1165 | |
| 1166 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) |
| 1167 | slot2_in_use = 1; |
| 1168 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) |
| 1169 | slot4_in_use = 1; |
| 1170 | |
| 1171 | if (bp_info->addr >= TASK_SIZE) |
| 1172 | return -EIO; |
| 1173 | |
| 1174 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) { |
| 1175 | |
| 1176 | /* Make sure range is valid. */ |
| 1177 | if (bp_info->addr2 >= TASK_SIZE) |
| 1178 | return -EIO; |
| 1179 | |
| 1180 | /* We need a pair of IAC regsisters */ |
| 1181 | if ((!slot1_in_use) && (!slot2_in_use)) { |
| 1182 | slot = 1; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1183 | child->thread.debug.iac1 = bp_info->addr; |
| 1184 | child->thread.debug.iac2 = bp_info->addr2; |
| 1185 | child->thread.debug.dbcr0 |= DBCR0_IAC1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1186 | if (bp_info->addr_mode == |
| 1187 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
| 1188 | dbcr_iac_range(child) |= DBCR_IAC12X; |
| 1189 | else |
| 1190 | dbcr_iac_range(child) |= DBCR_IAC12I; |
| 1191 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1192 | } else if ((!slot3_in_use) && (!slot4_in_use)) { |
| 1193 | slot = 3; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1194 | child->thread.debug.iac3 = bp_info->addr; |
| 1195 | child->thread.debug.iac4 = bp_info->addr2; |
| 1196 | child->thread.debug.dbcr0 |= DBCR0_IAC3; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1197 | if (bp_info->addr_mode == |
| 1198 | PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
| 1199 | dbcr_iac_range(child) |= DBCR_IAC34X; |
| 1200 | else |
| 1201 | dbcr_iac_range(child) |= DBCR_IAC34I; |
| 1202 | #endif |
| 1203 | } else |
| 1204 | return -ENOSPC; |
| 1205 | } else { |
| 1206 | /* We only need one. If possible leave a pair free in |
| 1207 | * case a range is needed later |
| 1208 | */ |
| 1209 | if (!slot1_in_use) { |
| 1210 | /* |
| 1211 | * Don't use iac1 if iac1-iac2 are free and either |
| 1212 | * iac3 or iac4 (but not both) are free |
| 1213 | */ |
| 1214 | if (slot2_in_use || (slot3_in_use == slot4_in_use)) { |
| 1215 | slot = 1; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1216 | child->thread.debug.iac1 = bp_info->addr; |
| 1217 | child->thread.debug.dbcr0 |= DBCR0_IAC1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1218 | goto out; |
| 1219 | } |
| 1220 | } |
| 1221 | if (!slot2_in_use) { |
| 1222 | slot = 2; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1223 | child->thread.debug.iac2 = bp_info->addr; |
| 1224 | child->thread.debug.dbcr0 |= DBCR0_IAC2; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1225 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1226 | } else if (!slot3_in_use) { |
| 1227 | slot = 3; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1228 | child->thread.debug.iac3 = bp_info->addr; |
| 1229 | child->thread.debug.dbcr0 |= DBCR0_IAC3; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1230 | } else if (!slot4_in_use) { |
| 1231 | slot = 4; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1232 | child->thread.debug.iac4 = bp_info->addr; |
| 1233 | child->thread.debug.dbcr0 |= DBCR0_IAC4; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1234 | #endif |
| 1235 | } else |
| 1236 | return -ENOSPC; |
| 1237 | } |
| 1238 | out: |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1239 | child->thread.debug.dbcr0 |= DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1240 | child->thread.regs->msr |= MSR_DE; |
| 1241 | |
| 1242 | return slot; |
| 1243 | } |
| 1244 | |
| 1245 | static int del_instruction_bp(struct task_struct *child, int slot) |
| 1246 | { |
| 1247 | switch (slot) { |
| 1248 | case 1: |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1249 | if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1250 | return -ENOENT; |
| 1251 | |
| 1252 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) { |
| 1253 | /* address range - clear slots 1 & 2 */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1254 | child->thread.debug.iac2 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1255 | dbcr_iac_range(child) &= ~DBCR_IAC12MODE; |
| 1256 | } |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1257 | child->thread.debug.iac1 = 0; |
| 1258 | child->thread.debug.dbcr0 &= ~DBCR0_IAC1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1259 | break; |
| 1260 | case 2: |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1261 | if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1262 | return -ENOENT; |
| 1263 | |
| 1264 | if (dbcr_iac_range(child) & DBCR_IAC12MODE) |
| 1265 | /* used in a range */ |
| 1266 | return -EINVAL; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1267 | child->thread.debug.iac2 = 0; |
| 1268 | child->thread.debug.dbcr0 &= ~DBCR0_IAC2; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1269 | break; |
| 1270 | #if CONFIG_PPC_ADV_DEBUG_IACS > 2 |
| 1271 | case 3: |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1272 | if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1273 | return -ENOENT; |
| 1274 | |
| 1275 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) { |
| 1276 | /* address range - clear slots 3 & 4 */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1277 | child->thread.debug.iac4 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1278 | dbcr_iac_range(child) &= ~DBCR_IAC34MODE; |
| 1279 | } |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1280 | child->thread.debug.iac3 = 0; |
| 1281 | child->thread.debug.dbcr0 &= ~DBCR0_IAC3; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1282 | break; |
| 1283 | case 4: |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1284 | if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1285 | return -ENOENT; |
| 1286 | |
| 1287 | if (dbcr_iac_range(child) & DBCR_IAC34MODE) |
| 1288 | /* Used in a range */ |
| 1289 | return -EINVAL; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1290 | child->thread.debug.iac4 = 0; |
| 1291 | child->thread.debug.dbcr0 &= ~DBCR0_IAC4; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1292 | break; |
| 1293 | #endif |
| 1294 | default: |
| 1295 | return -EINVAL; |
| 1296 | } |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info) |
| 1301 | { |
| 1302 | int byte_enable = |
| 1303 | (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT) |
| 1304 | & 0xf; |
| 1305 | int condition_mode = |
| 1306 | bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE; |
| 1307 | int slot; |
| 1308 | |
| 1309 | if (byte_enable && (condition_mode == 0)) |
| 1310 | return -EINVAL; |
| 1311 | |
| 1312 | if (bp_info->addr >= TASK_SIZE) |
| 1313 | return -EIO; |
| 1314 | |
| 1315 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) { |
| 1316 | slot = 1; |
| 1317 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
| 1318 | dbcr_dac(child) |= DBCR_DAC1R; |
| 1319 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
| 1320 | dbcr_dac(child) |= DBCR_DAC1W; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1321 | child->thread.debug.dac1 = (unsigned long)bp_info->addr; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1322 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1323 | if (byte_enable) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1324 | child->thread.debug.dvc1 = |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1325 | (unsigned long)bp_info->condition_value; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1326 | child->thread.debug.dbcr2 |= |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1327 | ((byte_enable << DBCR2_DVC1BE_SHIFT) | |
| 1328 | (condition_mode << DBCR2_DVC1M_SHIFT)); |
| 1329 | } |
| 1330 | #endif |
| 1331 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1332 | } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1333 | /* Both dac1 and dac2 are part of a range */ |
| 1334 | return -ENOSPC; |
| 1335 | #endif |
| 1336 | } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) { |
| 1337 | slot = 2; |
| 1338 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
| 1339 | dbcr_dac(child) |= DBCR_DAC2R; |
| 1340 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
| 1341 | dbcr_dac(child) |= DBCR_DAC2W; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1342 | child->thread.debug.dac2 = (unsigned long)bp_info->addr; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1343 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
| 1344 | if (byte_enable) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1345 | child->thread.debug.dvc2 = |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1346 | (unsigned long)bp_info->condition_value; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1347 | child->thread.debug.dbcr2 |= |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1348 | ((byte_enable << DBCR2_DVC2BE_SHIFT) | |
| 1349 | (condition_mode << DBCR2_DVC2M_SHIFT)); |
| 1350 | } |
| 1351 | #endif |
| 1352 | } else |
| 1353 | return -ENOSPC; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1354 | child->thread.debug.dbcr0 |= DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1355 | child->thread.regs->msr |= MSR_DE; |
| 1356 | |
| 1357 | return slot + 4; |
| 1358 | } |
| 1359 | |
| 1360 | static int del_dac(struct task_struct *child, int slot) |
| 1361 | { |
| 1362 | if (slot == 1) { |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1363 | if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1364 | return -ENOENT; |
| 1365 | |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1366 | child->thread.debug.dac1 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1367 | dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W); |
| 1368 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1369 | if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) { |
| 1370 | child->thread.debug.dac2 = 0; |
| 1371 | child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1372 | } |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1373 | child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1374 | #endif |
| 1375 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1376 | child->thread.debug.dvc1 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1377 | #endif |
| 1378 | } else if (slot == 2) { |
Dave Kleikamp | 30124d1 | 2010-03-01 04:57:34 +0000 | [diff] [blame] | 1379 | if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1380 | return -ENOENT; |
| 1381 | |
| 1382 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1383 | if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1384 | /* Part of a range */ |
| 1385 | return -EINVAL; |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1386 | child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1387 | #endif |
| 1388 | #if CONFIG_PPC_ADV_DEBUG_DVCS > 0 |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1389 | child->thread.debug.dvc2 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1390 | #endif |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1391 | child->thread.debug.dac2 = 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1392 | dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W); |
| 1393 | } else |
| 1394 | return -EINVAL; |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
| 1399 | |
| 1400 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1401 | static int set_dac_range(struct task_struct *child, |
| 1402 | struct ppc_hw_breakpoint *bp_info) |
| 1403 | { |
| 1404 | int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK; |
| 1405 | |
| 1406 | /* We don't allow range watchpoints to be used with DVC */ |
| 1407 | if (bp_info->condition_mode) |
| 1408 | return -EINVAL; |
| 1409 | |
| 1410 | /* |
| 1411 | * Best effort to verify the address range. The user/supervisor bits |
| 1412 | * prevent trapping in kernel space, but let's fail on an obvious bad |
| 1413 | * range. The simple test on the mask is not fool-proof, and any |
| 1414 | * exclusive range will spill over into kernel space. |
| 1415 | */ |
| 1416 | if (bp_info->addr >= TASK_SIZE) |
| 1417 | return -EIO; |
| 1418 | if (mode == PPC_BREAKPOINT_MODE_MASK) { |
| 1419 | /* |
| 1420 | * dac2 is a bitmask. Don't allow a mask that makes a |
| 1421 | * kernel space address from a valid dac1 value |
| 1422 | */ |
| 1423 | if (~((unsigned long)bp_info->addr2) >= TASK_SIZE) |
| 1424 | return -EIO; |
| 1425 | } else { |
| 1426 | /* |
| 1427 | * For range breakpoints, addr2 must also be a valid address |
| 1428 | */ |
| 1429 | if (bp_info->addr2 >= TASK_SIZE) |
| 1430 | return -EIO; |
| 1431 | } |
| 1432 | |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1433 | if (child->thread.debug.dbcr0 & |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1434 | (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)) |
| 1435 | return -ENOSPC; |
| 1436 | |
| 1437 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1438 | child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1439 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1440 | child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM); |
| 1441 | child->thread.debug.dac1 = bp_info->addr; |
| 1442 | child->thread.debug.dac2 = bp_info->addr2; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1443 | if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1444 | child->thread.debug.dbcr2 |= DBCR2_DAC12M; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1445 | else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE) |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1446 | child->thread.debug.dbcr2 |= DBCR2_DAC12MX; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1447 | else /* PPC_BREAKPOINT_MODE_MASK */ |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1448 | child->thread.debug.dbcr2 |= DBCR2_DAC12MM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1449 | child->thread.regs->msr |= MSR_DE; |
| 1450 | |
| 1451 | return 5; |
| 1452 | } |
| 1453 | #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */ |
| 1454 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1455 | static long ppc_set_hwdebug(struct task_struct *child, |
| 1456 | struct ppc_hw_breakpoint *bp_info) |
| 1457 | { |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1458 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1459 | int len = 0; |
| 1460 | struct thread_struct *thread = &(child->thread); |
| 1461 | struct perf_event *bp; |
| 1462 | struct perf_event_attr attr; |
| 1463 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1464 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1465 | struct arch_hw_breakpoint brk; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1466 | #endif |
| 1467 | |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1468 | if (bp_info->version != 1) |
| 1469 | return -ENOTSUPP; |
| 1470 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1471 | /* |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1472 | * Check for invalid flags and combinations |
| 1473 | */ |
| 1474 | if ((bp_info->trigger_type == 0) || |
| 1475 | (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE | |
| 1476 | PPC_BREAKPOINT_TRIGGER_RW)) || |
| 1477 | (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) || |
| 1478 | (bp_info->condition_mode & |
| 1479 | ~(PPC_BREAKPOINT_CONDITION_MODE | |
| 1480 | PPC_BREAKPOINT_CONDITION_BE_ALL))) |
| 1481 | return -EINVAL; |
| 1482 | #if CONFIG_PPC_ADV_DEBUG_DVCS == 0 |
| 1483 | if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) |
| 1484 | return -EINVAL; |
| 1485 | #endif |
| 1486 | |
| 1487 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) { |
| 1488 | if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) || |
| 1489 | (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)) |
| 1490 | return -EINVAL; |
Michael Neuling | 84295df | 2012-10-28 15:13:16 +0000 | [diff] [blame] | 1491 | return set_instruction_bp(child, bp_info); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1492 | } |
| 1493 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) |
| 1494 | return set_dac(child, bp_info); |
| 1495 | |
| 1496 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1497 | return set_dac_range(child, bp_info); |
| 1498 | #else |
| 1499 | return -EINVAL; |
| 1500 | #endif |
| 1501 | #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */ |
| 1502 | /* |
| 1503 | * We only support one data breakpoint |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1504 | */ |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1505 | if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 || |
| 1506 | (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 || |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1507 | bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1508 | return -EINVAL; |
| 1509 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1510 | if ((unsigned long)bp_info->addr >= TASK_SIZE) |
| 1511 | return -EIO; |
| 1512 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1513 | brk.address = bp_info->addr & ~7UL; |
| 1514 | brk.type = HW_BRK_TYPE_TRANSLATE; |
Michael Neuling | 2bb78ef | 2013-03-11 16:42:49 +0000 | [diff] [blame] | 1515 | brk.len = 8; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1516 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ) |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1517 | brk.type |= HW_BRK_TYPE_READ; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1518 | if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE) |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1519 | brk.type |= HW_BRK_TYPE_WRITE; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1520 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1521 | /* |
| 1522 | * Check if the request is for 'range' breakpoints. We can |
| 1523 | * support it if range < 8 bytes. |
| 1524 | */ |
Oleg Nesterov | 6961ed9 | 2013-07-08 16:00:49 -0700 | [diff] [blame] | 1525 | if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1526 | len = bp_info->addr2 - bp_info->addr; |
Oleg Nesterov | 6961ed9 | 2013-07-08 16:00:49 -0700 | [diff] [blame] | 1527 | else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT) |
Michael Neuling | b0b0aa9 | 2013-06-24 15:47:22 +1000 | [diff] [blame] | 1528 | len = 1; |
Oleg Nesterov | 6961ed9 | 2013-07-08 16:00:49 -0700 | [diff] [blame] | 1529 | else |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1530 | return -EINVAL; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1531 | bp = thread->ptrace_bps[0]; |
Oleg Nesterov | 6961ed9 | 2013-07-08 16:00:49 -0700 | [diff] [blame] | 1532 | if (bp) |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1533 | return -ENOSPC; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1534 | |
| 1535 | /* Create a new breakpoint request if one doesn't exist already */ |
| 1536 | hw_breakpoint_init(&attr); |
| 1537 | attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN; |
| 1538 | attr.bp_len = len; |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1539 | arch_bp_generic_fields(brk.type, &attr.bp_type); |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1540 | |
| 1541 | thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr, |
| 1542 | ptrace_triggered, NULL, child); |
| 1543 | if (IS_ERR(bp)) { |
| 1544 | thread->ptrace_bps[0] = NULL; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1545 | return PTR_ERR(bp); |
| 1546 | } |
| 1547 | |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1548 | return 1; |
| 1549 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
| 1550 | |
| 1551 | if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) |
| 1552 | return -EINVAL; |
| 1553 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1554 | if (child->thread.hw_brk.address) |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1555 | return -ENOSPC; |
Andreas Schwab | 4dfbf29 | 2010-11-27 14:24:53 +0000 | [diff] [blame] | 1556 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1557 | child->thread.hw_brk = brk; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1558 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1559 | return 1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1560 | #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Michael Neuling | ec1b33d | 2012-10-28 15:13:17 +0000 | [diff] [blame] | 1563 | static long ppc_del_hwdebug(struct task_struct *child, long data) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1564 | { |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1565 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1566 | int ret = 0; |
| 1567 | struct thread_struct *thread = &(child->thread); |
| 1568 | struct perf_event *bp; |
| 1569 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1570 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
| 1571 | int rc; |
| 1572 | |
| 1573 | if (data <= 4) |
| 1574 | rc = del_instruction_bp(child, (int)data); |
| 1575 | else |
| 1576 | rc = del_dac(child, (int)data - 4); |
| 1577 | |
| 1578 | if (!rc) { |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1579 | if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0, |
| 1580 | child->thread.debug.dbcr1)) { |
| 1581 | child->thread.debug.dbcr0 &= ~DBCR0_IDM; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1582 | child->thread.regs->msr &= ~MSR_DE; |
| 1583 | } |
| 1584 | } |
| 1585 | return rc; |
| 1586 | #else |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1587 | if (data != 1) |
| 1588 | return -EINVAL; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1589 | |
| 1590 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1591 | bp = thread->ptrace_bps[0]; |
| 1592 | if (bp) { |
| 1593 | unregister_hw_breakpoint(bp); |
| 1594 | thread->ptrace_bps[0] = NULL; |
| 1595 | } else |
| 1596 | ret = -ENOENT; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1597 | return ret; |
| 1598 | #else /* CONFIG_HAVE_HW_BREAKPOINT */ |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1599 | if (child->thread.hw_brk.address == 0) |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1600 | return -ENOENT; |
| 1601 | |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1602 | child->thread.hw_brk.address = 0; |
| 1603 | child->thread.hw_brk.type = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1604 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1605 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1606 | return 0; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1607 | #endif |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1610 | long arch_ptrace(struct task_struct *child, long request, |
| 1611 | unsigned long addr, unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | int ret = -EPERM; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1614 | void __user *datavp = (void __user *) data; |
| 1615 | unsigned long __user *datalp = datavp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | /* read the word at location addr in the USER area. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | case PTRACE_PEEKUSR: { |
| 1620 | unsigned long index, tmp; |
| 1621 | |
| 1622 | ret = -EIO; |
| 1623 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1624 | #ifdef CONFIG_PPC32 |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1625 | index = addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1626 | if ((addr & 3) || (index > PT_FPSCR) |
| 1627 | || (child->thread.regs == NULL)) |
| 1628 | #else |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1629 | index = addr >> 3; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1630 | if ((addr & 7) || (index > PT_FPSCR)) |
| 1631 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | break; |
| 1633 | |
| 1634 | CHECK_FULL_REGS(child->thread.regs); |
| 1635 | if (index < PT_FPR0) { |
Alexey Kardashevskiy | ee4a391 | 2013-02-14 17:44:23 +0000 | [diff] [blame] | 1636 | ret = ptrace_get_reg(child, (int) index, &tmp); |
| 1637 | if (ret) |
| 1638 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | } else { |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1640 | unsigned int fpidx = index - PT_FPR0; |
| 1641 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1642 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1643 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
Ulrich Weigand | 36aa1b1 | 2013-12-12 15:59:34 +1100 | [diff] [blame] | 1644 | memcpy(&tmp, &child->thread.TS_FPR(fpidx), |
Anton Blanchard | 87fec05 | 2013-09-23 12:04:38 +1000 | [diff] [blame] | 1645 | sizeof(long)); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1646 | else |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 1647 | tmp = child->thread.fp_state.fpscr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | } |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1649 | ret = put_user(tmp, datalp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | break; |
| 1651 | } |
| 1652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | /* write the word at location addr in the USER area */ |
| 1654 | case PTRACE_POKEUSR: { |
| 1655 | unsigned long index; |
| 1656 | |
| 1657 | ret = -EIO; |
| 1658 | /* convert to index and check */ |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1659 | #ifdef CONFIG_PPC32 |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1660 | index = addr >> 2; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1661 | if ((addr & 3) || (index > PT_FPSCR) |
| 1662 | || (child->thread.regs == NULL)) |
| 1663 | #else |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 1664 | index = addr >> 3; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1665 | if ((addr & 7) || (index > PT_FPSCR)) |
| 1666 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | break; |
| 1668 | |
| 1669 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 1671 | ret = ptrace_put_reg(child, index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | } else { |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1673 | unsigned int fpidx = index - PT_FPR0; |
| 1674 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1675 | flush_fp_to_thread(child); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1676 | if (fpidx < (PT_FPSCR - PT_FPR0)) |
Ulrich Weigand | 36aa1b1 | 2013-12-12 15:59:34 +1100 | [diff] [blame] | 1677 | memcpy(&child->thread.TS_FPR(fpidx), &data, |
Anton Blanchard | 87fec05 | 2013-09-23 12:04:38 +1000 | [diff] [blame] | 1678 | sizeof(long)); |
Benjamin Herrenschmidt | e69b742 | 2011-09-26 19:37:57 +0000 | [diff] [blame] | 1679 | else |
Paul Mackerras | de79f7b | 2013-09-10 20:20:42 +1000 | [diff] [blame] | 1680 | child->thread.fp_state.fpscr = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | ret = 0; |
| 1682 | } |
| 1683 | break; |
| 1684 | } |
| 1685 | |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1686 | case PPC_PTRACE_GETHWDBGINFO: { |
| 1687 | struct ppc_debug_info dbginfo; |
| 1688 | |
| 1689 | dbginfo.version = 1; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1690 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
| 1691 | dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS; |
| 1692 | dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS; |
| 1693 | dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS; |
| 1694 | dbginfo.data_bp_alignment = 4; |
| 1695 | dbginfo.sizeof_condition = 4; |
| 1696 | dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE | |
| 1697 | PPC_DEBUG_FEATURE_INSN_BP_MASK; |
| 1698 | #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE |
| 1699 | dbginfo.features |= |
| 1700 | PPC_DEBUG_FEATURE_DATA_BP_RANGE | |
| 1701 | PPC_DEBUG_FEATURE_DATA_BP_MASK; |
| 1702 | #endif |
| 1703 | #else /* !CONFIG_PPC_ADV_DEBUG_REGS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1704 | dbginfo.num_instruction_bps = 0; |
| 1705 | dbginfo.num_data_bps = 1; |
| 1706 | dbginfo.num_condition_regs = 0; |
| 1707 | #ifdef CONFIG_PPC64 |
| 1708 | dbginfo.data_bp_alignment = 8; |
| 1709 | #else |
| 1710 | dbginfo.data_bp_alignment = 4; |
| 1711 | #endif |
| 1712 | dbginfo.sizeof_condition = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1713 | #ifdef CONFIG_HAVE_HW_BREAKPOINT |
| 1714 | dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE; |
Michael Neuling | 517b731 | 2013-03-21 20:12:33 +0000 | [diff] [blame] | 1715 | if (cpu_has_feature(CPU_FTR_DAWR)) |
| 1716 | dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1717 | #else |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1718 | dbginfo.features = 0; |
K.Prasad | 6c7a285 | 2012-10-28 15:13:15 +0000 | [diff] [blame] | 1719 | #endif /* CONFIG_HAVE_HW_BREAKPOINT */ |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1720 | #endif /* CONFIG_PPC_ADV_DEBUG_REGS */ |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1721 | |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1722 | if (!access_ok(VERIFY_WRITE, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1723 | sizeof(struct ppc_debug_info))) |
| 1724 | return -EFAULT; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1725 | ret = __copy_to_user(datavp, &dbginfo, |
| 1726 | sizeof(struct ppc_debug_info)) ? |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1727 | -EFAULT : 0; |
| 1728 | break; |
| 1729 | } |
| 1730 | |
| 1731 | case PPC_PTRACE_SETHWDEBUG: { |
| 1732 | struct ppc_hw_breakpoint bp_info; |
| 1733 | |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1734 | if (!access_ok(VERIFY_READ, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1735 | sizeof(struct ppc_hw_breakpoint))) |
| 1736 | return -EFAULT; |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1737 | ret = __copy_from_user(&bp_info, datavp, |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1738 | sizeof(struct ppc_hw_breakpoint)) ? |
| 1739 | -EFAULT : 0; |
| 1740 | if (!ret) |
| 1741 | ret = ppc_set_hwdebug(child, &bp_info); |
| 1742 | break; |
| 1743 | } |
| 1744 | |
| 1745 | case PPC_PTRACE_DELHWDEBUG: { |
Michael Neuling | ec1b33d | 2012-10-28 15:13:17 +0000 | [diff] [blame] | 1746 | ret = ppc_del_hwdebug(child, data); |
Dave Kleikamp | 3162d92 | 2010-02-08 11:51:05 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1750 | case PTRACE_GET_DEBUGREG: { |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1751 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
| 1752 | unsigned long dabr_fake; |
| 1753 | #endif |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1754 | ret = -EINVAL; |
| 1755 | /* We only support one DABR and no IABRS at the moment */ |
| 1756 | if (addr > 0) |
| 1757 | break; |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1758 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
Bharat Bhushan | 51ae8d4 | 2013-07-04 11:45:46 +0530 | [diff] [blame] | 1759 | ret = put_user(child->thread.debug.dac1, datalp); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1760 | #else |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame] | 1761 | dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | |
| 1762 | (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); |
| 1763 | ret = put_user(dabr_fake, datalp); |
Dave Kleikamp | 3bffb65 | 2010-02-08 11:51:18 +0000 | [diff] [blame] | 1764 | #endif |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1765 | break; |
| 1766 | } |
| 1767 | |
| 1768 | case PTRACE_SET_DEBUGREG: |
| 1769 | ret = ptrace_set_debugreg(child, addr, data); |
| 1770 | break; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1771 | |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1772 | #ifdef CONFIG_PPC64 |
| 1773 | case PTRACE_GETREGS64: |
| 1774 | #endif |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1775 | case PTRACE_GETREGS: /* Get all pt_regs from the child. */ |
| 1776 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1777 | REGSET_GPR, |
| 1778 | 0, sizeof(struct pt_regs), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1779 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1780 | |
Benjamin Herrenschmidt | 0b3d5c4 | 2007-06-04 15:15:39 +1000 | [diff] [blame] | 1781 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1782 | case PTRACE_SETREGS64: |
| 1783 | #endif |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1784 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ |
| 1785 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1786 | REGSET_GPR, |
| 1787 | 0, sizeof(struct pt_regs), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1788 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1789 | |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1790 | case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */ |
| 1791 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1792 | REGSET_FPR, |
| 1793 | 0, sizeof(elf_fpregset_t), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1794 | datavp); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 1795 | |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1796 | case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */ |
| 1797 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1798 | REGSET_FPR, |
| 1799 | 0, sizeof(elf_fpregset_t), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1800 | datavp); |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | #ifdef CONFIG_ALTIVEC |
| 1803 | case PTRACE_GETVRREGS: |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1804 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1805 | REGSET_VMX, |
| 1806 | 0, (33 * sizeof(vector128) + |
| 1807 | sizeof(u32)), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1808 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | |
| 1810 | case PTRACE_SETVRREGS: |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1811 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1812 | REGSET_VMX, |
| 1813 | 0, (33 * sizeof(vector128) + |
| 1814 | sizeof(u32)), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1815 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | #endif |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1817 | #ifdef CONFIG_VSX |
| 1818 | case PTRACE_GETVSRREGS: |
| 1819 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1820 | REGSET_VSX, |
Michael Neuling | 1ac42ef8 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 1821 | 0, 32 * sizeof(double), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1822 | datavp); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1823 | |
| 1824 | case PTRACE_SETVSRREGS: |
| 1825 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1826 | REGSET_VSX, |
Michael Neuling | 1ac42ef8 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 1827 | 0, 32 * sizeof(double), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1828 | datavp); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 1829 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | #ifdef CONFIG_SPE |
| 1831 | case PTRACE_GETEVRREGS: |
| 1832 | /* Get the child spe register state. */ |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1833 | return copy_regset_to_user(child, &user_ppc_native_view, |
| 1834 | REGSET_SPE, 0, 35 * sizeof(u32), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1835 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
| 1837 | case PTRACE_SETEVRREGS: |
| 1838 | /* Set the child spe register state. */ |
Roland McGrath | c391cd0 | 2007-12-20 03:58:36 -0800 | [diff] [blame] | 1839 | return copy_regset_from_user(child, &user_ppc_native_view, |
| 1840 | REGSET_SPE, 0, 35 * sizeof(u32), |
Namhyung Kim | f68d204 | 2010-10-27 15:34:01 -0700 | [diff] [blame] | 1841 | datavp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | #endif |
| 1843 | |
| 1844 | default: |
| 1845 | ret = ptrace_request(child, request, addr, data); |
| 1846 | break; |
| 1847 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | return ret; |
| 1849 | } |
| 1850 | |
Michael Ellerman | 2449acc | 2015-07-23 20:21:09 +1000 | [diff] [blame] | 1851 | #ifdef CONFIG_SECCOMP |
| 1852 | static int do_seccomp(struct pt_regs *regs) |
| 1853 | { |
| 1854 | if (!test_thread_flag(TIF_SECCOMP)) |
| 1855 | return 0; |
| 1856 | |
| 1857 | /* |
| 1858 | * The ABI we present to seccomp tracers is that r3 contains |
| 1859 | * the syscall return value and orig_gpr3 contains the first |
| 1860 | * syscall parameter. This is different to the ptrace ABI where |
| 1861 | * both r3 and orig_gpr3 contain the first syscall parameter. |
| 1862 | */ |
| 1863 | regs->gpr[3] = -ENOSYS; |
| 1864 | |
| 1865 | /* |
| 1866 | * We use the __ version here because we have already checked |
| 1867 | * TIF_SECCOMP. If this fails, there is nothing left to do, we |
| 1868 | * have already loaded -ENOSYS into r3, or seccomp has put |
| 1869 | * something else in r3 (via SECCOMP_RET_ERRNO/TRACE). |
| 1870 | */ |
Andy Lutomirski | 2f275de | 2016-05-27 12:57:02 -0700 | [diff] [blame] | 1871 | if (__secure_computing(NULL)) |
Michael Ellerman | 2449acc | 2015-07-23 20:21:09 +1000 | [diff] [blame] | 1872 | return -1; |
| 1873 | |
| 1874 | /* |
| 1875 | * The syscall was allowed by seccomp, restore the register |
Kees Cook | 1addc57 | 2016-06-02 19:55:09 -0700 | [diff] [blame] | 1876 | * state to what audit expects. |
Michael Ellerman | 2449acc | 2015-07-23 20:21:09 +1000 | [diff] [blame] | 1877 | * Note that we use orig_gpr3, which means a seccomp tracer can |
| 1878 | * modify the first syscall parameter (in orig_gpr3) and also |
| 1879 | * allow the syscall to proceed. |
| 1880 | */ |
| 1881 | regs->gpr[3] = regs->orig_gpr3; |
| 1882 | |
| 1883 | return 0; |
| 1884 | } |
| 1885 | #else |
| 1886 | static inline int do_seccomp(struct pt_regs *regs) { return 0; } |
| 1887 | #endif /* CONFIG_SECCOMP */ |
| 1888 | |
Michael Ellerman | d383741 | 2015-07-23 20:21:02 +1000 | [diff] [blame] | 1889 | /** |
| 1890 | * do_syscall_trace_enter() - Do syscall tracing on kernel entry. |
| 1891 | * @regs: the pt_regs of the task to trace (current) |
| 1892 | * |
| 1893 | * Performs various types of tracing on syscall entry. This includes seccomp, |
| 1894 | * ptrace, syscall tracepoints and audit. |
| 1895 | * |
| 1896 | * The pt_regs are potentially visible to userspace via ptrace, so their |
| 1897 | * contents is ABI. |
| 1898 | * |
| 1899 | * One or more of the tracers may modify the contents of pt_regs, in particular |
| 1900 | * to modify arguments or even the syscall number itself. |
| 1901 | * |
| 1902 | * It's also possible that a tracer can choose to reject the system call. In |
| 1903 | * that case this function will return an illegal syscall number, and will put |
| 1904 | * an appropriate return value in regs->r3. |
| 1905 | * |
| 1906 | * Return: the (possibly changed) syscall number. |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1907 | */ |
| 1908 | long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
Li Zhong | 22ecbe8 | 2013-05-13 16:16:40 +0000 | [diff] [blame] | 1910 | user_exit(); |
| 1911 | |
Kees Cook | 1addc57 | 2016-06-02 19:55:09 -0700 | [diff] [blame] | 1912 | /* |
| 1913 | * The tracer may decide to abort the syscall, if so tracehook |
| 1914 | * will return !0. Note that the tracer may also just change |
| 1915 | * regs->gpr[0] to an invalid syscall number, that is handled |
| 1916 | * below on the exit path. |
| 1917 | */ |
| 1918 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 1919 | tracehook_report_syscall_entry(regs)) |
| 1920 | goto skip; |
| 1921 | |
| 1922 | /* Run seccomp after ptrace; allow it to set gpr[3]. */ |
Michael Ellerman | 2449acc | 2015-07-23 20:21:09 +1000 | [diff] [blame] | 1923 | if (do_seccomp(regs)) |
| 1924 | return -1; |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1925 | |
Kees Cook | 1addc57 | 2016-06-02 19:55:09 -0700 | [diff] [blame] | 1926 | /* Avoid trace and audit when syscall is invalid. */ |
| 1927 | if (regs->gpr[0] >= NR_syscalls) |
| 1928 | goto skip; |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1929 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 1930 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 1931 | trace_sys_enter(regs, regs->gpr[0]); |
| 1932 | |
David Woodhouse | cfcd170 | 2007-01-14 09:38:18 +0800 | [diff] [blame] | 1933 | #ifdef CONFIG_PPC64 |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1934 | if (!is_32bit_task()) |
Eric Paris | 9139740 | 2014-03-11 13:29:28 -0400 | [diff] [blame] | 1935 | audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1936 | regs->gpr[5], regs->gpr[6]); |
| 1937 | else |
Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 1938 | #endif |
Eric Paris | 9139740 | 2014-03-11 13:29:28 -0400 | [diff] [blame] | 1939 | audit_syscall_entry(regs->gpr[0], |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1940 | regs->gpr[3] & 0xffffffff, |
| 1941 | regs->gpr[4] & 0xffffffff, |
| 1942 | regs->gpr[5] & 0xffffffff, |
| 1943 | regs->gpr[6] & 0xffffffff); |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1944 | |
Michael Ellerman | d383741 | 2015-07-23 20:21:02 +1000 | [diff] [blame] | 1945 | /* Return the possibly modified but valid syscall number */ |
| 1946 | return regs->gpr[0]; |
Kees Cook | 1addc57 | 2016-06-02 19:55:09 -0700 | [diff] [blame] | 1947 | |
| 1948 | skip: |
| 1949 | /* |
| 1950 | * If we are aborting explicitly, or if the syscall number is |
| 1951 | * now invalid, set the return value to -ENOSYS. |
| 1952 | */ |
| 1953 | regs->gpr[3] = -ENOSYS; |
| 1954 | return -1; |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void do_syscall_trace_leave(struct pt_regs *regs) |
| 1958 | { |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1959 | int step; |
| 1960 | |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 1961 | audit_syscall_exit(regs); |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1962 | |
Ian Munsie | 02424d8 | 2011-02-02 17:27:24 +0000 | [diff] [blame] | 1963 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 1964 | trace_sys_exit(regs, regs->result); |
| 1965 | |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 1966 | step = test_thread_flag(TIF_SINGLESTEP); |
| 1967 | if (step || test_thread_flag(TIF_SYSCALL_TRACE)) |
| 1968 | tracehook_report_syscall_exit(regs, step); |
Li Zhong | 22ecbe8 | 2013-05-13 16:16:40 +0000 | [diff] [blame] | 1969 | |
| 1970 | user_enter(); |
David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 1971 | } |