/arch/powerpc/kernel/ptrace.c

http://github.com/mirrors/linux · C · 3378 lines · 2347 code · 403 blank · 628 comment · 428 complexity · ded8c5fcfef1f6a76c1bdf310e429be0 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/m68k/kernel/ptrace.c"
  6. * Copyright (C) 1994 by Hamish Macdonald
  7. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  8. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  9. *
  10. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  11. * and Paul Mackerras (paulus@samba.org).
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file README.legal in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/regset.h>
  24. #include <linux/tracehook.h>
  25. #include <linux/elf.h>
  26. #include <linux/user.h>
  27. #include <linux/security.h>
  28. #include <linux/signal.h>
  29. #include <linux/seccomp.h>
  30. #include <linux/audit.h>
  31. #include <trace/syscall.h>
  32. #include <linux/hw_breakpoint.h>
  33. #include <linux/perf_event.h>
  34. #include <linux/context_tracking.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/page.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/switch_to.h>
  39. #define CREATE_TRACE_POINTS
  40. #include <trace/events/syscalls.h>
  41. /*
  42. * The parameter save area on the stack is used to store arguments being passed
  43. * to callee function and is located at fixed offset from stack pointer.
  44. */
  45. #ifdef CONFIG_PPC32
  46. #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
  47. #else /* CONFIG_PPC32 */
  48. #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
  49. #endif
  50. struct pt_regs_offset {
  51. const char *name;
  52. int offset;
  53. };
  54. #define STR(s) #s /* convert to string */
  55. #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
  56. #define GPR_OFFSET_NAME(num) \
  57. {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
  58. {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
  59. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  60. #define TVSO(f) (offsetof(struct thread_vr_state, f))
  61. #define TFSO(f) (offsetof(struct thread_fp_state, f))
  62. #define TSO(f) (offsetof(struct thread_struct, f))
  63. static const struct pt_regs_offset regoffset_table[] = {
  64. GPR_OFFSET_NAME(0),
  65. GPR_OFFSET_NAME(1),
  66. GPR_OFFSET_NAME(2),
  67. GPR_OFFSET_NAME(3),
  68. GPR_OFFSET_NAME(4),
  69. GPR_OFFSET_NAME(5),
  70. GPR_OFFSET_NAME(6),
  71. GPR_OFFSET_NAME(7),
  72. GPR_OFFSET_NAME(8),
  73. GPR_OFFSET_NAME(9),
  74. GPR_OFFSET_NAME(10),
  75. GPR_OFFSET_NAME(11),
  76. GPR_OFFSET_NAME(12),
  77. GPR_OFFSET_NAME(13),
  78. GPR_OFFSET_NAME(14),
  79. GPR_OFFSET_NAME(15),
  80. GPR_OFFSET_NAME(16),
  81. GPR_OFFSET_NAME(17),
  82. GPR_OFFSET_NAME(18),
  83. GPR_OFFSET_NAME(19),
  84. GPR_OFFSET_NAME(20),
  85. GPR_OFFSET_NAME(21),
  86. GPR_OFFSET_NAME(22),
  87. GPR_OFFSET_NAME(23),
  88. GPR_OFFSET_NAME(24),
  89. GPR_OFFSET_NAME(25),
  90. GPR_OFFSET_NAME(26),
  91. GPR_OFFSET_NAME(27),
  92. GPR_OFFSET_NAME(28),
  93. GPR_OFFSET_NAME(29),
  94. GPR_OFFSET_NAME(30),
  95. GPR_OFFSET_NAME(31),
  96. REG_OFFSET_NAME(nip),
  97. REG_OFFSET_NAME(msr),
  98. REG_OFFSET_NAME(ctr),
  99. REG_OFFSET_NAME(link),
  100. REG_OFFSET_NAME(xer),
  101. REG_OFFSET_NAME(ccr),
  102. #ifdef CONFIG_PPC64
  103. REG_OFFSET_NAME(softe),
  104. #else
  105. REG_OFFSET_NAME(mq),
  106. #endif
  107. REG_OFFSET_NAME(trap),
  108. REG_OFFSET_NAME(dar),
  109. REG_OFFSET_NAME(dsisr),
  110. REG_OFFSET_END,
  111. };
  112. /**
  113. * regs_query_register_offset() - query register offset from its name
  114. * @name: the name of a register
  115. *
  116. * regs_query_register_offset() returns the offset of a register in struct
  117. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  118. */
  119. int regs_query_register_offset(const char *name)
  120. {
  121. const struct pt_regs_offset *roff;
  122. for (roff = regoffset_table; roff->name != NULL; roff++)
  123. if (!strcmp(roff->name, name))
  124. return roff->offset;
  125. return -EINVAL;
  126. }
  127. /**
  128. * regs_query_register_name() - query register name from its offset
  129. * @offset: the offset of a register in struct pt_regs.
  130. *
  131. * regs_query_register_name() returns the name of a register from its
  132. * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
  133. */
  134. const char *regs_query_register_name(unsigned int offset)
  135. {
  136. const struct pt_regs_offset *roff;
  137. for (roff = regoffset_table; roff->name != NULL; roff++)
  138. if (roff->offset == offset)
  139. return roff->name;
  140. return NULL;
  141. }
  142. /*
  143. * does not yet catch signals sent when the child dies.
  144. * in exit.c or in signal.c.
  145. */
  146. /*
  147. * Set of msr bits that gdb can change on behalf of a process.
  148. */
  149. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  150. #define MSR_DEBUGCHANGE 0
  151. #else
  152. #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
  153. #endif
  154. /*
  155. * Max register writeable via put_reg
  156. */
  157. #ifdef CONFIG_PPC32
  158. #define PT_MAX_PUT_REG PT_MQ
  159. #else
  160. #define PT_MAX_PUT_REG PT_CCR
  161. #endif
  162. static unsigned long get_user_msr(struct task_struct *task)
  163. {
  164. return task->thread.regs->msr | task->thread.fpexc_mode;
  165. }
  166. static int set_user_msr(struct task_struct *task, unsigned long msr)
  167. {
  168. task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
  169. task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
  170. return 0;
  171. }
  172. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  173. static unsigned long get_user_ckpt_msr(struct task_struct *task)
  174. {
  175. return task->thread.ckpt_regs.msr | task->thread.fpexc_mode;
  176. }
  177. static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr)
  178. {
  179. task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE;
  180. task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE;
  181. return 0;
  182. }
  183. static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap)
  184. {
  185. task->thread.ckpt_regs.trap = trap & 0xfff0;
  186. return 0;
  187. }
  188. #endif
  189. #ifdef CONFIG_PPC64
  190. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  191. {
  192. *data = task->thread.dscr;
  193. return 0;
  194. }
  195. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  196. {
  197. task->thread.dscr = dscr;
  198. task->thread.dscr_inherit = 1;
  199. return 0;
  200. }
  201. #else
  202. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  203. {
  204. return -EIO;
  205. }
  206. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  207. {
  208. return -EIO;
  209. }
  210. #endif
  211. /*
  212. * We prevent mucking around with the reserved area of trap
  213. * which are used internally by the kernel.
  214. */
  215. static int set_user_trap(struct task_struct *task, unsigned long trap)
  216. {
  217. task->thread.regs->trap = trap & 0xfff0;
  218. return 0;
  219. }
  220. /*
  221. * Get contents of register REGNO in task TASK.
  222. */
  223. int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)
  224. {
  225. if ((task->thread.regs == NULL) || !data)
  226. return -EIO;
  227. if (regno == PT_MSR) {
  228. *data = get_user_msr(task);
  229. return 0;
  230. }
  231. if (regno == PT_DSCR)
  232. return get_user_dscr(task, data);
  233. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) {
  234. *data = ((unsigned long *)task->thread.regs)[regno];
  235. return 0;
  236. }
  237. return -EIO;
  238. }
  239. /*
  240. * Write contents of register REGNO in task TASK.
  241. */
  242. int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
  243. {
  244. if (task->thread.regs == NULL)
  245. return -EIO;
  246. if (regno == PT_MSR)
  247. return set_user_msr(task, data);
  248. if (regno == PT_TRAP)
  249. return set_user_trap(task, data);
  250. if (regno == PT_DSCR)
  251. return set_user_dscr(task, data);
  252. if (regno <= PT_MAX_PUT_REG) {
  253. ((unsigned long *)task->thread.regs)[regno] = data;
  254. return 0;
  255. }
  256. return -EIO;
  257. }
  258. static int gpr_get(struct task_struct *target, const struct user_regset *regset,
  259. unsigned int pos, unsigned int count,
  260. void *kbuf, void __user *ubuf)
  261. {
  262. int i, ret;
  263. if (target->thread.regs == NULL)
  264. return -EIO;
  265. if (!FULL_REGS(target->thread.regs)) {
  266. /* We have a partial register set. Fill 14-31 with bogus values */
  267. for (i = 14; i < 32; i++)
  268. target->thread.regs->gpr[i] = NV_REG_POISON;
  269. }
  270. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  271. target->thread.regs,
  272. 0, offsetof(struct pt_regs, msr));
  273. if (!ret) {
  274. unsigned long msr = get_user_msr(target);
  275. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  276. offsetof(struct pt_regs, msr),
  277. offsetof(struct pt_regs, msr) +
  278. sizeof(msr));
  279. }
  280. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  281. offsetof(struct pt_regs, msr) + sizeof(long));
  282. if (!ret)
  283. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  284. &target->thread.regs->orig_gpr3,
  285. offsetof(struct pt_regs, orig_gpr3),
  286. sizeof(struct pt_regs));
  287. if (!ret)
  288. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  289. sizeof(struct pt_regs), -1);
  290. return ret;
  291. }
  292. static int gpr_set(struct task_struct *target, const struct user_regset *regset,
  293. unsigned int pos, unsigned int count,
  294. const void *kbuf, const void __user *ubuf)
  295. {
  296. unsigned long reg;
  297. int ret;
  298. if (target->thread.regs == NULL)
  299. return -EIO;
  300. CHECK_FULL_REGS(target->thread.regs);
  301. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  302. target->thread.regs,
  303. 0, PT_MSR * sizeof(reg));
  304. if (!ret && count > 0) {
  305. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  306. PT_MSR * sizeof(reg),
  307. (PT_MSR + 1) * sizeof(reg));
  308. if (!ret)
  309. ret = set_user_msr(target, reg);
  310. }
  311. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  312. offsetof(struct pt_regs, msr) + sizeof(long));
  313. if (!ret)
  314. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  315. &target->thread.regs->orig_gpr3,
  316. PT_ORIG_R3 * sizeof(reg),
  317. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  318. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  319. ret = user_regset_copyin_ignore(
  320. &pos, &count, &kbuf, &ubuf,
  321. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  322. PT_TRAP * sizeof(reg));
  323. if (!ret && count > 0) {
  324. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  325. PT_TRAP * sizeof(reg),
  326. (PT_TRAP + 1) * sizeof(reg));
  327. if (!ret)
  328. ret = set_user_trap(target, reg);
  329. }
  330. if (!ret)
  331. ret = user_regset_copyin_ignore(
  332. &pos, &count, &kbuf, &ubuf,
  333. (PT_TRAP + 1) * sizeof(reg), -1);
  334. return ret;
  335. }
  336. /*
  337. * When the transaction is active, 'transact_fp' holds the current running
  338. * value of all FPR registers and 'fp_state' holds the last checkpointed
  339. * value of all FPR registers for the current transaction. When transaction
  340. * is not active 'fp_state' holds the current running state of all the FPR
  341. * registers. So this function which returns the current running values of
  342. * all the FPR registers, needs to know whether any transaction is active
  343. * or not.
  344. *
  345. * Userspace interface buffer layout:
  346. *
  347. * struct data {
  348. * u64 fpr[32];
  349. * u64 fpscr;
  350. * };
  351. *
  352. * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM
  353. * which determines the final code in this function. All the combinations of
  354. * these two config options are possible except the one below as transactional
  355. * memory config pulls in CONFIG_VSX automatically.
  356. *
  357. * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  358. */
  359. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  360. unsigned int pos, unsigned int count,
  361. void *kbuf, void __user *ubuf)
  362. {
  363. #ifdef CONFIG_VSX
  364. u64 buf[33];
  365. int i;
  366. #endif
  367. flush_fp_to_thread(target);
  368. #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  369. /* copy to local buffer then write that out */
  370. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  371. flush_altivec_to_thread(target);
  372. flush_tmregs_to_thread(target);
  373. for (i = 0; i < 32 ; i++)
  374. buf[i] = target->thread.TS_TRANS_FPR(i);
  375. buf[32] = target->thread.transact_fp.fpscr;
  376. } else {
  377. for (i = 0; i < 32 ; i++)
  378. buf[i] = target->thread.TS_FPR(i);
  379. buf[32] = target->thread.fp_state.fpscr;
  380. }
  381. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  382. #endif
  383. #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  384. /* copy to local buffer then write that out */
  385. for (i = 0; i < 32 ; i++)
  386. buf[i] = target->thread.TS_FPR(i);
  387. buf[32] = target->thread.fp_state.fpscr;
  388. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  389. #endif
  390. #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  391. BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
  392. offsetof(struct thread_fp_state, fpr[32]));
  393. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  394. &target->thread.fp_state, 0, -1);
  395. #endif
  396. }
  397. /*
  398. * When the transaction is active, 'transact_fp' holds the current running
  399. * value of all FPR registers and 'fp_state' holds the last checkpointed
  400. * value of all FPR registers for the current transaction. When transaction
  401. * is not active 'fp_state' holds the current running state of all the FPR
  402. * registers. So this function which setss the current running values of
  403. * all the FPR registers, needs to know whether any transaction is active
  404. * or not.
  405. *
  406. * Userspace interface buffer layout:
  407. *
  408. * struct data {
  409. * u64 fpr[32];
  410. * u64 fpscr;
  411. * };
  412. *
  413. * There are two config options CONFIG_VSX and CONFIG_PPC_TRANSACTIONAL_MEM
  414. * which determines the final code in this function. All the combinations of
  415. * these two config options are possible except the one below as transactional
  416. * memory config pulls in CONFIG_VSX automatically.
  417. *
  418. * !defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  419. */
  420. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  421. unsigned int pos, unsigned int count,
  422. const void *kbuf, const void __user *ubuf)
  423. {
  424. #ifdef CONFIG_VSX
  425. u64 buf[33];
  426. int i;
  427. #endif
  428. flush_fp_to_thread(target);
  429. #if defined(CONFIG_VSX) && defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  430. /* copy to local buffer then write that out */
  431. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  432. if (i)
  433. return i;
  434. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  435. flush_altivec_to_thread(target);
  436. flush_tmregs_to_thread(target);
  437. for (i = 0; i < 32 ; i++)
  438. target->thread.TS_TRANS_FPR(i) = buf[i];
  439. target->thread.transact_fp.fpscr = buf[32];
  440. } else {
  441. for (i = 0; i < 32 ; i++)
  442. target->thread.TS_FPR(i) = buf[i];
  443. target->thread.fp_state.fpscr = buf[32];
  444. }
  445. return 0;
  446. #endif
  447. #if defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  448. /* copy to local buffer then write that out */
  449. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  450. if (i)
  451. return i;
  452. for (i = 0; i < 32 ; i++)
  453. target->thread.TS_FPR(i) = buf[i];
  454. target->thread.fp_state.fpscr = buf[32];
  455. return 0;
  456. #endif
  457. #if !defined(CONFIG_VSX) && !defined(CONFIG_PPC_TRANSACTIONAL_MEM)
  458. BUILD_BUG_ON(offsetof(struct thread_fp_state, fpscr) !=
  459. offsetof(struct thread_fp_state, fpr[32]));
  460. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  461. &target->thread.fp_state, 0, -1);
  462. #endif
  463. }
  464. #ifdef CONFIG_ALTIVEC
  465. /*
  466. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  467. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  468. * corresponding vector registers. Quadword 32 contains the vscr as the
  469. * last word (offset 12) within that quadword. Quadword 33 contains the
  470. * vrsave as the first word (offset 0) within the quadword.
  471. *
  472. * This definition of the VMX state is compatible with the current PPC32
  473. * ptrace interface. This allows signal handling and ptrace to use the
  474. * same structures. This also simplifies the implementation of a bi-arch
  475. * (combined (32- and 64-bit) gdb.
  476. */
  477. static int vr_active(struct task_struct *target,
  478. const struct user_regset *regset)
  479. {
  480. flush_altivec_to_thread(target);
  481. return target->thread.used_vr ? regset->n : 0;
  482. }
  483. /*
  484. * When the transaction is active, 'transact_vr' holds the current running
  485. * value of all the VMX registers and 'vr_state' holds the last checkpointed
  486. * value of all the VMX registers for the current transaction to fall back
  487. * on in case it aborts. When transaction is not active 'vr_state' holds
  488. * the current running state of all the VMX registers. So this function which
  489. * gets the current running values of all the VMX registers, needs to know
  490. * whether any transaction is active or not.
  491. *
  492. * Userspace interface buffer layout:
  493. *
  494. * struct data {
  495. * vector128 vr[32];
  496. * vector128 vscr;
  497. * vector128 vrsave;
  498. * };
  499. */
  500. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  501. unsigned int pos, unsigned int count,
  502. void *kbuf, void __user *ubuf)
  503. {
  504. struct thread_vr_state *addr;
  505. int ret;
  506. flush_altivec_to_thread(target);
  507. BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
  508. offsetof(struct thread_vr_state, vr[32]));
  509. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  510. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  511. flush_fp_to_thread(target);
  512. flush_tmregs_to_thread(target);
  513. addr = &target->thread.transact_vr;
  514. } else {
  515. addr = &target->thread.vr_state;
  516. }
  517. #else
  518. addr = &target->thread.vr_state;
  519. #endif
  520. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  521. addr, 0,
  522. 33 * sizeof(vector128));
  523. if (!ret) {
  524. /*
  525. * Copy out only the low-order word of vrsave.
  526. */
  527. union {
  528. elf_vrreg_t reg;
  529. u32 word;
  530. } vrsave;
  531. memset(&vrsave, 0, sizeof(vrsave));
  532. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  533. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  534. vrsave.word = target->thread.transact_vrsave;
  535. else
  536. vrsave.word = target->thread.vrsave;
  537. #else
  538. vrsave.word = target->thread.vrsave;
  539. #endif
  540. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  541. 33 * sizeof(vector128), -1);
  542. }
  543. return ret;
  544. }
  545. /*
  546. * When the transaction is active, 'transact_vr' holds the current running
  547. * value of all the VMX registers and 'vr_state' holds the last checkpointed
  548. * value of all the VMX registers for the current transaction to fall back
  549. * on in case it aborts. When transaction is not active 'vr_state' holds
  550. * the current running state of all the VMX registers. So this function which
  551. * sets the current running values of all the VMX registers, needs to know
  552. * whether any transaction is active or not.
  553. *
  554. * Userspace interface buffer layout:
  555. *
  556. * struct data {
  557. * vector128 vr[32];
  558. * vector128 vscr;
  559. * vector128 vrsave;
  560. * };
  561. */
  562. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  563. unsigned int pos, unsigned int count,
  564. const void *kbuf, const void __user *ubuf)
  565. {
  566. struct thread_vr_state *addr;
  567. int ret;
  568. flush_altivec_to_thread(target);
  569. BUILD_BUG_ON(offsetof(struct thread_vr_state, vscr) !=
  570. offsetof(struct thread_vr_state, vr[32]));
  571. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  572. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  573. flush_fp_to_thread(target);
  574. flush_tmregs_to_thread(target);
  575. addr = &target->thread.transact_vr;
  576. } else {
  577. addr = &target->thread.vr_state;
  578. }
  579. #else
  580. addr = &target->thread.vr_state;
  581. #endif
  582. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  583. addr, 0,
  584. 33 * sizeof(vector128));
  585. if (!ret && count > 0) {
  586. /*
  587. * We use only the first word of vrsave.
  588. */
  589. union {
  590. elf_vrreg_t reg;
  591. u32 word;
  592. } vrsave;
  593. memset(&vrsave, 0, sizeof(vrsave));
  594. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  595. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  596. vrsave.word = target->thread.transact_vrsave;
  597. else
  598. vrsave.word = target->thread.vrsave;
  599. #else
  600. vrsave.word = target->thread.vrsave;
  601. #endif
  602. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  603. 33 * sizeof(vector128), -1);
  604. if (!ret) {
  605. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  606. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  607. target->thread.transact_vrsave = vrsave.word;
  608. else
  609. target->thread.vrsave = vrsave.word;
  610. #else
  611. target->thread.vrsave = vrsave.word;
  612. #endif
  613. }
  614. }
  615. return ret;
  616. }
  617. #endif /* CONFIG_ALTIVEC */
  618. #ifdef CONFIG_VSX
  619. /*
  620. * Currently to set and and get all the vsx state, you need to call
  621. * the fp and VMX calls as well. This only get/sets the lower 32
  622. * 128bit VSX registers.
  623. */
  624. static int vsr_active(struct task_struct *target,
  625. const struct user_regset *regset)
  626. {
  627. flush_vsx_to_thread(target);
  628. return target->thread.used_vsr ? regset->n : 0;
  629. }
  630. /*
  631. * When the transaction is active, 'transact_fp' holds the current running
  632. * value of all FPR registers and 'fp_state' holds the last checkpointed
  633. * value of all FPR registers for the current transaction. When transaction
  634. * is not active 'fp_state' holds the current running state of all the FPR
  635. * registers. So this function which returns the current running values of
  636. * all the FPR registers, needs to know whether any transaction is active
  637. * or not.
  638. *
  639. * Userspace interface buffer layout:
  640. *
  641. * struct data {
  642. * u64 vsx[32];
  643. * };
  644. */
  645. static int vsr_get(struct task_struct *target, const struct user_regset *regset,
  646. unsigned int pos, unsigned int count,
  647. void *kbuf, void __user *ubuf)
  648. {
  649. u64 buf[32];
  650. int ret, i;
  651. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  652. flush_fp_to_thread(target);
  653. flush_altivec_to_thread(target);
  654. flush_tmregs_to_thread(target);
  655. #endif
  656. flush_vsx_to_thread(target);
  657. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  658. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  659. for (i = 0; i < 32 ; i++)
  660. buf[i] = target->thread.
  661. transact_fp.fpr[i][TS_VSRLOWOFFSET];
  662. } else {
  663. for (i = 0; i < 32 ; i++)
  664. buf[i] = target->thread.
  665. fp_state.fpr[i][TS_VSRLOWOFFSET];
  666. }
  667. #else
  668. for (i = 0; i < 32 ; i++)
  669. buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
  670. #endif
  671. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  672. buf, 0, 32 * sizeof(double));
  673. return ret;
  674. }
  675. /*
  676. * When the transaction is active, 'transact_fp' holds the current running
  677. * value of all FPR registers and 'fp_state' holds the last checkpointed
  678. * value of all FPR registers for the current transaction. When transaction
  679. * is not active 'fp_state' holds the current running state of all the FPR
  680. * registers. So this function which sets the current running values of all
  681. * the FPR registers, needs to know whether any transaction is active or not.
  682. *
  683. * Userspace interface buffer layout:
  684. *
  685. * struct data {
  686. * u64 vsx[32];
  687. * };
  688. */
  689. static int vsr_set(struct task_struct *target, const struct user_regset *regset,
  690. unsigned int pos, unsigned int count,
  691. const void *kbuf, const void __user *ubuf)
  692. {
  693. u64 buf[32];
  694. int ret,i;
  695. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  696. flush_fp_to_thread(target);
  697. flush_altivec_to_thread(target);
  698. flush_tmregs_to_thread(target);
  699. #endif
  700. flush_vsx_to_thread(target);
  701. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  702. buf, 0, 32 * sizeof(double));
  703. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  704. if (MSR_TM_ACTIVE(target->thread.regs->msr)) {
  705. for (i = 0; i < 32 ; i++)
  706. target->thread.transact_fp.
  707. fpr[i][TS_VSRLOWOFFSET] = buf[i];
  708. } else {
  709. for (i = 0; i < 32 ; i++)
  710. target->thread.fp_state.
  711. fpr[i][TS_VSRLOWOFFSET] = buf[i];
  712. }
  713. #else
  714. for (i = 0; i < 32 ; i++)
  715. target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  716. #endif
  717. return ret;
  718. }
  719. #endif /* CONFIG_VSX */
  720. #ifdef CONFIG_SPE
  721. /*
  722. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  723. *
  724. * struct {
  725. * u32 evr[32];
  726. * u64 acc;
  727. * u32 spefscr;
  728. * }
  729. */
  730. static int evr_active(struct task_struct *target,
  731. const struct user_regset *regset)
  732. {
  733. flush_spe_to_thread(target);
  734. return target->thread.used_spe ? regset->n : 0;
  735. }
  736. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  737. unsigned int pos, unsigned int count,
  738. void *kbuf, void __user *ubuf)
  739. {
  740. int ret;
  741. flush_spe_to_thread(target);
  742. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  743. &target->thread.evr,
  744. 0, sizeof(target->thread.evr));
  745. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  746. offsetof(struct thread_struct, spefscr));
  747. if (!ret)
  748. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  749. &target->thread.acc,
  750. sizeof(target->thread.evr), -1);
  751. return ret;
  752. }
  753. static 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. flush_spe_to_thread(target);
  759. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  760. &target->thread.evr,
  761. 0, sizeof(target->thread.evr));
  762. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  763. offsetof(struct thread_struct, spefscr));
  764. if (!ret)
  765. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  766. &target->thread.acc,
  767. sizeof(target->thread.evr), -1);
  768. return ret;
  769. }
  770. #endif /* CONFIG_SPE */
  771. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  772. /**
  773. * tm_cgpr_active - get active number of registers in CGPR
  774. * @target: The target task.
  775. * @regset: The user regset structure.
  776. *
  777. * This function checks for the active number of available
  778. * regisers in transaction checkpointed GPR category.
  779. */
  780. static int tm_cgpr_active(struct task_struct *target,
  781. const struct user_regset *regset)
  782. {
  783. if (!cpu_has_feature(CPU_FTR_TM))
  784. return -ENODEV;
  785. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  786. return 0;
  787. return regset->n;
  788. }
  789. /**
  790. * tm_cgpr_get - get CGPR registers
  791. * @target: The target task.
  792. * @regset: The user regset structure.
  793. * @pos: The buffer position.
  794. * @count: Number of bytes to copy.
  795. * @kbuf: Kernel buffer to copy from.
  796. * @ubuf: User buffer to copy into.
  797. *
  798. * This function gets transaction checkpointed GPR registers.
  799. *
  800. * When the transaction is active, 'ckpt_regs' holds all the checkpointed
  801. * GPR register values for the current transaction to fall back on if it
  802. * aborts in between. This function gets those checkpointed GPR registers.
  803. * The userspace interface buffer layout is as follows.
  804. *
  805. * struct data {
  806. * struct pt_regs ckpt_regs;
  807. * };
  808. */
  809. static int tm_cgpr_get(struct task_struct *target,
  810. const struct user_regset *regset,
  811. unsigned int pos, unsigned int count,
  812. void *kbuf, void __user *ubuf)
  813. {
  814. int ret;
  815. if (!cpu_has_feature(CPU_FTR_TM))
  816. return -ENODEV;
  817. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  818. return -ENODATA;
  819. flush_fp_to_thread(target);
  820. flush_altivec_to_thread(target);
  821. flush_tmregs_to_thread(target);
  822. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  823. &target->thread.ckpt_regs,
  824. 0, offsetof(struct pt_regs, msr));
  825. if (!ret) {
  826. unsigned long msr = get_user_ckpt_msr(target);
  827. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  828. offsetof(struct pt_regs, msr),
  829. offsetof(struct pt_regs, msr) +
  830. sizeof(msr));
  831. }
  832. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  833. offsetof(struct pt_regs, msr) + sizeof(long));
  834. if (!ret)
  835. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  836. &target->thread.ckpt_regs.orig_gpr3,
  837. offsetof(struct pt_regs, orig_gpr3),
  838. sizeof(struct pt_regs));
  839. if (!ret)
  840. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  841. sizeof(struct pt_regs), -1);
  842. return ret;
  843. }
  844. /*
  845. * tm_cgpr_set - set the CGPR registers
  846. * @target: The target task.
  847. * @regset: The user regset structure.
  848. * @pos: The buffer position.
  849. * @count: Number of bytes to copy.
  850. * @kbuf: Kernel buffer to copy into.
  851. * @ubuf: User buffer to copy from.
  852. *
  853. * This function sets in transaction checkpointed GPR registers.
  854. *
  855. * When the transaction is active, 'ckpt_regs' holds the checkpointed
  856. * GPR register values for the current transaction to fall back on if it
  857. * aborts in between. This function sets those checkpointed GPR registers.
  858. * The userspace interface buffer layout is as follows.
  859. *
  860. * struct data {
  861. * struct pt_regs ckpt_regs;
  862. * };
  863. */
  864. static int tm_cgpr_set(struct task_struct *target,
  865. const struct user_regset *regset,
  866. unsigned int pos, unsigned int count,
  867. const void *kbuf, const void __user *ubuf)
  868. {
  869. unsigned long reg;
  870. int ret;
  871. if (!cpu_has_feature(CPU_FTR_TM))
  872. return -ENODEV;
  873. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  874. return -ENODATA;
  875. flush_fp_to_thread(target);
  876. flush_altivec_to_thread(target);
  877. flush_tmregs_to_thread(target);
  878. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  879. &target->thread.ckpt_regs,
  880. 0, PT_MSR * sizeof(reg));
  881. if (!ret && count > 0) {
  882. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  883. PT_MSR * sizeof(reg),
  884. (PT_MSR + 1) * sizeof(reg));
  885. if (!ret)
  886. ret = set_user_ckpt_msr(target, reg);
  887. }
  888. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  889. offsetof(struct pt_regs, msr) + sizeof(long));
  890. if (!ret)
  891. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  892. &target->thread.ckpt_regs.orig_gpr3,
  893. PT_ORIG_R3 * sizeof(reg),
  894. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  895. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  896. ret = user_regset_copyin_ignore(
  897. &pos, &count, &kbuf, &ubuf,
  898. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  899. PT_TRAP * sizeof(reg));
  900. if (!ret && count > 0) {
  901. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  902. PT_TRAP * sizeof(reg),
  903. (PT_TRAP + 1) * sizeof(reg));
  904. if (!ret)
  905. ret = set_user_ckpt_trap(target, reg);
  906. }
  907. if (!ret)
  908. ret = user_regset_copyin_ignore(
  909. &pos, &count, &kbuf, &ubuf,
  910. (PT_TRAP + 1) * sizeof(reg), -1);
  911. return ret;
  912. }
  913. /**
  914. * tm_cfpr_active - get active number of registers in CFPR
  915. * @target: The target task.
  916. * @regset: The user regset structure.
  917. *
  918. * This function checks for the active number of available
  919. * regisers in transaction checkpointed FPR category.
  920. */
  921. static int tm_cfpr_active(struct task_struct *target,
  922. const struct user_regset *regset)
  923. {
  924. if (!cpu_has_feature(CPU_FTR_TM))
  925. return -ENODEV;
  926. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  927. return 0;
  928. return regset->n;
  929. }
  930. /**
  931. * tm_cfpr_get - get CFPR registers
  932. * @target: The target task.
  933. * @regset: The user regset structure.
  934. * @pos: The buffer position.
  935. * @count: Number of bytes to copy.
  936. * @kbuf: Kernel buffer to copy from.
  937. * @ubuf: User buffer to copy into.
  938. *
  939. * This function gets in transaction checkpointed FPR registers.
  940. *
  941. * When the transaction is active 'fp_state' holds the checkpointed
  942. * values for the current transaction to fall back on if it aborts
  943. * in between. This function gets those checkpointed FPR registers.
  944. * The userspace interface buffer layout is as follows.
  945. *
  946. * struct data {
  947. * u64 fpr[32];
  948. * u64 fpscr;
  949. *};
  950. */
  951. static int tm_cfpr_get(struct task_struct *target,
  952. const struct user_regset *regset,
  953. unsigned int pos, unsigned int count,
  954. void *kbuf, void __user *ubuf)
  955. {
  956. u64 buf[33];
  957. int i;
  958. if (!cpu_has_feature(CPU_FTR_TM))
  959. return -ENODEV;
  960. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  961. return -ENODATA;
  962. flush_fp_to_thread(target);
  963. flush_altivec_to_thread(target);
  964. flush_tmregs_to_thread(target);
  965. /* copy to local buffer then write that out */
  966. for (i = 0; i < 32 ; i++)
  967. buf[i] = target->thread.TS_FPR(i);
  968. buf[32] = target->thread.fp_state.fpscr;
  969. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  970. }
  971. /**
  972. * tm_cfpr_set - set CFPR registers
  973. * @target: The target task.
  974. * @regset: The user regset structure.
  975. * @pos: The buffer position.
  976. * @count: Number of bytes to copy.
  977. * @kbuf: Kernel buffer to copy into.
  978. * @ubuf: User buffer to copy from.
  979. *
  980. * This function sets in transaction checkpointed FPR registers.
  981. *
  982. * When the transaction is active 'fp_state' holds the checkpointed
  983. * FPR register values for the current transaction to fall back on
  984. * if it aborts in between. This function sets these checkpointed
  985. * FPR registers. The userspace interface buffer layout is as follows.
  986. *
  987. * struct data {
  988. * u64 fpr[32];
  989. * u64 fpscr;
  990. *};
  991. */
  992. static int tm_cfpr_set(struct task_struct *target,
  993. const struct user_regset *regset,
  994. unsigned int pos, unsigned int count,
  995. const void *kbuf, const void __user *ubuf)
  996. {
  997. u64 buf[33];
  998. int i;
  999. if (!cpu_has_feature(CPU_FTR_TM))
  1000. return -ENODEV;
  1001. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1002. return -ENODATA;
  1003. flush_fp_to_thread(target);
  1004. flush_altivec_to_thread(target);
  1005. flush_tmregs_to_thread(target);
  1006. /* copy to local buffer then write that out */
  1007. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  1008. if (i)
  1009. return i;
  1010. for (i = 0; i < 32 ; i++)
  1011. target->thread.TS_FPR(i) = buf[i];
  1012. target->thread.fp_state.fpscr = buf[32];
  1013. return 0;
  1014. }
  1015. /**
  1016. * tm_cvmx_active - get active number of registers in CVMX
  1017. * @target: The target task.
  1018. * @regset: The user regset structure.
  1019. *
  1020. * This function checks for the active number of available
  1021. * regisers in checkpointed VMX category.
  1022. */
  1023. static int tm_cvmx_active(struct task_struct *target,
  1024. const struct user_regset *regset)
  1025. {
  1026. if (!cpu_has_feature(CPU_FTR_TM))
  1027. return -ENODEV;
  1028. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1029. return 0;
  1030. return regset->n;
  1031. }
  1032. /**
  1033. * tm_cvmx_get - get CMVX registers
  1034. * @target: The target task.
  1035. * @regset: The user regset structure.
  1036. * @pos: The buffer position.
  1037. * @count: Number of bytes to copy.
  1038. * @kbuf: Kernel buffer to copy from.
  1039. * @ubuf: User buffer to copy into.
  1040. *
  1041. * This function gets in transaction checkpointed VMX registers.
  1042. *
  1043. * When the transaction is active 'vr_state' and 'vr_save' hold
  1044. * the checkpointed values for the current transaction to fall
  1045. * back on if it aborts in between. The userspace interface buffer
  1046. * layout is as follows.
  1047. *
  1048. * struct data {
  1049. * vector128 vr[32];
  1050. * vector128 vscr;
  1051. * vector128 vrsave;
  1052. *};
  1053. */
  1054. static int tm_cvmx_get(struct task_struct *target,
  1055. const struct user_regset *regset,
  1056. unsigned int pos, unsigned int count,
  1057. void *kbuf, void __user *ubuf)
  1058. {
  1059. int ret;
  1060. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  1061. if (!cpu_has_feature(CPU_FTR_TM))
  1062. return -ENODEV;
  1063. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1064. return -ENODATA;
  1065. /* Flush the state */
  1066. flush_fp_to_thread(target);
  1067. flush_altivec_to_thread(target);
  1068. flush_tmregs_to_thread(target);
  1069. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1070. &target->thread.vr_state, 0,
  1071. 33 * sizeof(vector128));
  1072. if (!ret) {
  1073. /*
  1074. * Copy out only the low-order word of vrsave.
  1075. */
  1076. union {
  1077. elf_vrreg_t reg;
  1078. u32 word;
  1079. } vrsave;
  1080. memset(&vrsave, 0, sizeof(vrsave));
  1081. vrsave.word = target->thread.vrsave;
  1082. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  1083. 33 * sizeof(vector128), -1);
  1084. }
  1085. return ret;
  1086. }
  1087. /**
  1088. * tm_cvmx_set - set CMVX registers
  1089. * @target: The target task.
  1090. * @regset: The user regset structure.
  1091. * @pos: The buffer position.
  1092. * @count: Number of bytes to copy.
  1093. * @kbuf: Kernel buffer to copy into.
  1094. * @ubuf: User buffer to copy from.
  1095. *
  1096. * This function sets in transaction checkpointed VMX registers.
  1097. *
  1098. * When the transaction is active 'vr_state' and 'vr_save' hold
  1099. * the checkpointed values for the current transaction to fall
  1100. * back on if it aborts in between. The userspace interface buffer
  1101. * layout is as follows.
  1102. *
  1103. * struct data {
  1104. * vector128 vr[32];
  1105. * vector128 vscr;
  1106. * vector128 vrsave;
  1107. *};
  1108. */
  1109. static int tm_cvmx_set(struct task_struct *target,
  1110. const struct user_regset *regset,
  1111. unsigned int pos, unsigned int count,
  1112. const void *kbuf, const void __user *ubuf)
  1113. {
  1114. int ret;
  1115. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  1116. if (!cpu_has_feature(CPU_FTR_TM))
  1117. return -ENODEV;
  1118. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1119. return -ENODATA;
  1120. flush_fp_to_thread(target);
  1121. flush_altivec_to_thread(target);
  1122. flush_tmregs_to_thread(target);
  1123. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1124. &target->thread.vr_state, 0,
  1125. 33 * sizeof(vector128));
  1126. if (!ret && count > 0) {
  1127. /*
  1128. * We use only the low-order word of vrsave.
  1129. */
  1130. union {
  1131. elf_vrreg_t reg;
  1132. u32 word;
  1133. } vrsave;
  1134. memset(&vrsave, 0, sizeof(vrsave));
  1135. vrsave.word = target->thread.vrsave;
  1136. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  1137. 33 * sizeof(vector128), -1);
  1138. if (!ret)
  1139. target->thread.vrsave = vrsave.word;
  1140. }
  1141. return ret;
  1142. }
  1143. /**
  1144. * tm_cvsx_active - get active number of registers in CVSX
  1145. * @target: The target task.
  1146. * @regset: The user regset structure.
  1147. *
  1148. * This function checks for the active number of available
  1149. * regisers in transaction checkpointed VSX category.
  1150. */
  1151. static int tm_cvsx_active(struct task_struct *target,
  1152. const struct user_regset *regset)
  1153. {
  1154. if (!cpu_has_feature(CPU_FTR_TM))
  1155. return -ENODEV;
  1156. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1157. return 0;
  1158. flush_vsx_to_thread(target);
  1159. return target->thread.used_vsr ? regset->n : 0;
  1160. }
  1161. /**
  1162. * tm_cvsx_get - get CVSX registers
  1163. * @target: The target task.
  1164. * @regset: The user regset structure.
  1165. * @pos: The buffer position.
  1166. * @count: Number of bytes to copy.
  1167. * @kbuf: Kernel buffer to copy from.
  1168. * @ubuf: User buffer to copy into.
  1169. *
  1170. * This function gets in transaction checkpointed VSX registers.
  1171. *
  1172. * When the transaction is active 'fp_state' holds the checkpointed
  1173. * values for the current transaction to fall back on if it aborts
  1174. * in between. This function gets those checkpointed VSX registers.
  1175. * The userspace interface buffer layout is as follows.
  1176. *
  1177. * struct data {
  1178. * u64 vsx[32];
  1179. *};
  1180. */
  1181. static int tm_cvsx_get(struct task_struct *target,
  1182. const struct user_regset *regset,
  1183. unsigned int pos, unsigned int count,
  1184. void *kbuf, void __user *ubuf)
  1185. {
  1186. u64 buf[32];
  1187. int ret, i;
  1188. if (!cpu_has_feature(CPU_FTR_TM))
  1189. return -ENODEV;
  1190. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1191. return -ENODATA;
  1192. /* Flush the state */
  1193. flush_fp_to_thread(target);
  1194. flush_altivec_to_thread(target);
  1195. flush_tmregs_to_thread(target);
  1196. flush_vsx_to_thread(target);
  1197. for (i = 0; i < 32 ; i++)
  1198. buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET];
  1199. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1200. buf, 0, 32 * sizeof(double));
  1201. return ret;
  1202. }
  1203. /**
  1204. * tm_cvsx_set - set CFPR registers
  1205. * @target: The target task.
  1206. * @regset: The user regset structure.
  1207. * @pos: The buffer position.
  1208. * @count: Number of bytes to copy.
  1209. * @kbuf: Kernel buffer to copy into.
  1210. * @ubuf: User buffer to copy from.
  1211. *
  1212. * This function sets in transaction checkpointed VSX registers.
  1213. *
  1214. * When the transaction is active 'fp_state' holds the checkpointed
  1215. * VSX register values for the current transaction to fall back on
  1216. * if it aborts in between. This function sets these checkpointed
  1217. * FPR registers. The userspace interface buffer layout is as follows.
  1218. *
  1219. * struct data {
  1220. * u64 vsx[32];
  1221. *};
  1222. */
  1223. static int tm_cvsx_set(struct task_struct *target,
  1224. const struct user_regset *regset,
  1225. unsigned int pos, unsigned int count,
  1226. const void *kbuf, const void __user *ubuf)
  1227. {
  1228. u64 buf[32];
  1229. int ret, i;
  1230. if (!cpu_has_feature(CPU_FTR_TM))
  1231. return -ENODEV;
  1232. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1233. return -ENODATA;
  1234. /* Flush the state */
  1235. flush_fp_to_thread(target);
  1236. flush_altivec_to_thread(target);
  1237. flush_tmregs_to_thread(target);
  1238. flush_vsx_to_thread(target);
  1239. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1240. buf, 0, 32 * sizeof(double));
  1241. for (i = 0; i < 32 ; i++)
  1242. target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  1243. return ret;
  1244. }
  1245. /**
  1246. * tm_spr_active - get active number of registers in TM SPR
  1247. * @target: The target task.
  1248. * @regset: The user regset structure.
  1249. *
  1250. * This function checks the active number of available
  1251. * regisers in the transactional memory SPR category.
  1252. */
  1253. static int tm_spr_active(struct task_struct *target,
  1254. const struct user_regset *regset)
  1255. {
  1256. if (!cpu_has_feature(CPU_FTR_TM))
  1257. return -ENODEV;
  1258. return regset->n;
  1259. }
  1260. /**
  1261. * tm_spr_get - get the TM related SPR registers
  1262. * @target: The target task.
  1263. * @regset: The user regset structure.
  1264. * @pos: The buffer position.
  1265. * @count: Number of bytes to copy.
  1266. * @kbuf: Kernel buffer to copy from.
  1267. * @ubuf: User buffer to copy into.
  1268. *
  1269. * This function gets transactional memory related SPR registers.
  1270. * The userspace interface buffer layout is as follows.
  1271. *
  1272. * struct {
  1273. * u64 tm_tfhar;
  1274. * u64 tm_texasr;
  1275. * u64 tm_tfiar;
  1276. * };
  1277. */
  1278. static int tm_spr_get(struct task_struct *target,
  1279. const struct user_regset *regset,
  1280. unsigned int pos, unsigned int count,
  1281. void *kbuf, void __user *ubuf)
  1282. {
  1283. int ret;
  1284. /* Build tests */
  1285. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  1286. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  1287. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  1288. if (!cpu_has_feature(CPU_FTR_TM))
  1289. return -ENODEV;
  1290. /* Flush the states */
  1291. flush_fp_to_thread(target);
  1292. flush_altivec_to_thread(target);
  1293. flush_tmregs_to_thread(target);
  1294. /* TFHAR register */
  1295. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1296. &target->thread.tm_tfhar, 0, sizeof(u64));
  1297. /* TEXASR register */
  1298. if (!ret)
  1299. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1300. &target->thread.tm_texasr, sizeof(u64),
  1301. 2 * sizeof(u64));
  1302. /* TFIAR register */
  1303. if (!ret)
  1304. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1305. &target->thread.tm_tfiar,
  1306. 2 * sizeof(u64), 3 * sizeof(u64));
  1307. return ret;
  1308. }
  1309. /**
  1310. * tm_spr_set - set the TM related SPR registers
  1311. * @target: The target task.
  1312. * @regset: The user regset structure.
  1313. * @pos: The buffer position.
  1314. * @count: Number of bytes to copy.
  1315. * @kbuf: Kernel buffer to copy into.
  1316. * @ubuf: User buffer to copy from.
  1317. *
  1318. * This function sets transactional memory related SPR registers.
  1319. * The userspace interface buffer layout is as follows.
  1320. *
  1321. * struct {
  1322. * u64 tm_tfhar;
  1323. * u64 tm_texasr;
  1324. * u64 tm_tfiar;
  1325. * };
  1326. */
  1327. static int tm_spr_set(struct task_struct *target,
  1328. const struct user_regset *regset,
  1329. unsigned int pos, unsigned int count,
  1330. const void *kbuf, const void __user *ubuf)
  1331. {
  1332. int ret;
  1333. /* Build tests */
  1334. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  1335. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  1336. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  1337. if (!cpu_has_feature(CPU_FTR_TM))
  1338. return -ENODEV;
  1339. /* Flush the states */
  1340. flush_fp_to_thread(target);
  1341. flush_altivec_to_thread(target);
  1342. flush_tmregs_to_thread(target);
  1343. /* TFHAR register */
  1344. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1345. &target->thread.tm_tfhar, 0, sizeof(u64));
  1346. /* TEXASR register */
  1347. if (!ret)
  1348. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1349. &target->thread.tm_texasr, sizeof(u64),
  1350. 2 * sizeof(u64));
  1351. /* TFIAR register */
  1352. if (!ret)
  1353. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1354. &target->thread.tm_tfiar,
  1355. 2 * sizeof(u64), 3 * sizeof(u64));
  1356. return ret;
  1357. }
  1358. static int tm_tar_active(struct task_struct *target,
  1359. const struct user_regset *regset)
  1360. {
  1361. if (!cpu_has_feature(CPU_FTR_TM))
  1362. return -ENODEV;
  1363. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1364. return regset->n;
  1365. return 0;
  1366. }
  1367. static int tm_tar_get(struct task_struct *target,
  1368. const struct user_regset *regset,
  1369. unsigned int pos, unsigned int count,
  1370. void *kbuf, void __user *ubuf)
  1371. {
  1372. int ret;
  1373. if (!cpu_has_feature(CPU_FTR_TM))
  1374. return -ENODEV;
  1375. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1376. return -ENODATA;
  1377. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1378. &target->thread.tm_tar, 0, sizeof(u64));
  1379. return ret;
  1380. }
  1381. static int tm_tar_set(struct task_struct *target,
  1382. const struct user_regset *regset,
  1383. unsigned int pos, unsigned int count,
  1384. const void *kbuf, const void __user *ubuf)
  1385. {
  1386. int ret;
  1387. if (!cpu_has_feature(CPU_FTR_TM))
  1388. return -ENODEV;
  1389. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1390. return -ENODATA;
  1391. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1392. &target->thread.tm_tar, 0, sizeof(u64));
  1393. return ret;
  1394. }
  1395. static int tm_ppr_active(struct task_struct *target,
  1396. const struct user_regset *regset)
  1397. {
  1398. if (!cpu_has_feature(CPU_FTR_TM))
  1399. return -ENODEV;
  1400. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1401. return regset->n;
  1402. return 0;
  1403. }
  1404. static int tm_ppr_get(struct task_struct *target,
  1405. const struct user_regset *regset,
  1406. unsigned int pos, unsigned int count,
  1407. void *kbuf, void __user *ubuf)
  1408. {
  1409. int ret;
  1410. if (!cpu_has_feature(CPU_FTR_TM))
  1411. return -ENODEV;
  1412. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1413. return -ENODATA;
  1414. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1415. &target->thread.tm_ppr, 0, sizeof(u64));
  1416. return ret;
  1417. }
  1418. static int tm_ppr_set(struct task_struct *target,
  1419. const struct user_regset *regset,
  1420. unsigned int pos, unsigned int count,
  1421. const void *kbuf, const void __user *ubuf)
  1422. {
  1423. int ret;
  1424. if (!cpu_has_feature(CPU_FTR_TM))
  1425. return -ENODEV;
  1426. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1427. return -ENODATA;
  1428. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1429. &target->thread.tm_ppr, 0, sizeof(u64));
  1430. return ret;
  1431. }
  1432. static int tm_dscr_active(struct task_struct *target,
  1433. const struct user_regset *regset)
  1434. {
  1435. if (!cpu_has_feature(CPU_FTR_TM))
  1436. return -ENODEV;
  1437. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  1438. return regset->n;
  1439. return 0;
  1440. }
  1441. static int tm_dscr_get(struct task_struct *target,
  1442. const struct user_regset *regset,
  1443. unsigned int pos, unsigned int count,
  1444. void *kbuf, void __user *ubuf)
  1445. {
  1446. int ret;
  1447. if (!cpu_has_feature(CPU_FTR_TM))
  1448. return -ENODEV;
  1449. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1450. return -ENODATA;
  1451. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1452. &target->thread.tm_dscr, 0, sizeof(u64));
  1453. return ret;
  1454. }
  1455. static int tm_dscr_set(struct task_struct *target,
  1456. const struct user_regset *regset,
  1457. unsigned int pos, unsigned int count,
  1458. const void *kbuf, const void __user *ubuf)
  1459. {
  1460. int ret;
  1461. if (!cpu_has_feature(CPU_FTR_TM))
  1462. return -ENODEV;
  1463. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  1464. return -ENODATA;
  1465. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1466. &target->thread.tm_dscr, 0, sizeof(u64));
  1467. return ret;
  1468. }
  1469. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  1470. #ifdef CONFIG_PPC64
  1471. static int ppr_get(struct task_struct *target,
  1472. const struct user_regset *regset,
  1473. unsigned int pos, unsigned int count,
  1474. void *kbuf, void __user *ubuf)
  1475. {
  1476. int ret;
  1477. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1478. &target->thread.ppr, 0, sizeof(u64));
  1479. return ret;
  1480. }
  1481. static int ppr_set(struct task_struct *target,
  1482. const struct user_regset *regset,
  1483. unsigned int pos, unsigned int count,
  1484. const void *kbuf, const void __user *ubuf)
  1485. {
  1486. int ret;
  1487. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1488. &target->thread.ppr, 0, sizeof(u64));
  1489. return ret;
  1490. }
  1491. static int dscr_get(struct task_struct *target,
  1492. const struct user_regset *regset,
  1493. unsigned int pos, unsigned int count,
  1494. void *kbuf, void __user *ubuf)
  1495. {
  1496. int ret;
  1497. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1498. &target->thread.dscr, 0, sizeof(u64));
  1499. return ret;
  1500. }
  1501. static int dscr_set(struct task_struct *target,
  1502. const struct user_regset *regset,
  1503. unsigned int pos, unsigned int count,
  1504. const void *kbuf, const void __user *ubuf)
  1505. {
  1506. int ret;
  1507. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1508. &target->thread.dscr, 0, sizeof(u64));
  1509. return ret;
  1510. }
  1511. #endif
  1512. #ifdef CONFIG_PPC_BOOK3S_64
  1513. static int tar_get(struct task_struct *target,
  1514. const struct user_regset *regset,
  1515. unsigned int pos, unsigned int count,
  1516. void *kbuf, void __user *ubuf)
  1517. {
  1518. int ret;
  1519. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1520. &target->thread.tar, 0, sizeof(u64));
  1521. return ret;
  1522. }
  1523. static int tar_set(struct task_struct *target,
  1524. const struct user_regset *regset,
  1525. unsigned int pos, unsigned int count,
  1526. const void *kbuf, const void __user *ubuf)
  1527. {
  1528. int ret;
  1529. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1530. &target->thread.tar, 0, sizeof(u64));
  1531. return ret;
  1532. }
  1533. static int ebb_active(struct task_struct *target,
  1534. const struct user_regset *regset)
  1535. {
  1536. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1537. return -ENODEV;
  1538. if (target->thread.used_ebb)
  1539. return regset->n;
  1540. return 0;
  1541. }
  1542. static int ebb_get(struct task_struct *target,
  1543. const struct user_regset *regset,
  1544. unsigned int pos, unsigned int count,
  1545. void *kbuf, void __user *ubuf)
  1546. {
  1547. /* Build tests */
  1548. BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
  1549. BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
  1550. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1551. return -ENODEV;
  1552. if (!target->thread.used_ebb)
  1553. return -ENODATA;
  1554. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1555. &target->thread.ebbrr, 0, 3 * sizeof(unsigned long));
  1556. }
  1557. static int ebb_set(struct task_struct *target,
  1558. const struct user_regset *regset,
  1559. unsigned int pos, unsigned int count,
  1560. const void *kbuf, const void __user *ubuf)
  1561. {
  1562. int ret = 0;
  1563. /* Build tests */
  1564. BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
  1565. BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
  1566. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1567. return -ENODEV;
  1568. if (target->thread.used_ebb)
  1569. return -ENODATA;
  1570. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1571. &target->thread.ebbrr, 0, sizeof(unsigned long));
  1572. if (!ret)
  1573. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1574. &target->thread.ebbhr, sizeof(unsigned long),
  1575. 2 * sizeof(unsigned long));
  1576. if (!ret)
  1577. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1578. &target->thread.bescr,
  1579. 2 * sizeof(unsigned long), 3 * sizeof(unsigned long));
  1580. return ret;
  1581. }
  1582. static int pmu_active(struct task_struct *target,
  1583. const struct user_regset *regset)
  1584. {
  1585. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1586. return -ENODEV;
  1587. return regset->n;
  1588. }
  1589. static int pmu_get(struct task_struct *target,
  1590. const struct user_regset *regset,
  1591. unsigned int pos, unsigned int count,
  1592. void *kbuf, void __user *ubuf)
  1593. {
  1594. /* Build tests */
  1595. BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
  1596. BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
  1597. BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
  1598. BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
  1599. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1600. return -ENODEV;
  1601. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  1602. &target->thread.siar, 0,
  1603. 5 * sizeof(unsigned long));
  1604. }
  1605. static int pmu_set(struct task_struct *target,
  1606. const struct user_regset *regset,
  1607. unsigned int pos, unsigned int count,
  1608. const void *kbuf, const void __user *ubuf)
  1609. {
  1610. int ret = 0;
  1611. /* Build tests */
  1612. BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
  1613. BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
  1614. BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
  1615. BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
  1616. if (!cpu_has_feature(CPU_FTR_ARCH_207S))
  1617. return -ENODEV;
  1618. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  1619. &target->thread.siar, 0,
  1620. sizeof(unsigned long));
  1621. if (!ret