Message ID | 20240403220328.455786-1-andrii@kernel.org (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | [v3,1/2] ftrace: make extra rcu_is_watching() validation check optional | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Wed, 3 Apr 2024 15:03:27 -0700 Andrii Nakryiko <andrii@kernel.org> wrote: > 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/ > This looks good to me :) Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thank you, > Cc: Steven Rostedt <rostedt@goodmis.org> > Cc: Masami Hiramatsu <mhiramat@kernel.org> > Cc: Paul E. McKenney <paulmck@kernel.org> > Signed-off-by: Andrii Nakryiko <andrii@kernel.org> > --- > include/linux/trace_recursion.h | 2 +- > kernel/trace/Kconfig | 13 +++++++++++++ > 2 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h > index d48cd92d2364..24ea8ac049b4 100644 > --- a/include/linux/trace_recursion.h > +++ b/include/linux/trace_recursion.h > @@ -135,7 +135,7 @@ extern void ftrace_record_recursion(unsigned long ip, unsigned long parent_ip); > # define do_ftrace_record_recursion(ip, pip) do { } while (0) > #endif > > -#ifdef CONFIG_ARCH_WANTS_NO_INSTR > +#ifdef CONFIG_FTRACE_VALIDATE_RCU_IS_WATCHING > # define trace_warn_on_no_rcu(ip) \ > ({ \ > bool __ret = !rcu_is_watching(); \ > diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig > index 61c541c36596..7aebd1b8f93e 100644 > --- a/kernel/trace/Kconfig > +++ b/kernel/trace/Kconfig > @@ -974,6 +974,19 @@ config FTRACE_RECORD_RECURSION_SIZE > This file can be reset, but the limit can not change in > size at runtime. > > +config FTRACE_VALIDATE_RCU_IS_WATCHING > + bool "Validate RCU is on during ftrace execution" > + depends on FUNCTION_TRACER > + depends on ARCH_WANTS_NO_INSTR > + help > + All callbacks that attach to the function tracing have some sort of > + protection against recursion. This option is only to verify that > + ftrace (and other users of ftrace_test_recursion_trylock()) are not > + called outside of RCU, as if they are, it can cause a race. But it > + also has a noticeable overhead when enabled. > + > + If unsure, say N > + > config RING_BUFFER_RECORD_RECURSION > bool "Record functions that recurse in the ring buffer" > depends on FTRACE_RECORD_RECURSION > -- > 2.43.0 >
diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h index d48cd92d2364..24ea8ac049b4 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -135,7 +135,7 @@ extern void ftrace_record_recursion(unsigned long ip, unsigned long parent_ip); # define do_ftrace_record_recursion(ip, pip) do { } while (0) #endif -#ifdef CONFIG_ARCH_WANTS_NO_INSTR +#ifdef CONFIG_FTRACE_VALIDATE_RCU_IS_WATCHING # define trace_warn_on_no_rcu(ip) \ ({ \ bool __ret = !rcu_is_watching(); \ diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig index 61c541c36596..7aebd1b8f93e 100644 --- a/kernel/trace/Kconfig +++ b/kernel/trace/Kconfig @@ -974,6 +974,19 @@ config FTRACE_RECORD_RECURSION_SIZE This file can be reset, but the limit can not change in size at runtime. +config FTRACE_VALIDATE_RCU_IS_WATCHING + bool "Validate RCU is on during ftrace execution" + depends on FUNCTION_TRACER + depends on ARCH_WANTS_NO_INSTR + help + All callbacks that attach to the function tracing have some sort of + protection against recursion. This option is only to verify that + ftrace (and other users of ftrace_test_recursion_trylock()) are not + called outside of RCU, as if they are, it can cause a race. But it + also has a noticeable overhead when enabled. + + If unsure, say N + config RING_BUFFER_RECORD_RECURSION bool "Record functions that recurse in the ring buffer" depends on FTRACE_RECORD_RECURSION
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/ Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> --- include/linux/trace_recursion.h | 2 +- kernel/trace/Kconfig | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)