From: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
To: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@ozlabs.org, "K.Prasad" <prasad@linux.vnet.ibm.com>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Subject: powerpc: remove resume_execution() in kprobes
Date: Fri, 28 May 2010 10:49:20 +0530 [thread overview]
Message-ID: <20100528051919.GC25946@in.ibm.com> (raw)
In-Reply-To: <20100528020556.GA10586@brick.ozlabs.ibm.com>
On Fri, May 28, 2010 at 12:05:56PM +1000, Paul Mackerras wrote:
> On Thu, May 27, 2010 at 07:42:03PM +0530, Ananth N Mavinakayanahalli wrote:
>
> > While we are at it, can we also add nop to the list of emulated
> > instructions?
>
> I have a patch in development that emulates most of the arithmetic,
> logical and shift/rotate instructions, including ori.
OK.
> While you're here (in a virtual sense at least :), could you explain
> what's going on with the emulate_step() call in resume_execution() in
> arch/powerpc/kernel/kprobes.c? It looks like, having decided that
> emulate_step() can't handle the instruction, you single-step the
> instruction out of line and then call emulate_step again on the same
> instruction, in resume_execution(). Why on earth is it trying to
> emulate the instruction when it has already been executed at this
> point? Is there any reason why we can't just remove the emulate_step
> call from resume_execution()?
You are right. We needed emulate_step() in resume_execution() before we
had the code to handle the emulation in kprobe_handler() at the time of
the breakpoint it. At the time we needed it mainly to ensure branch
targets are reflected correctly in regs->nip if the stepped instruction
was a branch.
However, we now don't get to post_kprobe_handler() at all if
emulate_step() returned 1 at the time of the breakpoint hit. It suffices
if we just fixup the nip here. Patch below. Tested for various
instructions that can and can't be emulated...
---
From: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
emulate_step() in kprobe_handler() would've already determined if the
probed instruction can be emulated. We single-step in hardware only if
the instruction couldn't be emulated. resume_execution() therefore is
superfluous -- all we need is to fix up the instruction pointer after
single-stepping.
Thanks to Paul Mackerras for catching this.
Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
---
arch/powerpc/kernel/kprobes.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
Index: linux-2.6.34/arch/powerpc/kernel/kprobes.c
===================================================================
--- linux-2.6.34.orig/arch/powerpc/kernel/kprobes.c
+++ linux-2.6.34/arch/powerpc/kernel/kprobes.c
@@ -375,17 +375,6 @@ static int __kprobes trampoline_probe_ha
* single-stepped a copy of the instruction. The address of this
* copy is p->ainsn.insn.
*/
-static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
-{
- int ret;
- unsigned int insn = *p->ainsn.insn;
-
- regs->nip = (unsigned long)p->addr;
- ret = emulate_step(regs, insn);
- if (ret == 0)
- regs->nip = (unsigned long)p->addr + 4;
-}
-
static int __kprobes post_kprobe_handler(struct pt_regs *regs)
{
struct kprobe *cur = kprobe_running();
@@ -403,7 +392,8 @@ static int __kprobes post_kprobe_handler
cur->post_handler(cur, regs, 0);
}
- resume_execution(cur, regs);
+ /* Adjust nip to after the single-stepped instruction */
+ regs->nip = (unsigned long)cur->addr + 4;
regs->msr |= kcb->kprobe_saved_msr;
/*Restore back the original saved kprobes variables and continue. */
next prev parent reply other threads:[~2010-05-28 5:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-20 12:49 [RFC PATCH] powerpc: Emulate most load and store instructions in emulate_step() Paul Mackerras
2010-05-21 16:35 ` Milton Miller
2010-05-27 14:12 ` [RFC PATCH] powerpc: Emulate nop too Ananth N Mavinakayanahalli
2010-05-27 20:22 ` Kumar Gala
2010-05-28 3:52 ` Ananth N Mavinakayanahalli
2010-05-28 2:05 ` Paul Mackerras
2010-05-28 5:19 ` Ananth N Mavinakayanahalli [this message]
2010-05-28 2:28 ` Michael Neuling
2010-05-28 4:16 ` Ananth N Mavinakayanahalli
2010-05-28 4:23 ` Michael Neuling
2010-05-28 5:54 ` Ananth N Mavinakayanahalli
2010-06-02 5:25 ` [RFC PATCH] powerpc: Emulate most load and store instructions in emulate_step() K.Prasad
2010-06-02 6:00 ` Paul Mackerras
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=20100528051919.GC25946@in.ibm.com \
--to=ananth@in.ibm.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@samba.org \
--cc=prasad@linux.vnet.ibm.com \
--cc=srikar@linux.vnet.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.