diff mbox series

[v2] bpf: test_bpf: turn of preemption in function __run_once

Message ID 20190222084652.1326-1-anders.roxell@linaro.org
State New
Headers show
Series [v2] bpf: test_bpf: turn of preemption in function __run_once | expand

Commit Message

Anders Roxell Feb. 22, 2019, 8:46 a.m. UTC
When running BPF test suite the following splat occurs:

[  415.930950] test_bpf: #0 TAX jited:0
[  415.931067] BUG: assuming atomic context at lib/test_bpf.c:6674
[  415.946169] in_atomic(): 0, irqs_disabled(): 0, pid: 11556, name: modprobe
[  415.953176] INFO: lockdep is turned off.
[  415.957207] CPU: 1 PID: 11556 Comm: modprobe Tainted: G        W         5.0.0-rc7-next-20190220 #1
[  415.966328] Hardware name: HiKey Development Board (DT)
[  415.971592] Call trace:
[  415.974069]  dump_backtrace+0x0/0x160
[  415.977761]  show_stack+0x24/0x30
[  415.981104]  dump_stack+0xc8/0x114
[  415.984534]  __cant_sleep+0xf0/0x108
[  415.988145]  test_bpf_init+0x5e0/0x1000 [test_bpf]
[  415.992971]  do_one_initcall+0x90/0x428
[  415.996837]  do_init_module+0x60/0x1e4
[  416.000614]  load_module+0x1de0/0x1f50
[  416.004391]  __se_sys_finit_module+0xc8/0xe0
[  416.008691]  __arm64_sys_finit_module+0x24/0x30
[  416.013255]  el0_svc_common+0x78/0x130
[  416.017031]  el0_svc_handler+0x38/0x78
[  416.020806]  el0_svc+0x8/0xc

Rework so that preemption is disabled when we loop over function
'BPF_PROG_RUN(...)'.
Commit 568f196756ad ("bpf: check that BPF programs run with preemption disabled")
highlighted the issue.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>

---
 lib/test_bpf.c | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.20.1

Comments

Daniel Borkmann Feb. 25, 2019, 9:28 p.m. UTC | #1
On 02/22/2019 09:46 AM, Anders Roxell wrote:
> When running BPF test suite the following splat occurs:

> 

> [  415.930950] test_bpf: #0 TAX jited:0

> [  415.931067] BUG: assuming atomic context at lib/test_bpf.c:6674

> [  415.946169] in_atomic(): 0, irqs_disabled(): 0, pid: 11556, name: modprobe

> [  415.953176] INFO: lockdep is turned off.

> [  415.957207] CPU: 1 PID: 11556 Comm: modprobe Tainted: G        W         5.0.0-rc7-next-20190220 #1

> [  415.966328] Hardware name: HiKey Development Board (DT)

> [  415.971592] Call trace:

> [  415.974069]  dump_backtrace+0x0/0x160

> [  415.977761]  show_stack+0x24/0x30

> [  415.981104]  dump_stack+0xc8/0x114

> [  415.984534]  __cant_sleep+0xf0/0x108

> [  415.988145]  test_bpf_init+0x5e0/0x1000 [test_bpf]

> [  415.992971]  do_one_initcall+0x90/0x428

> [  415.996837]  do_init_module+0x60/0x1e4

> [  416.000614]  load_module+0x1de0/0x1f50

> [  416.004391]  __se_sys_finit_module+0xc8/0xe0

> [  416.008691]  __arm64_sys_finit_module+0x24/0x30

> [  416.013255]  el0_svc_common+0x78/0x130

> [  416.017031]  el0_svc_handler+0x38/0x78

> [  416.020806]  el0_svc+0x8/0xc

> 

> Rework so that preemption is disabled when we loop over function

> 'BPF_PROG_RUN(...)'.

> Commit 568f196756ad ("bpf: check that BPF programs run with preemption disabled")

> highlighted the issue.


(Technically not an issue in the test suite itself, but good to have same
 guarantees everywhere in BPF_PROG_RUN().)

> Suggested-by: Arnd Bergmann <arnd@arndb.de>

> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>


Applied, thanks!
diff mbox series

Patch

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index f3e570722a7e..0845f635f404 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -6668,12 +6668,14 @@  static int __run_one(const struct bpf_prog *fp, const void *data,
 	u64 start, finish;
 	int ret = 0, i;
 
+	preempt_disable();
 	start = ktime_get_ns();
 
 	for (i = 0; i < runs; i++)
 		ret = BPF_PROG_RUN(fp, data);
 
 	finish = ktime_get_ns();
+	preempt_enable();
 
 	*duration = finish - start;
 	do_div(*duration, runs);