Netdev List
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexei Starovoitov <ast@fb.com>, Josef Bacik <jbacik@fb.com>,
	rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	ast@kernel.org, kernel-team@fb.com, daniel@iogearbox.net,
	linux-btrfs@vger.kernel.org, darrick.wong@oracle.com,
	Josef Bacik <josef@toxicpanda.com>,
	Akinobu Mita <akinobu.mita@gmail.com>
Subject: Re: [RFC PATCH bpf-next v2 2/4] tracing/kprobe: bpf: Compare instruction pointer with original one
Date: Tue, 26 Dec 2017 18:00:47 -0800	[thread overview]
Message-ID: <20171227020046.tcsorhzsxvp5awcg@ast-mbp> (raw)
In-Reply-To: <151427444611.32561.15006958504436049655.stgit@devbox>

On Tue, Dec 26, 2017 at 04:47:26PM +0900, Masami Hiramatsu wrote:
> Compare instruction pointer with original one on the
> stack instead using per-cpu bpf_kprobe_override flag.
> 
> This patch also consolidates reset_current_kprobe() and
> preempt_enable_no_resched() blocks. Those can be done
> in one place.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  kernel/trace/bpf_trace.c    |    1 -
>  kernel/trace/trace_kprobe.c |   21 +++++++--------------
>  2 files changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index d663660f8392..cefa9b0e396c 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -83,7 +83,6 @@ EXPORT_SYMBOL_GPL(trace_call_bpf);
>  #ifdef CONFIG_BPF_KPROBE_OVERRIDE
>  BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
>  {
> -	__this_cpu_write(bpf_kprobe_override, 1);
>  	regs_set_return_value(regs, rc);
>  	arch_ftrace_kprobe_override_function(regs);
>  	return 0;
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 265e3e27e8dc..a7c7035963f2 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -42,8 +42,6 @@ struct trace_kprobe {
>  	(offsetof(struct trace_kprobe, tp.args) +	\
>  	(sizeof(struct probe_arg) * (n)))
>  
> -DEFINE_PER_CPU(int, bpf_kprobe_override);
> -
>  static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
>  {
>  	return tk->rp.handler != NULL;
> @@ -1204,6 +1202,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
>  	int rctx;
>  
>  	if (bpf_prog_array_valid(call)) {
> +		unsigned long orig_ip = instruction_pointer(regs);
>  		int ret;
>  
>  		ret = trace_call_bpf(call, regs);
> @@ -1211,12 +1210,13 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
>  		/*
>  		 * We need to check and see if we modified the pc of the
>  		 * pt_regs, and if so clear the kprobe and return 1 so that we
> -		 * don't do the instruction skipping.  Also reset our state so
> -		 * we are clean the next pass through.
> +		 * don't do the single stepping.
> +		 * The ftrace kprobe handler leaves it up to us to re-enable
> +		 * preemption here before returning if we've modified the ip.
>  		 */
> -		if (__this_cpu_read(bpf_kprobe_override)) {
> -			__this_cpu_write(bpf_kprobe_override, 0);
> +		if (orig_ip != instruction_pointer(regs)) {
>  			reset_current_kprobe();
> +			preempt_enable_no_resched();

This is great idea.
Acked-by: Alexei Starovoitov <ast@kernel.org>

  reply	other threads:[~2017-12-27  2:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-26  7:46 [RFC PATCH bpf-next v2 0/4] Separate error injection table from kprobes Masami Hiramatsu
2017-12-26  7:46 ` [RFC PATCH bpf-next v2 1/4] tracing/kprobe: bpf: Check error injectable event is on function entry Masami Hiramatsu
2017-12-27  1:57   ` Alexei Starovoitov
2017-12-27  5:56     ` Masami Hiramatsu
2017-12-27 22:46       ` Alexei Starovoitov
2017-12-28  2:34         ` Masami Hiramatsu
2017-12-28  3:45           ` Alexei Starovoitov
2017-12-28  4:16             ` Steven Rostedt
2017-12-28  4:32               ` Alexei Starovoitov
2017-12-28  8:20                 ` Masami Hiramatsu
2017-12-29  1:03                   ` Alexei Starovoitov
2017-12-29  8:20                     ` Masami Hiramatsu
2018-01-08  3:01                       ` Alexei Starovoitov
2018-01-08 13:21                         ` Masami Hiramatsu
2017-12-28  7:56             ` Masami Hiramatsu
2017-12-26  7:47 ` [RFC PATCH bpf-next v2 2/4] tracing/kprobe: bpf: Compare instruction pointer with original one Masami Hiramatsu
2017-12-27  2:00   ` Alexei Starovoitov [this message]
2017-12-26  7:47 ` [RFC PATCH bpf-next v2 3/4] error-injection: Separate error-injection from kprobe Masami Hiramatsu
2017-12-27  2:07   ` Alexei Starovoitov
2017-12-26  7:48 ` [RFC PATCH bpf-next v2 4/4] error-injection: Support fault injection framework Masami Hiramatsu
2017-12-27  2:12   ` Alexei Starovoitov
2017-12-27  8:09     ` Masami Hiramatsu
2017-12-27 22:49       ` Alexei Starovoitov
2017-12-28  1:38         ` Masami Hiramatsu
2017-12-28  3:49           ` Alexei Starovoitov
2017-12-28  7:51             ` Masami Hiramatsu
2017-12-29  1:11               ` Alexei Starovoitov
2017-12-29  7:34                 ` Masami Hiramatsu
2018-01-04 16:07 ` [RFC PATCH bpf-next v2 0/4] Separate error injection table from kprobes Josef Bacik
2018-01-09  1:17   ` Masami Hiramatsu

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=20171227020046.tcsorhzsxvp5awcg@ast-mbp \
    --to=alexei.starovoitov@gmail.com \
    --cc=akinobu.mita@gmail.com \
    --cc=ast@fb.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=darrick.wong@oracle.com \
    --cc=davem@davemloft.net \
    --cc=jbacik@fb.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /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