From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
David Miller <davem@davemloft.net>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Sebastian Sewior <bigeasy@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Clark Williams <williams@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Juri Lelli <juri.lelli@redhat.com>,
Ingo Molnar <mingo@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Jakub Kicinski <kuba@kernel.org>
Subject: Re: [patch V3 06/22] bpf/trace: Remove redundant preempt_disable from trace_call_bpf()
Date: Mon, 24 Feb 2020 11:40:20 -0800 [thread overview]
Message-ID: <20200224194017.rtwjcgjxnmltisfe@ast-mbp> (raw)
In-Reply-To: <20200224145643.059995527@linutronix.de>
On Mon, Feb 24, 2020 at 03:01:37PM +0100, Thomas Gleixner wrote:
> Similar to __bpf_trace_run this is redundant because __bpf_trace_run() is
> invoked from a trace point via __DO_TRACE() which already disables
> preemption _before_ invoking any of the functions which are attached to a
> trace point.
>
> Remove it and add a cant_sleep() check.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
> V3: New patch. Replaces the previous one which converted this to migrate_disable()
> ---
> kernel/trace/bpf_trace.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -83,7 +83,7 @@ unsigned int trace_call_bpf(struct trace
> if (in_nmi()) /* not supported yet */
> return 1;
>
> - preempt_disable();
> + cant_sleep();
>
> if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
> /*
> @@ -115,7 +115,6 @@ unsigned int trace_call_bpf(struct trace
>
> out:
> __this_cpu_dec(bpf_prog_active);
> - preempt_enable();
My testing uncovered that above was too aggressive:
[ 41.533438] BUG: assuming atomic context at kernel/trace/bpf_trace.c:86
[ 41.534265] in_atomic(): 0, irqs_disabled(): 0, pid: 2348, name: test_progs
[ 41.536907] Call Trace:
[ 41.537167] dump_stack+0x75/0xa0
[ 41.537546] __cant_sleep.cold.105+0x8b/0xa3
[ 41.538018] ? exit_to_usermode_loop+0x77/0x140
[ 41.538493] trace_call_bpf+0x4e/0x2e0
[ 41.538908] __uprobe_perf_func.isra.15+0x38f/0x690
[ 41.539399] ? probes_profile_seq_show+0x220/0x220
[ 41.539962] ? __mutex_lock_slowpath+0x10/0x10
[ 41.540412] uprobe_dispatcher+0x5de/0x8f0
[ 41.540875] ? uretprobe_dispatcher+0x7c0/0x7c0
[ 41.541404] ? down_read_killable+0x200/0x200
[ 41.541852] ? __kasan_kmalloc.constprop.6+0xc1/0xd0
[ 41.542356] uprobe_notify_resume+0xacf/0x1d60
The following fixes it:
commit 7b7b71ff43cc0b15567b60c38a951c8a2cbc97f0 (HEAD -> bpf-next)
Author: Alexei Starovoitov <ast@kernel.org>
Date: Mon Feb 24 11:27:15 2020 -0800
bpf: disable migration for bpf progs attached to uprobe
trace_call_bpf() no longer disables preemption on its own.
All callers of this function has to do it explicitly.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 18d16f3ef980..7581f5eb6091 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -1333,8 +1333,15 @@ static void __uprobe_perf_func(struct trace_uprobe *tu,
int size, esize;
int rctx;
- if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs))
- return;
+ if (bpf_prog_array_valid(call)) {
+ u32 ret;
+
+ migrate_disable();
+ ret = trace_call_bpf(call, regs);
+ migrate_enable();
+ if (!ret)
+ return;
+ }
But looking at your patch cant_sleep() seems unnecessary strong.
Should it be cant_migrate() instead?
And two calls to __this_cpu*() replaced with this_cpu*() ?
If you can ack it I can fix it up in place and apply the whole thing.
That was the only issue I found.
next prev parent reply other threads:[~2020-02-24 19:40 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 14:01 [patch V3 00/22] bpf: Make BPF and PREEMPT_RT co-exist Thomas Gleixner
2020-02-24 14:01 ` [patch V3 01/22] bpf: Tighten the requirements for preallocated hash maps Thomas Gleixner
2020-02-24 14:01 ` [patch V3 02/22] bpf: Enforce preallocation for instrumentation programs on RT Thomas Gleixner
2020-02-24 14:01 ` [patch V3 03/22] bpf: Update locking comment in hashtab code Thomas Gleixner
2020-02-24 14:01 ` [patch V3 04/22] bpf/tracing: Remove redundant preempt_disable() in __bpf_trace_run() Thomas Gleixner
2020-02-24 14:01 ` [patch V3 05/22] bpf/trace: Remove EXPORT from trace_call_bpf() Thomas Gleixner
2020-02-24 18:16 ` Alexei Starovoitov
2020-02-24 14:01 ` [patch V3 06/22] bpf/trace: Remove redundant preempt_disable " Thomas Gleixner
2020-02-24 19:40 ` Alexei Starovoitov [this message]
2020-02-24 20:42 ` Thomas Gleixner
2020-02-25 0:33 ` Alexei Starovoitov
2020-02-25 12:36 ` Thomas Gleixner
2020-02-24 14:01 ` [patch V3 07/22] perf/bpf: Remove preempt disable around BPF invocation Thomas Gleixner
2020-02-24 14:01 ` [patch V3 08/22] bpf: Remove recursion prevention from rcu free callback Thomas Gleixner
2020-02-24 14:01 ` [patch V3 09/22] bpf: Dont iterate over possible CPUs with interrupts disabled Thomas Gleixner
2020-02-24 14:01 ` [patch V3 10/22] bpf: Provide bpf_prog_run_pin_on_cpu() helper Thomas Gleixner
2020-02-24 18:14 ` Thomas Gleixner
2020-02-24 18:41 ` [patch V4 " Thomas Gleixner
2020-02-24 14:01 ` [patch V3 11/22] bpf: Replace cant_sleep() with cant_migrate() Thomas Gleixner
2020-02-24 14:01 ` [patch V3 12/22] bpf: Use bpf_prog_run_pin_on_cpu() at simple call sites Thomas Gleixner
2020-02-24 14:01 ` [patch V3 13/22] bpf/tests: Use migrate disable instead of preempt disable Thomas Gleixner
2020-02-24 14:01 ` [patch V3 14/22] bpf: Use migrate_disable/enabe() in trampoline code Thomas Gleixner
2020-02-24 14:01 ` [patch V3 15/22] bpf: Use migrate_disable/enable in array macros and cgroup/lirc code Thomas Gleixner
2020-02-24 14:01 ` [patch V3 16/22] bpf: Provide recursion prevention helpers Thomas Gleixner
2020-02-24 14:01 ` [patch V3 17/22] bpf: Use recursion prevention helpers in hashtab code Thomas Gleixner
2020-02-24 14:01 ` [patch V3 18/22] bpf: Replace open coded recursion prevention in sys_bpf() Thomas Gleixner
2020-02-24 14:01 ` [patch V3 19/22] bpf: Factor out hashtab bucket lock operations Thomas Gleixner
2020-02-24 14:01 ` [patch V3 20/22] bpf: Prepare hashtab locking for PREEMPT_RT Thomas Gleixner
2020-02-24 14:01 ` [patch V3 21/22] bpf, lpm: Make locking RT friendly Thomas Gleixner
2020-02-24 14:01 ` [patch V3 22/22] bpf/stackmap: Dont trylock mmap_sem with PREEMPT_RT and interrupts disabled Thomas Gleixner
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=20200224194017.rtwjcgjxnmltisfe@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=juri.lelli@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=vinicius.gomes@intel.com \
--cc=williams@redhat.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