From: Masami Hiramatsu <mhiramat@kernel.org>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Anton Blanchard <anton@samba.org>,
linuxppc-dev@lists.ozlabs.org,
Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Subject: Re: [PATCH] powerpc: kprobes: invoke handlers directly
Date: Fri, 18 Nov 2016 23:48:41 +0900 [thread overview]
Message-ID: <20161118234841.ef216955ab8db0a9135c7582@kernel.org> (raw)
In-Reply-To: <20161118113926.31350-1-naveen.n.rao@linux.vnet.ibm.com>
On Fri, 18 Nov 2016 17:09:26 +0530
"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> wrote:
> ... rather than through notify_die(), to reduce path taken for handling
> kprobes. Similar to commit 6f6343f53d13 ("kprobes/x86: Call exception
> handlers directly from do_int3/do_debug").
>
> While at it, rename post_kprobe_handler() to kprobe_post_handler() for
> more uniform naming.
Looks good to me.
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Thanks!
>
> Reported-by: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> arch/powerpc/include/asm/kprobes.h | 2 ++
> arch/powerpc/kernel/kprobes.c | 29 +++++++----------------------
> arch/powerpc/kernel/traps.c | 20 ++++++++++++++++++++
> 3 files changed, 29 insertions(+), 22 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/kprobes.h b/arch/powerpc/include/asm/kprobes.h
> index 2c9759bd..47c60d0 100644
> --- a/arch/powerpc/include/asm/kprobes.h
> +++ b/arch/powerpc/include/asm/kprobes.h
> @@ -126,6 +126,8 @@ struct kprobe_ctlblk {
>
> extern int kprobe_exceptions_notify(struct notifier_block *self,
> unsigned long val, void *data);
> +extern int kprobe_handler(struct pt_regs *regs);
> +extern int kprobe_post_handler(struct pt_regs *regs);
> extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
> #endif /* __KERNEL__ */
> #endif /* _ASM_POWERPC_KPROBES_H */
> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
> index 9479d8e..ad108b8 100644
> --- a/arch/powerpc/kernel/kprobes.c
> +++ b/arch/powerpc/kernel/kprobes.c
> @@ -140,13 +140,16 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
> regs->link = (unsigned long)kretprobe_trampoline;
> }
>
> -static int __kprobes kprobe_handler(struct pt_regs *regs)
> +int __kprobes kprobe_handler(struct pt_regs *regs)
> {
> struct kprobe *p;
> int ret = 0;
> unsigned int *addr = (unsigned int *)regs->nip;
> struct kprobe_ctlblk *kcb;
>
> + if (user_mode(regs))
> + return 0;
> +
> /*
> * We don't want to be preempted for the entire
> * duration of kprobe processing
> @@ -359,12 +362,12 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
> * single-stepped a copy of the instruction. The address of this
> * copy is p->ainsn.insn.
> */
> -static int __kprobes post_kprobe_handler(struct pt_regs *regs)
> +int __kprobes kprobe_post_handler(struct pt_regs *regs)
> {
> struct kprobe *cur = kprobe_running();
> struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
>
> - if (!cur)
> + if (!cur || user_mode(regs))
> return 0;
>
> /* make sure we got here for instruction we have a kprobe on */
> @@ -470,25 +473,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
> int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
> unsigned long val, void *data)
> {
> - struct die_args *args = (struct die_args *)data;
> - int ret = NOTIFY_DONE;
> -
> - if (args->regs && user_mode(args->regs))
> - return ret;
> -
> - switch (val) {
> - case DIE_BPT:
> - if (kprobe_handler(args->regs))
> - ret = NOTIFY_STOP;
> - break;
> - case DIE_SSTEP:
> - if (post_kprobe_handler(args->regs))
> - ret = NOTIFY_STOP;
> - break;
> - default:
> - break;
> - }
> - return ret;
> + return NOTIFY_DONE;
> }
>
> unsigned long arch_deref_entry_point(void *entry)
> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
> index 91d278c..dbcdf48 100644
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -824,6 +824,11 @@ void single_step_exception(struct pt_regs *regs)
>
> clear_single_step(regs);
>
> +#ifdef CONFIG_KPROBES
> + if (kprobe_post_handler(regs))
> + return;
> +#endif
> +
> if (notify_die(DIE_SSTEP, "single_step", regs, 5,
> 5, SIGTRAP) == NOTIFY_STOP)
> goto bail;
> @@ -1177,6 +1182,11 @@ void program_check_exception(struct pt_regs *regs)
> if (debugger_bpt(regs))
> goto bail;
>
> +#ifdef CONFIG_KPROBES
> + if (kprobe_handler(regs))
> + goto bail;
> +#endif
> +
> /* trap exception */
> if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
> == NOTIFY_STOP)
> @@ -1745,6 +1755,11 @@ void DebugException(struct pt_regs *regs, unsigned long debug_status)
> return;
> }
>
> +#ifdef CONFIG_KPROBES
> + if (kprobe_post_handler(regs))
> + return;
> +#endif
> +
> if (notify_die(DIE_SSTEP, "block_step", regs, 5,
> 5, SIGTRAP) == NOTIFY_STOP) {
> return;
> @@ -1759,6 +1774,11 @@ void DebugException(struct pt_regs *regs, unsigned long debug_status)
> /* Clear the instruction completion event */
> mtspr(SPRN_DBSR, DBSR_IC);
>
> +#ifdef CONFIG_KPROBES
> + if (kprobe_post_handler(regs))
> + return;
> +#endif
> +
> if (notify_die(DIE_SSTEP, "single_step", regs, 5,
> 5, SIGTRAP) == NOTIFY_STOP) {
> return;
> --
> 2.10.2
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2016-11-18 14:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-18 11:39 [PATCH] powerpc: kprobes: invoke handlers directly Naveen N. Rao
2016-11-18 14:48 ` Masami Hiramatsu [this message]
2016-11-21 4:23 ` Ananth N Mavinakayanahalli
2016-11-21 10:24 ` Michael Ellerman
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=20161118234841.ef216955ab8db0a9135c7582@kernel.org \
--to=mhiramat@kernel.org \
--cc=ananth@in.ibm.com \
--cc=anton@samba.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=naveen.n.rao@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.