Skip to content

Commit b0e28a4

Browse files
anakryikomhiramat
authored andcommitted
ftrace: make extra rcu_is_watching() validation check optional
Introduce CONFIG_FTRACE_VALIDATE_RCU_IS_WATCHING config option to control whether ftrace low-level code performs additional rcu_is_watching()-based validation logic in an attempt to catch noinstr violations. This check is expected to never be true and is mostly useful for low-level validation of ftrace subsystem invariants. For most users it should probably be kept disabled to eliminate unnecessary runtime overhead. This improves BPF multi-kretprobe (relying on ftrace and rethook infrastructure) runtime throughput by 2%, according to BPF benchmarks ([0]). [0] https://lore.kernel.org/bpf/CAEf4BzauQ2WKMjZdc9s0rBWa01BYbgwHN6aNDXQSHYia47pQ-w@mail.gmail.com/ Link: https://lore.kernel.org/all/20240418190909.704286-1-andrii@kernel.org/ Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Paul E. McKenney <paulmck@kernel.org> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent 0dc7152 commit b0e28a4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/linux/trace_recursion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ extern void ftrace_record_recursion(unsigned long ip, unsigned long parent_ip);
135135
# define do_ftrace_record_recursion(ip, pip) do { } while (0)
136136
#endif
137137

138-
#ifdef CONFIG_ARCH_WANTS_NO_INSTR
138+
#ifdef CONFIG_FTRACE_VALIDATE_RCU_IS_WATCHING
139139
# define trace_warn_on_no_rcu(ip) \
140140
({ \
141141
bool __ret = !rcu_is_watching(); \

kernel/trace/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,19 @@ config FTRACE_RECORD_RECURSION_SIZE
974974
This file can be reset, but the limit can not change in
975975
size at runtime.
976976

977+
config FTRACE_VALIDATE_RCU_IS_WATCHING
978+
bool "Validate RCU is on during ftrace execution"
979+
depends on FUNCTION_TRACER
980+
depends on ARCH_WANTS_NO_INSTR
981+
help
982+
All callbacks that attach to the function tracing have some sort of
983+
protection against recursion. This option is only to verify that
984+
ftrace (and other users of ftrace_test_recursion_trylock()) are not
985+
called outside of RCU, as if they are, it can cause a race. But it
986+
also has a noticeable overhead when enabled.
987+
988+
If unsure, say N
989+
977990
config RING_BUFFER_RECORD_RECURSION
978991
bool "Record functions that recurse in the ring buffer"
979992
depends on FTRACE_RECORD_RECURSION

0 commit comments

Comments
 (0)