[PATCH 0/6] Switch __DECLARE_TRACE() to new notrace variant of SRCU-fast

Paul E. McKenney posted 6 patches 2 months, 2 weeks ago
There is a newer version of this series
b/include/linux/srcu.h       |    4 +++
b/include/linux/srcutree.h   |    2 -
b/include/linux/tracepoint.h |    6 +++--
b/kernel/rcu/srcutree.c      |   10 +++++++++
b/kernel/tracepoint.c        |   21 ++++++++++++++++++-
include/linux/srcu.h         |   35 ++++++++++++++++++++++++++++++--
include/linux/srcutree.h     |   47 +++++++++++++++++++++++++++----------------
7 files changed, 101 insertions(+), 24 deletions(-)
[PATCH 0/6] Switch __DECLARE_TRACE() to new notrace variant of SRCU-fast
Posted by Paul E. McKenney 2 months, 2 weeks ago
Hello!

This is version 4 of a patch series creating a new notrace variant of
SRCU-fast and introducing it to the __DECLARE_TRACE() in place of the
current preemption disabling.  This change enable preemption of BPF
programs attached to tracepoints, as is required for runtime use of BPF
in real-time systems.

This triggers continues to trigger a kernel test robot report of a
"using smp_processor_id() in preemptible" splat.  I looked for issues
with explicit preemption disabling, and, not finding any, will next turn
my attention to accesses to per-CPU variables.  Any and all insights
are welcome.

1.	Move rcu_is_watching() checks to srcu_read_{,un}lock_fast().

2.	Add srcu_read_lock_fast_notrace() and
	srcu_read_unlock_fast_notrace().

3.	Add guards for notrace variants of SRCU-fast readers.

4.	Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast.

5.	Document __srcu_read_{,un}lock_fast() implicit RCU readers.

6.	Document srcu_flip() memory-barrier D relation to SRCU-fast.

Changes since v3:

o	Add "notrace" per Joel, Steven, and Matthew feedback.

o	Upgrade explanatory comments and add new ones per Joel feedback.

	https://lore.kernel.org/all/20250721162433.10454-1-paulmck@kernel.org/

Changes since v2:

o	Posting standalone as opposed to a reply.

	https://lore.kernel.org/all/3cecf6c9-b2ee-4f34-9d1b-ca4cfb8e56a7@paulmck-laptop/

Changes since RFC version:

o	RFC patch 6/4 has been pulled into the shared RCU tree:
	e88c632a8698 ("srcu: Add guards for SRCU-fast readers")

o	RFC patch 5/4 (which removed the now-unnecessary special boot-time
	avoidance of SRCU) has been folded into patch 4/4 shown above,
	as suggested by Steven Rostedt.

	https://lore.kernel.org/all/bb20a575-235b-499e-aa1d-70fe9e2c7617@paulmck-laptop/

						Thanx, Paul

------------------------------------------------------------------------

 b/include/linux/srcu.h       |    4 +++
 b/include/linux/srcutree.h   |    2 -
 b/include/linux/tracepoint.h |    6 +++--
 b/kernel/rcu/srcutree.c      |   10 +++++++++
 b/kernel/tracepoint.c        |   21 ++++++++++++++++++-
 include/linux/srcu.h         |   35 ++++++++++++++++++++++++++++++--
 include/linux/srcutree.h     |   47 +++++++++++++++++++++++++++----------------
 7 files changed, 101 insertions(+), 24 deletions(-)
Re: [PATCH 0/6] Switch __DECLARE_TRACE() to new notrace variant of SRCU-fast
Posted by Steven Rostedt 2 months, 2 weeks ago
On Wed, 23 Jul 2025 13:27:54 -0700
"Paul E. McKenney" <paulmck@kernel.org> wrote:

> This triggers continues to trigger a kernel test robot report of a
> "using smp_processor_id() in preemptible" splat.  I looked for issues
> with explicit preemption disabling, and, not finding any, will next turn
> my attention to accesses to per-CPU variables.  Any and all insights
> are welcome.

Currently perf and ftrace expect the tracepoints to be called with
preemption disabled. You may need this:

diff --git a/include/trace/perf.h b/include/trace/perf.h
index a1754b73a8f5..1b7925a85966 100644
--- a/include/trace/perf.h
+++ b/include/trace/perf.h
@@ -71,7 +71,9 @@ perf_trace_##call(void *__data, proto)					\
 	u64 __count __attribute__((unused));				\
 	struct task_struct *__task __attribute__((unused));		\
 									\
+	preempt_disable_notrace();					\
 	do_perf_trace_##call(__data, args);				\
+	preempt_enable_notrace();					\
 }
 
 #undef DECLARE_EVENT_SYSCALL_CLASS
diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index 4f22136fd465..0504a423ca25 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -436,7 +436,9 @@ __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
 static notrace void							\
 trace_event_raw_event_##call(void *__data, proto)			\
 {									\
+	preempt_disable_notrace();					\
 	do_trace_event_raw_event_##call(__data, args);			\
+	preempt_enable_notrace();					\
 }
 
 #undef DECLARE_EVENT_SYSCALL_CLASS


But please add it with the change, as there's "preempt_count" accounting to
report to the user that accounts that preemption was disabled when called.

-- Steve
Re: [PATCH 0/6] Switch __DECLARE_TRACE() to new notrace variant of SRCU-fast
Posted by Paul E. McKenney 2 months, 2 weeks ago
On Wed, Jul 23, 2025 at 04:34:50PM -0400, Steven Rostedt wrote:
> On Wed, 23 Jul 2025 13:27:54 -0700
> "Paul E. McKenney" <paulmck@kernel.org> wrote:
> 
> > This triggers continues to trigger a kernel test robot report of a
> > "using smp_processor_id() in preemptible" splat.  I looked for issues
> > with explicit preemption disabling, and, not finding any, will next turn
> > my attention to accesses to per-CPU variables.  Any and all insights
> > are welcome.
> 
> Currently perf and ftrace expect the tracepoints to be called with
> preemption disabled. You may need this:
> 
> diff --git a/include/trace/perf.h b/include/trace/perf.h
> index a1754b73a8f5..1b7925a85966 100644
> --- a/include/trace/perf.h
> +++ b/include/trace/perf.h
> @@ -71,7 +71,9 @@ perf_trace_##call(void *__data, proto)					\
>  	u64 __count __attribute__((unused));				\
>  	struct task_struct *__task __attribute__((unused));		\
>  									\
> +	preempt_disable_notrace();					\
>  	do_perf_trace_##call(__data, args);				\
> +	preempt_enable_notrace();					\
>  }
>  
>  #undef DECLARE_EVENT_SYSCALL_CLASS
> diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
> index 4f22136fd465..0504a423ca25 100644
> --- a/include/trace/trace_events.h
> +++ b/include/trace/trace_events.h
> @@ -436,7 +436,9 @@ __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
>  static notrace void							\
>  trace_event_raw_event_##call(void *__data, proto)			\
>  {									\
> +	preempt_disable_notrace();					\
>  	do_trace_event_raw_event_##call(__data, args);			\
> +	preempt_enable_notrace();					\
>  }
>  
>  #undef DECLARE_EVENT_SYSCALL_CLASS
> 
> 
> But please add it with the change, as there's "preempt_count" accounting to
> report to the user that accounts that preemption was disabled when called.

Thank you, Steve!  I suspect that it would have taken me one good long
time to find that one, like maybe forever.  ;-)

I am doing local testing, then will expose it to the kernel test robot,
and if all goes well, fold it in with attribution.

							Thanx, Paul