18 #include <linux/kernel.h>
19 #include <linux/sched.h>
22 #include <linux/errno.h>
23 #include <linux/ptrace.h>
26 #include <linux/elf.h>
29 #include <linux/signal.h>
30 #include <linux/seccomp.h>
31 #include <linux/audit.h>
33 #include <linux/hw_breakpoint.h>
34 #include <linux/perf_event.h>
36 #include <asm/uaccess.h>
38 #include <asm/pgtable.h>
39 #include <asm/switch_to.h>
41 #define CREATE_TRACE_POINTS
49 #define PARAMETER_SAVE_AREA_OFFSET 24
51 #define PARAMETER_SAVE_AREA_OFFSET 48
60 #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
61 #define GPR_OFFSET_NAME(num) \
62 {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
63 #define REG_OFFSET_END {.name = NULL, .offset = 0}
125 for (roff = regoffset_table; roff->
name !=
NULL; roff++)
141 for (roff = regoffset_table; roff->
name !=
NULL; roff++)
142 if (roff->
offset == offset)
155 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
156 #define MSR_DEBUGCHANGE 0
158 #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
165 #define PT_MAX_PUT_REG PT_MQ
167 #define PT_MAX_PUT_REG PT_CCR
172 return task->
thread.regs->msr | task->
thread.fpexc_mode;
188 task->
thread.regs->trap = trap & 0xfff0;
201 return get_user_msr(task);
203 if (regno < (
sizeof(
struct pt_regs) /
sizeof(
unsigned long)))
204 return ((
unsigned long *)task->
thread.regs)[regno];
218 return set_user_msr(task, data);
220 return set_user_trap(task, data);
223 ((
unsigned long *)task->
thread.regs)[regno] =
data;
230 unsigned int pos,
unsigned int count,
231 void *kbuf,
void __user *ubuf)
240 for (i = 14; i < 32; i++)
244 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
248 unsigned long msr = get_user_msr(target);
249 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
259 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
260 &target->
thread.regs->orig_gpr3,
264 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
271 unsigned int pos,
unsigned int count,
272 const void *kbuf,
const void __user *ubuf)
282 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
286 if (!ret && count > 0) {
287 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®,
289 (
PT_MSR + 1) *
sizeof(reg));
291 ret = set_user_msr(target, reg);
298 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
299 &target->
thread.regs->orig_gpr3,
304 ret = user_regset_copyin_ignore(
305 &pos, &count, &kbuf, &ubuf,
309 if (!ret && count > 0) {
310 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®,
314 ret = set_user_trap(target, reg);
318 ret = user_regset_copyin_ignore(
319 &pos, &count, &kbuf, &ubuf,
320 (
PT_TRAP + 1) *
sizeof(reg), -1);
326 unsigned int pos,
unsigned int count,
327 void *kbuf,
void __user *ubuf)
337 for (i = 0; i < 32 ; i++)
338 buf[i] = target->
thread.TS_FPR(i);
339 memcpy(&buf[32], &target->
thread.fpscr,
sizeof(
double));
340 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
346 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
347 &target->
thread.fpr, 0, -1);
352 unsigned int pos,
unsigned int count,
353 const void *kbuf,
const void __user *ubuf)
363 i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
366 for (i = 0; i < 32 ; i++)
367 target->
thread.TS_FPR(i) = buf[
i];
368 memcpy(&target->
thread.fpscr, &buf[32],
sizeof(
double));
374 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
375 &target->
thread.fpr, 0, -1);
379 #ifdef CONFIG_ALTIVEC
396 flush_altivec_to_thread(target);
397 return target->
thread.used_vr ? regset->
n : 0;
401 unsigned int pos,
unsigned int count,
402 void *kbuf,
void __user *ubuf)
406 flush_altivec_to_thread(target);
411 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
422 memset(&vrsave, 0,
sizeof(vrsave));
423 vrsave.word = target->
thread.vrsave;
424 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
432 unsigned int pos,
unsigned int count,
433 const void *kbuf,
const void __user *ubuf)
437 flush_altivec_to_thread(target);
442 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
444 if (!ret && count > 0) {
452 memset(&vrsave, 0,
sizeof(vrsave));
453 vrsave.word = target->
thread.vrsave;
454 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
457 target->
thread.vrsave = vrsave.word;
474 flush_vsx_to_thread(target);
475 return target->
thread.used_vsr ? regset->
n : 0;
479 unsigned int pos,
unsigned int count,
480 void *kbuf,
void __user *ubuf)
485 flush_vsx_to_thread(target);
487 for (i = 0; i < 32 ; i++)
488 buf[i] = target->
thread.fpr[i][TS_VSRLOWOFFSET];
489 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
490 buf, 0, 32 *
sizeof(
double));
496 unsigned int pos,
unsigned int count,
497 const void *kbuf,
const void __user *ubuf)
502 flush_vsx_to_thread(target);
504 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
505 buf, 0, 32 *
sizeof(
double));
506 for (i = 0; i < 32 ; i++)
507 target->
thread.fpr[i][TS_VSRLOWOFFSET] = buf[i];
529 flush_spe_to_thread(target);
530 return target->
thread.used_spe ? regset->
n : 0;
534 unsigned int pos,
unsigned int count,
535 void *kbuf,
void __user *ubuf)
539 flush_spe_to_thread(target);
541 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
543 0,
sizeof(target->
thread.evr));
549 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
551 sizeof(target->
thread.evr), -1);
557 unsigned int pos,
unsigned int count,
558 const void *kbuf,
const void __user *ubuf)
562 flush_spe_to_thread(target);
564 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
566 0,
sizeof(target->
thread.evr));
572 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
574 sizeof(target->
thread.evr), -1);
587 #ifdef CONFIG_ALTIVEC
598 static const struct user_regset native_regsets[] = {
601 .size =
sizeof(
long), .
align =
sizeof(
long),
602 .get = gpr_get, .set = gpr_set
606 .size =
sizeof(double), .
align =
sizeof(
double),
607 .get = fpr_get, .set = fpr_set
609 #ifdef CONFIG_ALTIVEC
613 .active = vr_active, .get = vr_get, .set = vr_set
619 .size =
sizeof(double), .
align =
sizeof(
double),
620 .active = vsr_active, .get = vsr_get, .set = vsr_set
627 .active = evr_active, .get = evr_get, .set = evr_set
634 .regsets = native_regsets, .
n =
ARRAY_SIZE(native_regsets)
642 unsigned int pos,
unsigned int count,
643 void *kbuf,
void __user *ubuf)
645 const unsigned long *
regs = &target->
thread.regs->gpr[0];
656 for (i = 14; i < 32; i++)
661 count /=
sizeof(
reg);
671 if (count > 0 && pos == PT_MSR) {
672 reg = get_user_msr(target);
692 count *=
sizeof(
reg);
693 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
694 PT_REGS_COUNT *
sizeof(reg), -1);
699 unsigned int pos,
unsigned int count,
700 const void *kbuf,
const void __user *ubuf)
702 unsigned long *regs = &target->
thread.regs->gpr[0];
713 count /=
sizeof(
reg);
726 if (count > 0 && pos == PT_MSR) {
731 set_user_msr(target, reg);
752 if (count > 0 && pos == PT_TRAP) {
757 set_user_trap(target, reg);
765 count *=
sizeof(
reg);
766 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
767 (PT_TRAP + 1) *
sizeof(reg), -1);
773 static const struct user_regset compat_regsets[] = {
777 .get = gpr32_get, .set = gpr32_set
781 .size =
sizeof(double), .
align =
sizeof(
double),
782 .get = fpr_get, .set = fpr_set
784 #ifdef CONFIG_ALTIVEC
788 .active = vr_active, .get = vr_get, .set = vr_set
795 .active = evr_active, .get = evr_get, .set = evr_set
802 .regsets = compat_regsets, .
n =
ARRAY_SIZE(compat_regsets)
809 if (test_tsk_thread_flag(task, TIF_32BIT))
810 return &user_ppc_compat_view;
812 return &user_ppc_native_view;
821 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
822 task->
thread.dbcr0 &= ~DBCR0_BT;
823 task->
thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
838 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
839 task->
thread.dbcr0 &= ~DBCR0_IC;
840 task->
thread.dbcr0 = DBCR0_IDM | DBCR0_BT;
843 regs->
msr &= ~MSR_SE;
855 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
862 task->
thread.dbcr0 &= ~DBCR0_IC;
866 if (!DBCR_ACTIVE_EVENTS(task->
thread.dbcr0,
871 task->
thread.dbcr0 &= ~DBCR0_IDM;
872 regs->
msr &= ~MSR_DE;
881 #ifdef CONFIG_HAVE_HW_BREAKPOINT
883 struct perf_sample_data *
data,
struct pt_regs *regs)
894 attr.disabled =
true;
902 #ifdef CONFIG_HAVE_HW_BREAKPOINT
920 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
934 if (data && !(data & DABR_TRANSLATION))
936 #ifdef CONFIG_HAVE_HW_BREAKPOINT
937 if (ptrace_get_breakpoints(task) < 0)
941 if ((!data) || !(data & (DABR_DATA_WRITE | DABR_DATA_READ))) {
946 ptrace_put_breakpoints(task);
951 attr.
bp_addr = data & ~HW_BREAKPOINT_ALIGN;
953 (DABR_DATA_WRITE | DABR_DATA_READ),
957 ptrace_put_breakpoints(task);
961 ptrace_put_breakpoints(task);
963 thread->dabrx = DABRX_ALL;
968 hw_breakpoint_init(&attr);
969 attr.
bp_addr = data & ~HW_BREAKPOINT_ALIGN;
977 ptrace_put_breakpoints(task);
981 ptrace_put_breakpoints(task);
987 task->
thread.dabrx = DABRX_ALL;
997 if (task->
thread.dac1 == 0) {
998 dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
999 if (!DBCR_ACTIVE_EVENTS(task->
thread.dbcr0,
1001 task->
thread.regs->msr &= ~MSR_DE;
1002 task->
thread.dbcr0 &= ~DBCR0_IDM;
1009 if (!(data & 0x3UL))
1014 task->
thread.dbcr0 |= DBCR0_IDM;
1018 dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
1020 dbcr_dac(task) |= DBCR_DAC1R;
1022 dbcr_dac(task) |= DBCR_DAC1W;
1023 task->
thread.regs->msr |= MSR_DE;
1039 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1044 int slot1_in_use = ((child->
thread.dbcr0 & DBCR0_IAC1) != 0);
1045 int slot2_in_use = ((child->
thread.dbcr0 & DBCR0_IAC2) != 0);
1046 int slot3_in_use = ((child->
thread.dbcr0 & DBCR0_IAC3) != 0);
1047 int slot4_in_use = ((child->
thread.dbcr0 & DBCR0_IAC4) != 0);
1049 if (dbcr_iac_range(child) & DBCR_IAC12MODE)
1051 if (dbcr_iac_range(child) & DBCR_IAC34MODE)
1064 if ((!slot1_in_use) && (!slot2_in_use)) {
1068 child->
thread.dbcr0 |= DBCR0_IAC1;
1071 dbcr_iac_range(child) |= DBCR_IAC12X;
1073 dbcr_iac_range(child) |= DBCR_IAC12I;
1074 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1075 }
else if ((!slot3_in_use) && (!slot4_in_use)) {
1079 child->
thread.dbcr0 |= DBCR0_IAC3;
1082 dbcr_iac_range(child) |= DBCR_IAC34X;
1084 dbcr_iac_range(child) |= DBCR_IAC34I;
1092 if (!slot1_in_use) {
1097 if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
1100 child->
thread.dbcr0 |= DBCR0_IAC1;
1104 if (!slot2_in_use) {
1107 child->
thread.dbcr0 |= DBCR0_IAC2;
1108 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1109 }
else if (!slot3_in_use) {
1112 child->
thread.dbcr0 |= DBCR0_IAC3;
1113 }
else if (!slot4_in_use) {
1116 child->
thread.dbcr0 |= DBCR0_IAC4;
1122 child->
thread.dbcr0 |= DBCR0_IDM;
1123 child->
thread.regs->msr |= MSR_DE;
1128 static int del_instruction_bp(
struct task_struct *child,
int slot)
1132 if ((child->
thread.dbcr0 & DBCR0_IAC1) == 0)
1135 if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
1138 dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
1141 child->
thread.dbcr0 &= ~DBCR0_IAC1;
1144 if ((child->
thread.dbcr0 & DBCR0_IAC2) == 0)
1147 if (dbcr_iac_range(child) & DBCR_IAC12MODE)
1151 child->
thread.dbcr0 &= ~DBCR0_IAC2;
1153 #if CONFIG_PPC_ADV_DEBUG_IACS > 2
1155 if ((child->
thread.dbcr0 & DBCR0_IAC3) == 0)
1158 if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
1161 dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
1164 child->
thread.dbcr0 &= ~DBCR0_IAC3;
1167 if ((child->
thread.dbcr0 & DBCR0_IAC4) == 0)
1170 if (dbcr_iac_range(child) & DBCR_IAC34MODE)
1174 child->
thread.dbcr0 &= ~DBCR0_IAC4;
1188 int condition_mode =
1192 if (byte_enable && (condition_mode == 0))
1198 if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
1201 dbcr_dac(child) |= DBCR_DAC1R;
1203 dbcr_dac(child) |= DBCR_DAC1W;
1205 #
if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1210 ((byte_enable << DBCR2_DVC1BE_SHIFT) |
1211 (condition_mode << DBCR2_DVC1M_SHIFT));
1214 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1215 }
else if (child->
thread.dbcr2 & DBCR2_DAC12MODE) {
1219 }
else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
1222 dbcr_dac(child) |= DBCR_DAC2R;
1224 dbcr_dac(child) |= DBCR_DAC2W;
1226 #
if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1231 ((byte_enable << DBCR2_DVC2BE_SHIFT) |
1232 (condition_mode << DBCR2_DVC2M_SHIFT));
1237 child->
thread.dbcr0 |= DBCR0_IDM;
1238 child->
thread.regs->msr |= MSR_DE;
1243 static int del_dac(
struct task_struct *child,
int slot)
1246 if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
1250 dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
1251 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1252 if (child->
thread.dbcr2 & DBCR2_DAC12MODE) {
1254 child->
thread.dbcr2 &= ~DBCR2_DAC12MODE;
1256 child->
thread.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
1258 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1261 }
else if (slot == 2) {
1262 if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
1265 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1266 if (child->
thread.dbcr2 & DBCR2_DAC12MODE)
1269 child->
thread.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
1271 #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
1275 dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
1283 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1284 static int set_dac_range(
struct task_struct *child,
1316 if (child->
thread.dbcr0 &
1317 (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
1321 child->
thread.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
1323 child->
thread.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
1327 child->
thread.dbcr2 |= DBCR2_DAC12M;
1329 child->
thread.dbcr2 |= DBCR2_DAC12MX;
1331 child->
thread.dbcr2 |= DBCR2_DAC12MM;
1332 child->
thread.regs->msr |= MSR_DE;
1338 static long ppc_set_hwdebug(
struct task_struct *child,
1341 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
1347 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1359 #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
1368 return set_intruction_bp(child, bp_info);
1371 return set_dac(child, bp_info);
1373 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1374 return set_dac_range(child, bp_info);
1395 dabr |= DABR_TRANSLATION;
1397 dabr |= DABR_DATA_READ;
1399 dabr |= DABR_DATA_WRITE;
1401 child->
thread.dabr = dabr;
1402 child->
thread.dabrx = DABRX_ALL;
1410 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1414 rc = del_instruction_bp(child, (
int)data);
1416 rc = del_dac(child, (
int)data - 4);
1419 if (!DBCR_ACTIVE_EVENTS(child->
thread.dbcr0,
1421 child->
thread.dbcr0 &= ~DBCR0_IDM;
1422 child->
thread.regs->msr &= ~MSR_DE;
1429 if (child->
thread.dabr == 0)
1439 unsigned long addr,
unsigned long data)
1443 unsigned long __user *datalp = datavp;
1454 if ((addr & 3) || (index >
PT_FPSCR)
1458 if ((addr & 7) || (index >
PT_FPSCR))
1466 unsigned int fpidx = index -
PT_FPR0;
1470 tmp = ((
unsigned long *)child->
thread.fpr)
1473 tmp = child->
thread.fpscr.val;
1481 unsigned long index;
1487 if ((addr & 3) || (index >
PT_FPSCR)
1491 if ((addr & 7) || (index >
PT_FPSCR))
1499 unsigned int fpidx = index -
PT_FPR0;
1503 ((
unsigned long *)child->
thread.fpr)
1516 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1524 #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
1561 ret = ppc_set_hwdebug(child, &bp_info);
1566 ret = ppc_del_hwdebug(child, addr, data);
1575 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
1591 return copy_regset_to_user(child, &user_ppc_native_view,
1600 return copy_regset_from_user(child, &user_ppc_native_view,
1606 return copy_regset_to_user(child, &user_ppc_native_view,
1612 return copy_regset_from_user(child, &user_ppc_native_view,
1617 #ifdef CONFIG_ALTIVEC
1619 return copy_regset_to_user(child, &user_ppc_native_view,
1626 return copy_regset_from_user(child, &user_ppc_native_view,
1634 return copy_regset_to_user(child, &user_ppc_native_view,
1636 0, 32 *
sizeof(
double),
1640 return copy_regset_from_user(child, &user_ppc_native_view,
1642 0, 32 *
sizeof(
double),
1648 return copy_regset_to_user(child, &user_ppc_native_view,
1649 REGSET_SPE, 0, 35 *
sizeof(
u32),
1654 return copy_regset_from_user(child, &user_ppc_native_view,
1655 REGSET_SPE, 0, 35 *
sizeof(
u32),
1674 secure_computing_strict(regs->
gpr[0]);
1677 tracehook_report_syscall_entry(regs))
1686 trace_sys_enter(regs, regs->
gpr[0]);
1692 regs->
gpr[3], regs->
gpr[4],
1693 regs->
gpr[5], regs->
gpr[6]);
1698 regs->
gpr[3] & 0xffffffff,
1699 regs->
gpr[4] & 0xffffffff,
1700 regs->
gpr[5] & 0xffffffff,
1701 regs->
gpr[6] & 0xffffffff);
1703 return ret ?: regs->
gpr[0];
1710 audit_syscall_exit(regs);
1713 trace_sys_exit(regs, regs->
result);
1717 tracehook_report_syscall_exit(regs, step);