ptrace-tm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/regset.h>
  3. #include <asm/switch_to.h>
  4. #include <asm/tm.h>
  5. #include <asm/asm-prototypes.h>
  6. #include "ptrace-decl.h"
  7. void flush_tmregs_to_thread(struct task_struct *tsk)
  8. {
  9. /*
  10. * If task is not current, it will have been flushed already to
  11. * it's thread_struct during __switch_to().
  12. *
  13. * A reclaim flushes ALL the state or if not in TM save TM SPRs
  14. * in the appropriate thread structures from live.
  15. */
  16. if (!cpu_has_feature(CPU_FTR_TM) || tsk != current)
  17. return;
  18. if (MSR_TM_SUSPENDED(mfmsr())) {
  19. tm_reclaim_current(TM_CAUSE_SIGNAL);
  20. } else {
  21. tm_enable();
  22. tm_save_sprs(&tsk->thread);
  23. }
  24. }
  25. static unsigned long get_user_ckpt_msr(struct task_struct *task)
  26. {
  27. return task->thread.ckpt_regs.msr | task->thread.fpexc_mode;
  28. }
  29. static int set_user_ckpt_msr(struct task_struct *task, unsigned long msr)
  30. {
  31. task->thread.ckpt_regs.msr &= ~MSR_DEBUGCHANGE;
  32. task->thread.ckpt_regs.msr |= msr & MSR_DEBUGCHANGE;
  33. return 0;
  34. }
  35. static int set_user_ckpt_trap(struct task_struct *task, unsigned long trap)
  36. {
  37. set_trap(&task->thread.ckpt_regs, trap);
  38. return 0;
  39. }
  40. /**
  41. * tm_cgpr_active - get active number of registers in CGPR
  42. * @target: The target task.
  43. * @regset: The user regset structure.
  44. *
  45. * This function checks for the active number of available
  46. * regisers in transaction checkpointed GPR category.
  47. */
  48. int tm_cgpr_active(struct task_struct *target, const struct user_regset *regset)
  49. {
  50. if (!cpu_has_feature(CPU_FTR_TM))
  51. return -ENODEV;
  52. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  53. return 0;
  54. return regset->n;
  55. }
  56. /**
  57. * tm_cgpr_get - get CGPR registers
  58. * @target: The target task.
  59. * @regset: The user regset structure.
  60. * @to: Destination of copy.
  61. *
  62. * This function gets transaction checkpointed GPR registers.
  63. *
  64. * When the transaction is active, 'ckpt_regs' holds all the checkpointed
  65. * GPR register values for the current transaction to fall back on if it
  66. * aborts in between. This function gets those checkpointed GPR registers.
  67. * The userspace interface buffer layout is as follows.
  68. *
  69. * struct data {
  70. * struct pt_regs ckpt_regs;
  71. * };
  72. */
  73. int tm_cgpr_get(struct task_struct *target, const struct user_regset *regset,
  74. struct membuf to)
  75. {
  76. struct membuf to_msr = membuf_at(&to, offsetof(struct pt_regs, msr));
  77. #ifdef CONFIG_PPC64
  78. struct membuf to_softe = membuf_at(&to, offsetof(struct pt_regs, softe));
  79. #endif
  80. if (!cpu_has_feature(CPU_FTR_TM))
  81. return -ENODEV;
  82. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  83. return -ENODATA;
  84. flush_tmregs_to_thread(target);
  85. flush_fp_to_thread(target);
  86. flush_altivec_to_thread(target);
  87. membuf_write(&to, &target->thread.ckpt_regs, sizeof(struct user_pt_regs));
  88. membuf_store(&to_msr, get_user_ckpt_msr(target));
  89. #ifdef CONFIG_PPC64
  90. membuf_store(&to_softe, 0x1ul);
  91. #endif
  92. return membuf_zero(&to, ELF_NGREG * sizeof(unsigned long) -
  93. sizeof(struct user_pt_regs));
  94. }
  95. /*
  96. * tm_cgpr_set - set the CGPR registers
  97. * @target: The target task.
  98. * @regset: The user regset structure.
  99. * @pos: The buffer position.
  100. * @count: Number of bytes to copy.
  101. * @kbuf: Kernel buffer to copy into.
  102. * @ubuf: User buffer to copy from.
  103. *
  104. * This function sets in transaction checkpointed GPR registers.
  105. *
  106. * When the transaction is active, 'ckpt_regs' holds the checkpointed
  107. * GPR register values for the current transaction to fall back on if it
  108. * aborts in between. This function sets those checkpointed GPR registers.
  109. * The userspace interface buffer layout is as follows.
  110. *
  111. * struct data {
  112. * struct pt_regs ckpt_regs;
  113. * };
  114. */
  115. int tm_cgpr_set(struct task_struct *target, const struct user_regset *regset,
  116. unsigned int pos, unsigned int count,
  117. const void *kbuf, const void __user *ubuf)
  118. {
  119. unsigned long reg;
  120. int ret;
  121. if (!cpu_has_feature(CPU_FTR_TM))
  122. return -ENODEV;
  123. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  124. return -ENODATA;
  125. flush_tmregs_to_thread(target);
  126. flush_fp_to_thread(target);
  127. flush_altivec_to_thread(target);
  128. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  129. &target->thread.ckpt_regs,
  130. 0, PT_MSR * sizeof(reg));
  131. if (!ret && count > 0) {
  132. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  133. PT_MSR * sizeof(reg),
  134. (PT_MSR + 1) * sizeof(reg));
  135. if (!ret)
  136. ret = set_user_ckpt_msr(target, reg);
  137. }
  138. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  139. offsetof(struct pt_regs, msr) + sizeof(long));
  140. if (!ret)
  141. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  142. &target->thread.ckpt_regs.orig_gpr3,
  143. PT_ORIG_R3 * sizeof(reg),
  144. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  145. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  146. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  147. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  148. PT_TRAP * sizeof(reg));
  149. if (!ret && count > 0) {
  150. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  151. PT_TRAP * sizeof(reg),
  152. (PT_TRAP + 1) * sizeof(reg));
  153. if (!ret)
  154. ret = set_user_ckpt_trap(target, reg);
  155. }
  156. if (!ret)
  157. ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  158. (PT_TRAP + 1) * sizeof(reg), -1);
  159. return ret;
  160. }
  161. /**
  162. * tm_cfpr_active - get active number of registers in CFPR
  163. * @target: The target task.
  164. * @regset: The user regset structure.
  165. *
  166. * This function checks for the active number of available
  167. * regisers in transaction checkpointed FPR category.
  168. */
  169. int tm_cfpr_active(struct task_struct *target, const struct user_regset *regset)
  170. {
  171. if (!cpu_has_feature(CPU_FTR_TM))
  172. return -ENODEV;
  173. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  174. return 0;
  175. return regset->n;
  176. }
  177. /**
  178. * tm_cfpr_get - get CFPR registers
  179. * @target: The target task.
  180. * @regset: The user regset structure.
  181. * @to: Destination of copy.
  182. *
  183. * This function gets in transaction checkpointed FPR registers.
  184. *
  185. * When the transaction is active 'ckfp_state' holds the checkpointed
  186. * values for the current transaction to fall back on if it aborts
  187. * in between. This function gets those checkpointed FPR registers.
  188. * The userspace interface buffer layout is as follows.
  189. *
  190. * struct data {
  191. * u64 fpr[32];
  192. * u64 fpscr;
  193. *};
  194. */
  195. int tm_cfpr_get(struct task_struct *target, const struct user_regset *regset,
  196. struct membuf to)
  197. {
  198. u64 buf[33];
  199. int i;
  200. if (!cpu_has_feature(CPU_FTR_TM))
  201. return -ENODEV;
  202. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  203. return -ENODATA;
  204. flush_tmregs_to_thread(target);
  205. flush_fp_to_thread(target);
  206. flush_altivec_to_thread(target);
  207. /* copy to local buffer then write that out */
  208. for (i = 0; i < 32 ; i++)
  209. buf[i] = target->thread.TS_CKFPR(i);
  210. buf[32] = target->thread.ckfp_state.fpscr;
  211. return membuf_write(&to, buf, sizeof(buf));
  212. }
  213. /**
  214. * tm_cfpr_set - set CFPR registers
  215. * @target: The target task.
  216. * @regset: The user regset structure.
  217. * @pos: The buffer position.
  218. * @count: Number of bytes to copy.
  219. * @kbuf: Kernel buffer to copy into.
  220. * @ubuf: User buffer to copy from.
  221. *
  222. * This function sets in transaction checkpointed FPR registers.
  223. *
  224. * When the transaction is active 'ckfp_state' holds the checkpointed
  225. * FPR register values for the current transaction to fall back on
  226. * if it aborts in between. This function sets these checkpointed
  227. * FPR registers. The userspace interface buffer layout is as follows.
  228. *
  229. * struct data {
  230. * u64 fpr[32];
  231. * u64 fpscr;
  232. *};
  233. */
  234. int tm_cfpr_set(struct task_struct *target, const struct user_regset *regset,
  235. unsigned int pos, unsigned int count,
  236. const void *kbuf, const void __user *ubuf)
  237. {
  238. u64 buf[33];
  239. int i;
  240. if (!cpu_has_feature(CPU_FTR_TM))
  241. return -ENODEV;
  242. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  243. return -ENODATA;
  244. flush_tmregs_to_thread(target);
  245. flush_fp_to_thread(target);
  246. flush_altivec_to_thread(target);
  247. for (i = 0; i < 32; i++)
  248. buf[i] = target->thread.TS_CKFPR(i);
  249. buf[32] = target->thread.ckfp_state.fpscr;
  250. /* copy to local buffer then write that out */
  251. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  252. if (i)
  253. return i;
  254. for (i = 0; i < 32 ; i++)
  255. target->thread.TS_CKFPR(i) = buf[i];
  256. target->thread.ckfp_state.fpscr = buf[32];
  257. return 0;
  258. }
  259. /**
  260. * tm_cvmx_active - get active number of registers in CVMX
  261. * @target: The target task.
  262. * @regset: The user regset structure.
  263. *
  264. * This function checks for the active number of available
  265. * regisers in checkpointed VMX category.
  266. */
  267. int tm_cvmx_active(struct task_struct *target, const struct user_regset *regset)
  268. {
  269. if (!cpu_has_feature(CPU_FTR_TM))
  270. return -ENODEV;
  271. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  272. return 0;
  273. return regset->n;
  274. }
  275. /**
  276. * tm_cvmx_get - get CMVX registers
  277. * @target: The target task.
  278. * @regset: The user regset structure.
  279. * @to: Destination of copy.
  280. *
  281. * This function gets in transaction checkpointed VMX registers.
  282. *
  283. * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
  284. * the checkpointed values for the current transaction to fall
  285. * back on if it aborts in between. The userspace interface buffer
  286. * layout is as follows.
  287. *
  288. * struct data {
  289. * vector128 vr[32];
  290. * vector128 vscr;
  291. * vector128 vrsave;
  292. *};
  293. */
  294. int tm_cvmx_get(struct task_struct *target, const struct user_regset *regset,
  295. struct membuf to)
  296. {
  297. union {
  298. elf_vrreg_t reg;
  299. u32 word;
  300. } vrsave;
  301. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  302. if (!cpu_has_feature(CPU_FTR_TM))
  303. return -ENODEV;
  304. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  305. return -ENODATA;
  306. /* Flush the state */
  307. flush_tmregs_to_thread(target);
  308. flush_fp_to_thread(target);
  309. flush_altivec_to_thread(target);
  310. membuf_write(&to, &target->thread.ckvr_state, 33 * sizeof(vector128));
  311. /*
  312. * Copy out only the low-order word of vrsave.
  313. */
  314. memset(&vrsave, 0, sizeof(vrsave));
  315. vrsave.word = target->thread.ckvrsave;
  316. return membuf_write(&to, &vrsave, sizeof(vrsave));
  317. }
  318. /**
  319. * tm_cvmx_set - set CMVX registers
  320. * @target: The target task.
  321. * @regset: The user regset structure.
  322. * @pos: The buffer position.
  323. * @count: Number of bytes to copy.
  324. * @kbuf: Kernel buffer to copy into.
  325. * @ubuf: User buffer to copy from.
  326. *
  327. * This function sets in transaction checkpointed VMX registers.
  328. *
  329. * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
  330. * the checkpointed values for the current transaction to fall
  331. * back on if it aborts in between. The userspace interface buffer
  332. * layout is as follows.
  333. *
  334. * struct data {
  335. * vector128 vr[32];
  336. * vector128 vscr;
  337. * vector128 vrsave;
  338. *};
  339. */
  340. int tm_cvmx_set(struct task_struct *target, const struct user_regset *regset,
  341. unsigned int pos, unsigned int count,
  342. const void *kbuf, const void __user *ubuf)
  343. {
  344. int ret;
  345. BUILD_BUG_ON(TVSO(vscr) != TVSO(vr[32]));
  346. if (!cpu_has_feature(CPU_FTR_TM))
  347. return -ENODEV;
  348. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  349. return -ENODATA;
  350. flush_tmregs_to_thread(target);
  351. flush_fp_to_thread(target);
  352. flush_altivec_to_thread(target);
  353. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.ckvr_state,
  354. 0, 33 * sizeof(vector128));
  355. if (!ret && count > 0) {
  356. /*
  357. * We use only the low-order word of vrsave.
  358. */
  359. union {
  360. elf_vrreg_t reg;
  361. u32 word;
  362. } vrsave;
  363. memset(&vrsave, 0, sizeof(vrsave));
  364. vrsave.word = target->thread.ckvrsave;
  365. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  366. 33 * sizeof(vector128), -1);
  367. if (!ret)
  368. target->thread.ckvrsave = vrsave.word;
  369. }
  370. return ret;
  371. }
  372. /**
  373. * tm_cvsx_active - get active number of registers in CVSX
  374. * @target: The target task.
  375. * @regset: The user regset structure.
  376. *
  377. * This function checks for the active number of available
  378. * regisers in transaction checkpointed VSX category.
  379. */
  380. int tm_cvsx_active(struct task_struct *target, const struct user_regset *regset)
  381. {
  382. if (!cpu_has_feature(CPU_FTR_TM))
  383. return -ENODEV;
  384. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  385. return 0;
  386. flush_vsx_to_thread(target);
  387. return target->thread.used_vsr ? regset->n : 0;
  388. }
  389. /**
  390. * tm_cvsx_get - get CVSX registers
  391. * @target: The target task.
  392. * @regset: The user regset structure.
  393. * @to: Destination of copy.
  394. *
  395. * This function gets in transaction checkpointed VSX registers.
  396. *
  397. * When the transaction is active 'ckfp_state' holds the checkpointed
  398. * values for the current transaction to fall back on if it aborts
  399. * in between. This function gets those checkpointed VSX registers.
  400. * The userspace interface buffer layout is as follows.
  401. *
  402. * struct data {
  403. * u64 vsx[32];
  404. *};
  405. */
  406. int tm_cvsx_get(struct task_struct *target, const struct user_regset *regset,
  407. struct membuf to)
  408. {
  409. u64 buf[32];
  410. int i;
  411. if (!cpu_has_feature(CPU_FTR_TM))
  412. return -ENODEV;
  413. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  414. return -ENODATA;
  415. /* Flush the state */
  416. flush_tmregs_to_thread(target);
  417. flush_fp_to_thread(target);
  418. flush_altivec_to_thread(target);
  419. flush_vsx_to_thread(target);
  420. for (i = 0; i < 32 ; i++)
  421. buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
  422. return membuf_write(&to, buf, 32 * sizeof(double));
  423. }
  424. /**
  425. * tm_cvsx_set - set CFPR registers
  426. * @target: The target task.
  427. * @regset: The user regset structure.
  428. * @pos: The buffer position.
  429. * @count: Number of bytes to copy.
  430. * @kbuf: Kernel buffer to copy into.
  431. * @ubuf: User buffer to copy from.
  432. *
  433. * This function sets in transaction checkpointed VSX registers.
  434. *
  435. * When the transaction is active 'ckfp_state' holds the checkpointed
  436. * VSX register values for the current transaction to fall back on
  437. * if it aborts in between. This function sets these checkpointed
  438. * FPR registers. The userspace interface buffer layout is as follows.
  439. *
  440. * struct data {
  441. * u64 vsx[32];
  442. *};
  443. */
  444. int tm_cvsx_set(struct task_struct *target, const struct user_regset *regset,
  445. unsigned int pos, unsigned int count,
  446. const void *kbuf, const void __user *ubuf)
  447. {
  448. u64 buf[32];
  449. int ret, i;
  450. if (!cpu_has_feature(CPU_FTR_TM))
  451. return -ENODEV;
  452. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  453. return -ENODATA;
  454. /* Flush the state */
  455. flush_tmregs_to_thread(target);
  456. flush_fp_to_thread(target);
  457. flush_altivec_to_thread(target);
  458. flush_vsx_to_thread(target);
  459. for (i = 0; i < 32 ; i++)
  460. buf[i] = target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET];
  461. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  462. buf, 0, 32 * sizeof(double));
  463. if (!ret)
  464. for (i = 0; i < 32 ; i++)
  465. target->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  466. return ret;
  467. }
  468. /**
  469. * tm_spr_active - get active number of registers in TM SPR
  470. * @target: The target task.
  471. * @regset: The user regset structure.
  472. *
  473. * This function checks the active number of available
  474. * regisers in the transactional memory SPR category.
  475. */
  476. int tm_spr_active(struct task_struct *target, const struct user_regset *regset)
  477. {
  478. if (!cpu_has_feature(CPU_FTR_TM))
  479. return -ENODEV;
  480. return regset->n;
  481. }
  482. /**
  483. * tm_spr_get - get the TM related SPR registers
  484. * @target: The target task.
  485. * @regset: The user regset structure.
  486. * @to: Destination of copy.
  487. *
  488. * This function gets transactional memory related SPR registers.
  489. * The userspace interface buffer layout is as follows.
  490. *
  491. * struct {
  492. * u64 tm_tfhar;
  493. * u64 tm_texasr;
  494. * u64 tm_tfiar;
  495. * };
  496. */
  497. int tm_spr_get(struct task_struct *target, const struct user_regset *regset,
  498. struct membuf to)
  499. {
  500. /* Build tests */
  501. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  502. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  503. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  504. if (!cpu_has_feature(CPU_FTR_TM))
  505. return -ENODEV;
  506. /* Flush the states */
  507. flush_tmregs_to_thread(target);
  508. flush_fp_to_thread(target);
  509. flush_altivec_to_thread(target);
  510. /* TFHAR register */
  511. membuf_write(&to, &target->thread.tm_tfhar, sizeof(u64));
  512. /* TEXASR register */
  513. membuf_write(&to, &target->thread.tm_texasr, sizeof(u64));
  514. /* TFIAR register */
  515. return membuf_write(&to, &target->thread.tm_tfiar, sizeof(u64));
  516. }
  517. /**
  518. * tm_spr_set - set the TM related SPR registers
  519. * @target: The target task.
  520. * @regset: The user regset structure.
  521. * @pos: The buffer position.
  522. * @count: Number of bytes to copy.
  523. * @kbuf: Kernel buffer to copy into.
  524. * @ubuf: User buffer to copy from.
  525. *
  526. * This function sets transactional memory related SPR registers.
  527. * The userspace interface buffer layout is as follows.
  528. *
  529. * struct {
  530. * u64 tm_tfhar;
  531. * u64 tm_texasr;
  532. * u64 tm_tfiar;
  533. * };
  534. */
  535. int tm_spr_set(struct task_struct *target, const struct user_regset *regset,
  536. unsigned int pos, unsigned int count,
  537. const void *kbuf, const void __user *ubuf)
  538. {
  539. int ret;
  540. /* Build tests */
  541. BUILD_BUG_ON(TSO(tm_tfhar) + sizeof(u64) != TSO(tm_texasr));
  542. BUILD_BUG_ON(TSO(tm_texasr) + sizeof(u64) != TSO(tm_tfiar));
  543. BUILD_BUG_ON(TSO(tm_tfiar) + sizeof(u64) != TSO(ckpt_regs));
  544. if (!cpu_has_feature(CPU_FTR_TM))
  545. return -ENODEV;
  546. /* Flush the states */
  547. flush_tmregs_to_thread(target);
  548. flush_fp_to_thread(target);
  549. flush_altivec_to_thread(target);
  550. /* TFHAR register */
  551. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  552. &target->thread.tm_tfhar, 0, sizeof(u64));
  553. /* TEXASR register */
  554. if (!ret)
  555. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  556. &target->thread.tm_texasr, sizeof(u64),
  557. 2 * sizeof(u64));
  558. /* TFIAR register */
  559. if (!ret)
  560. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  561. &target->thread.tm_tfiar,
  562. 2 * sizeof(u64), 3 * sizeof(u64));
  563. return ret;
  564. }
  565. int tm_tar_active(struct task_struct *target, const struct user_regset *regset)
  566. {
  567. if (!cpu_has_feature(CPU_FTR_TM))
  568. return -ENODEV;
  569. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  570. return regset->n;
  571. return 0;
  572. }
  573. int tm_tar_get(struct task_struct *target, const struct user_regset *regset,
  574. struct membuf to)
  575. {
  576. if (!cpu_has_feature(CPU_FTR_TM))
  577. return -ENODEV;
  578. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  579. return -ENODATA;
  580. return membuf_write(&to, &target->thread.tm_tar, sizeof(u64));
  581. }
  582. int tm_tar_set(struct task_struct *target, const struct user_regset *regset,
  583. unsigned int pos, unsigned int count,
  584. const void *kbuf, const void __user *ubuf)
  585. {
  586. int ret;
  587. if (!cpu_has_feature(CPU_FTR_TM))
  588. return -ENODEV;
  589. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  590. return -ENODATA;
  591. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  592. &target->thread.tm_tar, 0, sizeof(u64));
  593. return ret;
  594. }
  595. int tm_ppr_active(struct task_struct *target, const struct user_regset *regset)
  596. {
  597. if (!cpu_has_feature(CPU_FTR_TM))
  598. return -ENODEV;
  599. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  600. return regset->n;
  601. return 0;
  602. }
  603. int tm_ppr_get(struct task_struct *target, const struct user_regset *regset,
  604. struct membuf to)
  605. {
  606. if (!cpu_has_feature(CPU_FTR_TM))
  607. return -ENODEV;
  608. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  609. return -ENODATA;
  610. return membuf_write(&to, &target->thread.tm_ppr, sizeof(u64));
  611. }
  612. int tm_ppr_set(struct task_struct *target, const struct user_regset *regset,
  613. unsigned int pos, unsigned int count,
  614. const void *kbuf, const void __user *ubuf)
  615. {
  616. int ret;
  617. if (!cpu_has_feature(CPU_FTR_TM))
  618. return -ENODEV;
  619. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  620. return -ENODATA;
  621. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  622. &target->thread.tm_ppr, 0, sizeof(u64));
  623. return ret;
  624. }
  625. int tm_dscr_active(struct task_struct *target, const struct user_regset *regset)
  626. {
  627. if (!cpu_has_feature(CPU_FTR_TM))
  628. return -ENODEV;
  629. if (MSR_TM_ACTIVE(target->thread.regs->msr))
  630. return regset->n;
  631. return 0;
  632. }
  633. int tm_dscr_get(struct task_struct *target, const struct user_regset *regset,
  634. struct membuf to)
  635. {
  636. if (!cpu_has_feature(CPU_FTR_TM))
  637. return -ENODEV;
  638. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  639. return -ENODATA;
  640. return membuf_write(&to, &target->thread.tm_dscr, sizeof(u64));
  641. }
  642. int tm_dscr_set(struct task_struct *target, const struct user_regset *regset,
  643. unsigned int pos, unsigned int count,
  644. const void *kbuf, const void __user *ubuf)
  645. {
  646. int ret;
  647. if (!cpu_has_feature(CPU_FTR_TM))
  648. return -ENODEV;
  649. if (!MSR_TM_ACTIVE(target->thread.regs->msr))
  650. return -ENODATA;
  651. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  652. &target->thread.tm_dscr, 0, sizeof(u64));
  653. return ret;
  654. }
  655. int tm_cgpr32_get(struct task_struct *target, const struct user_regset *regset,
  656. struct membuf to)
  657. {
  658. gpr32_get_common(target, regset, to,
  659. &target->thread.ckpt_regs.gpr[0]);
  660. return membuf_zero(&to, ELF_NGREG * sizeof(u32));
  661. }
  662. int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,
  663. unsigned int pos, unsigned int count,
  664. const void *kbuf, const void __user *ubuf)
  665. {
  666. return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
  667. &target->thread.ckpt_regs.gpr[0]);
  668. }