kprobes: Suppress the suspicious RCU warning on kprobes
authorMasami Hiramatsu <mhiramat@kernel.org>
Tue, 12 May 2020 08:02:33 +0000 (17:02 +0900)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 17 Jun 2020 01:21:01 +0000 (21:21 -0400)
commit6743ad432ec92e680cd0d9db86cb17b949cf5a43
treeaba82276d117d68f61e22d309199040cc889454d
parent4ef57b21d6fb49d2b25c47e4cff467a0c2c8b6b7
kprobes: Suppress the suspicious RCU warning on kprobes

Anders reported that the lockdep warns that suspicious
RCU list usage in register_kprobe() (detected by
CONFIG_PROVE_RCU_LIST.) This is because get_kprobe()
access kprobe_table[] by hlist_for_each_entry_rcu()
without rcu_read_lock.

If we call get_kprobe() from the breakpoint handler context,
it is run with preempt disabled, so this is not a problem.
But in other cases, instead of rcu_read_lock(), we locks
kprobe_mutex so that the kprobe_table[] is not updated.
So, current code is safe, but still not good from the view
point of RCU.

Joel suggested that we can silent that warning by passing
lockdep_is_held() to the last argument of
hlist_for_each_entry_rcu().

Add lockdep_is_held(&kprobe_mutex) at the end of the
hlist_for_each_entry_rcu() to suppress the warning.

Link: http://lkml.kernel.org/r/158927055350.27680.10261450713467997503.stgit@devnote2
Reported-by: Anders Roxell <anders.roxell@linaro.org>
Suggested-by: Joel Fernandes <joel@joelfernandes.org>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
kernel/kprobes.c