From: Michael Wolf <mjw@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@ozlabs.org, mikey@neuling.org, anton@samba.org
Subject: Re: [PATCH] powerpc/ptrace: remove BUG_ON when full register set not available
Date: Wed, 02 Mar 2011 09:44:09 -0600 [thread overview]
Message-ID: <1299080649.3087.6.camel@w500> (raw)
In-Reply-To: <1299035316.8833.806.camel@pasglop>
On Wed, 2011-03-02 at 14:08 +1100, Benjamin Herrenschmidt wrote:
> > --- ptracev2.orig/include/linux/regset.h 2011-02-20 12:15:57.000000000 -0600
> > +++ ptracev2/include/linux/regset.h 2011-02-28 13:33:36.685302349 -0600
> > @@ -240,6 +240,34 @@ static inline int user_regset_copyout(un
> > }
> > return 0;
> > }
> > +/* want the count to be the registers 14-31 inclusive */
> > +#define POISON_REG_CNT (PT_R31-PT_R14+1)
> > +static inline int user_regset_copyout_poison(unsigned int *pos,
> > + unsigned int *count,
> > + void **kbuf, void __user **ubuf,
> > + const int start_pos,
> > + const int end_pos)
> > +{
>
> I wouldn't put that in a generic location... especially something
> like POISON_REG_CNT is very specific to powerpc and our ABI.
Yeah I put it there thinking about readability but only use it in the
one place. If we go forward with this current strategy I will remove
the #define and just comment more.
>
> .../...
>
> > static inline int user_regset_copyin(unsigned int *pos, unsigned int *count,
> > const void **kbuf,
> > --- ptracev2.orig/arch/powerpc/kernel/ptrace.c 2011-02-20 12:15:57.000000000 -0600
> > +++ ptracev2/arch/powerpc/kernel/ptrace.c 2011-03-01 13:49:12.686354353 -0600
> > @@ -234,11 +234,29 @@ static int gpr_get(struct task_struct *t
> > if (target->thread.regs == NULL)
> > return -EIO;
> >
> > - CHECK_FULL_REGS(target->thread.regs);
>
> Wouldn't it be a simpler/cleaner approach to use a single function call
> here that checks if the reg set is full and if not, put poison values
> in the thread.regs structure itself ?
>
> The resulting code would be more palatable...
That was actually the way I had done the first patch while debugging the
problem but Paul Mackerras didn't like that I changed the thread struct.
It is not clear to me which is better. Reporting a poison value that
isn't actually there or to change the data. Hopefully a consensus can
be reached and then I can submit a new patch based on that.
>
> Cheers,
> Ben.
>
> > - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
> > - target->thread.regs,
> > - 0, offsetof(struct pt_regs, msr));
> > + if (!FULL_REGS(target->thread.regs)) {
> > + /* Don't have the full register set. Copy out register r0-r13 */
> > + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
> > + target->thread.regs,
> > + 0, sizeof(long)*PT_R14);
> > +
> > + /* Dont want to change the actual register values so rather than read the */
> > + /* actual register copy a poison value into the buffer instead */
> > + if (!ret)
> > + ret = user_regset_copyout_poison(&pos, &count, &kbuf, &ubuf,
> > + sizeof(long)*PT_R14, offsetof(struct pt_regs, nip));
> > +
> > + /* Copy out the rest of the registers as usual */
> > + if (!ret)
> > + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
> > + target->thread.regs,
> > + offsetof(struct pt_regs, nip), offsetof(struct pt_regs, msr));
> > +
> > + } else
> > + ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
> > + target->thread.regs,
> > + 0, offsetof(struct pt_regs, msr));
> > if (!ret) {
> > unsigned long msr = get_user_msr(target);
> > ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
> > @@ -645,11 +663,29 @@ static int gpr32_get(struct task_struct
> > if (target->thread.regs == NULL)
> > return -EIO;
> >
> > - CHECK_FULL_REGS(target->thread.regs);
> > -
> > pos /= sizeof(reg);
> > count /= sizeof(reg);
> >
> > + if(!FULL_REGS(target->thread.regs)) {
> > + if (kbuf) {
> > + /* Don't have the full register set. Copy out register r0-r13 */
> > + for (; count > 0 && pos < PT_R14; --count)
> > + *k++ = regs[pos++];
> > +
> > + /* Dont want to change the actual register values so rather than read the */
> > + /* actual register copy a poison value into the buffer instead */
> > + for (; count > 0 && pos <= PT_R31; --count,pos++)
> > + *k++ = 0xdeadbeef;
> > +
> > + } else {
> > + for (; count > 0 && pos < PT_R14; --count)
> > + if (__put_user((compat_ulong_t) regs[pos++], u++))
> > + return -EFAULT;
> > + for (; count > 0 && pos <= PT_R31; --count,pos++)
> > + if (__put_user((compat_ulong_t) 0xdeadbeef, u++))
> > + return -EFAULT;
> > + }
> > + }
> > if (kbuf)
> > for (; count > 0 && pos < PT_MSR; --count)
> > *k++ = regs[pos++];
> >
> >
> > _______________________________________________
> > Linuxppc-dev mailing list
> > Linuxppc-dev@lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/linuxppc-dev
>
>
next prev parent reply other threads:[~2011-03-02 15:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-01 20:26 [PATCH] powerpc/ptrace: remove BUG_ON when full register set not available Michael Wolf
2011-03-02 3:08 ` Benjamin Herrenschmidt
2011-03-02 15:44 ` Michael Wolf [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-03-21 0:18 [PATCH] powerpc/ptrace: Remove " Benjamin Herrenschmidt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299080649.3087.6.camel@w500 \
--to=mjw@linux.vnet.ibm.com \
--cc=anton@samba.org \
--cc=benh@kernel.crashing.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=mikey@neuling.org \
--cc=mjw@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).