linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: Refuse fprobe if RCU is not watching
@ 2023-03-21  2:01 Yafang Shao
  2023-03-21 14:12 ` Masami Hiramatsu
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Yafang Shao @ 2023-03-21  2:01 UTC (permalink / raw)
  To: rostedt, mhiramat, alexei.starovoitov
  Cc: linux-trace-kernel, bpf, Yafang Shao, Andrii Nakryiko, Jiri Olsa

It hits below warning on my test machine when running
selftests/bpf/test_progs,

[  702.223611] ------------[ cut here ]------------
[  702.224168] RCU not on for: preempt_count_sub+0x0/0xa0
[  702.224770] WARNING: CPU: 14 PID: 5267 at include/linux/trace_recursion.h:162 fprobe_handler.part.0+0x1b8/0x1c0
[  702.231740] CPU: 14 PID: 5267 Comm: main_amd64 Kdump: loaded Tainted: G           O       6.2.0+ #584
[  702.233169] RIP: 0010:fprobe_handler.part.0+0x1b8/0x1c0
[  702.241388] Call Trace:
[  702.241615]  <TASK>
[  702.241811]  fprobe_handler+0x22/0x30
[  702.242129]  0xffffffffc04710f7
[  702.242417] RIP: 0010:preempt_count_sub+0x5/0xa0
[  702.242809] Code: c8 50 68 94 42 0e b5 48 cf e9 f9 fd ff ff 0f 1f 80 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 e8 4b cd 38 0b <55> 8b 0d 9c d0 cf 02 48 89 e5 85 c9 75 1b 65 8b 05 be 78 f4 4a 89
[  702.244752] RSP: 0018:ffffaf6187d27f10 EFLAGS: 00000082 ORIG_RAX: 0000000000000000
[  702.245801] RAX: 000000000000000e RBX: 0000000001b6ab72 RCX: 0000000000000000
[  702.246804] RDX: 0000000000000000 RSI: ffffffffb627967d RDI: 0000000000000001
[  702.247801] RBP: ffffaf6187d27f30 R08: 0000000000000000 R09: 0000000000000000
[  702.248786] R10: 0000000000000000 R11: 0000000000000000 R12: 00000000000000ca
[  702.249782] R13: ffffaf6187d27f58 R14: 0000000000000000 R15: 0000000000000000
[  702.250785]  ? preempt_count_sub+0x5/0xa0
[  702.251540]  ? syscall_enter_from_user_mode+0x96/0xc0
[  702.252368]  ? preempt_count_sub+0x5/0xa0
[  702.253104]  ? syscall_enter_from_user_mode+0x96/0xc0
[  702.253918]  do_syscall_64+0x16/0x90
[  702.254613]  entry_SYSCALL_64_after_hwframe+0x72/0xdc
[  702.255422] RIP: 0033:0x46b793

This issue happens under CONFIG_CONTEXT_TRACKING_USER=y. When a task
enters from user mode to kernel mode, or enters from user mode to irq,
it excutes preempt_count_sub before RCU begins watching, and thus this
warning is triggered.

We should not handle fprobe if RCU is not watching.

Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <olsajiri@gmail.com>
---
 kernel/trace/fprobe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index e8143e3..fe4b248 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -27,6 +27,9 @@ static void fprobe_handler(unsigned long ip, unsigned long parent_ip,
 	struct fprobe *fp;
 	int bit;
 
+	if (!rcu_is_watching())
+		return;
+
 	fp = container_of(ops, struct fprobe, ops);
 	if (fprobe_disabled(fp))
 		return;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2023-04-12 19:05 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-21  2:01 [PATCH] tracing: Refuse fprobe if RCU is not watching Yafang Shao
2023-03-21 14:12 ` Masami Hiramatsu
2023-03-21 14:17 ` Steven Rostedt
2023-03-21 15:50   ` Peter Zijlstra
2023-03-23  5:59   ` Yafang Shao
2023-03-23 12:39     ` Steven Rostedt
2023-03-24  2:51       ` Yafang Shao
2023-03-24  3:01         ` Steven Rostedt
2023-04-09  5:32           ` Yafang Shao
2023-04-09 11:55             ` Steven Rostedt
2023-04-09 12:45               ` Yafang Shao
2023-04-09 13:54                 ` Masami Hiramatsu
2023-04-09 14:44                   ` Yafang Shao
2023-04-10  2:02                     ` Steven Rostedt
2023-04-10  5:36                       ` Yafang Shao
2023-04-10 10:30                         ` Steven Rostedt
2023-04-10 13:56                           ` Yafang Shao
2023-04-10 14:12                             ` Steven Rostedt
2023-04-10 14:20                               ` Yafang Shao
2023-04-10 21:35                                 ` Jiri Olsa
2023-04-12 14:37                                   ` Yafang Shao
2023-04-12 19:04                                     ` Jiri Olsa
2023-04-10 14:31                               ` Steven Rostedt
2023-04-12 14:30                                 ` Yafang Shao
2023-04-09 17:25                 ` Steven Rostedt
2023-04-10  4:28                   ` Yafang Shao
2023-03-21 14:43 ` Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).