1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/regset.h>
5 #include <linux/nospec.h>
6 #include <linux/pkeys.h>
8 #include "ptrace-decl.h"
10 struct pt_regs_offset {
15 #define STR(s) #s /* convert to string */
16 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
17 #define GPR_OFFSET_NAME(num) \
18 {.name = STR(r##num), .offset = offsetof(struct pt_regs, gpr[num])}, \
19 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
20 #define REG_OFFSET_END {.name = NULL, .offset = 0}
22 static const struct pt_regs_offset regoffset_table[] = {
58 REG_OFFSET_NAME(link),
62 REG_OFFSET_NAME(softe),
66 REG_OFFSET_NAME(trap),
68 REG_OFFSET_NAME(dsisr),
73 * regs_query_register_offset() - query register offset from its name
74 * @name: the name of a register
76 * regs_query_register_offset() returns the offset of a register in struct
77 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
79 int regs_query_register_offset(const char *name)
81 const struct pt_regs_offset *roff;
82 for (roff = regoffset_table; roff->name != NULL; roff++)
83 if (!strcmp(roff->name, name))
89 * regs_query_register_name() - query register name from its offset
90 * @offset: the offset of a register in struct pt_regs.
92 * regs_query_register_name() returns the name of a register from its
93 * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
95 const char *regs_query_register_name(unsigned int offset)
97 const struct pt_regs_offset *roff;
98 for (roff = regoffset_table; roff->name != NULL; roff++)
99 if (roff->offset == offset)
105 * does not yet catch signals sent when the child dies.
106 * in exit.c or in signal.c.
109 static unsigned long get_user_msr(struct task_struct *task)
111 return task->thread.regs->msr | task->thread.fpexc_mode;
114 static __always_inline int set_user_msr(struct task_struct *task, unsigned long msr)
116 unsigned long newmsr = (task->thread.regs->msr & ~MSR_DEBUGCHANGE) |
117 (msr & MSR_DEBUGCHANGE);
118 regs_set_return_msr(task->thread.regs, newmsr);
123 static int get_user_dscr(struct task_struct *task, unsigned long *data)
125 *data = task->thread.dscr;
129 static int set_user_dscr(struct task_struct *task, unsigned long dscr)
131 task->thread.dscr = dscr;
132 task->thread.dscr_inherit = 1;
136 static int get_user_dscr(struct task_struct *task, unsigned long *data)
141 static int set_user_dscr(struct task_struct *task, unsigned long dscr)
148 * We prevent mucking around with the reserved area of trap
149 * which are used internally by the kernel.
151 static __always_inline int set_user_trap(struct task_struct *task, unsigned long trap)
153 set_trap(task->thread.regs, trap);
158 * Get contents of register REGNO in task TASK.
160 int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)
162 unsigned int regs_max;
164 if (task->thread.regs == NULL || !data)
167 if (regno == PT_MSR) {
168 *data = get_user_msr(task);
172 if (regno == PT_DSCR)
173 return get_user_dscr(task, data);
176 * softe copies paca->irq_soft_mask variable state. Since irq_soft_mask is
177 * no more used as a flag, lets force usr to always see the softe value as 1
178 * which means interrupts are not soft disabled.
180 if (IS_ENABLED(CONFIG_PPC64) && regno == PT_SOFTE) {
185 regs_max = sizeof(struct user_pt_regs) / sizeof(unsigned long);
186 if (regno < regs_max) {
187 regno = array_index_nospec(regno, regs_max);
188 *data = ((unsigned long *)task->thread.regs)[regno];
196 * Write contents of register REGNO in task TASK.
198 int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
200 if (task->thread.regs == NULL)
204 return set_user_msr(task, data);
205 if (regno == PT_TRAP)
206 return set_user_trap(task, data);
207 if (regno == PT_DSCR)
208 return set_user_dscr(task, data);
210 if (regno <= PT_MAX_PUT_REG) {
211 regno = array_index_nospec(regno, PT_MAX_PUT_REG + 1);
212 ((unsigned long *)task->thread.regs)[regno] = data;
218 static int gpr_get(struct task_struct *target, const struct user_regset *regset,
221 struct membuf to_msr = membuf_at(&to, offsetof(struct pt_regs, msr));
223 struct membuf to_softe = membuf_at(&to, offsetof(struct pt_regs, softe));
225 if (target->thread.regs == NULL)
228 membuf_write(&to, target->thread.regs, sizeof(struct user_pt_regs));
230 membuf_store(&to_msr, get_user_msr(target));
232 membuf_store(&to_softe, 0x1ul);
234 return membuf_zero(&to, ELF_NGREG * sizeof(unsigned long) -
235 sizeof(struct user_pt_regs));
238 static int gpr_set(struct task_struct *target, const struct user_regset *regset,
239 unsigned int pos, unsigned int count, const void *kbuf,
240 const void __user *ubuf)
245 if (target->thread.regs == NULL)
248 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
250 0, PT_MSR * sizeof(reg));
252 if (!ret && count > 0) {
253 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®,
254 PT_MSR * sizeof(reg),
255 (PT_MSR + 1) * sizeof(reg));
257 ret = set_user_msr(target, reg);
260 BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
261 offsetof(struct pt_regs, msr) + sizeof(long));
264 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
265 &target->thread.regs->orig_gpr3,
266 PT_ORIG_R3 * sizeof(reg),
267 (PT_MAX_PUT_REG + 1) * sizeof(reg));
269 if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
270 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
271 (PT_MAX_PUT_REG + 1) * sizeof(reg),
272 PT_TRAP * sizeof(reg));
274 if (!ret && count > 0) {
275 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®,
276 PT_TRAP * sizeof(reg),
277 (PT_TRAP + 1) * sizeof(reg));
279 ret = set_user_trap(target, reg);
283 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
284 (PT_TRAP + 1) * sizeof(reg), -1);
290 static int ppr_get(struct task_struct *target, const struct user_regset *regset,
293 if (!target->thread.regs)
296 return membuf_write(&to, &target->thread.regs->ppr, sizeof(u64));
299 static int ppr_set(struct task_struct *target, const struct user_regset *regset,
300 unsigned int pos, unsigned int count, const void *kbuf,
301 const void __user *ubuf)
303 if (!target->thread.regs)
306 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
307 &target->thread.regs->ppr, 0, sizeof(u64));
310 static int dscr_get(struct task_struct *target, const struct user_regset *regset,
313 return membuf_write(&to, &target->thread.dscr, sizeof(u64));
315 static int dscr_set(struct task_struct *target, const struct user_regset *regset,
316 unsigned int pos, unsigned int count, const void *kbuf,
317 const void __user *ubuf)
319 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
320 &target->thread.dscr, 0, sizeof(u64));
323 #ifdef CONFIG_PPC_BOOK3S_64
324 static int tar_get(struct task_struct *target, const struct user_regset *regset,
327 return membuf_write(&to, &target->thread.tar, sizeof(u64));
329 static int tar_set(struct task_struct *target, const struct user_regset *regset,
330 unsigned int pos, unsigned int count, const void *kbuf,
331 const void __user *ubuf)
333 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
334 &target->thread.tar, 0, sizeof(u64));
337 static int ebb_active(struct task_struct *target, const struct user_regset *regset)
339 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
342 if (target->thread.used_ebb)
348 static int ebb_get(struct task_struct *target, const struct user_regset *regset,
352 BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
353 BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
355 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
358 if (!target->thread.used_ebb)
361 return membuf_write(&to, &target->thread.ebbrr, 3 * sizeof(unsigned long));
364 static int ebb_set(struct task_struct *target, const struct user_regset *regset,
365 unsigned int pos, unsigned int count, const void *kbuf,
366 const void __user *ubuf)
371 BUILD_BUG_ON(TSO(ebbrr) + sizeof(unsigned long) != TSO(ebbhr));
372 BUILD_BUG_ON(TSO(ebbhr) + sizeof(unsigned long) != TSO(bescr));
374 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
377 if (target->thread.used_ebb)
380 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.ebbrr,
381 0, sizeof(unsigned long));
384 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
385 &target->thread.ebbhr, sizeof(unsigned long),
386 2 * sizeof(unsigned long));
389 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
390 &target->thread.bescr, 2 * sizeof(unsigned long),
391 3 * sizeof(unsigned long));
395 static int pmu_active(struct task_struct *target, const struct user_regset *regset)
397 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
403 static int pmu_get(struct task_struct *target, const struct user_regset *regset,
407 BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
408 BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
409 BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
410 BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
412 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
415 return membuf_write(&to, &target->thread.siar, 5 * sizeof(unsigned long));
418 static int pmu_set(struct task_struct *target, const struct user_regset *regset,
419 unsigned int pos, unsigned int count, const void *kbuf,
420 const void __user *ubuf)
425 BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
426 BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
427 BUILD_BUG_ON(TSO(sier) + sizeof(unsigned long) != TSO(mmcr2));
428 BUILD_BUG_ON(TSO(mmcr2) + sizeof(unsigned long) != TSO(mmcr0));
430 if (!cpu_has_feature(CPU_FTR_ARCH_207S))
433 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.siar,
434 0, sizeof(unsigned long));
437 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
438 &target->thread.sdar, sizeof(unsigned long),
439 2 * sizeof(unsigned long));
442 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
443 &target->thread.sier, 2 * sizeof(unsigned long),
444 3 * sizeof(unsigned long));
447 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
448 &target->thread.mmcr2, 3 * sizeof(unsigned long),
449 4 * sizeof(unsigned long));
452 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
453 &target->thread.mmcr0, 4 * sizeof(unsigned long),
454 5 * sizeof(unsigned long));
458 static int dexcr_active(struct task_struct *target, const struct user_regset *regset)
460 if (!cpu_has_feature(CPU_FTR_ARCH_31))
466 static int dexcr_get(struct task_struct *target, const struct user_regset *regset,
469 if (!cpu_has_feature(CPU_FTR_ARCH_31))
473 * The DEXCR is currently static across all CPUs, so we don't
474 * store the target's value anywhere, but the static value
475 * will also be correct.
477 membuf_store(&to, (u64)lower_32_bits(DEXCR_INIT));
480 * Technically the HDEXCR is per-cpu, but a hypervisor can't reasonably
481 * change it between CPUs of the same guest.
483 return membuf_store(&to, (u64)lower_32_bits(mfspr(SPRN_HDEXCR_RO)));
486 #ifdef CONFIG_CHECKPOINT_RESTORE
487 static int hashkeyr_active(struct task_struct *target, const struct user_regset *regset)
489 if (!cpu_has_feature(CPU_FTR_ARCH_31))
495 static int hashkeyr_get(struct task_struct *target, const struct user_regset *regset,
498 if (!cpu_has_feature(CPU_FTR_ARCH_31))
501 return membuf_store(&to, target->thread.hashkeyr);
504 static int hashkeyr_set(struct task_struct *target, const struct user_regset *regset,
505 unsigned int pos, unsigned int count, const void *kbuf,
506 const void __user *ubuf)
508 if (!cpu_has_feature(CPU_FTR_ARCH_31))
511 return user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.hashkeyr,
512 0, sizeof(unsigned long));
514 #endif /* CONFIG_CHECKPOINT_RESTORE */
515 #endif /* CONFIG_PPC_BOOK3S_64 */
517 #ifdef CONFIG_PPC_MEM_KEYS
518 static int pkey_active(struct task_struct *target, const struct user_regset *regset)
520 if (!arch_pkeys_enabled())
526 static int pkey_get(struct task_struct *target, const struct user_regset *regset,
530 if (!arch_pkeys_enabled())
533 membuf_store(&to, target->thread.regs->amr);
534 membuf_store(&to, target->thread.regs->iamr);
535 return membuf_store(&to, default_uamor);
538 static int pkey_set(struct task_struct *target, const struct user_regset *regset,
539 unsigned int pos, unsigned int count, const void *kbuf,
540 const void __user *ubuf)
545 if (!arch_pkeys_enabled())
548 /* Only the AMR can be set from userspace */
549 if (pos != 0 || count != sizeof(new_amr))
552 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
553 &new_amr, 0, sizeof(new_amr));
558 * UAMOR determines which bits of the AMR can be set from userspace.
559 * UAMOR value 0b11 indicates that the AMR value can be modified
560 * from userspace. If the kernel is using a specific key, we avoid
561 * userspace modifying the AMR value for that key by masking them
564 * Pick the AMR values for the keys that kernel is using. This
565 * will be indicated by the ~default_uamor bits.
567 target->thread.regs->amr = (new_amr & default_uamor) |
568 (target->thread.regs->amr & ~default_uamor);
572 #endif /* CONFIG_PPC_MEM_KEYS */
574 static const struct user_regset native_regsets[] = {
576 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
577 .size = sizeof(long), .align = sizeof(long),
578 .regset_get = gpr_get, .set = gpr_set
581 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
582 .size = sizeof(double), .align = sizeof(double),
583 .regset_get = fpr_get, .set = fpr_set
585 #ifdef CONFIG_ALTIVEC
587 .core_note_type = NT_PPC_VMX, .n = 34,
588 .size = sizeof(vector128), .align = sizeof(vector128),
589 .active = vr_active, .regset_get = vr_get, .set = vr_set
594 .core_note_type = NT_PPC_VSX, .n = 32,
595 .size = sizeof(double), .align = sizeof(double),
596 .active = vsr_active, .regset_get = vsr_get, .set = vsr_set
601 .core_note_type = NT_PPC_SPE, .n = 35,
602 .size = sizeof(u32), .align = sizeof(u32),
603 .active = evr_active, .regset_get = evr_get, .set = evr_set
606 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
608 .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
609 .size = sizeof(long), .align = sizeof(long),
610 .active = tm_cgpr_active, .regset_get = tm_cgpr_get, .set = tm_cgpr_set
613 .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
614 .size = sizeof(double), .align = sizeof(double),
615 .active = tm_cfpr_active, .regset_get = tm_cfpr_get, .set = tm_cfpr_set
618 .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
619 .size = sizeof(vector128), .align = sizeof(vector128),
620 .active = tm_cvmx_active, .regset_get = tm_cvmx_get, .set = tm_cvmx_set
623 .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
624 .size = sizeof(double), .align = sizeof(double),
625 .active = tm_cvsx_active, .regset_get = tm_cvsx_get, .set = tm_cvsx_set
628 .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
629 .size = sizeof(u64), .align = sizeof(u64),
630 .active = tm_spr_active, .regset_get = tm_spr_get, .set = tm_spr_set
633 .core_note_type = NT_PPC_TM_CTAR, .n = 1,
634 .size = sizeof(u64), .align = sizeof(u64),
635 .active = tm_tar_active, .regset_get = tm_tar_get, .set = tm_tar_set
638 .core_note_type = NT_PPC_TM_CPPR, .n = 1,
639 .size = sizeof(u64), .align = sizeof(u64),
640 .active = tm_ppr_active, .regset_get = tm_ppr_get, .set = tm_ppr_set
642 [REGSET_TM_CDSCR] = {
643 .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
644 .size = sizeof(u64), .align = sizeof(u64),
645 .active = tm_dscr_active, .regset_get = tm_dscr_get, .set = tm_dscr_set
650 .core_note_type = NT_PPC_PPR, .n = 1,
651 .size = sizeof(u64), .align = sizeof(u64),
652 .regset_get = ppr_get, .set = ppr_set
655 .core_note_type = NT_PPC_DSCR, .n = 1,
656 .size = sizeof(u64), .align = sizeof(u64),
657 .regset_get = dscr_get, .set = dscr_set
660 #ifdef CONFIG_PPC_BOOK3S_64
662 .core_note_type = NT_PPC_TAR, .n = 1,
663 .size = sizeof(u64), .align = sizeof(u64),
664 .regset_get = tar_get, .set = tar_set
667 .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
668 .size = sizeof(u64), .align = sizeof(u64),
669 .active = ebb_active, .regset_get = ebb_get, .set = ebb_set
672 .core_note_type = NT_PPC_PMU, .n = ELF_NPMU,
673 .size = sizeof(u64), .align = sizeof(u64),
674 .active = pmu_active, .regset_get = pmu_get, .set = pmu_set
677 .core_note_type = NT_PPC_DEXCR, .n = ELF_NDEXCR,
678 .size = sizeof(u64), .align = sizeof(u64),
679 .active = dexcr_active, .regset_get = dexcr_get
681 #ifdef CONFIG_CHECKPOINT_RESTORE
682 [REGSET_HASHKEYR] = {
683 .core_note_type = NT_PPC_HASHKEYR, .n = ELF_NHASHKEYR,
684 .size = sizeof(u64), .align = sizeof(u64),
685 .active = hashkeyr_active, .regset_get = hashkeyr_get, .set = hashkeyr_set
689 #ifdef CONFIG_PPC_MEM_KEYS
691 .core_note_type = NT_PPC_PKEY, .n = ELF_NPKEY,
692 .size = sizeof(u64), .align = sizeof(u64),
693 .active = pkey_active, .regset_get = pkey_get, .set = pkey_set
698 const struct user_regset_view user_ppc_native_view = {
699 .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
700 .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
703 #include <linux/compat.h>
705 int gpr32_get_common(struct task_struct *target,
706 const struct user_regset *regset,
707 struct membuf to, unsigned long *regs)
711 for (i = 0; i < PT_MSR; i++)
712 membuf_store(&to, (u32)regs[i]);
713 membuf_store(&to, (u32)get_user_msr(target));
714 for (i++ ; i < PT_REGS_COUNT; i++)
715 membuf_store(&to, (u32)regs[i]);
716 return membuf_zero(&to, (ELF_NGREG - PT_REGS_COUNT) * sizeof(u32));
719 static int gpr32_set_common_kernel(struct task_struct *target,
720 const struct user_regset *regset,
721 unsigned int pos, unsigned int count,
722 const void *kbuf, unsigned long *regs)
724 const compat_ulong_t *k = kbuf;
726 pos /= sizeof(compat_ulong_t);
727 count /= sizeof(compat_ulong_t);
729 for (; count > 0 && pos < PT_MSR; --count)
732 if (count > 0 && pos == PT_MSR) {
733 set_user_msr(target, *k++);
738 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
740 for (; count > 0 && pos < PT_TRAP; --count, ++pos)
743 if (count > 0 && pos == PT_TRAP) {
744 set_user_trap(target, *k++);
750 pos *= sizeof(compat_ulong_t);
751 count *= sizeof(compat_ulong_t);
752 user_regset_copyin_ignore(&pos, &count, &kbuf, NULL,
753 (PT_TRAP + 1) * sizeof(compat_ulong_t), -1);
757 static int gpr32_set_common_user(struct task_struct *target,
758 const struct user_regset *regset,
759 unsigned int pos, unsigned int count,
760 const void __user *ubuf, unsigned long *regs)
762 const compat_ulong_t __user *u = ubuf;
763 const void *kbuf = NULL;
766 if (!user_read_access_begin(u, count))
770 count /= sizeof(reg);
772 for (; count > 0 && pos < PT_MSR; --count) {
773 unsafe_get_user(reg, u++, Efault);
777 if (count > 0 && pos == PT_MSR) {
778 unsafe_get_user(reg, u++, Efault);
779 set_user_msr(target, reg);
784 for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
785 unsafe_get_user(reg, u++, Efault);
788 for (; count > 0 && pos < PT_TRAP; --count, ++pos)
789 unsafe_get_user(reg, u++, Efault);
791 if (count > 0 && pos == PT_TRAP) {
792 unsafe_get_user(reg, u++, Efault);
793 set_user_trap(target, reg);
797 user_read_access_end();
801 count *= sizeof(reg);
802 user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
803 (PT_TRAP + 1) * sizeof(reg), -1);
807 user_read_access_end();
811 int gpr32_set_common(struct task_struct *target,
812 const struct user_regset *regset,
813 unsigned int pos, unsigned int count,
814 const void *kbuf, const void __user *ubuf,
818 return gpr32_set_common_kernel(target, regset, pos, count, kbuf, regs);
820 return gpr32_set_common_user(target, regset, pos, count, ubuf, regs);
823 static int gpr32_get(struct task_struct *target,
824 const struct user_regset *regset,
827 if (target->thread.regs == NULL)
830 return gpr32_get_common(target, regset, to,
831 &target->thread.regs->gpr[0]);
834 static int gpr32_set(struct task_struct *target,
835 const struct user_regset *regset,
836 unsigned int pos, unsigned int count,
837 const void *kbuf, const void __user *ubuf)
839 if (target->thread.regs == NULL)
842 return gpr32_set_common(target, regset, pos, count, kbuf, ubuf,
843 &target->thread.regs->gpr[0]);
847 * These are the regset flavors matching the CONFIG_PPC32 native set.
849 static const struct user_regset compat_regsets[] = {
851 .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
852 .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
853 .regset_get = gpr32_get, .set = gpr32_set
856 .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
857 .size = sizeof(double), .align = sizeof(double),
858 .regset_get = fpr_get, .set = fpr_set
860 #ifdef CONFIG_ALTIVEC
862 .core_note_type = NT_PPC_VMX, .n = 34,
863 .size = sizeof(vector128), .align = sizeof(vector128),
864 .active = vr_active, .regset_get = vr_get, .set = vr_set
869 .core_note_type = NT_PPC_SPE, .n = 35,
870 .size = sizeof(u32), .align = sizeof(u32),
871 .active = evr_active, .regset_get = evr_get, .set = evr_set
874 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
876 .core_note_type = NT_PPC_TM_CGPR, .n = ELF_NGREG,
877 .size = sizeof(long), .align = sizeof(long),
878 .active = tm_cgpr_active,
879 .regset_get = tm_cgpr32_get, .set = tm_cgpr32_set
882 .core_note_type = NT_PPC_TM_CFPR, .n = ELF_NFPREG,
883 .size = sizeof(double), .align = sizeof(double),
884 .active = tm_cfpr_active, .regset_get = tm_cfpr_get, .set = tm_cfpr_set
887 .core_note_type = NT_PPC_TM_CVMX, .n = ELF_NVMX,
888 .size = sizeof(vector128), .align = sizeof(vector128),
889 .active = tm_cvmx_active, .regset_get = tm_cvmx_get, .set = tm_cvmx_set
892 .core_note_type = NT_PPC_TM_CVSX, .n = ELF_NVSX,
893 .size = sizeof(double), .align = sizeof(double),
894 .active = tm_cvsx_active, .regset_get = tm_cvsx_get, .set = tm_cvsx_set
897 .core_note_type = NT_PPC_TM_SPR, .n = ELF_NTMSPRREG,
898 .size = sizeof(u64), .align = sizeof(u64),
899 .active = tm_spr_active, .regset_get = tm_spr_get, .set = tm_spr_set
902 .core_note_type = NT_PPC_TM_CTAR, .n = 1,
903 .size = sizeof(u64), .align = sizeof(u64),
904 .active = tm_tar_active, .regset_get = tm_tar_get, .set = tm_tar_set
907 .core_note_type = NT_PPC_TM_CPPR, .n = 1,
908 .size = sizeof(u64), .align = sizeof(u64),
909 .active = tm_ppr_active, .regset_get = tm_ppr_get, .set = tm_ppr_set
911 [REGSET_TM_CDSCR] = {
912 .core_note_type = NT_PPC_TM_CDSCR, .n = 1,
913 .size = sizeof(u64), .align = sizeof(u64),
914 .active = tm_dscr_active, .regset_get = tm_dscr_get, .set = tm_dscr_set
919 .core_note_type = NT_PPC_PPR, .n = 1,
920 .size = sizeof(u64), .align = sizeof(u64),
921 .regset_get = ppr_get, .set = ppr_set
924 .core_note_type = NT_PPC_DSCR, .n = 1,
925 .size = sizeof(u64), .align = sizeof(u64),
926 .regset_get = dscr_get, .set = dscr_set
929 #ifdef CONFIG_PPC_BOOK3S_64
931 .core_note_type = NT_PPC_TAR, .n = 1,
932 .size = sizeof(u64), .align = sizeof(u64),
933 .regset_get = tar_get, .set = tar_set
936 .core_note_type = NT_PPC_EBB, .n = ELF_NEBB,
937 .size = sizeof(u64), .align = sizeof(u64),
938 .active = ebb_active, .regset_get = ebb_get, .set = ebb_set
943 static const struct user_regset_view user_ppc_compat_view = {
944 .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
945 .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
948 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
950 if (IS_ENABLED(CONFIG_COMPAT) && is_tsk_32bit_task(task))
951 return &user_ppc_compat_view;
952 return &user_ppc_native_view;