blob: bd2c49475473d0438d487f69cda7ce6cd1fcf6e3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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 Mackerrasb1239232005-10-20 09:11:29 +100011 * and Paul Mackerras (paulus@samba.org).
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/errno.h>
23#include <linux/ptrace.h>
Roland McGrathf65255e2007-12-20 03:57:34 -080024#include <linux/regset.h>
Roland McGrath4f72c422008-07-27 16:51:03 +100025#include <linux/tracehook.h>
Roland McGrath3caf06c2007-12-20 03:57:39 -080026#include <linux/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/user.h>
28#include <linux/security.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070029#include <linux/signal.h>
David Woodhouseea9c1022005-05-08 15:56:09 +010030#include <linux/seccomp.h>
31#include <linux/audit.h>
Ian Munsie02424d82011-02-02 17:27:24 +000032#include <trace/syscall.h>
K.Prasad5aae8a52010-06-15 11:35:19 +053033#include <linux/hw_breakpoint.h>
34#include <linux/perf_event.h>
Li Zhong22ecbe82013-05-13 16:16:40 +000035#include <linux/context_tracking.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080037#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/page.h>
39#include <asm/pgtable.h>
David Howellsae3a1972012-03-28 18:30:02 +010040#include <asm/switch_to.h>
Cyril Burc7a318b2016-08-10 15:44:46 +100041#include <asm/tm.h>
Daniel Axtens0545d542016-09-06 15:32:43 +100042#include <asm/asm-prototypes.h>
Paul Mackerras21a62902005-11-19 20:47:22 +110043
Ian Munsie02424d82011-02-02 17:27:24 +000044#define CREATE_TRACE_POINTS
45#include <trace/events/syscalls.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/*
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +100048 * The parameter save area on the stack is used to store arguments being passed
49 * to callee function and is located at fixed offset from stack pointer.
50 */
51#ifdef CONFIG_PPC32
52#define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
53#else /* CONFIG_PPC32 */
54#define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
55#endif
56
57struct pt_regs_offset {
58 const char *name;
59 int offset;
60};
61
62#define STR(s) #s /* convert to string */
63#define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
64#define GPR_OFFSET_NAME(num) \
Rashmica Gupta343c3322015-11-21 17:08:16 +110065 {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +100066 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
67#define REG_OFFSET_END {.name = NULL, .offset = 0}
68
Anshuman Khandual8c13f592016-07-28 10:57:38 +080069#define TVSO(f) (offsetof(struct thread_vr_state, f))
Anshuman Khandual9d3918f2016-07-28 10:57:39 +080070#define TFSO(f) (offsetof(struct thread_fp_state, f))
Anshuman Khandual08e1c012016-07-28 10:57:40 +080071#define TSO(f) (offsetof(struct thread_struct, f))
Anshuman Khandual8c13f592016-07-28 10:57:38 +080072
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +100073static const struct pt_regs_offset regoffset_table[] = {
74 GPR_OFFSET_NAME(0),
75 GPR_OFFSET_NAME(1),
76 GPR_OFFSET_NAME(2),
77 GPR_OFFSET_NAME(3),
78 GPR_OFFSET_NAME(4),
79 GPR_OFFSET_NAME(5),
80 GPR_OFFSET_NAME(6),
81 GPR_OFFSET_NAME(7),
82 GPR_OFFSET_NAME(8),
83 GPR_OFFSET_NAME(9),
84 GPR_OFFSET_NAME(10),
85 GPR_OFFSET_NAME(11),
86 GPR_OFFSET_NAME(12),
87 GPR_OFFSET_NAME(13),
88 GPR_OFFSET_NAME(14),
89 GPR_OFFSET_NAME(15),
90 GPR_OFFSET_NAME(16),
91 GPR_OFFSET_NAME(17),
92 GPR_OFFSET_NAME(18),
93 GPR_OFFSET_NAME(19),
94 GPR_OFFSET_NAME(20),
95 GPR_OFFSET_NAME(21),
96 GPR_OFFSET_NAME(22),
97 GPR_OFFSET_NAME(23),
98 GPR_OFFSET_NAME(24),
99 GPR_OFFSET_NAME(25),
100 GPR_OFFSET_NAME(26),
101 GPR_OFFSET_NAME(27),
102 GPR_OFFSET_NAME(28),
103 GPR_OFFSET_NAME(29),
104 GPR_OFFSET_NAME(30),
105 GPR_OFFSET_NAME(31),
106 REG_OFFSET_NAME(nip),
107 REG_OFFSET_NAME(msr),
108 REG_OFFSET_NAME(ctr),
109 REG_OFFSET_NAME(link),
110 REG_OFFSET_NAME(xer),
111 REG_OFFSET_NAME(ccr),
112#ifdef CONFIG_PPC64
113 REG_OFFSET_NAME(softe),
114#else
115 REG_OFFSET_NAME(mq),
116#endif
117 REG_OFFSET_NAME(trap),
118 REG_OFFSET_NAME(dar),
119 REG_OFFSET_NAME(dsisr),
120 REG_OFFSET_END,
121};
122
Cyril Burc7a318b2016-08-10 15:44:46 +1000123#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
124static void flush_tmregs_to_thread(struct task_struct *tsk)
125{
126 /*
127 * If task is not current, it will have been flushed already to
128 * it's thread_struct during __switch_to().
129 *
Gustavo Romerocd63f3c2017-07-19 01:44:13 -0400130 * A reclaim flushes ALL the state or if not in TM save TM SPRs
131 * in the appropriate thread structures from live.
Cyril Burc7a318b2016-08-10 15:44:46 +1000132 */
133
Gustavo Romeroc1fa0762017-09-13 22:13:48 -0400134 if ((!cpu_has_feature(CPU_FTR_TM)) || (tsk != current))
Gustavo Romerocd63f3c2017-07-19 01:44:13 -0400135 return;
Cyril Burc7a318b2016-08-10 15:44:46 +1000136
Gustavo Romerocd63f3c2017-07-19 01:44:13 -0400137 if (MSR_TM_SUSPENDED(mfmsr())) {
138 tm_reclaim_current(TM_CAUSE_SIGNAL);
139 } else {
140 tm_enable();
141 tm_save_sprs(&(tsk->thread));
142 }
Cyril Burc7a318b2016-08-10 15:44:46 +1000143}
144#else
145static inline void flush_tmregs_to_thread(struct task_struct *tsk) { }
146#endif
147
Mahesh Salgaonkar359e4282010-04-07 18:10:20 +1000148/**
149 * regs_query_register_offset() - query register offset from its name
150 * @name: the name of a register
151 *
152 * regs_query_register_offset() returns the offset of a register in struct
153 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
154 */
155int regs_query_register_offset(const char *name)
156{
157 const struct pt_regs_offset *roff;
158 for (roff = regoffset_table; roff->name != NULL; roff++)
159 if (!strcmp(roff->name, name))
160 return roff->offset;
161 return -EINVAL;
162}
163
164/**
165 * regs_query_register_name() - query register name from its offset
166 * @offset: the offset of a register in struct pt_regs.
167 *
168 * regs_query_register_name() returns the name of a register from its
169 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
170 */
171const char *regs_query_register_name(unsigned int offset)
172{
173 const struct pt_regs_offset *roff;
174 for (roff = regoffset_table; roff->name != NULL; roff++)
175 if (roff->offset == offset)
176 return roff->name;
177 return NULL;
178}
179
180/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * does not yet catch signals sent when the child dies.
182 * in exit.c or in signal.c.
183 */
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/*
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000186 * Set of msr bits that gdb can change on behalf of a process.
187 */
Dave Kleikamp172ae2e2010-02-08 11:50:57 +0000188#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000189#define MSR_DEBUGCHANGE 0
190#else
191#define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
192#endif
193
194/*
195 * Max register writeable via put_reg
196 */
197#ifdef CONFIG_PPC32
198#define PT_MAX_PUT_REG PT_MQ
199#else
200#define PT_MAX_PUT_REG PT_CCR
201#endif
202
Roland McGrath26f77132007-12-20 03:57:51 -0800203static unsigned long get_user_msr(struct task_struct *task)
204{
205 return task->thread.regs->msr | task->thread.fpexc_mode;
206}
207
208static int set_user_msr(struct task_struct *task, unsigned long msr)
209{
210 task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
211 task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
212 return 0;
213}
214
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800215#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
216static unsigned long get_user_ckpt_msr(struct task_struct *task)
217{
218 return task->thread.ckpt_regs.msr | task->thread.fpexc_mode;
219}
220
221static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr)
222{
223 task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE;
224 task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE;
225 return 0;
226}
227
228static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap)
229{
230 task->thread.ckpt_regs.trap = trap & 0xfff0;
231 return 0;
232}
233#endif
234
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000235#ifdef CONFIG_PPC64
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000236static int get_user_dscr(struct task_struct *task, unsigned long *data)
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000237{
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000238 *data = task->thread.dscr;
239 return 0;
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000240}
241
242static int set_user_dscr(struct task_struct *task, unsigned long dscr)
243{
244 task->thread.dscr = dscr;
245 task->thread.dscr_inherit = 1;
246 return 0;
247}
248#else
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000249static int get_user_dscr(struct task_struct *task, unsigned long *data)
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000250{
251 return -EIO;
252}
253
254static int set_user_dscr(struct task_struct *task, unsigned long dscr)
255{
256 return -EIO;
257}
258#endif
259
Roland McGrath26f77132007-12-20 03:57:51 -0800260/*
261 * We prevent mucking around with the reserved area of trap
262 * which are used internally by the kernel.
263 */
264static int set_user_trap(struct task_struct *task, unsigned long trap)
265{
266 task->thread.regs->trap = trap & 0xfff0;
267 return 0;
268}
269
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +1000270/*
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000271 * Get contents of register REGNO in task TASK.
272 */
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000273int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000274{
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000275 if ((task->thread.regs == NULL) || !data)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000276 return -EIO;
277
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000278 if (regno == PT_MSR) {
279 *data = get_user_msr(task);
280 return 0;
281 }
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000282
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000283 if (regno == PT_DSCR)
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000284 return get_user_dscr(task, data);
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000285
Madhavan Srinivasana8a4b032017-08-20 23:28:24 +0530286#ifdef CONFIG_PPC64
287 /*
288 * softe copies paca->soft_enabled variable state. Since soft_enabled is
289 * no more used as a flag, lets force usr to alway see the softe value as 1
290 * which means interrupts are not soft disabled.
291 */
292 if (regno == PT_SOFTE) {
293 *data = 1;
294 return 0;
295 }
296#endif
297
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +0000298 if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) {
299 *data = ((unsigned long *)task->thread.regs)[regno];
300 return 0;
301 }
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000302
303 return -EIO;
304}
305
306/*
307 * Write contents of register REGNO in task TASK.
308 */
309int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
310{
311 if (task->thread.regs == NULL)
312 return -EIO;
313
Roland McGrath26f77132007-12-20 03:57:51 -0800314 if (regno == PT_MSR)
315 return set_user_msr(task, data);
316 if (regno == PT_TRAP)
317 return set_user_trap(task, data);
Alexey Kardashevskiy1715a822013-01-10 20:29:09 +0000318 if (regno == PT_DSCR)
319 return set_user_dscr(task, data);
Roland McGrath26f77132007-12-20 03:57:51 -0800320
321 if (regno <= PT_MAX_PUT_REG) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000322 ((unsigned long *)task->thread.regs)[regno] = data;
323 return 0;
324 }
325 return -EIO;
326}
327
Roland McGrath44dd3f52007-12-20 03:57:55 -0800328static int gpr_get(struct task_struct *target, const struct user_regset *regset,
329 unsigned int pos, unsigned int count,
330 void *kbuf, void __user *ubuf)
331{
Mike Wolfa71f5d52011-03-21 11:14:53 +1100332 int i, ret;
Roland McGrath44dd3f52007-12-20 03:57:55 -0800333
334 if (target->thread.regs == NULL)
335 return -EIO;
336
Mike Wolfa71f5d52011-03-21 11:14:53 +1100337 if (!FULL_REGS(target->thread.regs)) {
338 /* We have a partial register set. Fill 14-31 with bogus values */
339 for (i = 14; i < 32; i++)
340 target->thread.regs->gpr[i] = NV_REG_POISON;
341 }
Roland McGrath44dd3f52007-12-20 03:57:55 -0800342
343 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
344 target->thread.regs,
345 0, offsetof(struct pt_regs, msr));
346 if (!ret) {
347 unsigned long msr = get_user_msr(target);
348 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
349 offsetof(struct pt_regs, msr),
350 offsetof(struct pt_regs, msr) +
351 sizeof(msr));
352 }
353
354 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
355 offsetof(struct pt_regs, msr) + sizeof(long));
356
357 if (!ret)
358 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
359 &target->thread.regs->orig_gpr3,
360 offsetof(struct pt_regs, orig_gpr3),
361 sizeof(struct pt_regs));
362 if (!ret)
363 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
364 sizeof(struct pt_regs), -1);
365
366 return ret;
367}
368
369static int gpr_set(struct task_struct *target, const struct user_regset *regset,
370 unsigned int pos, unsigned int count,
371 const void *kbuf, const void __user *ubuf)
372{
373 unsigned long reg;
374 int ret;
375
376 if (target->thread.regs == NULL)
377 return -EIO;
378
379 CHECK_FULL_REGS(target->thread.regs);
380
381 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
382 target->thread.regs,
383 0, PT_MSR * sizeof(reg));
384
385 if (!ret && count > 0) {
386 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
387 PT_MSR * sizeof(reg),
388 (PT_MSR + 1) * sizeof(reg));
389 if (!ret)
390 ret = set_user_msr(target, reg);
391 }
392
393 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
394 offsetof(struct pt_regs, msr) + sizeof(long));
395
396 if (!ret)
397 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
398 &target->thread.regs->orig_gpr3,
399 PT_ORIG_R3 * sizeof(reg),
400 (PT_MAX_PUT_REG + 1) * sizeof(reg));
401
402 if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
403 ret = user_regset_copyin_ignore(
404 &pos, &count, &kbuf, &ubuf,
405 (PT_MAX_PUT_REG + 1) * sizeof(reg),
406 PT_TRAP * sizeof(reg));
407
408 if (!ret && count > 0) {
409 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
410 PT_TRAP * sizeof(reg),
411 (PT_TRAP + 1) * sizeof(reg));
412 if (!ret)
413 ret = set_user_trap(target, reg);
414 }
415
416 if (!ret)
417 ret = user_regset_copyin_ignore(
418 &pos, &count, &kbuf, &ubuf,
419 (PT_TRAP + 1) * sizeof(reg), -1);
420
421 return ret;
422}
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000423
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800424/*
Cyril Burdc310662016-09-23 16:18:24 +1000425 * Regardless of transactions, 'fp_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000426 * value of all FPR registers and 'ckfp_state' holds the last checkpointed
Cyril Burdc310662016-09-23 16:18:24 +1000427 * value of all FPR registers for the current transaction.
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800428 *
429 * Userspace interface buffer layout:
430 *
431 * struct data {
432 * u64 fpr[32];
433 * u64 fpscr;
434 * };
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800435 */
Roland McGrathf65255e2007-12-20 03:57:34 -0800436static int fpr_get(struct task_struct *target, const struct user_regset *regset,
437 unsigned int pos, unsigned int count,
438 void *kbuf, void __user *ubuf)
439{
Michael Neulingc6e67712008-06-25 14:07:18 +1000440#ifdef CONFIG_VSX
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000441 u64 buf[33];
Michael Neulingc6e67712008-06-25 14:07:18 +1000442 int i;
Cyril Burdc310662016-09-23 16:18:24 +1000443
Roland McGrathf65255e2007-12-20 03:57:34 -0800444 flush_fp_to_thread(target);
445
Michael Neulingc6e67712008-06-25 14:07:18 +1000446 /* copy to local buffer then write that out */
447 for (i = 0; i < 32 ; i++)
448 buf[i] = target->thread.TS_FPR(i);
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000449 buf[32] = target->thread.fp_state.fpscr;
Michael Neulingc6e67712008-06-25 14:07:18 +1000450 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
Cyril Burdc310662016-09-23 16:18:24 +1000451#else
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000452 BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
Khem Raj1e407ee2016-04-25 09:19:17 -0700453 offsetof(struct thread_fp_state, fpr[32]));
Roland McGrathf65255e2007-12-20 03:57:34 -0800454
Cyril Burdc310662016-09-23 16:18:24 +1000455 flush_fp_to_thread(target);
456
Roland McGrathf65255e2007-12-20 03:57:34 -0800457 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000458 &target->thread.fp_state, 0, -1);
Michael Neulingc6e67712008-06-25 14:07:18 +1000459#endif
Roland McGrathf65255e2007-12-20 03:57:34 -0800460}
461
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800462/*
Cyril Burdc310662016-09-23 16:18:24 +1000463 * Regardless of transactions, 'fp_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000464 * value of all FPR registers and 'ckfp_state' holds the last checkpointed
Cyril Burdc310662016-09-23 16:18:24 +1000465 * value of all FPR registers for the current transaction.
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800466 *
467 * Userspace interface buffer layout:
468 *
469 * struct data {
470 * u64 fpr[32];
471 * u64 fpscr;
472 * };
473 *
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800474 */
Roland McGrathf65255e2007-12-20 03:57:34 -0800475static int fpr_set(struct task_struct *target, const struct user_regset *regset,
476 unsigned int pos, unsigned int count,
477 const void *kbuf, const void __user *ubuf)
478{
Michael Neulingc6e67712008-06-25 14:07:18 +1000479#ifdef CONFIG_VSX
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000480 u64 buf[33];
Michael Neulingc6e67712008-06-25 14:07:18 +1000481 int i;
Cyril Burdc310662016-09-23 16:18:24 +1000482
Roland McGrathf65255e2007-12-20 03:57:34 -0800483 flush_fp_to_thread(target);
484
Dave Martin99dfe802017-01-05 16:50:57 +0000485 for (i = 0; i < 32 ; i++)
486 buf[i] = target->thread.TS_FPR(i);
487 buf[32] = target->thread.fp_state.fpscr;
488
Anshuman Khandual1ec85492016-07-28 10:57:32 +0800489 /* copy to local buffer then write that out */
490 i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
491 if (i)
492 return i;
493
Michael Neulingc6e67712008-06-25 14:07:18 +1000494 for (i = 0; i < 32 ; i++)
495 target->thread.TS_FPR(i) = buf[i];
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000496 target->thread.fp_state.fpscr = buf[32];
Michael Neulingc6e67712008-06-25 14:07:18 +1000497 return 0;
Cyril Burdc310662016-09-23 16:18:24 +1000498#else
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000499 BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
Khem Raj1e407ee2016-04-25 09:19:17 -0700500 offsetof(struct thread_fp_state, fpr[32]));
Roland McGrathf65255e2007-12-20 03:57:34 -0800501
Cyril Burdc310662016-09-23 16:18:24 +1000502 flush_fp_to_thread(target);
503
Roland McGrathf65255e2007-12-20 03:57:34 -0800504 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000505 &target->thread.fp_state, 0, -1);
Michael Neulingc6e67712008-06-25 14:07:18 +1000506#endif
Roland McGrathf65255e2007-12-20 03:57:34 -0800507}
508
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000509#ifdef CONFIG_ALTIVEC
510/*
511 * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
512 * The transfer totals 34 quadword. Quadwords 0-31 contain the
513 * corresponding vector registers. Quadword 32 contains the vscr as the
514 * last word (offset 12) within that quadword. Quadword 33 contains the
515 * vrsave as the first word (offset 0) within the quadword.
516 *
517 * This definition of the VMX state is compatible with the current PPC32
518 * ptrace interface. This allows signal handling and ptrace to use the
519 * same structures. This also simplifies the implementation of a bi-arch
520 * (combined (32- and 64-bit) gdb.
521 */
522
Roland McGrath3caf06c2007-12-20 03:57:39 -0800523static int vr_active(struct task_struct *target,
524 const struct user_regset *regset)
525{
526 flush_altivec_to_thread(target);
527 return target->thread.used_vr ? regset->n : 0;
528}
529
Anshuman Khanduald844e272016-07-28 10:57:33 +0800530/*
Cyril Burdc310662016-09-23 16:18:24 +1000531 * Regardless of transactions, 'vr_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000532 * value of all the VMX registers and 'ckvr_state' holds the last
Cyril Burdc310662016-09-23 16:18:24 +1000533 * checkpointed value of all the VMX registers for the current
534 * transaction to fall back on in case it aborts.
Anshuman Khanduald844e272016-07-28 10:57:33 +0800535 *
536 * Userspace interface buffer layout:
537 *
538 * struct data {
539 * vector128 vr[32];
540 * vector128 vscr;
541 * vector128 vrsave;
542 * };
543 */
Roland McGrath3caf06c2007-12-20 03:57:39 -0800544static int vr_get(struct task_struct *target, const struct user_regset *regset,
545 unsigned int pos, unsigned int count,
546 void *kbuf, void __user *ubuf)
547{
548 int ret;
549
550 flush_altivec_to_thread(target);
551
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000552 BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
553 offsetof(struct thread_vr_state, vr[32]));
Roland McGrath3caf06c2007-12-20 03:57:39 -0800554
555 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
Cyril Burdc310662016-09-23 16:18:24 +1000556 &target->thread.vr_state, 0,
Roland McGrath3caf06c2007-12-20 03:57:39 -0800557 33 * sizeof(vector128));
558 if (!ret) {
559 /*
560 * Copy out only the low-order word of vrsave.
561 */
562 union {
563 elf_vrreg_t reg;
564 u32 word;
565 } vrsave;
566 memset(&vrsave, 0, sizeof(vrsave));
Anshuman Khanduald844e272016-07-28 10:57:33 +0800567
Roland McGrath3caf06c2007-12-20 03:57:39 -0800568 vrsave.word = target->thread.vrsave;
Anshuman Khanduald844e272016-07-28 10:57:33 +0800569
Roland McGrath3caf06c2007-12-20 03:57:39 -0800570 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
571 33 * sizeof(vector128), -1);
572 }
573
574 return ret;
575}
576
Anshuman Khanduald844e272016-07-28 10:57:33 +0800577/*
Cyril Burdc310662016-09-23 16:18:24 +1000578 * Regardless of transactions, 'vr_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000579 * value of all the VMX registers and 'ckvr_state' holds the last
Cyril Burdc310662016-09-23 16:18:24 +1000580 * checkpointed value of all the VMX registers for the current
581 * transaction to fall back on in case it aborts.
Anshuman Khanduald844e272016-07-28 10:57:33 +0800582 *
583 * Userspace interface buffer layout:
584 *
585 * struct data {
586 * vector128 vr[32];
587 * vector128 vscr;
588 * vector128 vrsave;
589 * };
590 */
Roland McGrath3caf06c2007-12-20 03:57:39 -0800591static int vr_set(struct task_struct *target, const struct user_regset *regset,
592 unsigned int pos, unsigned int count,
593 const void *kbuf, const void __user *ubuf)
594{
595 int ret;
596
597 flush_altivec_to_thread(target);
598
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000599 BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
600 offsetof(struct thread_vr_state, vr[32]));
Roland McGrath3caf06c2007-12-20 03:57:39 -0800601
602 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
Cyril Burdc310662016-09-23 16:18:24 +1000603 &target->thread.vr_state, 0,
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000604 33 * sizeof(vector128));
Roland McGrath3caf06c2007-12-20 03:57:39 -0800605 if (!ret && count > 0) {
606 /*
607 * We use only the first word of vrsave.
608 */
609 union {
610 elf_vrreg_t reg;
611 u32 word;
612 } vrsave;
613 memset(&vrsave, 0, sizeof(vrsave));
Anshuman Khanduald844e272016-07-28 10:57:33 +0800614
Roland McGrath3caf06c2007-12-20 03:57:39 -0800615 vrsave.word = target->thread.vrsave;
Cyril Burdc310662016-09-23 16:18:24 +1000616
Roland McGrath3caf06c2007-12-20 03:57:39 -0800617 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
618 33 * sizeof(vector128), -1);
Cyril Burdc310662016-09-23 16:18:24 +1000619 if (!ret)
Roland McGrath3caf06c2007-12-20 03:57:39 -0800620 target->thread.vrsave = vrsave.word;
621 }
622
623 return ret;
624}
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000625#endif /* CONFIG_ALTIVEC */
626
Michael Neulingce48b212008-06-25 14:07:18 +1000627#ifdef CONFIG_VSX
628/*
629 * Currently to set and and get all the vsx state, you need to call
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300630 * the fp and VMX calls as well. This only get/sets the lower 32
Michael Neulingce48b212008-06-25 14:07:18 +1000631 * 128bit VSX registers.
632 */
633
634static int vsr_active(struct task_struct *target,
635 const struct user_regset *regset)
636{
637 flush_vsx_to_thread(target);
638 return target->thread.used_vsr ? regset->n : 0;
639}
640
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800641/*
Cyril Burdc310662016-09-23 16:18:24 +1000642 * Regardless of transactions, 'fp_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000643 * value of all FPR registers and 'ckfp_state' holds the last
Cyril Burdc310662016-09-23 16:18:24 +1000644 * checkpointed value of all FPR registers for the current
645 * transaction.
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800646 *
647 * Userspace interface buffer layout:
648 *
649 * struct data {
650 * u64 vsx[32];
651 * };
652 */
Michael Neulingce48b212008-06-25 14:07:18 +1000653static int vsr_get(struct task_struct *target, const struct user_regset *regset,
654 unsigned int pos, unsigned int count,
655 void *kbuf, void __user *ubuf)
656{
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000657 u64 buf[32];
Michael Neulingf3e909c2008-07-01 14:01:39 +1000658 int ret, i;
Michael Neulingce48b212008-06-25 14:07:18 +1000659
Cyril Burdc310662016-09-23 16:18:24 +1000660 flush_tmregs_to_thread(target);
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800661 flush_fp_to_thread(target);
662 flush_altivec_to_thread(target);
Michael Neulingce48b212008-06-25 14:07:18 +1000663 flush_vsx_to_thread(target);
664
Michael Neulingf3e909c2008-07-01 14:01:39 +1000665 for (i = 0; i < 32 ; i++)
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000666 buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
Cyril Burdc310662016-09-23 16:18:24 +1000667
Michael Neulingce48b212008-06-25 14:07:18 +1000668 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
Michael Neulingf3e909c2008-07-01 14:01:39 +1000669 buf, 0, 32 * sizeof(double));
Michael Neulingce48b212008-06-25 14:07:18 +1000670
671 return ret;
672}
673
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800674/*
Cyril Burdc310662016-09-23 16:18:24 +1000675 * Regardless of transactions, 'fp_state' holds the current running
Cyril Bur000ec282016-09-23 16:18:25 +1000676 * value of all FPR registers and 'ckfp_state' holds the last
Cyril Burdc310662016-09-23 16:18:24 +1000677 * checkpointed value of all FPR registers for the current
678 * transaction.
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800679 *
680 * Userspace interface buffer layout:
681 *
682 * struct data {
683 * u64 vsx[32];
684 * };
685 */
Michael Neulingce48b212008-06-25 14:07:18 +1000686static int vsr_set(struct task_struct *target, const struct user_regset *regset,
687 unsigned int pos, unsigned int count,
688 const void *kbuf, const void __user *ubuf)
689{
Paul Mackerrasde79f7b2013-09-10 20:20:42 +1000690 u64 buf[32];
Michael Neulingf3e909c2008-07-01 14:01:39 +1000691 int ret,i;
Michael Neulingce48b212008-06-25 14:07:18 +1000692
Cyril Burdc310662016-09-23 16:18:24 +1000693 flush_tmregs_to_thread(target);
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800694 flush_fp_to_thread(target);
695 flush_altivec_to_thread(target);
Michael Neulingce48b212008-06-25 14:07:18 +1000696 flush_vsx_to_thread(target);
697
Dave Martin99dfe802017-01-05 16:50:57 +0000698 for (i = 0; i < 32 ; i++)
699 buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
700
Michael Neulingce48b212008-06-25 14:07:18 +1000701 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
Michael Neulingf3e909c2008-07-01 14:01:39 +1000702 buf, 0, 32 * sizeof(double));
Cyril Burdc310662016-09-23 16:18:24 +1000703 if (!ret)
Anshuman Khandual94b7d362016-07-28 10:57:34 +0800704 for (i = 0; i < 32 ; i++)
Cyril Burdc310662016-09-23 16:18:24 +1000705 target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
Michael Neulingce48b212008-06-25 14:07:18 +1000706
707 return ret;
708}
709#endif /* CONFIG_VSX */
710
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000711#ifdef CONFIG_SPE
712
713/*
714 * For get_evrregs/set_evrregs functions 'data' has the following layout:
715 *
716 * struct {
717 * u32 evr[32];
718 * u64 acc;
719 * u32 spefscr;
720 * }
721 */
722
Roland McGratha4e4b172007-12-20 03:57:48 -0800723static int evr_active(struct task_struct *target,
724 const struct user_regset *regset)
725{
726 flush_spe_to_thread(target);
727 return target->thread.used_spe ? regset->n : 0;
728}
729
730static int evr_get(struct task_struct *target, const struct user_regset *regset,
731 unsigned int pos, unsigned int count,
732 void *kbuf, void __user *ubuf)
733{
734 int ret;
735
736 flush_spe_to_thread(target);
737
738 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
739 &target->thread.evr,
740 0, sizeof(target->thread.evr));
741
742 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
743 offsetof(struct thread_struct, spefscr));
744
745 if (!ret)
746 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
747 &target->thread.acc,
748 sizeof(target->thread.evr), -1);
749
750 return ret;
751}
752
753static int evr_set(struct task_struct *target, const struct user_regset *regset,
754 unsigned int pos, unsigned int count,
755 const void *kbuf, const void __user *ubuf)
756{
757 int ret;
758
759 flush_spe_to_thread(target);
760
761 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
762 &target->thread.evr,
763 0, sizeof(target->thread.evr));
764
765 BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
766 offsetof(struct thread_struct, spefscr));
767
768 if (!ret)
769 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
770 &target->thread.acc,
771 sizeof(target->thread.evr), -1);
772
773 return ret;
774}
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +1000775#endif /* CONFIG_SPE */
776
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800777#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
778/**
779 * tm_cgpr_active - get active number of registers in CGPR
780 * @target: The target task.
781 * @regset: The user regset structure.
782 *
783 * This function checks for the active number of available
784 * regisers in transaction checkpointed GPR category.
785 */
786static int tm_cgpr_active(struct task_struct *target,
787 const struct user_regset *regset)
788{
789 if (!cpu_has_feature(CPU_FTR_TM))
790 return -ENODEV;
791
792 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
793 return 0;
794
795 return regset->n;
796}
797
798/**
799 * tm_cgpr_get - get CGPR registers
800 * @target: The target task.
801 * @regset: The user regset structure.
802 * @pos: The buffer position.
803 * @count: Number of bytes to copy.
804 * @kbuf: Kernel buffer to copy from.
805 * @ubuf: User buffer to copy into.
806 *
807 * This function gets transaction checkpointed GPR registers.
808 *
809 * When the transaction is active, 'ckpt_regs' holds all the checkpointed
810 * GPR register values for the current transaction to fall back on if it
811 * aborts in between. This function gets those checkpointed GPR registers.
812 * The userspace interface buffer layout is as follows.
813 *
814 * struct data {
815 * struct pt_regs ckpt_regs;
816 * };
817 */
818static int tm_cgpr_get(struct task_struct *target,
819 const struct user_regset *regset,
820 unsigned int pos, unsigned int count,
821 void *kbuf, void __user *ubuf)
822{
823 int ret;
824
825 if (!cpu_has_feature(CPU_FTR_TM))
826 return -ENODEV;
827
828 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
829 return -ENODATA;
830
Cyril Burdc310662016-09-23 16:18:24 +1000831 flush_tmregs_to_thread(target);
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800832 flush_fp_to_thread(target);
833 flush_altivec_to_thread(target);
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800834
835 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
836 &target->thread.ckpt_regs,
837 0, offsetof(struct pt_regs, msr));
838 if (!ret) {
839 unsigned long msr = get_user_ckpt_msr(target);
840
841 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
842 offsetof(struct pt_regs, msr),
843 offsetof(struct pt_regs, msr) +
844 sizeof(msr));
845 }
846
847 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
848 offsetof(struct pt_regs, msr) + sizeof(long));
849
850 if (!ret)
851 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
852 &target->thread.ckpt_regs.orig_gpr3,
853 offsetof(struct pt_regs, orig_gpr3),
854 sizeof(struct pt_regs));
855 if (!ret)
856 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
857 sizeof(struct pt_regs), -1);
858
859 return ret;
860}
861
862/*
863 * tm_cgpr_set - set the CGPR registers
864 * @target: The target task.
865 * @regset: The user regset structure.
866 * @pos: The buffer position.
867 * @count: Number of bytes to copy.
868 * @kbuf: Kernel buffer to copy into.
869 * @ubuf: User buffer to copy from.
870 *
871 * This function sets in transaction checkpointed GPR registers.
872 *
873 * When the transaction is active, 'ckpt_regs' holds the checkpointed
874 * GPR register values for the current transaction to fall back on if it
875 * aborts in between. This function sets those checkpointed GPR registers.
876 * The userspace interface buffer layout is as follows.
877 *
878 * struct data {
879 * struct pt_regs ckpt_regs;
880 * };
881 */
882static int tm_cgpr_set(struct task_struct *target,
883 const struct user_regset *regset,
884 unsigned int pos, unsigned int count,
885 const void *kbuf, const void __user *ubuf)
886{
887 unsigned long reg;
888 int ret;
889
890 if (!cpu_has_feature(CPU_FTR_TM))
891 return -ENODEV;
892
893 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
894 return -ENODATA;
895
Cyril Burdc310662016-09-23 16:18:24 +1000896 flush_tmregs_to_thread(target);
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800897 flush_fp_to_thread(target);
898 flush_altivec_to_thread(target);
Anshuman Khandual25847fb2016-07-28 10:57:36 +0800899
900 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
901 &target->thread.ckpt_regs,
902 0, PT_MSR * sizeof(reg));
903
904 if (!ret && count > 0) {
905 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
906 PT_MSR * sizeof(reg),
907 (PT_MSR + 1) * sizeof(reg));
908 if (!ret)
909 ret = set_user_ckpt_msr(target, reg);
910 }
911
912 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
913 offsetof(struct pt_regs, msr) + sizeof(long));
914
915 if (!ret)
916 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
917 &target->thread.ckpt_regs.orig_gpr3,
918 PT_ORIG_R3 * sizeof(reg),
919 (PT_MAX_PUT_REG + 1) * sizeof(reg));
920
921 if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
922 ret = user_regset_copyin_ignore(
923 &pos, &count, &kbuf, &ubuf,
924 (PT_MAX_PUT_REG + 1) * sizeof(reg),
925 PT_TRAP * sizeof(reg));
926
927 if (!ret && count > 0) {
928 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
929 PT_TRAP * sizeof(reg),
930 (PT_TRAP + 1) * sizeof(reg));
931 if (!ret)
932 ret = set_user_ckpt_trap(target, reg);
933 }
934
935 if (!ret)
936 ret = user_regset_copyin_ignore(
937 &pos, &count, &kbuf, &ubuf,
938 (PT_TRAP + 1) * sizeof(reg), -1);
939
940 return ret;
941}
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +0800942
943/**
944 * tm_cfpr_active - get active number of registers in CFPR
945 * @target: The target task.
946 * @regset: The user regset structure.
947 *
948 * This function checks for the active number of available
949 * regisers in transaction checkpointed FPR category.
950 */
951static int tm_cfpr_active(struct task_struct *target,
952 const struct user_regset *regset)
953{
954 if (!cpu_has_feature(CPU_FTR_TM))
955 return -ENODEV;
956
957 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
958 return 0;
959
960 return regset->n;
961}
962
963/**
964 * tm_cfpr_get - get CFPR registers
965 * @target: The target task.
966 * @regset: The user regset structure.
967 * @pos: The buffer position.
968 * @count: Number of bytes to copy.
969 * @kbuf: Kernel buffer to copy from.
970 * @ubuf: User buffer to copy into.
971 *
972 * This function gets in transaction checkpointed FPR registers.
973 *
Cyril Bur000ec282016-09-23 16:18:25 +1000974 * When the transaction is active 'ckfp_state' holds the checkpointed
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +0800975 * values for the current transaction to fall back on if it aborts
976 * in between. This function gets those checkpointed FPR registers.
977 * The userspace interface buffer layout is as follows.
978 *
979 * struct data {
980 * u64 fpr[32];
981 * u64 fpscr;
982 *};
983 */
984static int tm_cfpr_get(struct task_struct *target,
985 const struct user_regset *regset,
986 unsigned int pos, unsigned int count,
987 void *kbuf, void __user *ubuf)
988{
989 u64 buf[33];
990 int i;
991
992 if (!cpu_has_feature(CPU_FTR_TM))
993 return -ENODEV;
994
995 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
996 return -ENODATA;
997
Cyril Burdc310662016-09-23 16:18:24 +1000998 flush_tmregs_to_thread(target);
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +0800999 flush_fp_to_thread(target);
1000 flush_altivec_to_thread(target);
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001001
1002 /* copy to local buffer then write that out */
1003 for (i = 0; i < 32 ; i++)
Cyril Bur000ec282016-09-23 16:18:25 +10001004 buf[i] = target->thread.TS_CKFPR(i);
1005 buf[32] = target->thread.ckfp_state.fpscr;
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001006 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
1007}
1008
1009/**
1010 * tm_cfpr_set - set CFPR registers
1011 * @target: The target task.
1012 * @regset: The user regset structure.
1013 * @pos: The buffer position.
1014 * @count: Number of bytes to copy.
1015 * @kbuf: Kernel buffer to copy into.
1016 * @ubuf: User buffer to copy from.
1017 *
1018 * This function sets in transaction checkpointed FPR registers.
1019 *
Cyril Bur000ec282016-09-23 16:18:25 +10001020 * When the transaction is active 'ckfp_state' holds the checkpointed
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001021 * FPR register values for the current transaction to fall back on
1022 * if it aborts in between. This function sets these checkpointed
1023 * FPR registers. The userspace interface buffer layout is as follows.
1024 *
1025 * struct data {
1026 * u64 fpr[32];
1027 * u64 fpscr;
1028 *};
1029 */
1030static int tm_cfpr_set(struct task_struct *target,
1031 const struct user_regset *regset,
1032 unsigned int pos, unsigned int count,
1033 const void *kbuf, const void __user *ubuf)
1034{
1035 u64 buf[33];
1036 int i;
1037
1038 if (!cpu_has_feature(CPU_FTR_TM))
1039 return -ENODEV;
1040
1041 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1042 return -ENODATA;
1043
Cyril Burdc310662016-09-23 16:18:24 +10001044 flush_tmregs_to_thread(target);
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001045 flush_fp_to_thread(target);
1046 flush_altivec_to_thread(target);
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001047
Dave Martinb34ca602017-01-05 16:50:57 +00001048 for (i = 0; i < 32; i++)
1049 buf[i] = target->thread.TS_CKFPR(i);
1050 buf[32] = target->thread.ckfp_state.fpscr;
1051
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001052 /* copy to local buffer then write that out */
1053 i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
1054 if (i)
1055 return i;
1056 for (i = 0; i < 32 ; i++)
Cyril Bur000ec282016-09-23 16:18:25 +10001057 target->thread.TS_CKFPR(i) = buf[i];
1058 target->thread.ckfp_state.fpscr = buf[32];
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001059 return 0;
1060}
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001061
1062/**
1063 * tm_cvmx_active - get active number of registers in CVMX
1064 * @target: The target task.
1065 * @regset: The user regset structure.
1066 *
1067 * This function checks for the active number of available
1068 * regisers in checkpointed VMX category.
1069 */
1070static int tm_cvmx_active(struct task_struct *target,
1071 const struct user_regset *regset)
1072{
1073 if (!cpu_has_feature(CPU_FTR_TM))
1074 return -ENODEV;
1075
1076 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1077 return 0;
1078
1079 return regset->n;
1080}
1081
1082/**
1083 * tm_cvmx_get - get CMVX registers
1084 * @target: The target task.
1085 * @regset: The user regset structure.
1086 * @pos: The buffer position.
1087 * @count: Number of bytes to copy.
1088 * @kbuf: Kernel buffer to copy from.
1089 * @ubuf: User buffer to copy into.
1090 *
1091 * This function gets in transaction checkpointed VMX registers.
1092 *
Cyril Bur000ec282016-09-23 16:18:25 +10001093 * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001094 * the checkpointed values for the current transaction to fall
1095 * back on if it aborts in between. The userspace interface buffer
1096 * layout is as follows.
1097 *
1098 * struct data {
1099 * vector128 vr[32];
1100 * vector128 vscr;
1101 * vector128 vrsave;
1102 *};
1103 */
1104static int tm_cvmx_get(struct task_struct *target,
1105 const struct user_regset *regset,
1106 unsigned int pos, unsigned int count,
1107 void *kbuf, void __user *ubuf)
1108{
1109 int ret;
1110
1111 BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
1112
1113 if (!cpu_has_feature(CPU_FTR_TM))
1114 return -ENODEV;
1115
1116 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1117 return -ENODATA;
1118
1119 /* Flush the state */
Cyril Burdc310662016-09-23 16:18:24 +10001120 flush_tmregs_to_thread(target);
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001121 flush_fp_to_thread(target);
1122 flush_altivec_to_thread(target);
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001123
1124 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
Cyril Bur000ec282016-09-23 16:18:25 +10001125 &target->thread.ckvr_state, 0,
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001126 33 * sizeof(vector128));
1127 if (!ret) {
1128 /*
1129 * Copy out only the low-order word of vrsave.
1130 */
1131 union {
1132 elf_vrreg_t reg;
1133 u32 word;
1134 } vrsave;
1135 memset(&vrsave, 0, sizeof(vrsave));
Cyril Bur000ec282016-09-23 16:18:25 +10001136 vrsave.word = target->thread.ckvrsave;
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001137 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
1138 33 * sizeof(vector128), -1);
1139 }
1140
1141 return ret;
1142}
1143
1144/**
1145 * tm_cvmx_set - set CMVX registers
1146 * @target: The target task.
1147 * @regset: The user regset structure.
1148 * @pos: The buffer position.
1149 * @count: Number of bytes to copy.
1150 * @kbuf: Kernel buffer to copy into.
1151 * @ubuf: User buffer to copy from.
1152 *
1153 * This function sets in transaction checkpointed VMX registers.
1154 *
Cyril Bur000ec282016-09-23 16:18:25 +10001155 * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001156 * the checkpointed values for the current transaction to fall
1157 * back on if it aborts in between. The userspace interface buffer
1158 * layout is as follows.
1159 *
1160 * struct data {
1161 * vector128 vr[32];
1162 * vector128 vscr;
1163 * vector128 vrsave;
1164 *};
1165 */
1166static int tm_cvmx_set(struct task_struct *target,
1167 const struct user_regset *regset,
1168 unsigned int pos, unsigned int count,
1169 const void *kbuf, const void __user *ubuf)
1170{
1171 int ret;
1172
1173 BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
1174
1175 if (!cpu_has_feature(CPU_FTR_TM))
1176 return -ENODEV;
1177
1178 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1179 return -ENODATA;
1180
Cyril Burdc310662016-09-23 16:18:24 +10001181 flush_tmregs_to_thread(target);
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001182 flush_fp_to_thread(target);
1183 flush_altivec_to_thread(target);
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001184
1185 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
Cyril Bur000ec282016-09-23 16:18:25 +10001186 &target->thread.ckvr_state, 0,
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001187 33 * sizeof(vector128));
1188 if (!ret && count > 0) {
1189 /*
1190 * We use only the low-order word of vrsave.
1191 */
1192 union {
1193 elf_vrreg_t reg;
1194 u32 word;
1195 } vrsave;
1196 memset(&vrsave, 0, sizeof(vrsave));
Cyril Bur000ec282016-09-23 16:18:25 +10001197 vrsave.word = target->thread.ckvrsave;
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001198 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
1199 33 * sizeof(vector128), -1);
1200 if (!ret)
Cyril Bur000ec282016-09-23 16:18:25 +10001201 target->thread.ckvrsave = vrsave.word;
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001202 }
1203
1204 return ret;
1205}
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001206
1207/**
1208 * tm_cvsx_active - get active number of registers in CVSX
1209 * @target: The target task.
1210 * @regset: The user regset structure.
1211 *
1212 * This function checks for the active number of available
1213 * regisers in transaction checkpointed VSX category.
1214 */
1215static int tm_cvsx_active(struct task_struct *target,
1216 const struct user_regset *regset)
1217{
1218 if (!cpu_has_feature(CPU_FTR_TM))
1219 return -ENODEV;
1220
1221 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1222 return 0;
1223
1224 flush_vsx_to_thread(target);
1225 return target->thread.used_vsr ? regset->n : 0;
1226}
1227
1228/**
1229 * tm_cvsx_get - get CVSX registers
1230 * @target: The target task.
1231 * @regset: The user regset structure.
1232 * @pos: The buffer position.
1233 * @count: Number of bytes to copy.
1234 * @kbuf: Kernel buffer to copy from.
1235 * @ubuf: User buffer to copy into.
1236 *
1237 * This function gets in transaction checkpointed VSX registers.
1238 *
Cyril Bur000ec282016-09-23 16:18:25 +10001239 * When the transaction is active 'ckfp_state' holds the checkpointed
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001240 * values for the current transaction to fall back on if it aborts
1241 * in between. This function gets those checkpointed VSX registers.
1242 * The userspace interface buffer layout is as follows.
1243 *
1244 * struct data {
1245 * u64 vsx[32];
1246 *};
1247 */
1248static int tm_cvsx_get(struct task_struct *target,
1249 const struct user_regset *regset,
1250 unsigned int pos, unsigned int count,
1251 void *kbuf, void __user *ubuf)
1252{
1253 u64 buf[32];
1254 int ret, i;
1255
1256 if (!cpu_has_feature(CPU_FTR_TM))
1257 return -ENODEV;
1258
1259 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1260 return -ENODATA;
1261
1262 /* Flush the state */
Cyril Burdc310662016-09-23 16:18:24 +10001263 flush_tmregs_to_thread(target);
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001264 flush_fp_to_thread(target);
1265 flush_altivec_to_thread(target);
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001266 flush_vsx_to_thread(target);
1267
1268 for (i = 0; i < 32 ; i++)
Cyril Bur000ec282016-09-23 16:18:25 +10001269 buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001270 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1271 buf, 0, 32 * sizeof(double));
1272
1273 return ret;
1274}
1275
1276/**
1277 * tm_cvsx_set - set CFPR registers
1278 * @target: The target task.
1279 * @regset: The user regset structure.
1280 * @pos: The buffer position.
1281 * @count: Number of bytes to copy.
1282 * @kbuf: Kernel buffer to copy into.
1283 * @ubuf: User buffer to copy from.
1284 *
1285 * This function sets in transaction checkpointed VSX registers.
1286 *
Cyril Bur000ec282016-09-23 16:18:25 +10001287 * When the transaction is active 'ckfp_state' holds the checkpointed
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001288 * VSX register values for the current transaction to fall back on
1289 * if it aborts in between. This function sets these checkpointed
1290 * FPR registers. The userspace interface buffer layout is as follows.
1291 *
1292 * struct data {
1293 * u64 vsx[32];
1294 *};
1295 */
1296static int tm_cvsx_set(struct task_struct *target,
1297 const struct user_regset *regset,
1298 unsigned int pos, unsigned int count,
1299 const void *kbuf, const void __user *ubuf)
1300{
1301 u64 buf[32];
1302 int ret, i;
1303
1304 if (!cpu_has_feature(CPU_FTR_TM))
1305 return -ENODEV;
1306
1307 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1308 return -ENODATA;
1309
1310 /* Flush the state */
Cyril Burdc310662016-09-23 16:18:24 +10001311 flush_tmregs_to_thread(target);
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001312 flush_fp_to_thread(target);
1313 flush_altivec_to_thread(target);
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001314 flush_vsx_to_thread(target);
1315
Dave Martinb34ca602017-01-05 16:50:57 +00001316 for (i = 0; i < 32 ; i++)
1317 buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
1318
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001319 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1320 buf, 0, 32 * sizeof(double));
Cyril Burdc310662016-09-23 16:18:24 +10001321 if (!ret)
1322 for (i = 0; i < 32 ; i++)
Cyril Bur000ec282016-09-23 16:18:25 +10001323 target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001324
1325 return ret;
1326}
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001327
1328/**
1329 * tm_spr_active - get active number of registers in TM SPR
1330 * @target: The target task.
1331 * @regset: The user regset structure.
1332 *
1333 * This function checks the active number of available
1334 * regisers in the transactional memory SPR category.
1335 */
1336static int tm_spr_active(struct task_struct *target,
1337 const struct user_regset *regset)
1338{
1339 if (!cpu_has_feature(CPU_FTR_TM))
1340 return -ENODEV;
1341
1342 return regset->n;
1343}
1344
1345/**
1346 * tm_spr_get - get the TM related SPR registers
1347 * @target: The target task.
1348 * @regset: The user regset structure.
1349 * @pos: The buffer position.
1350 * @count: Number of bytes to copy.
1351 * @kbuf: Kernel buffer to copy from.
1352 * @ubuf: User buffer to copy into.
1353 *
1354 * This function gets transactional memory related SPR registers.
1355 * The userspace interface buffer layout is as follows.
1356 *
1357 * struct {
1358 * u64 tm_tfhar;
1359 * u64 tm_texasr;
1360 * u64 tm_tfiar;
1361 * };
1362 */
1363static int tm_spr_get(struct task_struct *target,
1364 const struct user_regset *regset,
1365 unsigned int pos, unsigned int count,
1366 void *kbuf, void __user *ubuf)
1367{
1368 int ret;
1369
1370 /* Build tests */
1371 BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
1372 BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
1373 BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
1374
1375 if (!cpu_has_feature(CPU_FTR_TM))
1376 return -ENODEV;
1377
1378 /* Flush the states */
Cyril Burdc310662016-09-23 16:18:24 +10001379 flush_tmregs_to_thread(target);
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001380 flush_fp_to_thread(target);
1381 flush_altivec_to_thread(target);
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001382
1383 /* TFHAR register */
1384 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1385 &target->thread.tm_tfhar, 0, sizeof(u64));
1386
1387 /* TEXASR register */
1388 if (!ret)
1389 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1390 &target->thread.tm_texasr, sizeof(u64),
1391 2 * sizeof(u64));
1392
1393 /* TFIAR register */
1394 if (!ret)
1395 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1396 &target->thread.tm_tfiar,
1397 2 * sizeof(u64), 3 * sizeof(u64));
1398 return ret;
1399}
1400
1401/**
1402 * tm_spr_set - set the TM related SPR registers
1403 * @target: The target task.
1404 * @regset: The user regset structure.
1405 * @pos: The buffer position.
1406 * @count: Number of bytes to copy.
1407 * @kbuf: Kernel buffer to copy into.
1408 * @ubuf: User buffer to copy from.
1409 *
1410 * This function sets transactional memory related SPR registers.
1411 * The userspace interface buffer layout is as follows.
1412 *
1413 * struct {
1414 * u64 tm_tfhar;
1415 * u64 tm_texasr;
1416 * u64 tm_tfiar;
1417 * };
1418 */
1419static int tm_spr_set(struct task_struct *target,
1420 const struct user_regset *regset,
1421 unsigned int pos, unsigned int count,
1422 const void *kbuf, const void __user *ubuf)
1423{
1424 int ret;
1425
1426 /* Build tests */
1427 BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
1428 BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
1429 BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
1430
1431 if (!cpu_has_feature(CPU_FTR_TM))
1432 return -ENODEV;
1433
1434 /* Flush the states */
Cyril Burdc310662016-09-23 16:18:24 +10001435 flush_tmregs_to_thread(target);
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001436 flush_fp_to_thread(target);
1437 flush_altivec_to_thread(target);
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001438
1439 /* TFHAR register */
1440 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1441 &target->thread.tm_tfhar, 0, sizeof(u64));
1442
1443 /* TEXASR register */
1444 if (!ret)
1445 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1446 &target->thread.tm_texasr, sizeof(u64),
1447 2 * sizeof(u64));
1448
1449 /* TFIAR register */
1450 if (!ret)
1451 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1452 &target->thread.tm_tfiar,
1453 2 * sizeof(u64), 3 * sizeof(u64));
1454 return ret;
1455}
Anshuman Khandualc45dc902016-07-28 10:57:41 +08001456
1457static int tm_tar_active(struct task_struct *target,
1458 const struct user_regset *regset)
1459{
1460 if (!cpu_has_feature(CPU_FTR_TM))
1461 return -ENODEV;
1462
1463 if (MSR_TM_ACTIVE(target->thread.regs->msr))
1464 return regset->n;
1465
1466 return 0;
1467}
1468
1469static int tm_tar_get(struct task_struct *target,
1470 const struct user_regset *regset,
1471 unsigned int pos, unsigned int count,
1472 void *kbuf, void __user *ubuf)
1473{
1474 int ret;
1475
1476 if (!cpu_has_feature(CPU_FTR_TM))
1477 return -ENODEV;
1478
1479 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1480 return -ENODATA;
1481
1482 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1483 &target->thread.tm_tar, 0, sizeof(u64));
1484 return ret;
1485}
1486
1487static int tm_tar_set(struct task_struct *target,
1488 const struct user_regset *regset,
1489 unsigned int pos, unsigned int count,
1490 const void *kbuf, const void __user *ubuf)
1491{
1492 int ret;
1493
1494 if (!cpu_has_feature(CPU_FTR_TM))
1495 return -ENODEV;
1496
1497 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1498 return -ENODATA;
1499
1500 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1501 &target->thread.tm_tar, 0, sizeof(u64));
1502 return ret;
1503}
1504
1505static int tm_ppr_active(struct task_struct *target,
1506 const struct user_regset *regset)
1507{
1508 if (!cpu_has_feature(CPU_FTR_TM))
1509 return -ENODEV;
1510
1511 if (MSR_TM_ACTIVE(target->thread.regs->msr))
1512 return regset->n;
1513
1514 return 0;
1515}
1516
1517
1518static int tm_ppr_get(struct task_struct *target,
1519 const struct user_regset *regset,
1520 unsigned int pos, unsigned int count,
1521 void *kbuf, void __user *ubuf)
1522{
1523 int ret;
1524
1525 if (!cpu_has_feature(CPU_FTR_TM))
1526 return -ENODEV;
1527
1528 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1529 return -ENODATA;
1530
1531 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1532 &target->thread.tm_ppr, 0, sizeof(u64));
1533 return ret;
1534}
1535
1536static int tm_ppr_set(struct task_struct *target,
1537 const struct user_regset *regset,
1538 unsigned int pos, unsigned int count,
1539 const void *kbuf, const void __user *ubuf)
1540{
1541 int ret;
1542
1543 if (!cpu_has_feature(CPU_FTR_TM))
1544 return -ENODEV;
1545
1546 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1547 return -ENODATA;
1548
1549 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1550 &target->thread.tm_ppr, 0, sizeof(u64));
1551 return ret;
1552}
1553
1554static int tm_dscr_active(struct task_struct *target,
1555 const struct user_regset *regset)
1556{
1557 if (!cpu_has_feature(CPU_FTR_TM))
1558 return -ENODEV;
1559
1560 if (MSR_TM_ACTIVE(target->thread.regs->msr))
1561 return regset->n;
1562
1563 return 0;
1564}
1565
1566static int tm_dscr_get(struct task_struct *target,
1567 const struct user_regset *regset,
1568 unsigned int pos, unsigned int count,
1569 void *kbuf, void __user *ubuf)
1570{
1571 int ret;
1572
1573 if (!cpu_has_feature(CPU_FTR_TM))
1574 return -ENODEV;
1575
1576 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1577 return -ENODATA;
1578
1579 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1580 &target->thread.tm_dscr, 0, sizeof(u64));
1581 return ret;
1582}
1583
1584static int tm_dscr_set(struct task_struct *target,
1585 const struct user_regset *regset,
1586 unsigned int pos, unsigned int count,
1587 const void *kbuf, const void __user *ubuf)
1588{
1589 int ret;
1590
1591 if (!cpu_has_feature(CPU_FTR_TM))
1592 return -ENODEV;
1593
1594 if (!MSR_TM_ACTIVE(target->thread.regs->msr))
1595 return -ENODATA;
1596
1597 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1598 &target->thread.tm_dscr, 0, sizeof(u64));
1599 return ret;
1600}
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001601#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10001602
Anshuman Khandualfa439812016-07-28 10:57:42 +08001603#ifdef CONFIG_PPC64
1604static int ppr_get(struct task_struct *target,
1605 const struct user_regset *regset,
1606 unsigned int pos, unsigned int count,
1607 void *kbuf, void __user *ubuf)
1608{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001609 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1610 &target->thread.ppr, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001611}
1612
1613static int ppr_set(struct task_struct *target,
1614 const struct user_regset *regset,
1615 unsigned int pos, unsigned int count,
1616 const void *kbuf, const void __user *ubuf)
1617{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001618 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1619 &target->thread.ppr, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001620}
1621
1622static int dscr_get(struct task_struct *target,
1623 const struct user_regset *regset,
1624 unsigned int pos, unsigned int count,
1625 void *kbuf, void __user *ubuf)
1626{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001627 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1628 &target->thread.dscr, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001629}
1630static int dscr_set(struct task_struct *target,
1631 const struct user_regset *regset,
1632 unsigned int pos, unsigned int count,
1633 const void *kbuf, const void __user *ubuf)
1634{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001635 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1636 &target->thread.dscr, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001637}
1638#endif
1639#ifdef CONFIG_PPC_BOOK3S_64
1640static int tar_get(struct task_struct *target,
1641 const struct user_regset *regset,
1642 unsigned int pos, unsigned int count,
1643 void *kbuf, void __user *ubuf)
1644{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001645 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1646 &target->thread.tar, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001647}
1648static int tar_set(struct task_struct *target,
1649 const struct user_regset *regset,
1650 unsigned int pos, unsigned int count,
1651 const void *kbuf, const void __user *ubuf)
1652{
Masahiro Yamada7f2462a2016-09-06 20:21:50 +09001653 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1654 &target->thread.tar, 0, sizeof(u64));
Anshuman Khandualfa439812016-07-28 10:57:42 +08001655}
Anshuman Khandualcf89d4e2016-07-28 10:57:43 +08001656
1657static int ebb_active(struct task_struct *target,
1658 const struct user_regset *regset)
1659{
1660 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1661 return -ENODEV;
1662
1663 if (target->thread.used_ebb)
1664 return regset->n;
1665
1666 return 0;
1667}
1668
1669static int ebb_get(struct task_struct *target,
1670 const struct user_regset *regset,
1671 unsigned int pos, unsigned int count,
1672 void *kbuf, void __user *ubuf)
1673{
1674 /* Build tests */
1675 BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
1676 BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
1677
1678 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1679 return -ENODEV;
1680
1681 if (!target->thread.used_ebb)
1682 return -ENODATA;
1683
1684 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1685 &target->thread.ebbrr, 0, 3 * sizeof(unsigned long));
1686}
1687
1688static int ebb_set(struct task_struct *target,
1689 const struct user_regset *regset,
1690 unsigned int pos, unsigned int count,
1691 const void *kbuf, const void __user *ubuf)
1692{
1693 int ret = 0;
1694
1695 /* Build tests */
1696 BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
1697 BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
1698
1699 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1700 return -ENODEV;
1701
1702 if (target->thread.used_ebb)
1703 return -ENODATA;
1704
1705 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1706 &target->thread.ebbrr, 0, sizeof(unsigned long));
1707
1708 if (!ret)
1709 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1710 &target->thread.ebbhr, sizeof(unsigned long),
1711 2 * sizeof(unsigned long));
1712
1713 if (!ret)
1714 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1715 &target->thread.bescr,
1716 2 * sizeof(unsigned long), 3 * sizeof(unsigned long));
1717
1718 return ret;
1719}
Anshuman Khanduala67ae752016-07-28 10:57:44 +08001720static int pmu_active(struct task_struct *target,
1721 const struct user_regset *regset)
1722{
1723 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1724 return -ENODEV;
1725
1726 return regset->n;
1727}
1728
1729static int pmu_get(struct task_struct *target,
1730 const struct user_regset *regset,
1731 unsigned int pos, unsigned int count,
1732 void *kbuf, void __user *ubuf)
1733{
1734 /* Build tests */
1735 BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
1736 BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
1737 BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
1738 BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
1739
1740 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1741 return -ENODEV;
1742
1743 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1744 &target->thread.siar, 0,
1745 5 * sizeof(unsigned long));
1746}
1747
1748static int pmu_set(struct task_struct *target,
1749 const struct user_regset *regset,
1750 unsigned int pos, unsigned int count,
1751 const void *kbuf, const void __user *ubuf)
1752{
1753 int ret = 0;
1754
1755 /* Build tests */
1756 BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
1757 BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
1758 BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
1759 BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
1760
1761 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
1762 return -ENODEV;
1763
1764 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1765 &target->thread.siar, 0,
1766 sizeof(unsigned long));
1767
1768 if (!ret)
1769 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1770 &target->thread.sdar, sizeof(unsigned long),
1771 2 * sizeof(unsigned long));
1772
1773 if (!ret)
1774 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1775 &target->thread.sier, 2 * sizeof(unsigned long),
1776 3 * sizeof(unsigned long));
1777
1778 if (!ret)
1779 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1780 &target->thread.mmcr2, 3 * sizeof(unsigned long),
1781 4 * sizeof(unsigned long));
1782
1783 if (!ret)
1784 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1785 &target->thread.mmcr0, 4 * sizeof(unsigned long),
1786 5 * sizeof(unsigned long));
1787 return ret;
1788}
Anshuman Khandualfa439812016-07-28 10:57:42 +08001789#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08001790/*
1791 * These are our native regset flavors.
1792 */
1793enum powerpc_regset {
1794 REGSET_GPR,
1795 REGSET_FPR,
1796#ifdef CONFIG_ALTIVEC
1797 REGSET_VMX,
1798#endif
Michael Neulingce48b212008-06-25 14:07:18 +10001799#ifdef CONFIG_VSX
1800 REGSET_VSX,
1801#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08001802#ifdef CONFIG_SPE
1803 REGSET_SPE,
1804#endif
Anshuman Khandual25847fb2016-07-28 10:57:36 +08001805#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1806 REGSET_TM_CGPR, /* TM checkpointed GPR registers */
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001807 REGSET_TM_CFPR, /* TM checkpointed FPR registers */
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001808 REGSET_TM_CVMX, /* TM checkpointed VMX registers */
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001809 REGSET_TM_CVSX, /* TM checkpointed VSX registers */
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001810 REGSET_TM_SPR, /* TM specific SPR registers */
Anshuman Khandualc45dc902016-07-28 10:57:41 +08001811 REGSET_TM_CTAR, /* TM checkpointed TAR register */
1812 REGSET_TM_CPPR, /* TM checkpointed PPR register */
1813 REGSET_TM_CDSCR, /* TM checkpointed DSCR register */
Anshuman Khandual25847fb2016-07-28 10:57:36 +08001814#endif
Anshuman Khandualfa439812016-07-28 10:57:42 +08001815#ifdef CONFIG_PPC64
1816 REGSET_PPR, /* PPR register */
1817 REGSET_DSCR, /* DSCR register */
1818#endif
1819#ifdef CONFIG_PPC_BOOK3S_64
1820 REGSET_TAR, /* TAR register */
Anshuman Khandualcf89d4e2016-07-28 10:57:43 +08001821 REGSET_EBB, /* EBB registers */
Anshuman Khanduala67ae752016-07-28 10:57:44 +08001822 REGSET_PMR, /* Performance Monitor Registers */
Anshuman Khandualfa439812016-07-28 10:57:42 +08001823#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08001824};
1825
1826static const struct user_regset native_regsets[] = {
1827 [REGSET_GPR] = {
1828 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
1829 .size = sizeof(long), .align = sizeof(long),
1830 .get = gpr_get, .set = gpr_set
1831 },
1832 [REGSET_FPR] = {
1833 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
1834 .size = sizeof(double), .align = sizeof(double),
1835 .get = fpr_get, .set = fpr_set
1836 },
1837#ifdef CONFIG_ALTIVEC
1838 [REGSET_VMX] = {
1839 .core_note_type = NT_PPC_VMX, .n = 34,
1840 .size = sizeof(vector128), .align = sizeof(vector128),
1841 .active = vr_active, .get = vr_get, .set = vr_set
1842 },
1843#endif
Michael Neulingce48b212008-06-25 14:07:18 +10001844#ifdef CONFIG_VSX
1845 [REGSET_VSX] = {
Michael Neulingf3e909c2008-07-01 14:01:39 +10001846 .core_note_type = NT_PPC_VSX, .n = 32,
1847 .size = sizeof(double), .align = sizeof(double),
Michael Neulingce48b212008-06-25 14:07:18 +10001848 .active = vsr_active, .get = vsr_get, .set = vsr_set
1849 },
1850#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08001851#ifdef CONFIG_SPE
1852 [REGSET_SPE] = {
Suzuki Poulosea0b38b42013-08-27 13:22:14 +05301853 .core_note_type = NT_PPC_SPE, .n = 35,
Roland McGrath80fdf472007-12-20 03:58:00 -08001854 .size = sizeof(u32), .align = sizeof(u32),
1855 .active = evr_active, .get = evr_get, .set = evr_set
1856 },
1857#endif
Anshuman Khandual25847fb2016-07-28 10:57:36 +08001858#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
1859 [REGSET_TM_CGPR] = {
1860 .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
1861 .size = sizeof(long), .align = sizeof(long),
1862 .active = tm_cgpr_active, .get = tm_cgpr_get, .set = tm_cgpr_set
1863 },
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08001864 [REGSET_TM_CFPR] = {
1865 .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
1866 .size = sizeof(double), .align = sizeof(double),
1867 .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
1868 },
Anshuman Khandual8c13f592016-07-28 10:57:38 +08001869 [REGSET_TM_CVMX] = {
1870 .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
1871 .size = sizeof(vector128), .align = sizeof(vector128),
1872 .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
1873 },
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08001874 [REGSET_TM_CVSX] = {
1875 .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
1876 .size = sizeof(double), .align = sizeof(double),
1877 .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set
1878 },
Anshuman Khandual08e1c012016-07-28 10:57:40 +08001879 [REGSET_TM_SPR] = {
1880 .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
1881 .size = sizeof(u64), .align = sizeof(u64),
1882 .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
1883 },
Anshuman Khandualc45dc902016-07-28 10:57:41 +08001884 [REGSET_TM_CTAR] = {
1885 .core_note_type = NT_PPC_TM_CTAR, .n = 1,
1886 .size = sizeof(u64), .align = sizeof(u64),
1887 .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set
1888 },
1889 [REGSET_TM_CPPR] = {
1890 .core_note_type = NT_PPC_TM_CPPR, .n = 1,
1891 .size = sizeof(u64), .align = sizeof(u64),
1892 .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set
1893 },
1894 [REGSET_TM_CDSCR] = {
1895 .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
1896 .size = sizeof(u64), .align = sizeof(u64),
1897 .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set
1898 },
Anshuman Khandual25847fb2016-07-28 10:57:36 +08001899#endif
Anshuman Khandualfa439812016-07-28 10:57:42 +08001900#ifdef CONFIG_PPC64
1901 [REGSET_PPR] = {
1902 .core_note_type = NT_PPC_PPR, .n = 1,
1903 .size = sizeof(u64), .align = sizeof(u64),
1904 .get = ppr_get, .set = ppr_set
1905 },
1906 [REGSET_DSCR] = {
1907 .core_note_type = NT_PPC_DSCR, .n = 1,
1908 .size = sizeof(u64), .align = sizeof(u64),
1909 .get = dscr_get, .set = dscr_set
1910 },
1911#endif
1912#ifdef CONFIG_PPC_BOOK3S_64
1913 [REGSET_TAR] = {
1914 .core_note_type = NT_PPC_TAR, .n = 1,
1915 .size = sizeof(u64), .align = sizeof(u64),
1916 .get = tar_get, .set = tar_set
1917 },
Anshuman Khandualcf89d4e2016-07-28 10:57:43 +08001918 [REGSET_EBB] = {
1919 .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
1920 .size = sizeof(u64), .align = sizeof(u64),
1921 .active = ebb_active, .get = ebb_get, .set = ebb_set
1922 },
Anshuman Khanduala67ae752016-07-28 10:57:44 +08001923 [REGSET_PMR] = {
1924 .core_note_type = NT_PPC_PMU, .n = ELF_NPMU,
1925 .size = sizeof(u64), .align = sizeof(u64),
1926 .active = pmu_active, .get = pmu_get, .set = pmu_set
1927 },
Anshuman Khandualfa439812016-07-28 10:57:42 +08001928#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08001929};
1930
1931static const struct user_regset_view user_ppc_native_view = {
1932 .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
1933 .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
1934};
1935
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001936#ifdef CONFIG_PPC64
1937#include <linux/compat.h>
1938
Anshuman Khandual04fcadc2016-07-28 10:57:35 +08001939static int gpr32_get_common(struct task_struct *target,
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001940 const struct user_regset *regset,
1941 unsigned int pos, unsigned int count,
Simon Guo26183112016-09-11 21:44:13 +08001942 void *kbuf, void __user *ubuf,
1943 unsigned long *regs)
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001944{
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001945 compat_ulong_t *k = kbuf;
1946 compat_ulong_t __user *u = ubuf;
1947 compat_ulong_t reg;
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001948
1949 pos /= sizeof(reg);
1950 count /= sizeof(reg);
1951
1952 if (kbuf)
1953 for (; count > 0 && pos < PT_MSR; --count)
1954 *k++ = regs[pos++];
1955 else
1956 for (; count > 0 && pos < PT_MSR; --count)
1957 if (__put_user((compat_ulong_t) regs[pos++], u++))
1958 return -EFAULT;
1959
1960 if (count > 0 && pos == PT_MSR) {
1961 reg = get_user_msr(target);
1962 if (kbuf)
1963 *k++ = reg;
1964 else if (__put_user(reg, u++))
1965 return -EFAULT;
1966 ++pos;
1967 --count;
1968 }
1969
1970 if (kbuf)
1971 for (; count > 0 && pos < PT_REGS_COUNT; --count)
1972 *k++ = regs[pos++];
1973 else
1974 for (; count > 0 && pos < PT_REGS_COUNT; --count)
1975 if (__put_user((compat_ulong_t) regs[pos++], u++))
1976 return -EFAULT;
1977
1978 kbuf = k;
1979 ubuf = u;
1980 pos *= sizeof(reg);
1981 count *= sizeof(reg);
1982 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
1983 PT_REGS_COUNT * sizeof(reg), -1);
1984}
1985
Anshuman Khandual04fcadc2016-07-28 10:57:35 +08001986static int gpr32_set_common(struct task_struct *target,
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001987 const struct user_regset *regset,
1988 unsigned int pos, unsigned int count,
Simon Guo26183112016-09-11 21:44:13 +08001989 const void *kbuf, const void __user *ubuf,
1990 unsigned long *regs)
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001991{
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001992 const compat_ulong_t *k = kbuf;
1993 const compat_ulong_t __user *u = ubuf;
1994 compat_ulong_t reg;
1995
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08001996 pos /= sizeof(reg);
1997 count /= sizeof(reg);
1998
1999 if (kbuf)
2000 for (; count > 0 && pos < PT_MSR; --count)
2001 regs[pos++] = *k++;
2002 else
2003 for (; count > 0 && pos < PT_MSR; --count) {
2004 if (__get_user(reg, u++))
2005 return -EFAULT;
2006 regs[pos++] = reg;
2007 }
2008
2009
2010 if (count > 0 && pos == PT_MSR) {
2011 if (kbuf)
2012 reg = *k++;
2013 else if (__get_user(reg, u++))
2014 return -EFAULT;
2015 set_user_msr(target, reg);
2016 ++pos;
2017 --count;
2018 }
2019
Roland McGrathc2372eb2008-03-13 19:25:35 +11002020 if (kbuf) {
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002021 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
2022 regs[pos++] = *k++;
Roland McGrathc2372eb2008-03-13 19:25:35 +11002023 for (; count > 0 && pos < PT_TRAP; --count, ++pos)
2024 ++k;
2025 } else {
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002026 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
2027 if (__get_user(reg, u++))
2028 return -EFAULT;
2029 regs[pos++] = reg;
2030 }
Roland McGrathc2372eb2008-03-13 19:25:35 +11002031 for (; count > 0 && pos < PT_TRAP; --count, ++pos)
2032 if (__get_user(reg, u++))
2033 return -EFAULT;
2034 }
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002035
2036 if (count > 0 && pos == PT_TRAP) {
2037 if (kbuf)
2038 reg = *k++;
2039 else if (__get_user(reg, u++))
2040 return -EFAULT;
2041 set_user_trap(target, reg);
2042 ++pos;
2043 --count;
2044 }
2045
2046 kbuf = k;
2047 ubuf = u;
2048 pos *= sizeof(reg);
2049 count *= sizeof(reg);
2050 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
2051 (PT_TRAP + 1) * sizeof(reg), -1);
2052}
2053
Anshuman Khandual25847fb2016-07-28 10:57:36 +08002054#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2055static int tm_cgpr32_get(struct task_struct *target,
2056 const struct user_regset *regset,
2057 unsigned int pos, unsigned int count,
2058 void *kbuf, void __user *ubuf)
2059{
Simon Guo26183112016-09-11 21:44:13 +08002060 return gpr32_get_common(target, regset, pos, count, kbuf, ubuf,
2061 &target->thread.ckpt_regs.gpr[0]);
Anshuman Khandual25847fb2016-07-28 10:57:36 +08002062}
2063
2064static int tm_cgpr32_set(struct task_struct *target,
2065 const struct user_regset *regset,
2066 unsigned int pos, unsigned int count,
2067 const void *kbuf, const void __user *ubuf)
2068{
Simon Guo26183112016-09-11 21:44:13 +08002069 return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
2070 &target->thread.ckpt_regs.gpr[0]);
Anshuman Khandual25847fb2016-07-28 10:57:36 +08002071}
2072#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
2073
Anshuman Khandual04fcadc2016-07-28 10:57:35 +08002074static int gpr32_get(struct task_struct *target,
2075 const struct user_regset *regset,
2076 unsigned int pos, unsigned int count,
2077 void *kbuf, void __user *ubuf)
2078{
Simon Guo26183112016-09-11 21:44:13 +08002079 int i;
2080
2081 if (target->thread.regs == NULL)
2082 return -EIO;
2083
2084 if (!FULL_REGS(target->thread.regs)) {
2085 /*
2086 * We have a partial register set.
2087 * Fill 14-31 with bogus values.
2088 */
2089 for (i = 14; i < 32; i++)
2090 target->thread.regs->gpr[i] = NV_REG_POISON;
2091 }
2092 return gpr32_get_common(target, regset, pos, count, kbuf, ubuf,
2093 &target->thread.regs->gpr[0]);
Anshuman Khandual04fcadc2016-07-28 10:57:35 +08002094}
2095
2096static int gpr32_set(struct task_struct *target,
2097 const struct user_regset *regset,
2098 unsigned int pos, unsigned int count,
2099 const void *kbuf, const void __user *ubuf)
2100{
Simon Guo26183112016-09-11 21:44:13 +08002101 if (target->thread.regs == NULL)
2102 return -EIO;
2103
2104 CHECK_FULL_REGS(target->thread.regs);
2105 return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
2106 &target->thread.regs->gpr[0]);
Anshuman Khandual04fcadc2016-07-28 10:57:35 +08002107}
2108
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002109/*
2110 * These are the regset flavors matching the CONFIG_PPC32 native set.
2111 */
2112static const struct user_regset compat_regsets[] = {
2113 [REGSET_GPR] = {
2114 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
2115 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
2116 .get = gpr32_get, .set = gpr32_set
2117 },
2118 [REGSET_FPR] = {
2119 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
2120 .size = sizeof(double), .align = sizeof(double),
2121 .get = fpr_get, .set = fpr_set
2122 },
2123#ifdef CONFIG_ALTIVEC
2124 [REGSET_VMX] = {
2125 .core_note_type = NT_PPC_VMX, .n = 34,
2126 .size = sizeof(vector128), .align = sizeof(vector128),
2127 .active = vr_active, .get = vr_get, .set = vr_set
2128 },
2129#endif
2130#ifdef CONFIG_SPE
2131 [REGSET_SPE] = {
Roland McGrath24f1a842008-01-02 17:05:48 -08002132 .core_note_type = NT_PPC_SPE, .n = 35,
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002133 .size = sizeof(u32), .align = sizeof(u32),
2134 .active = evr_active, .get = evr_get, .set = evr_set
2135 },
2136#endif
Anshuman Khandual25847fb2016-07-28 10:57:36 +08002137#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2138 [REGSET_TM_CGPR] = {
2139 .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
2140 .size = sizeof(long), .align = sizeof(long),
2141 .active = tm_cgpr_active,
2142 .get = tm_cgpr32_get, .set = tm_cgpr32_set
2143 },
Anshuman Khandual19cbcbf2016-07-28 10:57:37 +08002144 [REGSET_TM_CFPR] = {
2145 .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
2146 .size = sizeof(double), .align = sizeof(double),
2147 .active = tm_cfpr_active, .get = tm_cfpr_get, .set = tm_cfpr_set
2148 },
Anshuman Khandual8c13f592016-07-28 10:57:38 +08002149 [REGSET_TM_CVMX] = {
2150 .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
2151 .size = sizeof(vector128), .align = sizeof(vector128),
2152 .active = tm_cvmx_active, .get = tm_cvmx_get, .set = tm_cvmx_set
2153 },
Anshuman Khandual9d3918f2016-07-28 10:57:39 +08002154 [REGSET_TM_CVSX] = {
2155 .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
2156 .size = sizeof(double), .align = sizeof(double),
2157 .active = tm_cvsx_active, .get = tm_cvsx_get, .set = tm_cvsx_set
2158 },
Anshuman Khandual08e1c012016-07-28 10:57:40 +08002159 [REGSET_TM_SPR] = {
2160 .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
2161 .size = sizeof(u64), .align = sizeof(u64),
2162 .active = tm_spr_active, .get = tm_spr_get, .set = tm_spr_set
2163 },
Anshuman Khandualc45dc902016-07-28 10:57:41 +08002164 [REGSET_TM_CTAR] = {
2165 .core_note_type = NT_PPC_TM_CTAR, .n = 1,
2166 .size = sizeof(u64), .align = sizeof(u64),
2167 .active = tm_tar_active, .get = tm_tar_get, .set = tm_tar_set
2168 },
2169 [REGSET_TM_CPPR] = {
2170 .core_note_type = NT_PPC_TM_CPPR, .n = 1,
2171 .size = sizeof(u64), .align = sizeof(u64),
2172 .active = tm_ppr_active, .get = tm_ppr_get, .set = tm_ppr_set
2173 },
2174 [REGSET_TM_CDSCR] = {
2175 .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
2176 .size = sizeof(u64), .align = sizeof(u64),
2177 .active = tm_dscr_active, .get = tm_dscr_get, .set = tm_dscr_set
2178 },
Anshuman Khandual25847fb2016-07-28 10:57:36 +08002179#endif
Anshuman Khandualfa439812016-07-28 10:57:42 +08002180#ifdef CONFIG_PPC64
2181 [REGSET_PPR] = {
2182 .core_note_type = NT_PPC_PPR, .n = 1,
2183 .size = sizeof(u64), .align = sizeof(u64),
2184 .get = ppr_get, .set = ppr_set
2185 },
2186 [REGSET_DSCR] = {
2187 .core_note_type = NT_PPC_DSCR, .n = 1,
2188 .size = sizeof(u64), .align = sizeof(u64),
2189 .get = dscr_get, .set = dscr_set
2190 },
2191#endif
2192#ifdef CONFIG_PPC_BOOK3S_64
2193 [REGSET_TAR] = {
2194 .core_note_type = NT_PPC_TAR, .n = 1,
2195 .size = sizeof(u64), .align = sizeof(u64),
2196 .get = tar_get, .set = tar_set
2197 },
Anshuman Khandualcf89d4e2016-07-28 10:57:43 +08002198 [REGSET_EBB] = {
2199 .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
2200 .size = sizeof(u64), .align = sizeof(u64),
2201 .active = ebb_active, .get = ebb_get, .set = ebb_set
2202 },
Anshuman Khandualfa439812016-07-28 10:57:42 +08002203#endif
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002204};
2205
2206static const struct user_regset_view user_ppc_compat_view = {
2207 .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
2208 .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
2209};
2210#endif /* CONFIG_PPC64 */
2211
Roland McGrath80fdf472007-12-20 03:58:00 -08002212const struct user_regset_view *task_user_regset_view(struct task_struct *task)
2213{
Roland McGrathfa8f5cb2007-12-20 03:58:08 -08002214#ifdef CONFIG_PPC64
2215 if (test_tsk_thread_flag(task, TIF_32BIT))
2216 return &user_ppc_compat_view;
2217#endif
Roland McGrath80fdf472007-12-20 03:58:00 -08002218 return &user_ppc_native_view;
2219}
2220
2221
Roland McGrath2a84b0d2008-01-30 13:30:51 +01002222void user_enable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002223{
2224 struct pt_regs *regs = task->thread.regs;
2225
2226 if (regs != NULL) {
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002227#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302228 task->thread.debug.dbcr0 &= ~DBCR0_BT;
2229 task->thread.debug.dbcr0 |= DBCR0_IDM | DBCR0_IC;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002230 regs->msr |= MSR_DE;
2231#else
Roland McGrathec097c82009-05-28 21:26:38 +00002232 regs->msr &= ~MSR_BE;
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002233 regs->msr |= MSR_SE;
2234#endif
2235 }
2236 set_tsk_thread_flag(task, TIF_SINGLESTEP);
2237}
2238
Roland McGrathec097c82009-05-28 21:26:38 +00002239void user_enable_block_step(struct task_struct *task)
2240{
2241 struct pt_regs *regs = task->thread.regs;
2242
2243 if (regs != NULL) {
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002244#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302245 task->thread.debug.dbcr0 &= ~DBCR0_IC;
2246 task->thread.debug.dbcr0 = DBCR0_IDM | DBCR0_BT;
Roland McGrathec097c82009-05-28 21:26:38 +00002247 regs->msr |= MSR_DE;
2248#else
2249 regs->msr &= ~MSR_SE;
2250 regs->msr |= MSR_BE;
2251#endif
2252 }
2253 set_tsk_thread_flag(task, TIF_SINGLESTEP);
2254}
2255
Roland McGrath2a84b0d2008-01-30 13:30:51 +01002256void user_disable_single_step(struct task_struct *task)
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002257{
2258 struct pt_regs *regs = task->thread.regs;
2259
2260 if (regs != NULL) {
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002261#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002262 /*
2263 * The logic to disable single stepping should be as
2264 * simple as turning off the Instruction Complete flag.
2265 * And, after doing so, if all debug flags are off, turn
2266 * off DBCR0(IDM) and MSR(DE) .... Torez
2267 */
James Yang682775b2013-07-05 14:49:43 -05002268 task->thread.debug.dbcr0 &= ~(DBCR0_IC|DBCR0_BT);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002269 /*
2270 * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
2271 */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302272 if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
2273 task->thread.debug.dbcr1)) {
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002274 /*
2275 * All debug events were off.....
2276 */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302277 task->thread.debug.dbcr0 &= ~DBCR0_IDM;
Dave Kleikamp28477fb2009-07-08 13:46:18 +00002278 regs->msr &= ~MSR_DE;
2279 }
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002280#else
Roland McGrathec097c82009-05-28 21:26:38 +00002281 regs->msr &= ~(MSR_SE | MSR_BE);
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002282#endif
2283 }
2284 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
2285}
2286
K.Prasad5aae8a52010-06-15 11:35:19 +05302287#ifdef CONFIG_HAVE_HW_BREAKPOINT
Peter Zijlstraa8b0ca12011-06-27 14:41:57 +02002288void ptrace_triggered(struct perf_event *bp,
K.Prasad5aae8a52010-06-15 11:35:19 +05302289 struct perf_sample_data *data, struct pt_regs *regs)
2290{
2291 struct perf_event_attr attr;
2292
2293 /*
2294 * Disable the breakpoint request here since ptrace has defined a
2295 * one-shot behaviour for breakpoint exceptions in PPC64.
2296 * The SIGTRAP signal is generated automatically for us in do_dabr().
2297 * We don't have to do anything about that here
2298 */
2299 attr = bp->attr;
2300 attr.disabled = true;
2301 modify_user_hw_breakpoint(bp, &attr);
2302}
2303#endif /* CONFIG_HAVE_HW_BREAKPOINT */
2304
Anton Blancharde51df2c2014-08-20 08:55:18 +10002305static int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002306 unsigned long data)
2307{
K.Prasad5aae8a52010-06-15 11:35:19 +05302308#ifdef CONFIG_HAVE_HW_BREAKPOINT
2309 int ret;
2310 struct thread_struct *thread = &(task->thread);
2311 struct perf_event *bp;
2312 struct perf_event_attr attr;
2313#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Michael Neuling9422de32012-12-20 14:06:44 +00002314#ifndef CONFIG_PPC_ADV_DEBUG_REGS
2315 struct arch_hw_breakpoint hw_brk;
2316#endif
K.Prasad5aae8a52010-06-15 11:35:19 +05302317
Luis Machadod6a61bf2008-07-24 02:10:41 +10002318 /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
2319 * For embedded processors we support one DAC and no IAC's at the
2320 * moment.
2321 */
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002322 if (addr > 0)
2323 return -EINVAL;
2324
Kumar Gala2325f0a2008-07-26 05:27:33 +10002325 /* The bottom 3 bits in dabr are flags */
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002326 if ((data & ~0x7UL) >= TASK_SIZE)
2327 return -EIO;
2328
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002329#ifndef CONFIG_PPC_ADV_DEBUG_REGS
Luis Machadod6a61bf2008-07-24 02:10:41 +10002330 /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
2331 * It was assumed, on previous implementations, that 3 bits were
2332 * passed together with the data address, fitting the design of the
2333 * DABR register, as follows:
2334 *
2335 * bit 0: Read flag
2336 * bit 1: Write flag
2337 * bit 2: Breakpoint translation
2338 *
2339 * Thus, we use them here as so.
2340 */
2341
2342 /* Ensure breakpoint translation bit is set */
Michael Neuling9422de32012-12-20 14:06:44 +00002343 if (data && !(data & HW_BRK_TYPE_TRANSLATE))
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002344 return -EIO;
Michael Neuling9422de32012-12-20 14:06:44 +00002345 hw_brk.address = data & (~HW_BRK_TYPE_DABR);
2346 hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
2347 hw_brk.len = 8;
K.Prasad5aae8a52010-06-15 11:35:19 +05302348#ifdef CONFIG_HAVE_HW_BREAKPOINT
2349 bp = thread->ptrace_bps[0];
Michael Neuling9422de32012-12-20 14:06:44 +00002350 if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) {
K.Prasad5aae8a52010-06-15 11:35:19 +05302351 if (bp) {
2352 unregister_hw_breakpoint(bp);
2353 thread->ptrace_bps[0] = NULL;
2354 }
2355 return 0;
2356 }
2357 if (bp) {
2358 attr = bp->attr;
Michael Neuling9422de32012-12-20 14:06:44 +00002359 attr.bp_addr = hw_brk.address;
2360 arch_bp_generic_fields(hw_brk.type, &attr.bp_type);
Aravinda Prasada53fd612012-11-04 22:15:28 +00002361
2362 /* Enable breakpoint */
2363 attr.disabled = false;
2364
K.Prasad5aae8a52010-06-15 11:35:19 +05302365 ret = modify_user_hw_breakpoint(bp, &attr);
Frederic Weisbecker925f83c2011-05-06 01:53:18 +02002366 if (ret) {
K.Prasad5aae8a52010-06-15 11:35:19 +05302367 return ret;
Frederic Weisbecker925f83c2011-05-06 01:53:18 +02002368 }
K.Prasad5aae8a52010-06-15 11:35:19 +05302369 thread->ptrace_bps[0] = bp;
Michael Neuling9422de32012-12-20 14:06:44 +00002370 thread->hw_brk = hw_brk;
K.Prasad5aae8a52010-06-15 11:35:19 +05302371 return 0;
2372 }
2373
2374 /* Create a new breakpoint request if one doesn't exist already */
2375 hw_breakpoint_init(&attr);
Michael Neuling9422de32012-12-20 14:06:44 +00002376 attr.bp_addr = hw_brk.address;
2377 arch_bp_generic_fields(hw_brk.type,
2378 &attr.bp_type);
K.Prasad5aae8a52010-06-15 11:35:19 +05302379
2380 thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
Avi Kivity4dc0da82011-06-29 18:42:35 +03002381 ptrace_triggered, NULL, task);
K.Prasad5aae8a52010-06-15 11:35:19 +05302382 if (IS_ERR(bp)) {
2383 thread->ptrace_bps[0] = NULL;
2384 return PTR_ERR(bp);
2385 }
2386
2387#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Michael Neuling9422de32012-12-20 14:06:44 +00002388 task->thread.hw_brk = hw_brk;
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002389#else /* CONFIG_PPC_ADV_DEBUG_REGS */
Luis Machadod6a61bf2008-07-24 02:10:41 +10002390 /* As described above, it was assumed 3 bits were passed with the data
2391 * address, but we will assume only the mode bits will be passed
2392 * as to not cause alignment restrictions for DAC-based processors.
2393 */
2394
2395 /* DAC's hold the whole address without any mode flags */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302396 task->thread.debug.dac1 = data & ~0x3UL;
Luis Machadod6a61bf2008-07-24 02:10:41 +10002397
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302398 if (task->thread.debug.dac1 == 0) {
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002399 dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302400 if (!DBCR_ACTIVE_EVENTS(task->thread.debug.dbcr0,
2401 task->thread.debug.dbcr1)) {
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002402 task->thread.regs->msr &= ~MSR_DE;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302403 task->thread.debug.dbcr0 &= ~DBCR0_IDM;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002404 }
Luis Machadod6a61bf2008-07-24 02:10:41 +10002405 return 0;
2406 }
2407
2408 /* Read or Write bits must be set */
2409
2410 if (!(data & 0x3UL))
2411 return -EINVAL;
2412
2413 /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
2414 register */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302415 task->thread.debug.dbcr0 |= DBCR0_IDM;
Luis Machadod6a61bf2008-07-24 02:10:41 +10002416
2417 /* Check for write and read flags and set DBCR0
2418 accordingly */
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002419 dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
Luis Machadod6a61bf2008-07-24 02:10:41 +10002420 if (data & 0x1UL)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002421 dbcr_dac(task) |= DBCR_DAC1R;
Luis Machadod6a61bf2008-07-24 02:10:41 +10002422 if (data & 0x2UL)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002423 dbcr_dac(task) |= DBCR_DAC1W;
Luis Machadod6a61bf2008-07-24 02:10:41 +10002424 task->thread.regs->msr |= MSR_DE;
Dave Kleikamp172ae2e2010-02-08 11:50:57 +00002425#endif /* CONFIG_PPC_ADV_DEBUG_REGS */
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002426 return 0;
2427}
Benjamin Herrenschmidtabd06502007-06-04 15:15:47 +10002428
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002429/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 * Called by kernel/ptrace.c when detaching..
2431 *
2432 * Make sure single step bits etc are not set.
2433 */
2434void ptrace_disable(struct task_struct *child)
2435{
2436 /* make sure the single step bit is not set. */
Roland McGrath2a84b0d2008-01-30 13:30:51 +01002437 user_disable_single_step(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438}
2439
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002440#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Michael Neuling84295df2012-10-28 15:13:16 +00002441static long set_instruction_bp(struct task_struct *child,
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002442 struct ppc_hw_breakpoint *bp_info)
2443{
2444 int slot;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302445 int slot1_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC1) != 0);
2446 int slot2_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC2) != 0);
2447 int slot3_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC3) != 0);
2448 int slot4_in_use = ((child->thread.debug.dbcr0 & DBCR0_IAC4) != 0);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002449
2450 if (dbcr_iac_range(child) & DBCR_IAC12MODE)
2451 slot2_in_use = 1;
2452 if (dbcr_iac_range(child) & DBCR_IAC34MODE)
2453 slot4_in_use = 1;
2454
2455 if (bp_info->addr >= TASK_SIZE)
2456 return -EIO;
2457
2458 if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
2459
2460 /* Make sure range is valid. */
2461 if (bp_info->addr2 >= TASK_SIZE)
2462 return -EIO;
2463
2464 /* We need a pair of IAC regsisters */
2465 if ((!slot1_in_use) && (!slot2_in_use)) {
2466 slot = 1;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302467 child->thread.debug.iac1 = bp_info->addr;
2468 child->thread.debug.iac2 = bp_info->addr2;
2469 child->thread.debug.dbcr0 |= DBCR0_IAC1;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002470 if (bp_info->addr_mode ==
2471 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
2472 dbcr_iac_range(child) |= DBCR_IAC12X;
2473 else
2474 dbcr_iac_range(child) |= DBCR_IAC12I;
2475#if CONFIG_PPC_ADV_DEBUG_IACS > 2
2476 } else if ((!slot3_in_use) && (!slot4_in_use)) {
2477 slot = 3;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302478 child->thread.debug.iac3 = bp_info->addr;
2479 child->thread.debug.iac4 = bp_info->addr2;
2480 child->thread.debug.dbcr0 |= DBCR0_IAC3;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002481 if (bp_info->addr_mode ==
2482 PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
2483 dbcr_iac_range(child) |= DBCR_IAC34X;
2484 else
2485 dbcr_iac_range(child) |= DBCR_IAC34I;
2486#endif
2487 } else
2488 return -ENOSPC;
2489 } else {
2490 /* We only need one. If possible leave a pair free in
2491 * case a range is needed later
2492 */
2493 if (!slot1_in_use) {
2494 /*
2495 * Don't use iac1 if iac1-iac2 are free and either
2496 * iac3 or iac4 (but not both) are free
2497 */
2498 if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
2499 slot = 1;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302500 child->thread.debug.iac1 = bp_info->addr;
2501 child->thread.debug.dbcr0 |= DBCR0_IAC1;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002502 goto out;
2503 }
2504 }
2505 if (!slot2_in_use) {
2506 slot = 2;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302507 child->thread.debug.iac2 = bp_info->addr;
2508 child->thread.debug.dbcr0 |= DBCR0_IAC2;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002509#if CONFIG_PPC_ADV_DEBUG_IACS > 2
2510 } else if (!slot3_in_use) {
2511 slot = 3;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302512 child->thread.debug.iac3 = bp_info->addr;
2513 child->thread.debug.dbcr0 |= DBCR0_IAC3;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002514 } else if (!slot4_in_use) {
2515 slot = 4;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302516 child->thread.debug.iac4 = bp_info->addr;
2517 child->thread.debug.dbcr0 |= DBCR0_IAC4;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002518#endif
2519 } else
2520 return -ENOSPC;
2521 }
2522out:
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302523 child->thread.debug.dbcr0 |= DBCR0_IDM;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002524 child->thread.regs->msr |= MSR_DE;
2525
2526 return slot;
2527}
2528
2529static int del_instruction_bp(struct task_struct *child, int slot)
2530{
2531 switch (slot) {
2532 case 1:
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302533 if ((child->thread.debug.dbcr0 & DBCR0_IAC1) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002534 return -ENOENT;
2535
2536 if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
2537 /* address range - clear slots 1 & 2 */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302538 child->thread.debug.iac2 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002539 dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
2540 }
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302541 child->thread.debug.iac1 = 0;
2542 child->thread.debug.dbcr0 &= ~DBCR0_IAC1;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002543 break;
2544 case 2:
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302545 if ((child->thread.debug.dbcr0 & DBCR0_IAC2) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002546 return -ENOENT;
2547
2548 if (dbcr_iac_range(child) & DBCR_IAC12MODE)
2549 /* used in a range */
2550 return -EINVAL;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302551 child->thread.debug.iac2 = 0;
2552 child->thread.debug.dbcr0 &= ~DBCR0_IAC2;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002553 break;
2554#if CONFIG_PPC_ADV_DEBUG_IACS > 2
2555 case 3:
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302556 if ((child->thread.debug.dbcr0 & DBCR0_IAC3) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002557 return -ENOENT;
2558
2559 if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
2560 /* address range - clear slots 3 & 4 */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302561 child->thread.debug.iac4 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002562 dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
2563 }
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302564 child->thread.debug.iac3 = 0;
2565 child->thread.debug.dbcr0 &= ~DBCR0_IAC3;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002566 break;
2567 case 4:
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302568 if ((child->thread.debug.dbcr0 & DBCR0_IAC4) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002569 return -ENOENT;
2570
2571 if (dbcr_iac_range(child) & DBCR_IAC34MODE)
2572 /* Used in a range */
2573 return -EINVAL;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302574 child->thread.debug.iac4 = 0;
2575 child->thread.debug.dbcr0 &= ~DBCR0_IAC4;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002576 break;
2577#endif
2578 default:
2579 return -EINVAL;
2580 }
2581 return 0;
2582}
2583
2584static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
2585{
2586 int byte_enable =
2587 (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT)
2588 & 0xf;
2589 int condition_mode =
2590 bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE;
2591 int slot;
2592
2593 if (byte_enable && (condition_mode == 0))
2594 return -EINVAL;
2595
2596 if (bp_info->addr >= TASK_SIZE)
2597 return -EIO;
2598
2599 if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
2600 slot = 1;
2601 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
2602 dbcr_dac(child) |= DBCR_DAC1R;
2603 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
2604 dbcr_dac(child) |= DBCR_DAC1W;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302605 child->thread.debug.dac1 = (unsigned long)bp_info->addr;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002606#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2607 if (byte_enable) {
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302608 child->thread.debug.dvc1 =
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002609 (unsigned long)bp_info->condition_value;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302610 child->thread.debug.dbcr2 |=
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002611 ((byte_enable << DBCR2_DVC1BE_SHIFT) |
2612 (condition_mode << DBCR2_DVC1M_SHIFT));
2613 }
2614#endif
2615#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302616 } else if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002617 /* Both dac1 and dac2 are part of a range */
2618 return -ENOSPC;
2619#endif
2620 } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
2621 slot = 2;
2622 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
2623 dbcr_dac(child) |= DBCR_DAC2R;
2624 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
2625 dbcr_dac(child) |= DBCR_DAC2W;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302626 child->thread.debug.dac2 = (unsigned long)bp_info->addr;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002627#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
2628 if (byte_enable) {
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302629 child->thread.debug.dvc2 =
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002630 (unsigned long)bp_info->condition_value;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302631 child->thread.debug.dbcr2 |=
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002632 ((byte_enable << DBCR2_DVC2BE_SHIFT) |
2633 (condition_mode << DBCR2_DVC2M_SHIFT));
2634 }
2635#endif
2636 } else
2637 return -ENOSPC;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302638 child->thread.debug.dbcr0 |= DBCR0_IDM;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002639 child->thread.regs->msr |= MSR_DE;
2640
2641 return slot + 4;
2642}
2643
2644static int del_dac(struct task_struct *child, int slot)
2645{
2646 if (slot == 1) {
Dave Kleikamp30124d12010-03-01 04:57:34 +00002647 if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002648 return -ENOENT;
2649
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302650 child->thread.debug.dac1 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002651 dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
2652#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302653 if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE) {
2654 child->thread.debug.dac2 = 0;
2655 child->thread.debug.dbcr2 &= ~DBCR2_DAC12MODE;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002656 }
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302657 child->thread.debug.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002658#endif
2659#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302660 child->thread.debug.dvc1 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002661#endif
2662 } else if (slot == 2) {
Dave Kleikamp30124d12010-03-01 04:57:34 +00002663 if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002664 return -ENOENT;
2665
2666#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302667 if (child->thread.debug.dbcr2 & DBCR2_DAC12MODE)
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002668 /* Part of a range */
2669 return -EINVAL;
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302670 child->thread.debug.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002671#endif
2672#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302673 child->thread.debug.dvc2 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002674#endif
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302675 child->thread.debug.dac2 = 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002676 dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
2677 } else
2678 return -EINVAL;
2679
2680 return 0;
2681}
2682#endif /* CONFIG_PPC_ADV_DEBUG_REGS */
2683
2684#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2685static int set_dac_range(struct task_struct *child,
2686 struct ppc_hw_breakpoint *bp_info)
2687{
2688 int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK;
2689
2690 /* We don't allow range watchpoints to be used with DVC */
2691 if (bp_info->condition_mode)
2692 return -EINVAL;
2693
2694 /*
2695 * Best effort to verify the address range. The user/supervisor bits
2696 * prevent trapping in kernel space, but let's fail on an obvious bad
2697 * range. The simple test on the mask is not fool-proof, and any
2698 * exclusive range will spill over into kernel space.
2699 */
2700 if (bp_info->addr >= TASK_SIZE)
2701 return -EIO;
2702 if (mode == PPC_BREAKPOINT_MODE_MASK) {
2703 /*
2704 * dac2 is a bitmask. Don't allow a mask that makes a
2705 * kernel space address from a valid dac1 value
2706 */
2707 if (~((unsigned long)bp_info->addr2) >= TASK_SIZE)
2708 return -EIO;
2709 } else {
2710 /*
2711 * For range breakpoints, addr2 must also be a valid address
2712 */
2713 if (bp_info->addr2 >= TASK_SIZE)
2714 return -EIO;
2715 }
2716
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302717 if (child->thread.debug.dbcr0 &
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002718 (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
2719 return -ENOSPC;
2720
2721 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302722 child->thread.debug.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002723 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302724 child->thread.debug.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
2725 child->thread.debug.dac1 = bp_info->addr;
2726 child->thread.debug.dac2 = bp_info->addr2;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002727 if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302728 child->thread.debug.dbcr2 |= DBCR2_DAC12M;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002729 else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302730 child->thread.debug.dbcr2 |= DBCR2_DAC12MX;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002731 else /* PPC_BREAKPOINT_MODE_MASK */
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302732 child->thread.debug.dbcr2 |= DBCR2_DAC12MM;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002733 child->thread.regs->msr |= MSR_DE;
2734
2735 return 5;
2736}
2737#endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
2738
Dave Kleikamp3162d922010-02-08 11:51:05 +00002739static long ppc_set_hwdebug(struct task_struct *child,
2740 struct ppc_hw_breakpoint *bp_info)
2741{
K.Prasad6c7a2852012-10-28 15:13:15 +00002742#ifdef CONFIG_HAVE_HW_BREAKPOINT
2743 int len = 0;
2744 struct thread_struct *thread = &(child->thread);
2745 struct perf_event *bp;
2746 struct perf_event_attr attr;
2747#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002748#ifndef CONFIG_PPC_ADV_DEBUG_REGS
Michael Neuling9422de32012-12-20 14:06:44 +00002749 struct arch_hw_breakpoint brk;
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002750#endif
2751
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002752 if (bp_info->version != 1)
2753 return -ENOTSUPP;
2754#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Dave Kleikamp3162d922010-02-08 11:51:05 +00002755 /*
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002756 * Check for invalid flags and combinations
2757 */
2758 if ((bp_info->trigger_type == 0) ||
2759 (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE |
2760 PPC_BREAKPOINT_TRIGGER_RW)) ||
2761 (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) ||
2762 (bp_info->condition_mode &
2763 ~(PPC_BREAKPOINT_CONDITION_MODE |
2764 PPC_BREAKPOINT_CONDITION_BE_ALL)))
2765 return -EINVAL;
2766#if CONFIG_PPC_ADV_DEBUG_DVCS == 0
2767 if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
2768 return -EINVAL;
2769#endif
2770
2771 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) {
2772 if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
2773 (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
2774 return -EINVAL;
Michael Neuling84295df2012-10-28 15:13:16 +00002775 return set_instruction_bp(child, bp_info);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002776 }
2777 if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
2778 return set_dac(child, bp_info);
2779
2780#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2781 return set_dac_range(child, bp_info);
2782#else
2783 return -EINVAL;
2784#endif
2785#else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
2786 /*
2787 * We only support one data breakpoint
Dave Kleikamp3162d922010-02-08 11:51:05 +00002788 */
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002789 if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 ||
2790 (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 ||
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002791 bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
Dave Kleikamp3162d922010-02-08 11:51:05 +00002792 return -EINVAL;
2793
Dave Kleikamp3162d922010-02-08 11:51:05 +00002794 if ((unsigned long)bp_info->addr >= TASK_SIZE)
2795 return -EIO;
2796
Michael Neuling9422de32012-12-20 14:06:44 +00002797 brk.address = bp_info->addr & ~7UL;
2798 brk.type = HW_BRK_TYPE_TRANSLATE;
Michael Neuling2bb78ef2013-03-11 16:42:49 +00002799 brk.len = 8;
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002800 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
Michael Neuling9422de32012-12-20 14:06:44 +00002801 brk.type |= HW_BRK_TYPE_READ;
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002802 if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
Michael Neuling9422de32012-12-20 14:06:44 +00002803 brk.type |= HW_BRK_TYPE_WRITE;
K.Prasad6c7a2852012-10-28 15:13:15 +00002804#ifdef CONFIG_HAVE_HW_BREAKPOINT
K.Prasad6c7a2852012-10-28 15:13:15 +00002805 /*
2806 * Check if the request is for 'range' breakpoints. We can
2807 * support it if range < 8 bytes.
2808 */
Oleg Nesterov6961ed92013-07-08 16:00:49 -07002809 if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
K.Prasad6c7a2852012-10-28 15:13:15 +00002810 len = bp_info->addr2 - bp_info->addr;
Oleg Nesterov6961ed92013-07-08 16:00:49 -07002811 else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
Michael Neulingb0b0aa92013-06-24 15:47:22 +10002812 len = 1;
Oleg Nesterov6961ed92013-07-08 16:00:49 -07002813 else
K.Prasad6c7a2852012-10-28 15:13:15 +00002814 return -EINVAL;
K.Prasad6c7a2852012-10-28 15:13:15 +00002815 bp = thread->ptrace_bps[0];
Oleg Nesterov6961ed92013-07-08 16:00:49 -07002816 if (bp)
K.Prasad6c7a2852012-10-28 15:13:15 +00002817 return -ENOSPC;
K.Prasad6c7a2852012-10-28 15:13:15 +00002818
2819 /* Create a new breakpoint request if one doesn't exist already */
2820 hw_breakpoint_init(&attr);
2821 attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN;
2822 attr.bp_len = len;
Michael Neuling9422de32012-12-20 14:06:44 +00002823 arch_bp_generic_fields(brk.type, &attr.bp_type);
K.Prasad6c7a2852012-10-28 15:13:15 +00002824
2825 thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
2826 ptrace_triggered, NULL, child);
2827 if (IS_ERR(bp)) {
2828 thread->ptrace_bps[0] = NULL;
K.Prasad6c7a2852012-10-28 15:13:15 +00002829 return PTR_ERR(bp);
2830 }
2831
K.Prasad6c7a2852012-10-28 15:13:15 +00002832 return 1;
2833#endif /* CONFIG_HAVE_HW_BREAKPOINT */
2834
2835 if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT)
2836 return -EINVAL;
2837
Michael Neuling9422de32012-12-20 14:06:44 +00002838 if (child->thread.hw_brk.address)
K.Prasad6c7a2852012-10-28 15:13:15 +00002839 return -ENOSPC;
Andreas Schwab4dfbf292010-11-27 14:24:53 +00002840
Michael Neuling9422de32012-12-20 14:06:44 +00002841 child->thread.hw_brk = brk;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002842
Dave Kleikamp3162d922010-02-08 11:51:05 +00002843 return 1;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002844#endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
Dave Kleikamp3162d922010-02-08 11:51:05 +00002845}
2846
Michael Neulingec1b33d2012-10-28 15:13:17 +00002847static long ppc_del_hwdebug(struct task_struct *child, long data)
Dave Kleikamp3162d922010-02-08 11:51:05 +00002848{
K.Prasad6c7a2852012-10-28 15:13:15 +00002849#ifdef CONFIG_HAVE_HW_BREAKPOINT
2850 int ret = 0;
2851 struct thread_struct *thread = &(child->thread);
2852 struct perf_event *bp;
2853#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002854#ifdef CONFIG_PPC_ADV_DEBUG_REGS
2855 int rc;
2856
2857 if (data <= 4)
2858 rc = del_instruction_bp(child, (int)data);
2859 else
2860 rc = del_dac(child, (int)data - 4);
2861
2862 if (!rc) {
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05302863 if (!DBCR_ACTIVE_EVENTS(child->thread.debug.dbcr0,
2864 child->thread.debug.dbcr1)) {
2865 child->thread.debug.dbcr0 &= ~DBCR0_IDM;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002866 child->thread.regs->msr &= ~MSR_DE;
2867 }
2868 }
2869 return rc;
2870#else
Dave Kleikamp3162d922010-02-08 11:51:05 +00002871 if (data != 1)
2872 return -EINVAL;
K.Prasad6c7a2852012-10-28 15:13:15 +00002873
2874#ifdef CONFIG_HAVE_HW_BREAKPOINT
K.Prasad6c7a2852012-10-28 15:13:15 +00002875 bp = thread->ptrace_bps[0];
2876 if (bp) {
2877 unregister_hw_breakpoint(bp);
2878 thread->ptrace_bps[0] = NULL;
2879 } else
2880 ret = -ENOENT;
K.Prasad6c7a2852012-10-28 15:13:15 +00002881 return ret;
2882#else /* CONFIG_HAVE_HW_BREAKPOINT */
Michael Neuling9422de32012-12-20 14:06:44 +00002883 if (child->thread.hw_brk.address == 0)
Dave Kleikamp3162d922010-02-08 11:51:05 +00002884 return -ENOENT;
2885
Michael Neuling9422de32012-12-20 14:06:44 +00002886 child->thread.hw_brk.address = 0;
2887 child->thread.hw_brk.type = 0;
K.Prasad6c7a2852012-10-28 15:13:15 +00002888#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002889
Dave Kleikamp3162d922010-02-08 11:51:05 +00002890 return 0;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002891#endif
Dave Kleikamp3162d922010-02-08 11:51:05 +00002892}
2893
Namhyung Kim9b05a692010-10-27 15:33:47 -07002894long arch_ptrace(struct task_struct *child, long request,
2895 unsigned long addr, unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 int ret = -EPERM;
Namhyung Kimf68d2042010-10-27 15:34:01 -07002898 void __user *datavp = (void __user *) data;
2899 unsigned long __user *datalp = datavp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 switch (request) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 /* read the word at location addr in the USER area. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 case PTRACE_PEEKUSR: {
2904 unsigned long index, tmp;
2905
2906 ret = -EIO;
2907 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002908#ifdef CONFIG_PPC32
Namhyung Kim9b05a692010-10-27 15:33:47 -07002909 index = addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002910 if ((addr & 3) || (index > PT_FPSCR)
2911 || (child->thread.regs == NULL))
2912#else
Namhyung Kim9b05a692010-10-27 15:33:47 -07002913 index = addr >> 3;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002914 if ((addr & 7) || (index > PT_FPSCR))
2915#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 break;
2917
2918 CHECK_FULL_REGS(child->thread.regs);
2919 if (index < PT_FPR0) {
Alexey Kardashevskiyee4a3912013-02-14 17:44:23 +00002920 ret = ptrace_get_reg(child, (int) index, &tmp);
2921 if (ret)
2922 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 } else {
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002924 unsigned int fpidx = index - PT_FPR0;
2925
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002926 flush_fp_to_thread(child);
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002927 if (fpidx < (PT_FPSCR - PT_FPR0))
Ulrich Weigand36aa1b12013-12-12 15:59:34 +11002928 memcpy(&tmp, &child->thread.TS_FPR(fpidx),
Anton Blanchard87fec052013-09-23 12:04:38 +10002929 sizeof(long));
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002930 else
Paul Mackerrasde79f7b2013-09-10 20:20:42 +10002931 tmp = child->thread.fp_state.fpscr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 }
Namhyung Kimf68d2042010-10-27 15:34:01 -07002933 ret = put_user(tmp, datalp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 break;
2935 }
2936
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 /* write the word at location addr in the USER area */
2938 case PTRACE_POKEUSR: {
2939 unsigned long index;
2940
2941 ret = -EIO;
2942 /* convert to index and check */
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002943#ifdef CONFIG_PPC32
Namhyung Kim9b05a692010-10-27 15:33:47 -07002944 index = addr >> 2;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002945 if ((addr & 3) || (index > PT_FPSCR)
2946 || (child->thread.regs == NULL))
2947#else
Namhyung Kim9b05a692010-10-27 15:33:47 -07002948 index = addr >> 3;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002949 if ((addr & 7) || (index > PT_FPSCR))
2950#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 break;
2952
2953 CHECK_FULL_REGS(child->thread.regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 if (index < PT_FPR0) {
Benjamin Herrenschmidt865418d2007-06-04 15:15:44 +10002955 ret = ptrace_put_reg(child, index, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 } else {
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002957 unsigned int fpidx = index - PT_FPR0;
2958
Stephen Rothwelle8a30302005-10-13 15:52:04 +10002959 flush_fp_to_thread(child);
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002960 if (fpidx < (PT_FPSCR - PT_FPR0))
Ulrich Weigand36aa1b12013-12-12 15:59:34 +11002961 memcpy(&child->thread.TS_FPR(fpidx), &data,
Anton Blanchard87fec052013-09-23 12:04:38 +10002962 sizeof(long));
Benjamin Herrenschmidte69b7422011-09-26 19:37:57 +00002963 else
Paul Mackerrasde79f7b2013-09-10 20:20:42 +10002964 child->thread.fp_state.fpscr = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 ret = 0;
2966 }
2967 break;
2968 }
2969
Dave Kleikamp3162d922010-02-08 11:51:05 +00002970 case PPC_PTRACE_GETHWDBGINFO: {
2971 struct ppc_debug_info dbginfo;
2972
2973 dbginfo.version = 1;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00002974#ifdef CONFIG_PPC_ADV_DEBUG_REGS
2975 dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
2976 dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
2977 dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
2978 dbginfo.data_bp_alignment = 4;
2979 dbginfo.sizeof_condition = 4;
2980 dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
2981 PPC_DEBUG_FEATURE_INSN_BP_MASK;
2982#ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
2983 dbginfo.features |=
2984 PPC_DEBUG_FEATURE_DATA_BP_RANGE |
2985 PPC_DEBUG_FEATURE_DATA_BP_MASK;
2986#endif
2987#else /* !CONFIG_PPC_ADV_DEBUG_REGS */
Dave Kleikamp3162d922010-02-08 11:51:05 +00002988 dbginfo.num_instruction_bps = 0;
2989 dbginfo.num_data_bps = 1;
2990 dbginfo.num_condition_regs = 0;
2991#ifdef CONFIG_PPC64
2992 dbginfo.data_bp_alignment = 8;
2993#else
2994 dbginfo.data_bp_alignment = 4;
2995#endif
2996 dbginfo.sizeof_condition = 0;
K.Prasad6c7a2852012-10-28 15:13:15 +00002997#ifdef CONFIG_HAVE_HW_BREAKPOINT
2998 dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
Michael Neuling517b7312013-03-21 20:12:33 +00002999 if (cpu_has_feature(CPU_FTR_DAWR))
3000 dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR;
K.Prasad6c7a2852012-10-28 15:13:15 +00003001#else
Dave Kleikamp3162d922010-02-08 11:51:05 +00003002 dbginfo.features = 0;
K.Prasad6c7a2852012-10-28 15:13:15 +00003003#endif /* CONFIG_HAVE_HW_BREAKPOINT */
Dave Kleikamp3bffb652010-02-08 11:51:18 +00003004#endif /* CONFIG_PPC_ADV_DEBUG_REGS */
Dave Kleikamp3162d922010-02-08 11:51:05 +00003005
Namhyung Kimf68d2042010-10-27 15:34:01 -07003006 if (!access_ok(VERIFY_WRITE, datavp,
Dave Kleikamp3162d922010-02-08 11:51:05 +00003007 sizeof(struct ppc_debug_info)))
3008 return -EFAULT;
Namhyung Kimf68d2042010-10-27 15:34:01 -07003009 ret = __copy_to_user(datavp, &dbginfo,
3010 sizeof(struct ppc_debug_info)) ?
Dave Kleikamp3162d922010-02-08 11:51:05 +00003011 -EFAULT : 0;
3012 break;
3013 }
3014
3015 case PPC_PTRACE_SETHWDEBUG: {
3016 struct ppc_hw_breakpoint bp_info;
3017
Namhyung Kimf68d2042010-10-27 15:34:01 -07003018 if (!access_ok(VERIFY_READ, datavp,
Dave Kleikamp3162d922010-02-08 11:51:05 +00003019 sizeof(struct ppc_hw_breakpoint)))
3020 return -EFAULT;
Namhyung Kimf68d2042010-10-27 15:34:01 -07003021 ret = __copy_from_user(&bp_info, datavp,
Dave Kleikamp3162d922010-02-08 11:51:05 +00003022 sizeof(struct ppc_hw_breakpoint)) ?
3023 -EFAULT : 0;
3024 if (!ret)
3025 ret = ppc_set_hwdebug(child, &bp_info);
3026 break;
3027 }
3028
3029 case PPC_PTRACE_DELHWDEBUG: {
Michael Neulingec1b33d2012-10-28 15:13:17 +00003030 ret = ppc_del_hwdebug(child, data);
Dave Kleikamp3162d922010-02-08 11:51:05 +00003031 break;
3032 }
3033
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003034 case PTRACE_GET_DEBUGREG: {
Michael Neuling9422de32012-12-20 14:06:44 +00003035#ifndef CONFIG_PPC_ADV_DEBUG_REGS
3036 unsigned long dabr_fake;
3037#endif
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003038 ret = -EINVAL;
3039 /* We only support one DABR and no IABRS at the moment */
3040 if (addr > 0)
3041 break;
Dave Kleikamp3bffb652010-02-08 11:51:18 +00003042#ifdef CONFIG_PPC_ADV_DEBUG_REGS
Bharat Bhushan51ae8d42013-07-04 11:45:46 +05303043 ret = put_user(child->thread.debug.dac1, datalp);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00003044#else
Michael Neuling9422de32012-12-20 14:06:44 +00003045 dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
3046 (child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
3047 ret = put_user(dabr_fake, datalp);
Dave Kleikamp3bffb652010-02-08 11:51:18 +00003048#endif
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003049 break;
3050 }
3051
3052 case PTRACE_SET_DEBUGREG:
3053 ret = ptrace_set_debugreg(child, addr, data);
3054 break;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003055
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +10003056#ifdef CONFIG_PPC64
3057 case PTRACE_GETREGS64:
3058#endif
Roland McGrathc391cd02007-12-20 03:58:36 -08003059 case PTRACE_GETREGS: /* Get all pt_regs from the child. */
3060 return copy_regset_to_user(child, &user_ppc_native_view,
3061 REGSET_GPR,
3062 0, sizeof(struct pt_regs),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003063 datavp);
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003064
Benjamin Herrenschmidt0b3d5c42007-06-04 15:15:39 +10003065#ifdef CONFIG_PPC64
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +10003066 case PTRACE_SETREGS64:
3067#endif
Roland McGrathc391cd02007-12-20 03:58:36 -08003068 case PTRACE_SETREGS: /* Set all gp regs in the child. */
3069 return copy_regset_from_user(child, &user_ppc_native_view,
3070 REGSET_GPR,
3071 0, sizeof(struct pt_regs),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003072 datavp);
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003073
Roland McGrathc391cd02007-12-20 03:58:36 -08003074 case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
3075 return copy_regset_to_user(child, &user_ppc_native_view,
3076 REGSET_FPR,
3077 0, sizeof(elf_fpregset_t),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003078 datavp);
Benjamin Herrenschmidte17666b2007-06-04 15:15:43 +10003079
Roland McGrathc391cd02007-12-20 03:58:36 -08003080 case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
3081 return copy_regset_from_user(child, &user_ppc_native_view,
3082 REGSET_FPR,
3083 0, sizeof(elf_fpregset_t),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003084 datavp);
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003085
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086#ifdef CONFIG_ALTIVEC
3087 case PTRACE_GETVRREGS:
Roland McGrathc391cd02007-12-20 03:58:36 -08003088 return copy_regset_to_user(child, &user_ppc_native_view,
3089 REGSET_VMX,
3090 0, (33 * sizeof(vector128) +
3091 sizeof(u32)),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003092 datavp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
3094 case PTRACE_SETVRREGS:
Roland McGrathc391cd02007-12-20 03:58:36 -08003095 return copy_regset_from_user(child, &user_ppc_native_view,
3096 REGSET_VMX,
3097 0, (33 * sizeof(vector128) +
3098 sizeof(u32)),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003099 datavp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100#endif
Michael Neulingce48b212008-06-25 14:07:18 +10003101#ifdef CONFIG_VSX
3102 case PTRACE_GETVSRREGS:
3103 return copy_regset_to_user(child, &user_ppc_native_view,
3104 REGSET_VSX,
Michael Neuling1ac42ef82008-07-29 01:13:14 +10003105 0, 32 * sizeof(double),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003106 datavp);
Michael Neulingce48b212008-06-25 14:07:18 +10003107
3108 case PTRACE_SETVSRREGS:
3109 return copy_regset_from_user(child, &user_ppc_native_view,
3110 REGSET_VSX,
Michael Neuling1ac42ef82008-07-29 01:13:14 +10003111 0, 32 * sizeof(double),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003112 datavp);
Michael Neulingce48b212008-06-25 14:07:18 +10003113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114#ifdef CONFIG_SPE
3115 case PTRACE_GETEVRREGS:
3116 /* Get the child spe register state. */
Roland McGrathc391cd02007-12-20 03:58:36 -08003117 return copy_regset_to_user(child, &user_ppc_native_view,
3118 REGSET_SPE, 0, 35 * sizeof(u32),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003119 datavp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 case PTRACE_SETEVRREGS:
3122 /* Set the child spe register state. */
Roland McGrathc391cd02007-12-20 03:58:36 -08003123 return copy_regset_from_user(child, &user_ppc_native_view,
3124 REGSET_SPE, 0, 35 * sizeof(u32),
Namhyung Kimf68d2042010-10-27 15:34:01 -07003125 datavp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126#endif
3127
3128 default:
3129 ret = ptrace_request(child, request, addr, data);
3130 break;
3131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 return ret;
3133}
3134
Michael Ellerman2449acc2015-07-23 20:21:09 +10003135#ifdef CONFIG_SECCOMP
3136static int do_seccomp(struct pt_regs *regs)
3137{
3138 if (!test_thread_flag(TIF_SECCOMP))
3139 return 0;
3140
3141 /*
3142 * The ABI we present to seccomp tracers is that r3 contains
3143 * the syscall return value and orig_gpr3 contains the first
3144 * syscall parameter. This is different to the ptrace ABI where
3145 * both r3 and orig_gpr3 contain the first syscall parameter.
3146 */
3147 regs->gpr[3] = -ENOSYS;
3148
3149 /*
3150 * We use the __ version here because we have already checked
3151 * TIF_SECCOMP. If this fails, there is nothing left to do, we
3152 * have already loaded -ENOSYS into r3, or seccomp has put
3153 * something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
3154 */
Andy Lutomirski2f275de2016-05-27 12:57:02 -07003155 if (__secure_computing(NULL))
Michael Ellerman2449acc2015-07-23 20:21:09 +10003156 return -1;
3157
3158 /*
3159 * The syscall was allowed by seccomp, restore the register
Kees Cook1addc572016-06-02 19:55:09 -07003160 * state to what audit expects.
Michael Ellerman2449acc2015-07-23 20:21:09 +10003161 * Note that we use orig_gpr3, which means a seccomp tracer can
3162 * modify the first syscall parameter (in orig_gpr3) and also
3163 * allow the syscall to proceed.
3164 */
3165 regs->gpr[3] = regs->orig_gpr3;
3166
3167 return 0;
3168}
3169#else
3170static inline int do_seccomp(struct pt_regs *regs) { return 0; }
3171#endif /* CONFIG_SECCOMP */
3172
Michael Ellermand3837412015-07-23 20:21:02 +10003173/**
3174 * do_syscall_trace_enter() - Do syscall tracing on kernel entry.
3175 * @regs: the pt_regs of the task to trace (current)
3176 *
3177 * Performs various types of tracing on syscall entry. This includes seccomp,
3178 * ptrace, syscall tracepoints and audit.
3179 *
3180 * The pt_regs are potentially visible to userspace via ptrace, so their
3181 * contents is ABI.
3182 *
3183 * One or more of the tracers may modify the contents of pt_regs, in particular
3184 * to modify arguments or even the syscall number itself.
3185 *
3186 * It's also possible that a tracer can choose to reject the system call. In
3187 * that case this function will return an illegal syscall number, and will put
3188 * an appropriate return value in regs->r3.
3189 *
3190 * Return: the (possibly changed) syscall number.
Roland McGrath4f72c422008-07-27 16:51:03 +10003191 */
3192long do_syscall_trace_enter(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193{
Li Zhong22ecbe82013-05-13 16:16:40 +00003194 user_exit();
3195
Kees Cook1addc572016-06-02 19:55:09 -07003196 /*
3197 * The tracer may decide to abort the syscall, if so tracehook
3198 * will return !0. Note that the tracer may also just change
3199 * regs->gpr[0] to an invalid syscall number, that is handled
3200 * below on the exit path.
3201 */
3202 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
3203 tracehook_report_syscall_entry(regs))
3204 goto skip;
3205
3206 /* Run seccomp after ptrace; allow it to set gpr[3]. */
Michael Ellerman2449acc2015-07-23 20:21:09 +10003207 if (do_seccomp(regs))
3208 return -1;
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003209
Kees Cook1addc572016-06-02 19:55:09 -07003210 /* Avoid trace and audit when syscall is invalid. */
3211 if (regs->gpr[0] >= NR_syscalls)
3212 goto skip;
David Woodhouseea9c1022005-05-08 15:56:09 +01003213
Ian Munsie02424d82011-02-02 17:27:24 +00003214 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
3215 trace_sys_enter(regs, regs->gpr[0]);
3216
David Woodhousecfcd1702007-01-14 09:38:18 +08003217#ifdef CONFIG_PPC64
Eric Parisb05d8442012-01-03 14:23:06 -05003218 if (!is_32bit_task())
Eric Paris91397402014-03-11 13:29:28 -04003219 audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4],
Eric Parisb05d8442012-01-03 14:23:06 -05003220 regs->gpr[5], regs->gpr[6]);
3221 else
Stephen Rothwelle8a30302005-10-13 15:52:04 +10003222#endif
Eric Paris91397402014-03-11 13:29:28 -04003223 audit_syscall_entry(regs->gpr[0],
Eric Parisb05d8442012-01-03 14:23:06 -05003224 regs->gpr[3] & 0xffffffff,
3225 regs->gpr[4] & 0xffffffff,
3226 regs->gpr[5] & 0xffffffff,
3227 regs->gpr[6] & 0xffffffff);
Roland McGrath4f72c422008-07-27 16:51:03 +10003228
Michael Ellermand3837412015-07-23 20:21:02 +10003229 /* Return the possibly modified but valid syscall number */
3230 return regs->gpr[0];
Kees Cook1addc572016-06-02 19:55:09 -07003231
3232skip:
3233 /*
3234 * If we are aborting explicitly, or if the syscall number is
3235 * now invalid, set the return value to -ENOSYS.
3236 */
3237 regs->gpr[3] = -ENOSYS;
3238 return -1;
David Woodhouseea9c1022005-05-08 15:56:09 +01003239}
3240
3241void do_syscall_trace_leave(struct pt_regs *regs)
3242{
Roland McGrath4f72c422008-07-27 16:51:03 +10003243 int step;
3244
Eric Parisd7e75282012-01-03 14:23:06 -05003245 audit_syscall_exit(regs);
David Woodhouseea9c1022005-05-08 15:56:09 +01003246
Ian Munsie02424d82011-02-02 17:27:24 +00003247 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
3248 trace_sys_exit(regs, regs->result);
3249
Roland McGrath4f72c422008-07-27 16:51:03 +10003250 step = test_thread_flag(TIF_SINGLESTEP);
3251 if (step || test_thread_flag(TIF_SYSCALL_TRACE))
3252 tracehook_report_syscall_exit(regs, step);
Li Zhong22ecbe82013-05-13 16:16:40 +00003253
3254 user_enter();
David Woodhouseea9c1022005-05-08 15:56:09 +01003255}