* [PATCH] powerpc: added DSCR support to ptrace @ 2013-01-11 6:29 Alexey Kardashevskiy 2013-01-15 18:17 ` Benjamin Herrenschmidt 0 siblings, 1 reply; 4+ messages in thread From: Alexey Kardashevskiy @ 2013-01-11 6:29 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Alexey Kardashevskiy, Michael Neuling, linuxppc-dev, linux-kernel The DSCR (aka Data Stream Control Register) is supported on some server PowerPC chips and allow some control over the prefetch of data streams. The kernel already supports DSCR value per thread but there is also a need in a ability to change it from an external process for the specific pid. The patch adds new register index PT_DSCR (index=44) which can be set/get by: ptrace(PTRACE_POKEUSER, traced_process, PT_DSCR << 3, dscr); dscr = ptrace(PTRACE_PEEKUSER, traced_process, PT_DSCR << 3, NULL); The patch does not increase PT_REGS_COUNT as the pt_regs struct has not been changed. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- arch/powerpc/include/uapi/asm/ptrace.h | 1 + arch/powerpc/kernel/ptrace.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/powerpc/include/uapi/asm/ptrace.h b/arch/powerpc/include/uapi/asm/ptrace.h index ee67a2b..5a4863c 100644 --- a/arch/powerpc/include/uapi/asm/ptrace.h +++ b/arch/powerpc/include/uapi/asm/ptrace.h @@ -108,6 +108,7 @@ struct pt_regs { #define PT_DAR 41 #define PT_DSISR 42 #define PT_RESULT 43 +#define PT_DSCR 44 #define PT_REGS_COUNT 44 #define PT_FPR0 48 /* each FP reg occupies 2 slots in this space */ diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index d4afccc..245c1b6 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -179,6 +179,30 @@ static int set_user_msr(struct task_struct *task, unsigned long msr) return 0; } +#ifdef CONFIG_PPC64 +static unsigned long get_user_dscr(struct task_struct *task) +{ + return task->thread.dscr; +} + +static int set_user_dscr(struct task_struct *task, unsigned long dscr) +{ + task->thread.dscr = dscr; + task->thread.dscr_inherit = 1; + return 0; +} +#else +static unsigned long get_user_dscr(struct task_struct *task) +{ + return -EIO; +} + +static int set_user_dscr(struct task_struct *task, unsigned long dscr) +{ + return -EIO; +} +#endif + /* * We prevent mucking around with the reserved area of trap * which are used internally by the kernel. @@ -200,6 +224,9 @@ unsigned long ptrace_get_reg(struct task_struct *task, int regno) if (regno == PT_MSR) return get_user_msr(task); + if (regno == PT_DSCR) + return get_user_dscr(task); + if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) return ((unsigned long *)task->thread.regs)[regno]; @@ -218,6 +245,8 @@ int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data) return set_user_msr(task, data); if (regno == PT_TRAP) return set_user_trap(task, data); + if (regno == PT_DSCR) + return set_user_dscr(task, data); if (regno <= PT_MAX_PUT_REG) { ((unsigned long *)task->thread.regs)[regno] = data; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc: added DSCR support to ptrace 2013-01-11 6:29 [PATCH] powerpc: added DSCR support to ptrace Alexey Kardashevskiy @ 2013-01-15 18:17 ` Benjamin Herrenschmidt 2013-02-15 3:44 ` [PATCH] powerpc: fixing ptrace_get_reg to return an error Alexey Kardashevskiy 0 siblings, 1 reply; 4+ messages in thread From: Benjamin Herrenschmidt @ 2013-01-15 18:17 UTC (permalink / raw) To: Alexey Kardashevskiy; +Cc: Michael Neuling, linuxppc-dev, linux-kernel On Fri, 2013-01-11 at 17:29 +1100, Alexey Kardashevskiy wrote: > +static unsigned long get_user_dscr(struct task_struct *task) > +{ > + return -EIO; > +} > + Does it make sense to return an error here ? ptrace_get_reg() doesn't seem to have provisions for returning errors, it just return register values, there's no way to differenciate an error code from a register value as far as I can tell... I'll apply your patch anyway because this is an existing problem with that function (it already returns -EIO in other circumstances), but I would like if you could submit a followup patch that changes it to return the register by value and return a real error code, which can be then handled properly in the two call sites (ptrace.c and ptrace32.c). Cheers, Ben. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] powerpc: fixing ptrace_get_reg to return an error 2013-01-15 18:17 ` Benjamin Herrenschmidt @ 2013-02-15 3:44 ` Alexey Kardashevskiy 2013-04-10 5:00 ` Michael Neuling 0 siblings, 1 reply; 4+ messages in thread From: Alexey Kardashevskiy @ 2013-02-15 3:44 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: Michael Neuling, Alexey Kardashevskiy, linux-kernel, Paul Mackerras, linuxppc-dev, David Gibson Currently ptrace_get_reg returns error as a value what make impossible to tell whether it is a correct value or error code. The patch adds a parameter which points to the real return data and returns an error code. As get_user_msr() never fails and it is used in multiple places so it has not been changed by this patch. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> --- arch/powerpc/include/asm/ptrace.h | 3 ++- arch/powerpc/kernel/ptrace.c | 29 ++++++++++++++++++----------- arch/powerpc/kernel/ptrace32.c | 15 ++++++++++++--- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h index 5f99568..becc08e 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -92,7 +92,8 @@ static inline long regs_return_value(struct pt_regs *regs) } while(0) struct task_struct; -extern unsigned long ptrace_get_reg(struct task_struct *task, int regno); +extern int ptrace_get_reg(struct task_struct *task, int regno, + unsigned long *data); extern int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data); diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index 245c1b6..d5ff7ea 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -180,9 +180,10 @@ static int set_user_msr(struct task_struct *task, unsigned long msr) } #ifdef CONFIG_PPC64 -static unsigned long get_user_dscr(struct task_struct *task) +static int get_user_dscr(struct task_struct *task, unsigned long *data) { - return task->thread.dscr; + *data = task->thread.dscr; + return 0; } static int set_user_dscr(struct task_struct *task, unsigned long dscr) @@ -192,7 +193,7 @@ static int set_user_dscr(struct task_struct *task, unsigned long dscr) return 0; } #else -static unsigned long get_user_dscr(struct task_struct *task) +static int get_user_dscr(struct task_struct *task, unsigned long *data) { return -EIO; } @@ -216,19 +217,23 @@ static int set_user_trap(struct task_struct *task, unsigned long trap) /* * Get contents of register REGNO in task TASK. */ -unsigned long ptrace_get_reg(struct task_struct *task, int regno) +int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) { - if (task->thread.regs == NULL) + if ((task->thread.regs == NULL) || !data) return -EIO; - if (regno == PT_MSR) - return get_user_msr(task); + if (regno == PT_MSR) { + *data = get_user_msr(task); + return 0; + } if (regno == PT_DSCR) - return get_user_dscr(task); + return get_user_dscr(task, data); - if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) - return ((unsigned long *)task->thread.regs)[regno]; + if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { + *data = ((unsigned long *)task->thread.regs)[regno]; + return 0; + } return -EIO; } @@ -1559,7 +1564,9 @@ long arch_ptrace(struct task_struct *child, long request, CHECK_FULL_REGS(child->thread.regs); if (index < PT_FPR0) { - tmp = ptrace_get_reg(child, (int) index); + ret = ptrace_get_reg(child, (int) index, &tmp); + if (ret) + break; } else { unsigned int fpidx = index - PT_FPR0; diff --git a/arch/powerpc/kernel/ptrace32.c b/arch/powerpc/kernel/ptrace32.c index c0244e7..f51599e 100644 --- a/arch/powerpc/kernel/ptrace32.c +++ b/arch/powerpc/kernel/ptrace32.c @@ -95,7 +95,9 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, CHECK_FULL_REGS(child->thread.regs); if (index < PT_FPR0) { - tmp = ptrace_get_reg(child, index); + ret = ptrace_get_reg(child, index, &tmp); + if (ret) + break; } else { flush_fp_to_thread(child); /* @@ -148,7 +150,11 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, tmp = ((u64 *)child->thread.fpr) [FPRINDEX_3264(numReg)]; } else { /* register within PT_REGS struct */ - tmp = ptrace_get_reg(child, numReg); + unsigned long tmp2; + ret = ptrace_get_reg(child, numReg, &tmp2); + if (ret) + break; + tmp = tmp2; } reg32bits = ((u32*)&tmp)[part]; ret = put_user(reg32bits, (u32 __user *)data); @@ -232,7 +238,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, break; CHECK_FULL_REGS(child->thread.regs); if (numReg < PT_FPR0) { - unsigned long freg = ptrace_get_reg(child, numReg); + unsigned long freg; + ret = ptrace_get_reg(child, numReg, &freg); + if (ret) + break; if (index % 2) freg = (freg & ~0xfffffffful) | (data & 0xfffffffful); else -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] powerpc: fixing ptrace_get_reg to return an error 2013-02-15 3:44 ` [PATCH] powerpc: fixing ptrace_get_reg to return an error Alexey Kardashevskiy @ 2013-04-10 5:00 ` Michael Neuling 0 siblings, 0 replies; 4+ messages in thread From: Michael Neuling @ 2013-04-10 5:00 UTC (permalink / raw) To: Alexey Kardashevskiy Cc: linuxppc-dev, Paul Mackerras, linux-kernel, David Gibson Alexey Kardashevskiy <aik@ozlabs.ru> wrote: > Currently ptrace_get_reg returns error as a value > what make impossible to tell whether it is a correct value or error code. > > The patch adds a parameter which points to the real return data and > returns an error code. > > As get_user_msr() never fails and it is used in multiple places so it has not > been changed by this patch. > > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> FWIW: Acked-by: Michael Neuling <mikey@neuling.org> > --- > arch/powerpc/include/asm/ptrace.h | 3 ++- > arch/powerpc/kernel/ptrace.c | 29 ++++++++++++++++++----------- > arch/powerpc/kernel/ptrace32.c | 15 ++++++++++++--- > 3 files changed, 32 insertions(+), 15 deletions(-) > > diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h > index 5f99568..becc08e 100644 > --- a/arch/powerpc/include/asm/ptrace.h > +++ b/arch/powerpc/include/asm/ptrace.h > @@ -92,7 +92,8 @@ static inline long regs_return_value(struct pt_regs *regs) > } while(0) > > struct task_struct; > -extern unsigned long ptrace_get_reg(struct task_struct *task, int regno); > +extern int ptrace_get_reg(struct task_struct *task, int regno, > + unsigned long *data); > extern int ptrace_put_reg(struct task_struct *task, int regno, > unsigned long data); > > diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c > index 245c1b6..d5ff7ea 100644 > --- a/arch/powerpc/kernel/ptrace.c > +++ b/arch/powerpc/kernel/ptrace.c > @@ -180,9 +180,10 @@ static int set_user_msr(struct task_struct *task, unsigned long msr) > } > > #ifdef CONFIG_PPC64 > -static unsigned long get_user_dscr(struct task_struct *task) > +static int get_user_dscr(struct task_struct *task, unsigned long *data) > { > - return task->thread.dscr; > + *data = task->thread.dscr; > + return 0; > } > > static int set_user_dscr(struct task_struct *task, unsigned long dscr) > @@ -192,7 +193,7 @@ static int set_user_dscr(struct task_struct *task, unsigned long dscr) > return 0; > } > #else > -static unsigned long get_user_dscr(struct task_struct *task) > +static int get_user_dscr(struct task_struct *task, unsigned long *data) > { > return -EIO; > } > @@ -216,19 +217,23 @@ static int set_user_trap(struct task_struct *task, unsigned long trap) > /* > * Get contents of register REGNO in task TASK. > */ > -unsigned long ptrace_get_reg(struct task_struct *task, int regno) > +int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data) > { > - if (task->thread.regs == NULL) > + if ((task->thread.regs == NULL) || !data) > return -EIO; > > - if (regno == PT_MSR) > - return get_user_msr(task); > + if (regno == PT_MSR) { > + *data = get_user_msr(task); > + return 0; > + } > > if (regno == PT_DSCR) > - return get_user_dscr(task); > + return get_user_dscr(task, data); > > - if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) > - return ((unsigned long *)task->thread.regs)[regno]; > + if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) { > + *data = ((unsigned long *)task->thread.regs)[regno]; > + return 0; > + } > > return -EIO; > } > @@ -1559,7 +1564,9 @@ long arch_ptrace(struct task_struct *child, long request, > > CHECK_FULL_REGS(child->thread.regs); > if (index < PT_FPR0) { > - tmp = ptrace_get_reg(child, (int) index); > + ret = ptrace_get_reg(child, (int) index, &tmp); > + if (ret) > + break; > } else { > unsigned int fpidx = index - PT_FPR0; > > diff --git a/arch/powerpc/kernel/ptrace32.c b/arch/powerpc/kernel/ptrace32.c > index c0244e7..f51599e 100644 > --- a/arch/powerpc/kernel/ptrace32.c > +++ b/arch/powerpc/kernel/ptrace32.c > @@ -95,7 +95,9 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, > > CHECK_FULL_REGS(child->thread.regs); > if (index < PT_FPR0) { > - tmp = ptrace_get_reg(child, index); > + ret = ptrace_get_reg(child, index, &tmp); > + if (ret) > + break; > } else { > flush_fp_to_thread(child); > /* > @@ -148,7 +150,11 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, > tmp = ((u64 *)child->thread.fpr) > [FPRINDEX_3264(numReg)]; > } else { /* register within PT_REGS struct */ > - tmp = ptrace_get_reg(child, numReg); > + unsigned long tmp2; > + ret = ptrace_get_reg(child, numReg, &tmp2); > + if (ret) > + break; > + tmp = tmp2; > } > reg32bits = ((u32*)&tmp)[part]; > ret = put_user(reg32bits, (u32 __user *)data); > @@ -232,7 +238,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, > break; > CHECK_FULL_REGS(child->thread.regs); > if (numReg < PT_FPR0) { > - unsigned long freg = ptrace_get_reg(child, numReg); > + unsigned long freg; > + ret = ptrace_get_reg(child, numReg, &freg); > + if (ret) > + break; > if (index % 2) > freg = (freg & ~0xfffffffful) | (data & 0xfffffffful); > else > -- > 1.7.10.4 > > _______________________________________________ > Linuxppc-dev mailing list > Linuxppc-dev@lists.ozlabs.org > https://lists.ozlabs.org/listinfo/linuxppc-dev > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-10 5:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-01-11 6:29 [PATCH] powerpc: added DSCR support to ptrace Alexey Kardashevskiy 2013-01-15 18:17 ` Benjamin Herrenschmidt 2013-02-15 3:44 ` [PATCH] powerpc: fixing ptrace_get_reg to return an error Alexey Kardashevskiy 2013-04-10 5:00 ` Michael Neuling
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).