1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/regset.h>
5 #include <asm/switch_to.h>
7 #include <asm/asm-prototypes.h>
9 #include "ptrace-decl.h"
11 void flush_tmregs_to_thread(struct task_struct
*tsk
)
14 * If task is not current, it will have been flushed already to
15 * it's thread_struct during __switch_to().
17 * A reclaim flushes ALL the state or if not in TM save TM SPRs
18 * in the appropriate thread structures from live.
21 if (!cpu_has_feature(CPU_FTR_TM
) || tsk
!= current
)
24 if (MSR_TM_SUSPENDED(mfmsr())) {
25 tm_reclaim_current(TM_CAUSE_SIGNAL
);
28 tm_save_sprs(&tsk
->thread
);
32 static unsigned long get_user_ckpt_msr(struct task_struct
*task
)
34 return task
->thread
.ckpt_regs
.msr
| task
->thread
.fpexc_mode
;
37 static int set_user_ckpt_msr(struct task_struct
*task
, unsigned long msr
)
39 task
->thread
.ckpt_regs
.msr
&= ~MSR_DEBUGCHANGE
;
40 task
->thread
.ckpt_regs
.msr
|= msr
& MSR_DEBUGCHANGE
;
44 static int set_user_ckpt_trap(struct task_struct
*task
, unsigned long trap
)
46 set_trap(&task
->thread
.ckpt_regs
, trap
);
51 * tm_cgpr_active - get active number of registers in CGPR
52 * @target: The target task.
53 * @regset: The user regset structure.
55 * This function checks for the active number of available
56 * regisers in transaction checkpointed GPR category.
58 int tm_cgpr_active(struct task_struct
*target
, const struct user_regset
*regset
)
60 if (!cpu_has_feature(CPU_FTR_TM
))
63 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
70 * tm_cgpr_get - get CGPR registers
71 * @target: The target task.
72 * @regset: The user regset structure.
73 * @to: Destination of copy.
75 * This function gets transaction checkpointed GPR registers.
77 * When the transaction is active, 'ckpt_regs' holds all the checkpointed
78 * GPR register values for the current transaction to fall back on if it
79 * aborts in between. This function gets those checkpointed GPR registers.
80 * The userspace interface buffer layout is as follows.
83 * struct pt_regs ckpt_regs;
86 int tm_cgpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
89 struct membuf to_msr
= membuf_at(&to
, offsetof(struct pt_regs
, msr
));
91 struct membuf to_softe
= membuf_at(&to
, offsetof(struct pt_regs
, softe
));
94 if (!cpu_has_feature(CPU_FTR_TM
))
97 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
100 flush_tmregs_to_thread(target
);
101 flush_fp_to_thread(target
);
102 flush_altivec_to_thread(target
);
104 membuf_write(&to
, &target
->thread
.ckpt_regs
, sizeof(struct user_pt_regs
));
106 membuf_store(&to_msr
, get_user_ckpt_msr(target
));
108 membuf_store(&to_softe
, 0x1ul
);
110 return membuf_zero(&to
, ELF_NGREG
* sizeof(unsigned long) -
111 sizeof(struct user_pt_regs
));
115 * tm_cgpr_set - set the CGPR registers
116 * @target: The target task.
117 * @regset: The user regset structure.
118 * @pos: The buffer position.
119 * @count: Number of bytes to copy.
120 * @kbuf: Kernel buffer to copy into.
121 * @ubuf: User buffer to copy from.
123 * This function sets in transaction checkpointed GPR registers.
125 * When the transaction is active, 'ckpt_regs' holds the checkpointed
126 * GPR register values for the current transaction to fall back on if it
127 * aborts in between. This function sets those checkpointed GPR registers.
128 * The userspace interface buffer layout is as follows.
131 * struct pt_regs ckpt_regs;
134 int tm_cgpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
135 unsigned int pos
, unsigned int count
,
136 const void *kbuf
, const void __user
*ubuf
)
141 if (!cpu_has_feature(CPU_FTR_TM
))
144 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
147 flush_tmregs_to_thread(target
);
148 flush_fp_to_thread(target
);
149 flush_altivec_to_thread(target
);
151 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
152 &target
->thread
.ckpt_regs
,
153 0, PT_MSR
* sizeof(reg
));
155 if (!ret
&& count
> 0) {
156 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
157 PT_MSR
* sizeof(reg
),
158 (PT_MSR
+ 1) * sizeof(reg
));
160 ret
= set_user_ckpt_msr(target
, reg
);
163 BUILD_BUG_ON(offsetof(struct pt_regs
, orig_gpr3
) !=
164 offsetof(struct pt_regs
, msr
) + sizeof(long));
167 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
168 &target
->thread
.ckpt_regs
.orig_gpr3
,
169 PT_ORIG_R3
* sizeof(reg
),
170 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
));
172 if (PT_MAX_PUT_REG
+ 1 < PT_TRAP
&& !ret
)
173 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
174 (PT_MAX_PUT_REG
+ 1) * sizeof(reg
),
175 PT_TRAP
* sizeof(reg
));
177 if (!ret
&& count
> 0) {
178 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, ®
,
179 PT_TRAP
* sizeof(reg
),
180 (PT_TRAP
+ 1) * sizeof(reg
));
182 ret
= set_user_ckpt_trap(target
, reg
);
186 ret
= user_regset_copyin_ignore(&pos
, &count
, &kbuf
, &ubuf
,
187 (PT_TRAP
+ 1) * sizeof(reg
), -1);
193 * tm_cfpr_active - get active number of registers in CFPR
194 * @target: The target task.
195 * @regset: The user regset structure.
197 * This function checks for the active number of available
198 * regisers in transaction checkpointed FPR category.
200 int tm_cfpr_active(struct task_struct
*target
, const struct user_regset
*regset
)
202 if (!cpu_has_feature(CPU_FTR_TM
))
205 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
212 * tm_cfpr_get - get CFPR registers
213 * @target: The target task.
214 * @regset: The user regset structure.
215 * @to: Destination of copy.
217 * This function gets in transaction checkpointed FPR registers.
219 * When the transaction is active 'ckfp_state' holds the checkpointed
220 * values for the current transaction to fall back on if it aborts
221 * in between. This function gets those checkpointed FPR registers.
222 * The userspace interface buffer layout is as follows.
229 int tm_cfpr_get(struct task_struct
*target
, const struct user_regset
*regset
,
235 if (!cpu_has_feature(CPU_FTR_TM
))
238 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
241 flush_tmregs_to_thread(target
);
242 flush_fp_to_thread(target
);
243 flush_altivec_to_thread(target
);
245 /* copy to local buffer then write that out */
246 for (i
= 0; i
< 32 ; i
++)
247 buf
[i
] = target
->thread
.TS_CKFPR(i
);
248 buf
[32] = target
->thread
.ckfp_state
.fpscr
;
249 return membuf_write(&to
, buf
, sizeof(buf
));
253 * tm_cfpr_set - set CFPR registers
254 * @target: The target task.
255 * @regset: The user regset structure.
256 * @pos: The buffer position.
257 * @count: Number of bytes to copy.
258 * @kbuf: Kernel buffer to copy into.
259 * @ubuf: User buffer to copy from.
261 * This function sets in transaction checkpointed FPR registers.
263 * When the transaction is active 'ckfp_state' holds the checkpointed
264 * FPR register values for the current transaction to fall back on
265 * if it aborts in between. This function sets these checkpointed
266 * FPR registers. The userspace interface buffer layout is as follows.
273 int tm_cfpr_set(struct task_struct
*target
, const struct user_regset
*regset
,
274 unsigned int pos
, unsigned int count
,
275 const void *kbuf
, const void __user
*ubuf
)
280 if (!cpu_has_feature(CPU_FTR_TM
))
283 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
286 flush_tmregs_to_thread(target
);
287 flush_fp_to_thread(target
);
288 flush_altivec_to_thread(target
);
290 for (i
= 0; i
< 32; i
++)
291 buf
[i
] = target
->thread
.TS_CKFPR(i
);
292 buf
[32] = target
->thread
.ckfp_state
.fpscr
;
294 /* copy to local buffer then write that out */
295 i
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, buf
, 0, -1);
298 for (i
= 0; i
< 32 ; i
++)
299 target
->thread
.TS_CKFPR(i
) = buf
[i
];
300 target
->thread
.ckfp_state
.fpscr
= buf
[32];
305 * tm_cvmx_active - get active number of registers in CVMX
306 * @target: The target task.
307 * @regset: The user regset structure.
309 * This function checks for the active number of available
310 * regisers in checkpointed VMX category.
312 int tm_cvmx_active(struct task_struct
*target
, const struct user_regset
*regset
)
314 if (!cpu_has_feature(CPU_FTR_TM
))
317 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
324 * tm_cvmx_get - get CMVX registers
325 * @target: The target task.
326 * @regset: The user regset structure.
327 * @to: Destination of copy.
329 * This function gets in transaction checkpointed VMX registers.
331 * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
332 * the checkpointed values for the current transaction to fall
333 * back on if it aborts in between. The userspace interface buffer
334 * layout is as follows.
342 int tm_cvmx_get(struct task_struct
*target
, const struct user_regset
*regset
,
349 BUILD_BUG_ON(TVSO(vscr
) != TVSO(vr
[32]));
351 if (!cpu_has_feature(CPU_FTR_TM
))
354 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
357 /* Flush the state */
358 flush_tmregs_to_thread(target
);
359 flush_fp_to_thread(target
);
360 flush_altivec_to_thread(target
);
362 membuf_write(&to
, &target
->thread
.ckvr_state
, 33 * sizeof(vector128
));
364 * Copy out only the low-order word of vrsave.
366 memset(&vrsave
, 0, sizeof(vrsave
));
367 vrsave
.word
= target
->thread
.ckvrsave
;
368 return membuf_write(&to
, &vrsave
, sizeof(vrsave
));
372 * tm_cvmx_set - set CMVX registers
373 * @target: The target task.
374 * @regset: The user regset structure.
375 * @pos: The buffer position.
376 * @count: Number of bytes to copy.
377 * @kbuf: Kernel buffer to copy into.
378 * @ubuf: User buffer to copy from.
380 * This function sets in transaction checkpointed VMX registers.
382 * When the transaction is active 'ckvr_state' and 'ckvrsave' hold
383 * the checkpointed values for the current transaction to fall
384 * back on if it aborts in between. The userspace interface buffer
385 * layout is as follows.
393 int tm_cvmx_set(struct task_struct
*target
, const struct user_regset
*regset
,
394 unsigned int pos
, unsigned int count
,
395 const void *kbuf
, const void __user
*ubuf
)
399 BUILD_BUG_ON(TVSO(vscr
) != TVSO(vr
[32]));
401 if (!cpu_has_feature(CPU_FTR_TM
))
404 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
407 flush_tmregs_to_thread(target
);
408 flush_fp_to_thread(target
);
409 flush_altivec_to_thread(target
);
411 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &target
->thread
.ckvr_state
,
412 0, 33 * sizeof(vector128
));
413 if (!ret
&& count
> 0) {
415 * We use only the low-order word of vrsave.
421 memset(&vrsave
, 0, sizeof(vrsave
));
422 vrsave
.word
= target
->thread
.ckvrsave
;
423 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
, &vrsave
,
424 33 * sizeof(vector128
), -1);
426 target
->thread
.ckvrsave
= vrsave
.word
;
433 * tm_cvsx_active - get active number of registers in CVSX
434 * @target: The target task.
435 * @regset: The user regset structure.
437 * This function checks for the active number of available
438 * regisers in transaction checkpointed VSX category.
440 int tm_cvsx_active(struct task_struct
*target
, const struct user_regset
*regset
)
442 if (!cpu_has_feature(CPU_FTR_TM
))
445 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
448 flush_vsx_to_thread(target
);
449 return target
->thread
.used_vsr
? regset
->n
: 0;
453 * tm_cvsx_get - get CVSX registers
454 * @target: The target task.
455 * @regset: The user regset structure.
456 * @to: Destination of copy.
458 * This function gets in transaction checkpointed VSX registers.
460 * When the transaction is active 'ckfp_state' holds the checkpointed
461 * values for the current transaction to fall back on if it aborts
462 * in between. This function gets those checkpointed VSX registers.
463 * The userspace interface buffer layout is as follows.
469 int tm_cvsx_get(struct task_struct
*target
, const struct user_regset
*regset
,
475 if (!cpu_has_feature(CPU_FTR_TM
))
478 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
481 /* Flush the state */
482 flush_tmregs_to_thread(target
);
483 flush_fp_to_thread(target
);
484 flush_altivec_to_thread(target
);
485 flush_vsx_to_thread(target
);
487 for (i
= 0; i
< 32 ; i
++)
488 buf
[i
] = target
->thread
.ckfp_state
.fpr
[i
][TS_VSRLOWOFFSET
];
489 return membuf_write(&to
, buf
, 32 * sizeof(double));
493 * tm_cvsx_set - set CFPR registers
494 * @target: The target task.
495 * @regset: The user regset structure.
496 * @pos: The buffer position.
497 * @count: Number of bytes to copy.
498 * @kbuf: Kernel buffer to copy into.
499 * @ubuf: User buffer to copy from.
501 * This function sets in transaction checkpointed VSX registers.
503 * When the transaction is active 'ckfp_state' holds the checkpointed
504 * VSX register values for the current transaction to fall back on
505 * if it aborts in between. This function sets these checkpointed
506 * FPR registers. The userspace interface buffer layout is as follows.
512 int tm_cvsx_set(struct task_struct
*target
, const struct user_regset
*regset
,
513 unsigned int pos
, unsigned int count
,
514 const void *kbuf
, const void __user
*ubuf
)
519 if (!cpu_has_feature(CPU_FTR_TM
))
522 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
525 /* Flush the state */
526 flush_tmregs_to_thread(target
);
527 flush_fp_to_thread(target
);
528 flush_altivec_to_thread(target
);
529 flush_vsx_to_thread(target
);
531 for (i
= 0; i
< 32 ; i
++)
532 buf
[i
] = target
->thread
.ckfp_state
.fpr
[i
][TS_VSRLOWOFFSET
];
534 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
535 buf
, 0, 32 * sizeof(double));
537 for (i
= 0; i
< 32 ; i
++)
538 target
->thread
.ckfp_state
.fpr
[i
][TS_VSRLOWOFFSET
] = buf
[i
];
544 * tm_spr_active - get active number of registers in TM SPR
545 * @target: The target task.
546 * @regset: The user regset structure.
548 * This function checks the active number of available
549 * regisers in the transactional memory SPR category.
551 int tm_spr_active(struct task_struct
*target
, const struct user_regset
*regset
)
553 if (!cpu_has_feature(CPU_FTR_TM
))
560 * tm_spr_get - get the TM related SPR registers
561 * @target: The target task.
562 * @regset: The user regset structure.
563 * @to: Destination of copy.
565 * This function gets transactional memory related SPR registers.
566 * The userspace interface buffer layout is as follows.
574 int tm_spr_get(struct task_struct
*target
, const struct user_regset
*regset
,
578 BUILD_BUG_ON(TSO(tm_tfhar
) + sizeof(u64
) != TSO(tm_texasr
));
579 BUILD_BUG_ON(TSO(tm_texasr
) + sizeof(u64
) != TSO(tm_tfiar
));
580 BUILD_BUG_ON(TSO(tm_tfiar
) + sizeof(u64
) != TSO(ckpt_regs
));
582 if (!cpu_has_feature(CPU_FTR_TM
))
585 /* Flush the states */
586 flush_tmregs_to_thread(target
);
587 flush_fp_to_thread(target
);
588 flush_altivec_to_thread(target
);
591 membuf_write(&to
, &target
->thread
.tm_tfhar
, sizeof(u64
));
592 /* TEXASR register */
593 membuf_write(&to
, &target
->thread
.tm_texasr
, sizeof(u64
));
595 return membuf_write(&to
, &target
->thread
.tm_tfiar
, sizeof(u64
));
599 * tm_spr_set - set the TM related SPR registers
600 * @target: The target task.
601 * @regset: The user regset structure.
602 * @pos: The buffer position.
603 * @count: Number of bytes to copy.
604 * @kbuf: Kernel buffer to copy into.
605 * @ubuf: User buffer to copy from.
607 * This function sets transactional memory related SPR registers.
608 * The userspace interface buffer layout is as follows.
616 int tm_spr_set(struct task_struct
*target
, const struct user_regset
*regset
,
617 unsigned int pos
, unsigned int count
,
618 const void *kbuf
, const void __user
*ubuf
)
623 BUILD_BUG_ON(TSO(tm_tfhar
) + sizeof(u64
) != TSO(tm_texasr
));
624 BUILD_BUG_ON(TSO(tm_texasr
) + sizeof(u64
) != TSO(tm_tfiar
));
625 BUILD_BUG_ON(TSO(tm_tfiar
) + sizeof(u64
) != TSO(ckpt_regs
));
627 if (!cpu_has_feature(CPU_FTR_TM
))
630 /* Flush the states */
631 flush_tmregs_to_thread(target
);
632 flush_fp_to_thread(target
);
633 flush_altivec_to_thread(target
);
636 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
637 &target
->thread
.tm_tfhar
, 0, sizeof(u64
));
639 /* TEXASR register */
641 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
642 &target
->thread
.tm_texasr
, sizeof(u64
),
647 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
648 &target
->thread
.tm_tfiar
,
649 2 * sizeof(u64
), 3 * sizeof(u64
));
653 int tm_tar_active(struct task_struct
*target
, const struct user_regset
*regset
)
655 if (!cpu_has_feature(CPU_FTR_TM
))
658 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
664 int tm_tar_get(struct task_struct
*target
, const struct user_regset
*regset
,
667 if (!cpu_has_feature(CPU_FTR_TM
))
670 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
673 return membuf_write(&to
, &target
->thread
.tm_tar
, sizeof(u64
));
676 int tm_tar_set(struct task_struct
*target
, const struct user_regset
*regset
,
677 unsigned int pos
, unsigned int count
,
678 const void *kbuf
, const void __user
*ubuf
)
682 if (!cpu_has_feature(CPU_FTR_TM
))
685 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
688 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
689 &target
->thread
.tm_tar
, 0, sizeof(u64
));
693 int tm_ppr_active(struct task_struct
*target
, const struct user_regset
*regset
)
695 if (!cpu_has_feature(CPU_FTR_TM
))
698 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
705 int tm_ppr_get(struct task_struct
*target
, const struct user_regset
*regset
,
708 if (!cpu_has_feature(CPU_FTR_TM
))
711 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
714 return membuf_write(&to
, &target
->thread
.tm_ppr
, sizeof(u64
));
717 int tm_ppr_set(struct task_struct
*target
, const struct user_regset
*regset
,
718 unsigned int pos
, unsigned int count
,
719 const void *kbuf
, const void __user
*ubuf
)
723 if (!cpu_has_feature(CPU_FTR_TM
))
726 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
729 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
730 &target
->thread
.tm_ppr
, 0, sizeof(u64
));
734 int tm_dscr_active(struct task_struct
*target
, const struct user_regset
*regset
)
736 if (!cpu_has_feature(CPU_FTR_TM
))
739 if (MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
745 int tm_dscr_get(struct task_struct
*target
, const struct user_regset
*regset
,
748 if (!cpu_has_feature(CPU_FTR_TM
))
751 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
754 return membuf_write(&to
, &target
->thread
.tm_dscr
, sizeof(u64
));
757 int tm_dscr_set(struct task_struct
*target
, const struct user_regset
*regset
,
758 unsigned int pos
, unsigned int count
,
759 const void *kbuf
, const void __user
*ubuf
)
763 if (!cpu_has_feature(CPU_FTR_TM
))
766 if (!MSR_TM_ACTIVE(target
->thread
.regs
->msr
))
769 ret
= user_regset_copyin(&pos
, &count
, &kbuf
, &ubuf
,
770 &target
->thread
.tm_dscr
, 0, sizeof(u64
));
774 int tm_cgpr32_get(struct task_struct
*target
, const struct user_regset
*regset
,
777 gpr32_get_common(target
, regset
, to
,
778 &target
->thread
.ckpt_regs
.gpr
[0]);
779 return membuf_zero(&to
, ELF_NGREG
* sizeof(u32
));
782 int tm_cgpr32_set(struct task_struct
*target
, const struct user_regset
*regset
,
783 unsigned int pos
, unsigned int count
,
784 const void *kbuf
, const void __user
*ubuf
)
786 return gpr32_set_common(target
, regset
, pos
, count
, kbuf
, ubuf
,
787 &target
->thread
.ckpt_regs
.gpr
[0]);