[RFC PATCH 3/5] powerpc: Fix pmu get/set functions
Pedro Franco de Carvalho
pedromfc at linux.vnet.ibm.com
Fri Jun 8 01:25:32 AEST 2018
The PMU regset exposed through ptrace has 5 64-bit words, which are
all copied in and out. However, mmcr0 in the thread_struct is an
unsigned, which causes pmu_set to clobber the next variable in the
thread_struct (used_ebb), and pmu_get to return the same variable in
one half of the mmcr0 slot.
---
arch/powerpc/kernel/ptrace.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
index be8ca03a0bd5..69123feaef9e 100644
--- a/arch/powerpc/kernel/ptrace.c
+++ b/arch/powerpc/kernel/ptrace.c
@@ -1733,6 +1733,9 @@ static int pmu_get(struct task_struct *target,
unsigned int pos, unsigned int count,
void *kbuf, void __user *ubuf)
{
+ int ret = 0;
+ unsigned long mmcr0 = target->thread.mmcr0;
+
/* Build tests */
BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
@@ -1742,9 +1745,16 @@ static int pmu_get(struct task_struct *target,
if (!cpu_has_feature(CPU_FTR_ARCH_207S))
return -ENODEV;
- return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
- &target->thread.siar, 0,
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+ &target->thread.siar, 0,
+ 4 * sizeof(unsigned long));
+
+ if (!ret)
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+ &mmcr0, 4 * sizeof(unsigned long),
5 * sizeof(unsigned long));
+
+ return ret;
}
static int pmu_set(struct task_struct *target,
@@ -1754,6 +1764,12 @@ static int pmu_set(struct task_struct *target,
{
int ret = 0;
+#ifdef __BIG_ENDIAN
+ int mmcr0_offset = sizeof(unsigned);
+#else
+ int mmcr0_offset = 0;
+#endif
+
/* Build tests */
BUILD_BUG_ON(TSO(siar) + sizeof(unsigned long) != TSO(sdar));
BUILD_BUG_ON(TSO(sdar) + sizeof(unsigned long) != TSO(sier));
@@ -1783,9 +1799,16 @@ static int pmu_set(struct task_struct *target,
4 * sizeof(unsigned long));
if (!ret)
+ ret = user_regset_copyin_ignore(&pos, &count, &kbuf,
+ &ubuf, 4 * sizeof(unsigned long),
+ 4 * sizeof(unsigned long) + mmcr0_offset);
+
+ if (!ret)
ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
- &target->thread.mmcr0, 4 * sizeof(unsigned long),
- 5 * sizeof(unsigned long));
+ &target->thread.mmcr0,
+ 4 * sizeof(unsigned long) + mmcr0_offset,
+ 4 * sizeof(unsigned long) + mmcr0_offset
+ + sizeof (unsigned));
return ret;
}
#endif
--
2.13.6
More information about the Linuxppc-dev
mailing list