Next-level bug in SRCU implementation of RCU Tasks Trace + PREEMPT_RT
Subsystems (6)
Paul E. McKenney
maintainerHello!
Kumar Kartikeya Dwivedi (CCed) privately reported a bug in my implementation of the RCU Tasks Trace API in terms of SRCU-fast. You see, I forgot to ask what contexts call_rcu_tasks_trace() is called from, and it turns out that it can in fact be called with the scheduler pi/rq locks held. This results in a deadlock when SRCU-fast invokes the scheduler in order to start the SRCU-fast grace period. So RCU needs a fix to my fix found here:
b540c63cf6e5 ("srcu: Use raw spinlocks so call_srcu() can be used under preempt_disable()")
Sebastian, the PREEMPT_RT aspect is that lockdep does not complain about acquisition of non-raw spinlocks from preemption-disabled regions of code. This might be intentional, for example, there might be large bodies of Linux-kernel code that frequently acquire non-raw spinlocks from preemption-disabled regions of code, but which are never part of PREEMPT_RT kernels. Otherwise, it might be good for lockdep to diagnose this sort of thing.
Back to the actual bug, that call_srcu() now needs to tolerate being called with scheduler rq/pi locks held...
The straightforward (but perhaps broken) way to resolve this is to make srcu_gp_start_if_needed() defer invoking the scheduler, similar to the way that vanilla RCU's call_rcu_core() function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.
In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Thanx, Paul [2]
[1] The exceptions to this rule being handled by the call to invoke_rcu_core() when rcu_is_watching() returns false.
[2] Ah, and should vanilla RCU's call_rcu() be invokable from NMI handlers? Or should there be a call_rcu_nmi() for this purpose? Or should we continue to have its callers check in_nmi() when needed?
Quoted 1 line · Paul E. McKenney
Hello!
Hi,
Quoted 9 lines
Kumar Kartikeya Dwivedi (CCed) privately reported a bug in my implementation of the RCU Tasks Trace API in terms of SRCU-fast. You see, I forgot to ask what contexts
call_rcu_tasks_trace()is called from, and it turns out that it can in fact be called with the scheduler pi/rq locks held. This results in a deadlock when SRCU-fast invokes the scheduler in order to start the SRCU-fast grace period. So RCU needs a fix to my fix found here:
b540c63cf6e5("srcu: Use raw spinlocks socall_srcu()can be used underpreempt_disable()")
I can't find it. I looked in next and the rcu tree.
Quoted 7 lines
Sebastian, the
PREEMPT_RTaspect is that lockdep does not complain about acquisition of non-raw spinlocks from preemption-disabled regions of code. This might be intentional, for example, there might be large bodies of Linux-kernel code that frequently acquire non-raw spinlocks from preemption-disabled regions of code, but which are never part ofPREEMPT_RTkernels. Otherwise, it might be good for lockdep to diagnose this sort of thing.
The point is you don't know where this preempt_disable() is coming from on !RT. It might be part of spinlock_t it might be explicit. We only have the might_sleep() on PREEMPT_RT.
To catch this we would have to iterate over all held locks, compare the expected preemption level with the current and account for possible corner cases such as in-IRQ will be one higher and so on…
However, if you hold a raw_spinlock_t (such as rq/pi) then are asking for a spinlock_t lockdep should respond with a
| BUG: Invalid wait context
report.
Quoted 2 lines
Back to the actual bug, that
call_srcu()now needs to tolerate being called with scheduler rq/pi locks held...
This is because it is called from sched_ext BPF callbacks?
Quoted 2 lines
The straightforward (but perhaps broken) way to resolve this is to make
srcu_gp_start_if_needed()defer invoking the scheduler, similar to the
Quick question. If srcu_gp_start_if_needed() can be invoked from a preempt-disabled section (due to rq/pi lock) then
spin_lock_irqsave_sdp_contention(sdp, &flags);
does not work, right?
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 9 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?
Did someone ask for this?
Sebastian
Paul E. McKenney
maintainerQuoted 12 lines · Sebastian Andrzej Siewior
Quoted 1 line · Paul E. McKenney
Hello!
Hi,
Quoted 8 lines
Kumar Kartikeya Dwivedi (CCed) privately reported a bug in my implementation of the RCU Tasks Trace API in terms of SRCU-fast. You see, I forgot to ask what contexts
call_rcu_tasks_trace()is called from, and it turns out that it can in fact be called with the scheduler pi/rq locks held. This results in a deadlock when SRCU-fast invokes the scheduler in order to start the SRCU-fast grace period. So RCU needs a fix to my fix found here:
Quoted 3 lines
Quoted 1 line
b540c63cf6e5("srcu: Use raw spinlocks socall_srcu()can be used underpreempt_disable()")I can't find it. I looked in next and the rcu tree.
Ah, it is in my RCU tree, not in the shared one. The patch is at the end of this email.
Quoted 15 lines
Quoted 7 lines
Sebastian, the
PREEMPT_RTaspect is that lockdep does not complain about acquisition of non-raw spinlocks from preemption-disabled regions of code. This might be intentional, for example, there might be large bodies of Linux-kernel code that frequently acquire non-raw spinlocks from preemption-disabled regions of code, but which are never part ofPREEMPT_RTkernels. Otherwise, it might be good for lockdep to diagnose this sort of thing.The point is you don't know where this
preempt_disable()is coming from on !RT. It might be part ofspinlock_tit might be explicit. We only have themight_sleep()onPREEMPT_RT.
To catch this we would have to iterate over all held locks, compare the expected preemption level with the current and account for possible corner cases such as in-IRQ will be one higher and so on…
Quoted 5 lines
However, if you hold a
raw_spinlock_t(such as rq/pi) then are asking for aspinlock_tlockdep should respond with a
| BUG: Invalid wait contextreport.
Got it, and thank you for the explanation.
Quoted 4 lines
Quoted 2 lines
Back to the actual bug, that
call_srcu()now needs to tolerate being called with scheduler rq/pi locks held...This is because it is called from
sched_extBPF callbacks?
You got it! We are re-implementing Tasks Trace RCU in terms of SRCU-fast, and I missed this requirement the first time around. I *did* make readers able to deal with BPF being invoked from everywhere, so two out of three?
Quoted 8 lines
Quoted 2 lines
The straightforward (but perhaps broken) way to resolve this is to make
srcu_gp_start_if_needed()defer invoking the scheduler, similar to theQuick question. If
srcu_gp_start_if_needed()can be invoked from a preempt-disabled section (due to rq/pi lock) thenspin_lock_irqsave_sdp_contention(sdp, &flags);does not work, right?
Agreed, which is why the patch at the end of this email converts this to:
raw_spin_lock_irqsave_sdp_contention(sdp, &flags)
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
Quoted 10 lines
Quoted 8 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?Did someone ask for this?
Yes. The BPF guys need to invoke call_srcu() from interrupts-disabled regions of code. I am way to old and lazy to do this sort of thing spontaneously. ;-)
Thanx, Paul
------------------------------------------------------------------------
commit b540c63cf6e500e2f81d20b5de6ea11df8b7d22e
Author: Paul E. McKenney <[email protected]> Date: Sat Mar 14 04:12:58 2026 -0700
srcu: Use raw spinlocks so call_srcu() can be used under preempt_disable()
Tree SRCU has used non-raw spinlocks for many years, motivated by a desire to avoid unnecessary real-time latency and the absence of any reason to use raw spinlocks. However, the recent use of SRCU in tracing as the underlying implementation of RCU Tasks Trace means that call_srcu() is invoked from preemption-disabled regions of code, which in turn requires that any locks acquired by call_srcu() or its callees must be raw spinlocks.
This commit therefore converts SRCU's spinlocks to raw spinlocks.
include/linux/srcutree.h +4 -4
@@ -34,7 +34,7 @@ struct srcu_data {/* Values: SRCU_READ_FLAVOR_.* */ /* Update-side state. */ -spinlock_t __private lock____cacheline_internodealigned_in_smp ; +raw_spinlock_t __private lock____cacheline_internodealigned_in_smp ;struct rcu_segcblist srcu_cblist;/* List of callbacks.*/ unsigned long srcu_gp_seq_needed;/* Furthest future GP needed. */ unsigned long srcu_gp_seq_needed_exp;/* Furthest future exp GP. */
@@ -55,7 +55,7 @@ struct srcu_data {* Node in SRCU combining tree, similar in function to rcu_data. */ struct srcu_node { -spinlock_t __private lock; +raw_spinlock_t __private lock;unsigned long srcu_have_cbs[4 ];/* GP seq for children having CBs, but only */ /* if greater than ->srcu_gp_seq. */ unsigned long srcu_data_have_cbs[4 ];/* Which srcu_data structs have CBs for given GP? */
@@ -74,7 +74,7 @@ struct srcu_usage {/* First node at each level. */ int srcu_size_state;/* Small-to-big transition state. */ struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ -spinlock_t __private lock;/* Protect counters and size state. */ +raw_spinlock_t __private lock;/* Protect counters and size state. */ struct mutex srcu_gp_mutex;/* Serialize GP work. */ unsigned long srcu_gp_seq;/* Grace-period seq #. */ unsigned long srcu_gp_seq_needed;/* Latest gp_seq needed. */
@@ -156,7 +156,7 @@ struct srcu_struct {#define __SRCU_USAGE_INIT (name) \ { \ - .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ + .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ .srcu_gp_seq = SRCU_GP_SEQ_INITIAL_VAL, \ .srcu_gp_seq_needed = SRCU_GP_SEQ_INITIAL_VAL_WITH_STATE, \ .srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL, \
kernel/rcu/rcu.h +9 -0
@@ -502,6 +502,15 @@ do { \ ___locked; \ }) +#define raw_spin_trylock_irqsave_rcu_node (p, flags) \ +({ \ + bool ___locked = raw_spin_trylock_irqsave(&ACCESS_PRIVATE(p, lock), flags); \ + \ + if (___locked) \ + smp_mb__after_unlock_lock(); \ + ___locked; \ +}) +#define raw_lockdep_assert_held_rcu_node (p) \ lockdep_assert_held(&ACCESS_PRIVATE(p, lock))
kernel/rcu/srcutree.c +69 -105
472 lines not on this page · raw message
Quoted 8 lines · Paul E. McKenney
Quoted 4 lines
Quoted 2 lines
Back to the actual bug, that
call_srcu()now needs to tolerate being called with scheduler rq/pi locks held...This is because it is called from
sched_extBPF callbacks?You got it! We are re-implementing Tasks Trace RCU in terms of SRCU-fast, and I missed this requirement the first time around. I *did* make readers able to deal with BPF being invoked from everywhere, so two out of three?
right ;)
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
The straightforward (but perhaps broken) way to resolve this is to make
srcu_gp_start_if_needed()defer invoking the scheduler, similar to theQuick question. If
srcu_gp_start_if_needed()can be invoked from a preempt-disabled section (due to rq/pi lock) thenspin_lock_irqsave_sdp_contention(sdp, &flags);
Quoted 5 lines
Quoted 1 line
does not work, right?
Agreed, which is why the patch at the end of this email converts this to:
raw_spin_lock_irqsave_sdp_contention(sdp, &flags)
I've seen that now. So the spinlock_t usage in SRCU was short.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is just srcu_funnel_gp_start(). If its srcu_schedule_cbs_sdp() / queue_delayed_work() usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Thinking about it further, you don't need to worry about local_bh_disable() but RCU will becomes another corner case. You would have to exclude "rcu_read_lock(); spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?
Quoted 5 lines
Quoted 1 line
Did someone ask for this?
Yes. The BPF guys need to invoke
call_srcu()from interrupts-disabled regions of code. I am way to old and lazy to do this sort of thing spontaneously. ;-)
IRQ disabled should work but you asked about call_rcu_nmi() and NMI is already complicated because "most" other things don't work and you would need irq_work to let the remaining kernel know that you did something in NMI and this needs to be integrated now. I don't think regular RCU has call_rcu() from NMI. But I guess wrapping it via irq_work would be one way of dealing with it.
Quoted 2 lines
Thanx, Paul
Sebastian
Paul E. McKenney
maintainerQuoted 19 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Paul E. McKenney
Quoted 4 lines
Quoted 2 lines
Back to the actual bug, that
call_srcu()now needs to tolerate being called with scheduler rq/pi locks held...This is because it is called from
sched_extBPF callbacks?You got it! We are re-implementing Tasks Trace RCU in terms of SRCU-fast, and I missed this requirement the first time around. I *did* make readers able to deal with BPF being invoked from everywhere, so two out of three?
right ;)
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
The straightforward (but perhaps broken) way to resolve this is to make
srcu_gp_start_if_needed()defer invoking the scheduler, similar to theQuick question. If
srcu_gp_start_if_needed()can be invoked from a preempt-disabled section (due to rq/pi lock) thenspin_lock_irqsave_sdp_contention(sdp, &flags);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
does not work, right?
Agreed, which is why the patch at the end of this email converts this to:
raw_spin_lock_irqsave_sdp_contention(sdp, &flags)I've seen that now. So the
spinlock_tusage in SRCU was short.
Almost ten years. ;-)
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?
Right, that patch fixes one lockdep problem, but another remains.
Quoted 12 lines
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Quoted 6 lines
Thinking about it further, you don't need to worry about
local_bh_disable()but RCU will becomes another corner case. You would have to exclude "rcu_read_lock();spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.
With a raw spinlock held, agreed.
Not a big deal, just working out what to put in rcutorture to avoid regressions that would otherwise result in being unable to invoke call_srcu() from non-preemptible contexts.
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?Quoted 5 lines
Quoted 1 line
Did someone ask for this?
Yes. The BPF guys need to invoke
call_srcu()from interrupts-disabled regions of code. I am way to old and lazy to do this sort of thing spontaneously. ;-)
Quoted 6 lines
IRQ disabled should work but you asked about
call_rcu_nmi()and NMI is already complicated because "most" other things don't work and you would needirq_workto let the remaining kernel know that you did something in NMI and this needs to be integrated now. I don't think regular RCU hascall_rcu()from NMI. But I guess wrapping it viairq_workwould be one way of dealing with it.
Agreed, and as long as there is only a few call_rcu() call sites within NMI handlers, it is best to let the caller deal with it. But if this becomes popular enough, it would be better to have a call_rcu_nmi() or some such.
Thanx, Paul
Quoted 8 lines · Paul E. McKenney
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Right, that patch fixes one lockdep problem, but another remains.
What remains?
Quoted 19 lines
Quoted 12 lines
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Quoted 6 lines
Thinking about it further, you don't need to worry about
local_bh_disable()but RCU will becomes another corner case. You would have to exclude "rcu_read_lock();spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.
Quoted 5 lines
With a raw spinlock held, agreed.
Not a big deal, just working out what to put in rcutorture to avoid regressions that would otherwise result in being unable to invoke
call_srcu()from non-preemptible contexts.
Okay. So take this as _no_ more work items ;)
Quoted 22 lines
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?Quoted 5 lines
Quoted 1 line
Did someone ask for this?
Yes. The BPF guys need to invoke
call_srcu()from interrupts-disabled regions of code. I am way to old and lazy to do this sort of thing spontaneously. ;-)Quoted 6 lines
IRQ disabled should work but you asked about
call_rcu_nmi()and NMI is already complicated because "most" other things don't work and you would needirq_workto let the remaining kernel know that you did something in NMI and this needs to be integrated now. I don't think regular RCU hascall_rcu()from NMI. But I guess wrapping it viairq_workwould be one way of dealing with it.
Quoted 4 lines
Agreed, and as long as there is only a few
call_rcu()call sites within NMI handlers, it is best to let the caller deal with it. But if this becomes popular enough, it would be better to have acall_rcu_nmi()or some such.
Popular? Okay. Keep me posted, please.
Quoted 1 line
Thanx, Paul
Sebastian
Paul E. McKenney
maintainerQuoted 11 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Paul E. McKenney
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Right, that patch fixes one lockdep problem, but another remains.
What remains?
With that patch, we no longer have call_srcu() directly acquiring a non-raw spinlock, but as you say, we still have the wakeup problem.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Thinking about it further, you don't need to worry about
local_bh_disable()but RCU will becomes another corner case. You would have to exclude "rcu_read_lock();spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.
Quoted 7 lines
Quoted 5 lines
With a raw spinlock held, agreed.
Not a big deal, just working out what to put in rcutorture to avoid regressions that would otherwise result in being unable to invoke
call_srcu()from non-preemptible contexts.Okay. So take this as _no_ more work items ;)
I agree that the rcutorture can wait until the next merge window.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Thanx, Paul [2][1] The exceptions to this rule being handled by the call to
invoke_rcu_core()whenrcu_is_watching()returns false.[2] Ah, and should vanilla RCU's
call_rcu()be invokable from NMI handlers? Or should there be acall_rcu_nmi()for this purpose? Or should we continue to have its callers checkin_nmi()when needed?Quoted 5 lines
Quoted 1 line
Did someone ask for this?
Yes. The BPF guys need to invoke
call_srcu()from interrupts-disabled regions of code. I am way to old and lazy to do this sort of thing spontaneously. ;-)IRQ disabled should work but you asked about
call_rcu_nmi()and NMI is already complicated because "most" other things don't work and you would needirq_workto let the remaining kernel know that you did something in NMI and this needs to be integrated now. I don't think regular RCU hascall_rcu()from NMI. But I guess wrapping it viairq_workwould be one way of dealing with it.
Quoted 6 lines
Quoted 4 lines
Agreed, and as long as there is only a few
call_rcu()call sites within NMI handlers, it is best to let the caller deal with it. But if this becomes popular enough, it would be better to have acall_rcu_nmi()or some such.Popular? Okay. Keep me posted, please.
Will do. Just out of curiosity, what are your concerns?
Thanx, Paul
Boqun Feng
maintainerQuoted 9 lines · Paul E. McKenney
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Paul E. McKenney
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Right, that patch fixes one lockdep problem, but another remains.
What remains?
With that patch, we no longer have
call_srcu()directly acquiring a non-raw spinlock, but as you say, we still have the wakeup problem.
I don't think we have a wakeup problem since we use workqueue to defer the wakeup, but maybe I'm missing something here?
Regards,
Boqun
Paul E. McKenney
maintainerQuoted 12 lines · Boqun Feng
Quoted 11 lines · Paul E. McKenney
Quoted 10 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Paul E. McKenney
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Right, that patch fixes one lockdep problem, but another remains.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
What remains?
With that patch, we no longer have
call_srcu()directly acquiring a non-raw spinlock, but as you say, we still have the wakeup problem.I don't think we have a wakeup problem since we use workqueue to defer the wakeup, but maybe I'm missing something here?
You are right, I was confused. We instead have a deadlock problem.
Thanx, Paul
Quoted 4 lines · Paul E. McKenney
Quoted 1 line
What remains?
With that patch, we no longer have
call_srcu()directly acquiring a non-raw spinlock, but as you say, we still have the wakeup problem.
Isn't this is just srcu_funnel_gp_start()? And where you could ensure that it is always a delayed worked (delay always 1+) that is scheduled so that it always setups a timer and never does a direct wake.
Quoted 3 lines
Quoted 1 line
Popular? Okay. Keep me posted, please.
Will do. Just out of curiosity, what are your concerns?
We don't have many NMI code paths and the possibilities are quite dense. I would imagine having this possibility would lead to things that wouldn't be needed otherwise. I mean we don't even allow allocating memory from hardirq (except for _nolock() variant which I think is used by bpf for $reasons) but need to call rcu_free from NMI. This would require to remove an item from some kind of data structure without regular locking. Unless RCU is used to get a delayed invocation of some sorts.
I mean I am curious here who needs it any why ;)
Quoted 1 line
Thanx, Paul
Sebastian
Paul E. McKenney
maintainerQuoted 14 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Paul E. McKenney
Quoted 1 line
What remains?
With that patch, we no longer have
call_srcu()directly acquiring a non-raw spinlock, but as you say, we still have the wakeup problem.Isn't this is just
srcu_funnel_gp_start()? And where you could ensure that it is always a delayed worked (delay always 1+) that is scheduled so that it always setups a timer and never does a direct wake.Quoted 3 lines
Quoted 1 line
Popular? Okay. Keep me posted, please.
Will do. Just out of curiosity, what are your concerns?
Quoted 8 lines
We don't have many NMI code paths and the possibilities are quite dense. I would imagine having this possibility would lead to things that wouldn't be needed otherwise. I mean we don't even allow allocating memory from hardirq (except for
_nolock()variant which I think is used by bpf for $reasons) but need to callrcu_freefrom NMI. This would require to remove an item from some kind of data structure without regular locking. Unless RCU is used to get a delayed invocation of some sorts.
We would need a lockless enqueue, which we have in llist.h.
The irq-work to actually do the call_rcu() or similar.
There would also need to be rcu_barrier() changes, for example, to drain all the llists.
Quoted 1 line
I mean I am curious here who needs it any why ;)
You got it right above, BPF. ;-)
They currently check in_nmi() and to the irq-work step themselves.
Thanx, Paul
Quoted 1 line · Paul E. McKenney
We would need a lockless enqueue, which we have in
llist.h.
Only if CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. Otherwise you must not provide call_rcu_nmi().
Quoted 1 line
The irq-work to actually do the
call_rcu()or similar.
reasonable.
Quoted 8 lines
There would also need to be
rcu_barrier()changes, for example, to drain all the llists.Quoted 1 line
I mean I am curious here who needs it any why ;)
You got it right above, BPF. ;-)
They currently check
in_nmi()and to the irq-work step themselves.
Then it would make sense since you do actually have users.
Quoted 1 line
Thanx, Paul
Sebastian
Paul E. McKenney
maintainerQuoted 5 lines · Sebastian Andrzej Siewior
Quoted 1 line · Paul E. McKenney
We would need a lockless enqueue, which we have in
llist.h.Only if
CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. Otherwise you must not providecall_rcu_nmi().
I *think* that BPF is provided only in such architectures, so agreed.
Quoted 7 lines
Quoted 1 line
The irq-work to actually do the
call_rcu()or similar.reasonable.
Quoted 3 lines
There would also need to be
rcu_barrier()changes, for example, to drain all the llists.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I mean I am curious here who needs it any why ;)
You got it right above, BPF. ;-)
They currently check
in_nmi()and to the irq-work step themselves.Then it would make sense since you do actually have users.
For more fun, they would like to attach BPF programs to call_rcu() and call_srcu() internals, which would require a per-task recursion check. Or perhaps some other trick.
Thanx, Paul
Paul E. McKenney
maintainerQuoted 8 lines · Paul E. McKenney
Quoted 5 lines · Sebastian Andrzej Siewior
Quoted 1 line · Paul E. McKenney
We would need a lockless enqueue, which we have in
llist.h.Only if
CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. Otherwise you must not providecall_rcu_nmi().I *think* that BPF is provided only in such architectures, so agreed.
Plus srcu_read_lock_fast() uses atomic_long_inc(), which is supposed to be NMI-safe anyway, correct?
Thanx, Paul
Quoted 20 lines
Quoted 7 lines
Quoted 1 line
The irq-work to actually do the
call_rcu()or similar.reasonable.
Quoted 3 lines
There would also need to be
rcu_barrier()changes, for example, to drain all the llists.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I mean I am curious here who needs it any why ;)
You got it right above, BPF. ;-)
They currently check
in_nmi()and to the irq-work step themselves.Then it would make sense since you do actually have users.
For more fun, they would like to attach BPF programs to
call_rcu()andcall_srcu()internals, which would require a per-task recursion check. Or perhaps some other trick.Thanx, Paul
Quoted 5 lines · Paul E. McKenney
Quoted 4 lines · Paul E. McKenney
Quoted 3 lines · Sebastian Andrzej Siewior
Quoted 1 line · Paul E. McKenney
We would need a lockless enqueue, which we have in
llist.h.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Only if
CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. Otherwise you must not providecall_rcu_nmi().I *think* that BPF is provided only in such architectures, so agreed.
Plus
srcu_read_lock_fast()usesatomic_long_inc(), which is supposed to be NMI-safe anyway, correct?
I am not aware of any NMI restrictions for the atomic ops, just cmpxchg.
Quoted 1 line
Thanx, Paul
Sebastian
Boqun Feng
maintainerOn Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 7 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?
Late to the party, so just make sure I understand the problem. The problem is the wakeup in call_srcu() when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.
(but Paul, we are not talking about calling call_srcu(), that requires some more work to get it work)
Quoted 12 lines
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Quoted 7 lines
Thinking about it further, you don't need to worry about
local_bh_disable()but RCU will becomes another corner case. You would have to exclude "rcu_read_lock();spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.
Right, otherwise there is a lockdep bug ;-)
Regards,
Boqun
Paul E. McKenney
maintainerQuoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?
Quoted 4 lines
Late to the party, so just make sure I understand the problem. The problem is the wakeup in
call_srcu()when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.
The issue is that call_rcu_tasks() (which is call_srcu() now) is also invoked with a scheduler pi/rq lock held, which results in a deadlock cycle. So the srcu_gp_start_if_needed() function's call to raw_spin_lock_irqsave_sdp_contention() must be deferred to the workqueue handler, not just the wake-up. And that in turn means that the callback point also needs to be passed to this handler.
See this email thread:
https://lore.kernel.org/all/CAP01T75eKpvw+95NqNWg9P-1+kzVzojpN0NLat+28SF1B9wQQQ@mail.gmail.com/
Quoted 2 lines
(but Paul, we are not talking about calling
call_srcu(), that requires some more work to get it work)
Agreed, splitting srcu_gp_start_if_needed() and using a workqueue if interrupts were already disabled on entry. Otherwise, directly invoking the split-out portion of srcu_gp_start_if_needed().
But we might be talking past each other.
Thanx, Paul
Quoted 23 lines
Quoted 12 lines
Quoted 8 lines
It would be nice, but your point about needing to worry about spinlocks is compelling.
But couldn't lockdep scan the current task's list of held locks and see whether only raw spinlocks are held (including when no spinlocks of any type are held), and complain in that case? Or would that scanning be too high of overhead? (But we need that scan anyway to check deadlock, don't we?)
PeterZ didn't like it and the nesting thing identified most of the problem cases. It should also catch _this_ one.
Quoted 6 lines
Thinking about it further, you don't need to worry about
local_bh_disable()but RCU will becomes another corner case. You would have to exclude "rcu_read_lock();spin_lock();" on a !preempt kernel which would otherwise lead to false positives.
But as I said, this case as explained is a nesting problem and should be reported by lockdep with its current features.Right, otherwise there is a lockdep bug ;-)
Regards,
Boqun
Joel Fernandes
maintainerQuoted 46 lines · Paul E. McKenney
Quoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Quoted 4 lines
Late to the party, so just make sure I understand the problem. The problem is the wakeup in
call_srcu()when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.The issue is that
call_rcu_tasks()(which iscall_srcu()now) is also invoked with a scheduler pi/rq lock held, which results in a deadlock cycle. So thesrcu_gp_start_if_needed()function's call toraw_spin_lock_irqsave_sdp_contention()must be deferred to the workqueue handler, not just the wake-up. And that in turn means that the callback point also needs to be passed to this handler.See this email thread:
https://lore.kernel.org/all/CAP01T75eKpvw+95NqNWg9P-1+kzVzojpN0NLat+28SF1B9wQQQ@mail.gmail.com/
Quoted 9 lines
Quoted 2 lines
(but Paul, we are not talking about calling
call_srcu(), that requires some more work to get it work)Agreed, splitting
srcu_gp_start_if_needed()and using a workqueue if interrupts were already disabled on entry. Otherwise, directly invoking the split-out portion ofsrcu_gp_start_if_needed().But we might be talking past each other.
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling call_srcu API with scheduler locks held.
Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent call_srcu)
---------------------------- ------------------------------------
[1] holds &rq->__lock
[2]
-> call_srcu
-> srcu_gp_start_if_needed
-> srcu_funnel_gp_start
-> spin_lock_irqsave_ssp_content...
-> holds srcu locks [4] calls call_rcu_tasks_trace() [5] srcu_funnel_gp_start (cont..)
-> queue_delayed_work
-> call_srcu() -> __queue_work()
-> srcu_gp_start_if_needed() -> wake_up_worker()
-> srcu_funnel_gp_start() -> try_to_wake_up()
-> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock
-> WANTS srcu locksIf I understand this, this looks like an issue that can happen independent of the conversion of the spin locks.
thanks,
Signature · 1 line
Joel Fernandes
Kumar Kartikeya Dwivedi
maintainerQuoted 82 lines · Joel Fernandes
Quoted 46 lines · Paul E. McKenney
Quoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Quoted 4 lines
Late to the party, so just make sure I understand the problem. The problem is the wakeup in
call_srcu()when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.The issue is that
call_rcu_tasks()(which iscall_srcu()now) is also invoked with a scheduler pi/rq lock held, which results in a deadlock cycle. So thesrcu_gp_start_if_needed()function's call toraw_spin_lock_irqsave_sdp_contention()must be deferred to the workqueue handler, not just the wake-up. And that in turn means that the callback point also needs to be passed to this handler.See this email thread:
https://lore.kernel.org/all/CAP01T75eKpvw+95NqNWg9P-1+kzVzojpN0NLat+28SF1B9wQQQ@mail.gmail.com/
Quoted 9 lines
Quoted 2 lines
(but Paul, we are not talking about calling
call_srcu(), that requires some more work to get it work)Agreed, splitting
srcu_gp_start_if_needed()and using a workqueue if interrupts were already disabled on entry. Otherwise, directly invoking the split-out portion ofsrcu_gp_start_if_needed().But we might be talking past each other.
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locks[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locks
Quoted 3 lines
If I understand this, this looks like an issue that can happen independent of the conversion of the spin locks.
Yes, this is a separate issue, we should make the conversion to raw spin locks anyway, but lockdep found this once we applied that fix from Paul.
In sched-ext, we can end up calling call_srcu() while rq->lock is held, e.g. from exit_task() -> some bpf map that deletes an element -> call_srcu().
There are other callbacks of course where it can be held, and other programs that can run tracing the kernel while it is held.
Quoted 4 lines
thanks,
--
Joel Fernandes
Joel Fernandes
maintainerQuoted 87 lines · Kumar Kartikeya Dwivedi
Quoted 82 lines · Joel Fernandes
Quoted 46 lines · Paul E. McKenney
Quoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Quoted 4 lines
Late to the party, so just make sure I understand the problem. The problem is the wakeup in
call_srcu()when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.The issue is that
call_rcu_tasks()(which iscall_srcu()now) is also invoked with a scheduler pi/rq lock held, which results in a deadlock cycle. So thesrcu_gp_start_if_needed()function's call toraw_spin_lock_irqsave_sdp_contention()must be deferred to the workqueue handler, not just the wake-up. And that in turn means that the callback point also needs to be passed to this handler.See this email thread:
https://lore.kernel.org/all/CAP01T75eKpvw+95NqNWg9P-1+kzVzojpN0NLat+28SF1B9wQQQ@mail.gmail.com/
Quoted 9 lines
Quoted 2 lines
(but Paul, we are not talking about calling
call_srcu(), that requires some more work to get it work)Agreed, splitting
srcu_gp_start_if_needed()and using a workqueue if interrupts were already disabled on entry. Otherwise, directly invoking the split-out portion ofsrcu_gp_start_if_needed().But we might be talking past each other.
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locks[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksQuoted 3 lines
If I understand this, this looks like an issue that can happen independent of the conversion of the spin locks.
Quoted 9 lines
Yes, this is a separate issue, we should make the conversion to raw spin locks anyway, but lockdep found this once we applied that fix from Paul.
In sched-ext, we can end up callingcall_srcu()whilerq->lockis held, e.g. fromexit_task()-> some bpf map that deletes an element ->call_srcu().
There are other callbacks of course where it can be held, and other programs that can run tracing the kernel while it is held.
Thanks. I guess I am also wondering, why didn't lockdep find it without the conversion to raw spin locks though? An ABBA deadlock should have been detected either way. Is there some difference in lockdep's ability to find deadlocks depending on whether a spinlock is raw?
Anyway, I am applying the raw lock conversion fix and running some more tests.
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 73 lines · Joel Fernandes
Quoted 46 lines · Paul E. McKenney
Quoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
[..]Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
way that vanilla RCU's
call_rcu_core()function takes an early exit if interrupts are disabled. Of course, vanilla RCU can rely on things like the scheduling-clock interrupt to start any needed grace periods [1], but SRCU will instead need to manually defer this work, perhaps using workqueues or IRQ work.In addition, rcutorture needs to be upgraded to sometimes invoke ->call() with the scheduler pi lock held, but this change is not fixing a regression, so could be deferred. (There is already code in rcutorture that invokes the readers while holding a scheduler pi lock.)
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Given that RCU for this week through the end of March belongs to you guys, if one of you can get this done by end of day Thursday, London time, very good! Otherwise, I can put something together.
Please let me know!
Given that the current locking does allow it and lockdep should have complained, I am curious if we could rule that out ;)
Quoted 6 lines
Your patch just s/spinlock_t/raw_spinlock_t so we get the locking/ nesting right. The wakeup problem remains, right?
But looking at the code, there is justsrcu_funnel_gp_start(). If itssrcu_schedule_cbs_sdp()/queue_delayed_work()usage is always delayed then there will be always a timer and never a direct wake up of the worker. Wouldn't that work?Quoted 4 lines
Late to the party, so just make sure I understand the problem. The problem is the wakeup in
call_srcu()when it's called with scheduler lock held, right? If so I think the current code works as what you already explain, we defer the wakeup into a workqueue.The issue is that
call_rcu_tasks()(which iscall_srcu()now) is also invoked with a scheduler pi/rq lock held, which results in a deadlock cycle. So thesrcu_gp_start_if_needed()function's call toraw_spin_lock_irqsave_sdp_contention()must be deferred to the workqueue handler, not just the wake-up. And that in turn means that the callback point also needs to be passed to this handler.See this email thread:
https://lore.kernel.org/all/CAP01T75eKpvw+95NqNWg9P-1+kzVzojpN0NLat+28SF1B9wQQQ@mail.gmail.com/
Quoted 9 lines
Quoted 2 lines
(but Paul, we are not talking about calling
call_srcu(), that requires some more work to get it work)Agreed, splitting
srcu_gp_start_if_needed()and using a workqueue if interrupts were already disabled on entry. Otherwise, directly invoking the split-out portion ofsrcu_gp_start_if_needed().But we might be talking past each other.
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locks
Quoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locks
I see, we can also have a self deadlock even without CPU B, when CPU A is going to try_to_wake_up() the a worker on the same CPU.
An interesting observation is that the deadlock can be avoided in queue_delayed_work() uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.
(But I guess BPF also wants to run with timer base lock held, right? ;-) ;-) ;-)).
/me going to check Paul's second fix at rcu/dev.
Regards,
Boqun
Quoted 8 lines
If I understand this, this looks like an issue that can happen independent of the conversion of the spin locks.
thanks,
Signature · 1 line
Joel Fernandes
Boqun Feng
maintainerOn Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]
Quoted 27 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.
Quoted 9 lines
An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.(But I guess BPF also wants to run with timer base lock held, right? ;-) ;-) ;-)).
/me going to check Paul's second fix at rcu/dev.
Oh I mis-read, there is no second fix, just a rcutorture changes. Let me see if I can find out a quick fix ;-)
Regards,
Boqun
Quoted 11 lines
Regards,
BoqunQuoted 8 lines
If I understand this, this looks like an issue that can happen independent of the conversion of the spin locks.
thanks,
Signature · 1 line
Joel Fernandes
Boqun Feng
maintainerQuoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.
If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun
------>
kernel/rcu/srcutree.c +10 -1
@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )
@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load
@@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
Joel Fernandes
maintainerQuoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +//
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);
Nice, I wonder if it is better to do this in __queue_delayed_work() itself. Do we have queue_delayed_work() with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 87 lines · Joel Fernandes
Quoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);Nice, I wonder if it is better to do this in
__queue_delayed_work()itself. Do we havequeue_delayed_work()with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?
Quoted 8 lines
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
I think all of these are probably a good point. However my fix is not complete :( It's missing the ABBA case in your example (it obviously could solve the self deadlock if my observation is correct), because we will still build rcu_node::lock -> runqueue::lock in some conditions, and BPF contributes the runqueue::lock -> rcu_node::lock dependency. Hence we still have ABBA deadlock.
To remove the rcu_node::lock -> runqueue::lock entirely, we need to always delay 1+ jiffies:
kernel/rcu/srcutree.c +5 -1
@@ -1118,9 +1118,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) +1 );else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
Paul's suggestion at [1] is basically breaking another dependecy runqueue::lock -> rcu_node::lock, I'm investigating how we can do that.
[1]: https://lore.kernel.org/rcu/214fb140-041d-4fd1-8694-658547209b84@paulmck-laptop/
Regards,
Boqun
Quoted 5 lines
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 104 lines · Boqun Feng
Quoted 87 lines · Joel Fernandes
Quoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);Nice, I wonder if it is better to do this in
__queue_delayed_work()itself. Do we havequeue_delayed_work()with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?Quoted 8 lines
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
I think all of these are probably a good point. However my fix is not complete :( It's missing the ABBA case in your example (it obviously could solve the self deadlock if my observation is correct), because we will still build
rcu_node::lock->runqueue::lockin some conditions, and BPF contributes therunqueue::lock->rcu_node::lockdependency. Hence we still have ABBA deadlock.
Quoted 3 lines
To remove the
rcu_node::lock->runqueue::lockentirely, we need to always delay 1+ jiffies:
Hmm.. or I can do as the old call_rcu_tasks_trace() does: using an irq_work. I also pushed it at:
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
(based on Paul's fix on spinlock already, but only lightly build test).
Regards,
Boqun
-------------------------->8
Subject: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Since commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held), call_srcu() now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using an irq_work to delay the queuing of the work to start process_srcu().
--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
include/linux/srcutree.h +1 -0
@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };
kernel/rcu/srcutree.c +20 -2
@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h>
@@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/*
@@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);
@@ -1118,9 +1121,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 5 lines · Boqun Feng
kernel/rcu/srcutree.c +1
-0@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work)
kernel/rcu/srcutree.c static void process_srcu(struct work_struct *work) · line 1999
Quoted 10 lines
kernel/rcu/srcutree.c +10
-0+{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +
Please just use the queue_delayed_work() with a delay >0.
Sebastian
Boqun Feng
maintainerQuoted 5 lines · Sebastian Andrzej Siewior
Quoted 4 lines · Boqun Feng
kernel/rcu/srcutree.c +0
-0@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); }
Quoted 14 lines
kernel/rcu/srcutree.c static void process_srcu(struct work_struct *work) · line 1999
Quoted 11 lines
kernel/rcu/srcutree.c +11
-0+static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +Please just use the
queue_delayed_work()with a delay >0.
That doesn't work since queue_delayed_work() with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. calling call_srcu() with timer base lock.
irq_work on the other hand doesn't use any locking.
Regards,
Boqun
Quoted 1 line
Sebastian
Quoted 9 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.
irq_workon the other hand doesn't use any locking.
Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have irq_work() in call_srcu() just because it might acquire locks.
Quoted 3 lines
Regards,
Boqun
Sebastian
Boqun Feng
maintainerQuoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.
Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.
I agree it's not RCU's fault ;-)
I guess it'll be difficult to restrict BPF, however maybe BPF can call call_srcu() in irq_work instead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot call kfree_rcu() in some cases IIRC).
But we need to fix this in v7.0, so this short-term fix is still needed.
Regars,
Boqun
Quoted 4 lines
Quoted 3 lines
Regards,
BoqunSebastian
Kumar Kartikeya Dwivedi
maintainerQuoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke call_rcu() or any other API in a specific context (e.g., NMI, where we punt it using irq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were using call_rcu_tasks_trace() just fine in scx callbacks where rq->lock is held before, so the conversion underneath to call_srcu() should continue to remain transparent in this respect.
Quoted 7 lines
Regars,
BoqunQuoted 4 lines
Quoted 3 lines
Regards,
BoqunSebastian
Boqun Feng
maintainerQuoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
Regards,
Boqun
Quoted 7 lines
Quoted 7 lines
Regars,
BoqunQuoted 4 lines
Quoted 3 lines
Regards,
BoqunSebastian
Kumar Kartikeya Dwivedi
maintainerQuoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.
Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the call_srcu() from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.
Also, any unconditional deferral in the caller for APIs that can "hold locks" to avoid all this is not without its cost.
The implementation of RCU knows and can stay in sync with those conditions for when deferral is needed, and hide all that complexity from the caller. The cost should definitely be paid by the caller if we would break the API's broad contract, e.g., by trying to invoke it in NMI which it is not supposed to run in yet, in that case we already handle things using irq_work. Anything more complicated than that is hard to scale. All of this may also change in the future where we support call_rcu_nolock() to make it work everywhere, and only defer when we detect reentrancy (in the same or different context).
Quoted 11 lines
Regards,
BoqunQuoted 7 lines
Quoted 7 lines
Regars,
BoqunQuoted 4 lines
Quoted 3 lines
Regards,
BoqunSebastian
Boqun Feng
maintainerQuoted 55 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
Quoted 9 lines
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.
My suggestion would be: deferring all call_srcu()s that in BPF core. For new locks, I think every lock usage in BPF core should be carefully audited because that's very similar to NMI. It's not hard to trade BPF as a different context and let lockdep detect lock mis-usage, similar as what we do for interrupts and NMIs.
Basically, if we want to use some synchronization in BPF core:
1. If it's re-entrant safe, then go ahead and use it.
2. If it has a lock, but can be deferred, use the general BPF defer mechanism to defer the operation.
3. If it cannot be deferred, it has to change or add a new variant that support either 1 or 2.
i.e. a universal solution.
Quoted 7 lines
Also, any unconditional deferral in the caller for APIs that can "hold locks" to avoid all this is not without its cost.
The implementation of RCU knows and can stay in sync with those conditions for when deferral is needed, and hide all that complexity from the caller. The cost should definitely be paid by the caller if we would break the API's broad contract, e.g., by trying to invoke it
The thing is, lots of the synchronization primitives existed before BPF, and they were not designed or implemented with "BPF safe" in mind, and they could be dragged into BPF core code path if we begin to use them. For example, irq_work may be just "happen-to-work" here, or there is a bug that we are missing. It would be rather easier or clearer if we design a dedicate defer mechanism with BPF core in mind, and then we use that for all the deferrable operations.
Regards,
Boqun
Quoted 19 lines
in NMI which it is not supposed to run in yet, in that case we already handle things using
irq_work. Anything more complicated than that is hard to scale. All of this may also change in the future where we supportcall_rcu_nolock()to make it work everywhere, and only defer when we detect reentrancy (in the same or different context).Quoted 11 lines
Regards,
BoqunQuoted 7 lines
Quoted 7 lines
Regars,
BoqunQuoted 4 lines
Quoted 3 lines
Regards,
BoqunSebastian
Joel Fernandes
maintainerQuoted 66 lines · Boqun Feng
Quoted 55 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
Quoted 9 lines
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.
Quoted 2 lines
My suggestion would be: deferring all call_srcu()s that in BPF core. [...]
isn't one of the issues is that BPF is using call_rcu_tasks_trace() which is now internally using call_srcu? So whether other parts of BPF use call_srcu() or not, the issue still stands AFAICS.
I think we have to fix RCU tasks trace, one way or the other.
Or did I miss something?
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 69 lines · Joel Fernandes
Quoted 66 lines · Boqun Feng
Quoted 64 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.
Quoted 5 lines
Quoted 2 lines
My suggestion would be: deferring all call_srcu()s that in BPF core. [...]
isn't one of the issues is that BPF is using
call_rcu_tasks_trace()which is now internally usingcall_srcu? So whether other parts of BPF usecall_srcu()or
I was talking about the long term solution in that thread ;-)
Short-term, yes the switching from call_rcu_tasks_trace() to call_srcu() is the cause the issue, and we have the lockdep report to prove that. So in order to continue the process of switching to SRCU for BPF, we need to restore the behavior of call_rcu_tasks_trace() in call_srcu().
Quoted 2 lines
not, the issue still stands AFAICS.
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless defer
so the issue won't happen.
Quoted 4 lines
I think we have to fix RCU tasks trace, one way or the other.
Or did I miss something?
No I don't think so ;-)
Regards,
Boqun
Quoted 7 lines
thanks,
--
Joel Fernandes
Paul E. McKenney
maintainerQuoted 84 lines · Boqun Feng
Quoted 67 lines · Joel Fernandes
Quoted 66 lines · Boqun Feng
Quoted 64 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.Quoted 5 lines
Quoted 2 lines
My suggestion would be: deferring all call_srcu()s that in BPF core. [...]
isn't one of the issues is that BPF is using
call_rcu_tasks_trace()which is now internally usingcall_srcu? So whether other parts of BPF usecall_srcu()orI was talking about the long term solution in that thread ;-)
Short-term, yes the switching from
call_rcu_tasks_trace()tocall_srcu()is the cause the issue, and we have the lockdep report to prove that. So in order to continue the process of switching to SRCU for BPF, we need to restore the behavior ofcall_rcu_tasks_trace()incall_srcu().Quoted 2 lines
not, the issue still stands AFAICS.
Quoted 6 lines
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless deferso the issue won't happen.
In theory, this is quite true.
In practice, unfortunately for keeping this part of RCU as simple as we might wish, when a BPF program gets attached to some function in the kernel, it does not know whether or not that function holds a given scheduler lock. For example, there are any number of utility functions that can be (and are) called both with and without those scheduler locks held. Worse yet, it might be attached to a function that is *never* invoked with a scheduler lock held -- until some out-of-tree module is loaded. Which means that this module might well be loaded after BPF has JIT-ed the BPF program.
So we really do need to make some variant of call_srcu() that deals with this.
We do have some options. First, we could make call_srcu() deal with it directly, or second, we could create something like call_srcu_lockless() or call_srcu_nolock() or whatever that can safely be invoked from any context, including NMI handlers, and that invokes call_srcu() directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.
Thoughts?
Thanx, Paul
Quoted 17 lines
Quoted 4 lines
I think we have to fix RCU tasks trace, one way or the other.
Or did I miss something?
No I don't think so ;-)
Regards,
BoqunQuoted 7 lines
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 94 lines · Paul E. McKenney
Quoted 84 lines · Boqun Feng
Quoted 67 lines · Joel Fernandes
Quoted 66 lines · Boqun Feng
Quoted 64 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.Quoted 5 lines
Quoted 2 lines
My suggestion would be: deferring all call_srcu()s that in BPF core. [...]
isn't one of the issues is that BPF is using
call_rcu_tasks_trace()which is now internally usingcall_srcu? So whether other parts of BPF usecall_srcu()orI was talking about the long term solution in that thread ;-)
Short-term, yes the switching from
call_rcu_tasks_trace()tocall_srcu()is the cause the issue, and we have the lockdep report to prove that. So in order to continue the process of switching to SRCU for BPF, we need to restore the behavior ofcall_rcu_tasks_trace()incall_srcu().Quoted 2 lines
not, the issue still stands AFAICS.
Quoted 6 lines
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless deferso the issue won't happen.
In theory, this is quite true.
Quoted 10 lines
In practice, unfortunately for keeping this part of RCU as simple as we might wish, when a BPF program gets attached to some function in the kernel, it does not know whether or not that function holds a given scheduler lock. For example, there are any number of utility functions that can be (and are) called both with and without those scheduler locks held. Worse yet, it might be attached to a function that is *never* invoked with a scheduler lock held -- until some out-of-tree module is loaded. Which means that this module might well be loaded after BPF has JIT-ed the BPF program.
Hmm.. maybe I failed to make myself more clear. I was suggesting we treat BPF as a special context, and you cannot do everything, if there is any call_srcu() needed, switch it to bpf_defer(). We should have the same result as either 1) call_srcu() locklessly defer itself or 2) a call_srcu_lockless().
Certainly we can call_srcu() do locklessly defer, but if it's only for BPF, that looks like a whack-a-mole approach to me. Say later on we want to use call_hazptr() in BPF for some reason (there is hoping!), then we need to make it locklessly defer as well. Now we have two lockless logic in both call_srcu() and call_hazptr(), if there is a third one, we need to do that as well. So where's the end?
The lockless defer request comes from BPF being special, a proper way to deal with it IMO would be BPF has a general defer mechanism. Whether call_srcu() or call_srcu_lockless() can do lockless defer is orthogonal.
BTW, an example to my point, I think we have a deadlock even with the old call_rcu_tasks_trace(), because at:
https://elixir.bootlin.com/linux/v6.19.8/source/kernel/rcu/tasks.h#L384
We do a:
mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp));
which means call_rcu_tasks_trace() may acquire timer base lock, and that means if BPF was to trace a point where timer base lock is held, then we may have a deadlock. So Now I wonder whether you had any magic to avoid the deadlock pre-7.0 or we are just lucky ;-)
See, without a general defer mechanism, we will have a lot of fun auditing all the primitives that BPF may use.
Quoted 11 lines
So we really do need to make some variant of
call_srcu()that deals with this.We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.
Within the RCU scope, I prefer the second option.
Regards,
Boqun
Quoted 21 lines
Thoughts?
Thanx, Paul
Quoted 17 lines
Quoted 4 lines
I think we have to fix RCU tasks trace, one way or the other.
Or did I miss something?
No I don't think so ;-)
Regards,
BoqunQuoted 7 lines
thanks,
--
Joel Fernandes
Paul E. McKenney
maintainerQuoted 112 lines · Boqun Feng
Quoted 94 lines · Paul E. McKenney
Quoted 84 lines · Boqun Feng
Quoted 67 lines · Joel Fernandes
Quoted 66 lines · Boqun Feng
Quoted 64 lines · Kumar Kartikeya Dwivedi
Quoted 42 lines · Boqun Feng
Quoted 30 lines · Kumar Kartikeya Dwivedi
Quoted 20 lines · Boqun Feng
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Boqun Feng
Quoted 2 lines · Sebastian Andrzej Siewior
Please just use the
queue_delayed_work()with a delay >0.That doesn't work since
queue_delayed_work()with a positive delay will still acquire timer base lock, and we can have BPF instrument with timer base lock held i.e. callingcall_srcu()with timer base lock.Quoted 6 lines
Quoted 1 line
irq_workon the other hand doesn't use any locking.Could we please restrict BPF somehow so it does roam free? It is absolutely awful to have
irq_work()incall_srcu()just because it might acquire locks.I agree it's not RCU's fault ;-)
Quoted 8 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
Quoted 9 lines
I don't think this is an option, even longer term. We already do it when it's incorrect to invoke
call_rcu()or any other API in a specific context (e.g., NMI, where we punt it usingirq_work). However, the case reported in this thread is different. It was an existing user which worked fine before but got broken now. We were usingcall_rcu_tasks_trace()just fine in scx callbacks whererq->lockis held before, so the conversion underneath tocall_srcu()should continue to remain transparent in this respect.Quoted 7 lines
I'm not sure that's a real argument here, kernel doesn't have a stable internal API, which allows developers to refactor the code into a saner way. There are currently multiple issues that suggest we may need a defer mechanism for BPF core, and if it makes the code more easier to reason about then why not? Think about it like a process that we learn about all the defer patterns that BPF currently needs and wrap them in a nice and maintainable way.
This is all right in theory, but I don't understand how your theoretical deferral mechanism for BPF will help here in the case we're discussing, or is even appealing.
How do we decide when to defer? Will we annotate all locks that can be held by RCU internals to be able to check if they are held (on the current cpu, which is non-trivial except by maintaining a held lock table, testing the locked bit is too conservative), and then deferring the
call_srcu()from the caller in BPF? What if you gain new locks? It doesn't seem practical to me. Plus it pushes the burden of detection and deferral to the caller, making everything more complicated and error-prone.Quoted 5 lines
Quoted 2 lines
My suggestion would be: deferring all call_srcu()s that in BPF core. [...]
isn't one of the issues is that BPF is using
call_rcu_tasks_trace()which is now internally usingcall_srcu? So whether other parts of BPF usecall_srcu()orI was talking about the long term solution in that thread ;-)
Short-term, yes the switching from
call_rcu_tasks_trace()tocall_srcu()is the cause the issue, and we have the lockdep report to prove that. So in order to continue the process of switching to SRCU for BPF, we need to restore the behavior ofcall_rcu_tasks_trace()incall_srcu().Quoted 2 lines
not, the issue still stands AFAICS.
Quoted 6 lines
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless deferso the issue won't happen.
In theory, this is quite true.
Quoted 10 lines
In practice, unfortunately for keeping this part of RCU as simple as we might wish, when a BPF program gets attached to some function in the kernel, it does not know whether or not that function holds a given scheduler lock. For example, there are any number of utility functions that can be (and are) called both with and without those scheduler locks held. Worse yet, it might be attached to a function that is *never* invoked with a scheduler lock held -- until some out-of-tree module is loaded. Which means that this module might well be loaded after BPF has JIT-ed the BPF program.
Hmm.. maybe I failed to make myself more clear. I was suggesting we treat BPF as a special context, and you cannot do everything, if there is any
call_srcu()needed, switch it tobpf_defer(). We should have the same result as either 1)call_srcu()locklessly defer itself or 2) acall_srcu_lockless().
Quoted 6 lines
Certainly we can
call_srcu()do locklessly defer, but if it's only for BPF, that looks like a whack-a-mole approach to me. Say later on we want to usecall_hazptr()in BPF for some reason (there is hoping!), then we need to make it locklessly defer as well. Now we have two lockless logic in bothcall_srcu()andcall_hazptr(), if there is a third one, we need to do that as well. So where's the end?
Except that by the same line of reasoning, how do the BPF guys figure out exactly which function calls they need to defer and under what conditions they need to defer them? Keeping in mind that the list of functions and corresponding conditions is subject to change as the kernel continues to change.
Quoted 4 lines
The lockless defer request comes from BPF being special, a proper way to deal with it IMO would be BPF has a general defer mechanism. Whether
call_srcu()orcall_srcu_lockless()can do lockless defer is orthogonal.
Fair point, and for the general defer mechanism, I hereby nominate the irq_work_queue() function. We can use this both for RCU and for hazard pointers. The code to make a call_srcu_lockless() and call_hazptr_lockless() that includes the relevant checks and that does the deferral will not be large, complex, or slow. Especially assuming that we consolidate common checks.
Quoted 5 lines
BTW, an example to my point, I think we have a deadlock even with the old
call_rcu_tasks_trace(), because at:https://elixir.bootlin.com/linux/v6.19.8/source/kernel/rcu/tasks.h#L384
Quoted 8 lines
We do a:
mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp));which means
call_rcu_tasks_trace()may acquire timer base lock, and that means if BPF was to trace a point where timer base lock is held, then we may have a deadlock. So Now I wonder whether you had any magic to avoid the deadlock pre-7.0 or we are just lucky ;-)
Test it and see! ;-)
Quoted 2 lines
See, without a general defer mechanism, we will have a lot of fun auditing all the primitives that BPF may use.
No, *we* only audit the primitives in our subsystem that BPF actually uses when BPF starts using them. We let the *other* subsystems worry about *their* interactions with BPF.
Quoted 11 lines
Quoted 10 lines
So we really do need to make some variant of
call_srcu()that deals with this.We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.
Quoted 1 line
Within the RCU scope, I prefer the second option.
Works for me!
Would you guys like to implement this, or would you prefer that I do so?
Thanx, Paul
Quoted 24 lines
Regards,
BoqunQuoted 21 lines
Thoughts?
Thanx, Paul
Quoted 17 lines
Quoted 4 lines
I think we have to fix RCU tasks trace, one way or the other.
Or did I miss something?
No I don't think so ;-)
Regards,
BoqunQuoted 7 lines
thanks,
--
Joel Fernandes
Boqun Feng
maintainerOn Fri, Mar 20, 2026 at 09:24:15AM -0700, Paul E. McKenney wrote:
[...]
Quoted 33 lines
Quoted 26 lines
Quoted 9 lines
Quoted 6 lines
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless deferso the issue won't happen.
In theory, this is quite true.
Quoted 10 lines
In practice, unfortunately for keeping this part of RCU as simple as we might wish, when a BPF program gets attached to some function in the kernel, it does not know whether or not that function holds a given scheduler lock. For example, there are any number of utility functions that can be (and are) called both with and without those scheduler locks held. Worse yet, it might be attached to a function that is *never* invoked with a scheduler lock held -- until some out-of-tree module is loaded. Which means that this module might well be loaded after BPF has JIT-ed the BPF program.
Hmm.. maybe I failed to make myself more clear. I was suggesting we treat BPF as a special context, and you cannot do everything, if there is any
call_srcu()needed, switch it tobpf_defer(). We should have the same result as either 1)call_srcu()locklessly defer itself or 2) acall_srcu_lockless().Quoted 6 lines
Certainly we can
call_srcu()do locklessly defer, but if it's only for BPF, that looks like a whack-a-mole approach to me. Say later on we want to usecall_hazptr()in BPF for some reason (there is hoping!), then we need to make it locklessly defer as well. Now we have two lockless logic in bothcall_srcu()andcall_hazptr(), if there is a third one, we need to do that as well. So where's the end?
Quoted 3 lines
Except that by the same line of reasoning, how do the BPF guys figure out exactly which function calls they need to defer and under what conditions they need to defer them? Keeping in mind that the list of functions and
Can't they just defer anything that is deferrable? If it's deferrable, then what's the actual cost for BPF to defer it?
Quoted 22 lines
corresponding conditions is subject to change as the kernel continues to change.
Quoted 4 lines
The lockless defer request comes from BPF being special, a proper way to deal with it IMO would be BPF has a general defer mechanism. Whether
call_srcu()orcall_srcu_lockless()can do lockless defer is orthogonal.Fair point, and for the general defer mechanism, I hereby nominate the
irq_work_queue()function. We can use this both for RCU and for hazard pointers. The code to make acall_srcu_lockless()andcall_hazptr_lockless()that includes the relevant checks and that does the deferral will not be large, complex, or slow. Especially assuming that we consolidate common checks.Quoted 7 lines
BTW, an example to my point, I think we have a deadlock even with the old
call_rcu_tasks_trace(), because at:https://elixir.bootlin.com/linux/v6.19.8/source/kernel/rcu/tasks.h#L384
We do a:
Quoted 9 lines
Quoted 6 lines
mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp));which means
call_rcu_tasks_trace()may acquire timer base lock, and that means if BPF was to trace a point where timer base lock is held, then we may have a deadlock. So Now I wonder whether you had any magic to avoid the deadlock pre-7.0 or we are just lucky ;-)Test it and see! ;-)
"Program testing can be used to show the presence of bugs, but never to show their absence!" ;-)
Quoted 7 lines
Quoted 2 lines
See, without a general defer mechanism, we will have a lot of fun auditing all the primitives that BPF may use.
No, *we* only audit the primitives in our subsystem that BPF actually uses when BPF starts using them. We let the *other* subsystems worry about *their* interactions with BPF.
As an RCU mainatainer: fine
As a LOCKING maintainer: shake my head, because for every primitive that BPF uses, now there could be a normal version and a _bpf/lockless() version. That could create more maintenance issues, but only time can tell.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
So we really do need to make some variant of
call_srcu()that deals with this.We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.
Quoted 6 lines
Quoted 1 line
Within the RCU scope, I prefer the second option.
Works for me!
Would you guys like to implement this, or would you prefer that I do so?
I feel I don't have cycles for it soon, I have a big backlog (including making preempt_count 64bit on 64bit x86). But I will send the fix in the current call_srcu() for v7.0 and work with Joel to get into Linus' tree.
I will definitely review it if you beat me to it ;-)
Regards,
Boqun
Quoted 5 lines
Thanx, Paul
Quoted 3 lines
Regards,
Boqun
[..]
Joel Fernandes
maintainerQuoted 11 lines · Boqun Feng
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
So we really do need to make some variant of
call_srcu()that deals with this.We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Within the RCU scope, I prefer the second option.
Works for me!
Would you guys like to implement this, or would you prefer that I do so?
I feel I don't have cycles for it soon, I have a big backlog (including making
preempt_count64bit on 64bit x86). But I will send the fix in the currentcall_srcu()for v7.0 and work with Joel to get into Linus' tree.
Boqun, I get a splat as below with your irq_work patch on rcutorture:
Maybe the srcu_get_delay call needs:
raw_spin_lock_irqsave_rcu_node(ssp->srcu_sup, flags);
delay = srcu_get_delay(ssp);
raw_spin_unlock_irqrestore_rcu_node(ssp->srcu_sup, flags);can you check?
[ 0.459781] ------------[ cut here ]------------ [ 0.460401] WARNING: kernel/rcu/srcutree.c:681 at srcu_get_delay+0xb4/0xd0, CPU#0: swapper/0/1 [ 0.460751] Modules linked in: [ 0.460751] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-00020-gc18a9e13ce7f #96 PREEMPTLAZY [ 0.460751] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 0.460751] RIP: 0010:srcu_get_delay+0xb4/0xd0 [ 0.460751] Code: 00 00 00 5b 5d 48 39 d0 48 0f 47 c2 e9 45 b0 0b 01 48 89 fd be ff ff ff ff 48 8d bb d0 00 00 00 e8 e1 86 0a 01 85 c0 75 0d 90 <0f> 0b 90 48 8b 55 40 e9 57 ff ff ff 48 8b 55 40 e9 4e ff ff ff 0f [ 0.460751] RSP: 0000:ffffb4ba80003f80 EFLAGS: 00010046 [ 0.460751] RAX: 0000000000000000 RBX: ffffffffac1604c0 RCX: 0000000000000001 [ 0.460751] RDX: 0000000000000000 RSI: 00000000ffffffff RDI: ffffffffac160590 [ 0.460751] RBP: ffffffffac160460 R08: 0000000000000000 R09: 0000000000000000 [ 0.460751] R10: 0000000000000000 R11: ffffb4ba80003ff8 R12: 0000000000000023 [ 0.460751] R13: ffff9de181214b00 R14: 0000000000000000 R15: 0000000000000000 [ 0.460751] FS: 0000000000000000(0000) GS:ffff9de1f2799000(0000) knlGS:0000000000000000 [ 0.460751] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.460751] CR2: ffff9de18ddda000 CR3: 000000000c64e000 CR4: 00000000000006f0 [ 0.460751] Call Trace: [ 0.460751] <IRQ> [ 0.460751] srcu_irq_work+0x11/0x40 [ 0.460751] irq_work_single+0x42/0x90 [ 0.460751] irq_work_run_list+0x26/0x40 [ 0.460751] irq_work_run+0x18/0x30 [ 0.460751] __sysvec_irq_work+0x30/0x180 [ 0.460751] sysvec_irq_work+0x6a/0x80 [ 0.460751] </IRQ> [ 0.460751] <TASK> [ 0.460751] asm_sysvec_irq_work+0x1a/0x20 [ 0.460751] RIP: 0010:_raw_spin_unlock_irqrestore+0x34/0x50 [ 0.460751] Code: c7 18 53 48 89 f3 48 8b 74 24 10 e8 e6 58 f1 fe 48 89 ef e8 2e 92 f1 fe 80 e7 02 74 06 e8 e4 c0 00 ff fb 65 ff 0d fc 63 66 01 <74> 07 5b 5d c3 cc cc cc cc e8 7e 03 df fe 5b 5d e9 57 1b 00 00 0f [ 0.460751] RSP: 0000:ffffb4ba80013d50 EFLAGS: 00000286 [ 0.460751] RAX: 0000000000001c8b RBX: 0000000000000297 RCX: 0000000000000000 [ 0.460751] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffab614c2c [ 0.460751] RBP: ffffffffac160578 R08: 0000000000000001 R09: 0000000000000000 [ 0.460751] R10: 0000000000000001 R11: 0000000000000000 R12: fffffffffffffe74 [ 0.460751] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000001 [ 0.460751] ? _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.460751] srcu_gp_start_if_needed+0x354/0x530 [ 0.460751] __synchronize_srcu+0xcc/0x180 [ 0.460751] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.460751] ? synchronize_srcu+0x3f/0x170 [ 0.460751] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.460751] rcu_init_tasks_generic+0x104/0x150 [ 0.460751] do_one_initcall+0x59/0x2e0 [ 0.460751] ? _printk+0x56/0x70 [ 0.460751] kernel_init_freeable+0x227/0x440 [ 0.460751] ? __pfx_kernel_init+0x10/0x10 [ 0.460751] kernel_init+0x15/0x1c0 [ 0.460751] ret_from_fork+0x2ac/0x330 [ 0.460751] ? __pfx_kernel_init+0x10/0x10 [ 0.460751] ret_from_fork_asm+0x1a/0x30 [ 0.460751] </TASK>
Boqun Feng
maintainerPATCH 1/1 rcu: Use an intermediate irq_work to start process_srcu()
Since commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held), call_srcu() now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using an irq_work to delay the queuing of the work to start process_srcu().
[boqun: Apply Joel's feedback]
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.
@Joel, I did two updates (including your test feedback, other one is call irq_work_sync() when we clean the srcu_struct), please give it a try.
include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)
include/linux/srcutree.h +1 -0
@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };
kernel/rcu/srcutree.c +27 -2
@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h>
@@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/*
@@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);
@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);
@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); + +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {
Signature · 1 line
2.50.1 (Apple Git-155)
Joel Fernandes
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 16 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 7 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.
Thanks Boqun, I applied it for testing further. It would be good if Andrea and Kumar can try this patch as well to confirm that the BPF issues are gone.
thanks,
--
Joel Fernandes
Re: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengHi Boqun,
Quoted 16 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 7 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.
I'm getting this at boot with this patch applied (testing directly from Joel's branch rcu/dev):
[ 0.639477] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) [ 0.639479] WARNING: kernel/locking/lockdep.c:4404 at lockdep_hardirqs_on_prepare+0x15e/0x1a0, CPU#0: swapper/0/1 [ 0.639507] Modules linked in: [ 0.639507] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-virtme #5 PREEMPT(full) [ 0.639507] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 0.639507] RIP: 0010:lockdep_hardirqs_on_prepare+0x165/0x1a0 [ 0.639507] Code: cc 90 e8 0e b1 4e 00 85 c0 74 0a 8b 35 54 08 43 02 85 f6 74 31 90 5b c3 cc cc cc cc 48 8d 3d d2 3c 44 02 48 c7 c6 b9 58 c5 b2 <67> 48 0f b9 3a eb ac 48 8d 3d cd 3c 44 02 48 c7 c6 37 55 c5 b2 67 [ 0.639507] RSP: 0018:ffffd26700003f58 EFLAGS: 00010046 [ 0.639507] RAX: 0000000000000001 RBX: ffffffffb35719f8 RCX: 0000000000000001 [ 0.639507] RDX: 0000000000000000 RSI: ffffffffb2c558b9 RDI: ffffffffb36bf810 [ 0.639507] RBP: ffffffffb35718e0 R08: 0000000000000001 R09: 0000000000000000 [ 0.639507] R10: 0000000000000001 R11: 000000007cb360a8 R12: 0000000000000000 [ 0.639507] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.639507] FS: 0000000000000000(0000) GS:ffff8a7e076f6000(0000) knlGS:0000000000000000 [ 0.639507] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.639507] CR2: ffff8a7dbffff000 CR3: 0000000023452000 CR4: 0000000000750ef0 [ 0.639507] PKRU: 55555554 [ 0.639507] Call Trace: [ 0.639507] <IRQ> [ 0.639507] trace_hardirqs_on+0x18/0x100 [ 0.639507] _raw_spin_unlock_irq+0x28/0x50 [ 0.639507] srcu_irq_work+0x63/0x90 [ 0.639507] irq_work_single+0x69/0x90 [ 0.639507] irq_work_run_list+0x26/0x40 [ 0.639507] irq_work_run+0x18/0x30 [ 0.639507] __sysvec_irq_work+0x35/0x1b0 [ 0.639507] ? irq_exit_rcu+0xe/0x20 [ 0.639507] sysvec_irq_work+0x6e/0x80 [ 0.639507] </IRQ> [ 0.639507] <TASK> [ 0.639507] asm_sysvec_irq_work+0x1a/0x20 [ 0.639507] RIP: 0010:_raw_spin_unlock_irqrestore+0x36/0x70 [ 0.639507] Code: f5 53 48 8b 74 24 10 48 89 fb 48 83 c7 18 e8 b1 3d 26 ff 48 89 df e8 d9 a1 26 ff f7 c5 00 02 00 00 75 17 9c 58 f6 c4 02 75 2b <65> ff 0d 33 62 f0 01 74 16 5b 5d c3 cc cc cc cc e8 f5 83 35 ff 9c [ 0.639507] RSP: 0018:ffffd26700013d48 EFLAGS: 00000246 [ 0.639507] RAX: 0000000000000092 RBX: ffffffffb35719f8 RCX: ffffffffb2017e0b [ 0.639507] RDX: ffff8a7d80338000 RSI: 0000000000000000 RDI: ffffffffb2017e0b [ 0.639507] RBP: 0000000000000282 R08: 0000000000000000 R09: 0000000000000001 [ 0.639507] R10: 0000000000000001 R11: 000000007cb360a8 R12: ffff8a7dbb628a40 [ 0.639507] R13: 0000000000000000 R14: ffffffffb3571940 R15: 0000000000000001 [ 0.639507] ? _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] ? _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] srcu_gp_start_if_needed+0x37a/0x520 [ 0.639507] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.639507] __synchronize_srcu+0xf6/0x1b0 [ 0.639507] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.639507] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.639507] rcu_init_tasks_generic+0xfe/0x120 [ 0.639507] do_one_initcall+0x6f/0x300 [ 0.639507] kernel_init_freeable+0x24b/0x2b0 [ 0.639507] ? __pfx_kernel_init+0x10/0x10 [ 0.639507] kernel_init+0x1a/0x130 [ 0.639507] ret_from_fork+0x2bd/0x370 [ 0.639507] ? __pfx_kernel_init+0x10/0x10 [ 0.639507] ret_from_fork_asm+0x1a/0x30 [ 0.639507] </TASK> [ 0.639507] irq event stamp: 6418 [ 0.639507] hardirqs last enabled at (6417): [<ffffffffb2017e0b>] _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] hardirqs last disabled at (6418): [<ffffffffb20013fe>] sysvec_irq_work+0xe/0x80 [ 0.639507] softirqs last enabled at (6406): [<ffffffffb11ce7b6>] __irq_exit_rcu+0x96/0xc0 [ 0.639507] softirqs last disabled at (6401): [<ffffffffb11ce7b6>] __irq_exit_rcu+0x96/0xc0 [ 0.639507] ---[ end trace 0000000000000000 ]---
Thanks,
-Andrea
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 23 lines · Andrea Righi
Hi Boqun,
Quoted 20 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.
Quoted 8 lines
Quoted 3 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.I'm getting this at boot with this patch applied (testing directly from Joel's branch rcu/dev):
[ 0.639477] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context())
My bad, this is missing:
kernel/rcu/srcutree.c +3 -2
@@ -1993,13 +1993,14 @@ static void srcu_irq_work(struct irq_work *work)struct srcu_struct *ssp;struct srcu_usage *sup;unsigned long delay; +unsigned long flags; sup = container_of(work, struct srcu_usage, irq_work); ssp = sup->srcu_ssp; -raw_spin_lock_irq_rcu_node (ssp->srcu_sup); +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); delay =srcu_get_delay (ssp); -raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags);queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); }
Regards,
Boqun
Quoted 63 lines
[ 0.639479] WARNING: kernel/locking/lockdep.c:4404 at lockdep_hardirqs_on_prepare+0x15e/0x1a0, CPU#0: swapper/0/1 [ 0.639507] Modules linked in: [ 0.639507] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-virtme #5 PREEMPT(full) [ 0.639507] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 0.639507] RIP: 0010:lockdep_hardirqs_on_prepare+0x165/0x1a0 [ 0.639507] Code: cc 90 e8 0e b1 4e 00 85 c0 74 0a 8b 35 54 08 43 02 85 f6 74 31 90 5b c3 cc cc cc cc 48 8d 3d d2 3c 44 02 48 c7 c6 b9 58 c5 b2 <67> 48 0f b9 3a eb ac 48 8d 3d cd 3c 44 02 48 c7 c6 37 55 c5 b2 67 [ 0.639507] RSP: 0018:ffffd26700003f58 EFLAGS: 00010046 [ 0.639507] RAX: 0000000000000001 RBX: ffffffffb35719f8 RCX: 0000000000000001 [ 0.639507] RDX: 0000000000000000 RSI: ffffffffb2c558b9 RDI: ffffffffb36bf810 [ 0.639507] RBP: ffffffffb35718e0 R08: 0000000000000001 R09: 0000000000000000 [ 0.639507] R10: 0000000000000001 R11: 000000007cb360a8 R12: 0000000000000000 [ 0.639507] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 0.639507] FS: 0000000000000000(0000) GS:ffff8a7e076f6000(0000) knlGS:0000000000000000 [ 0.639507] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.639507] CR2: ffff8a7dbffff000 CR3: 0000000023452000 CR4: 0000000000750ef0 [ 0.639507] PKRU: 55555554 [ 0.639507] Call Trace: [ 0.639507] <IRQ> [ 0.639507] trace_hardirqs_on+0x18/0x100 [ 0.639507] _raw_spin_unlock_irq+0x28/0x50 [ 0.639507] srcu_irq_work+0x63/0x90 [ 0.639507] irq_work_single+0x69/0x90 [ 0.639507] irq_work_run_list+0x26/0x40 [ 0.639507] irq_work_run+0x18/0x30 [ 0.639507] __sysvec_irq_work+0x35/0x1b0 [ 0.639507] ? irq_exit_rcu+0xe/0x20 [ 0.639507] sysvec_irq_work+0x6e/0x80 [ 0.639507] </IRQ> [ 0.639507] <TASK> [ 0.639507] asm_sysvec_irq_work+0x1a/0x20 [ 0.639507] RIP: 0010:_raw_spin_unlock_irqrestore+0x36/0x70 [ 0.639507] Code: f5 53 48 8b 74 24 10 48 89 fb 48 83 c7 18 e8 b1 3d 26 ff 48 89 df e8 d9 a1 26 ff f7 c5 00 02 00 00 75 17 9c 58 f6 c4 02 75 2b <65> ff 0d 33 62 f0 01 74 16 5b 5d c3 cc cc cc cc e8 f5 83 35 ff 9c [ 0.639507] RSP: 0018:ffffd26700013d48 EFLAGS: 00000246 [ 0.639507] RAX: 0000000000000092 RBX: ffffffffb35719f8 RCX: ffffffffb2017e0b [ 0.639507] RDX: ffff8a7d80338000 RSI: 0000000000000000 RDI: ffffffffb2017e0b [ 0.639507] RBP: 0000000000000282 R08: 0000000000000000 R09: 0000000000000001 [ 0.639507] R10: 0000000000000001 R11: 000000007cb360a8 R12: ffff8a7dbb628a40 [ 0.639507] R13: 0000000000000000 R14: ffffffffb3571940 R15: 0000000000000001 [ 0.639507] ? _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] ? _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] srcu_gp_start_if_needed+0x37a/0x520 [ 0.639507] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.639507] __synchronize_srcu+0xf6/0x1b0 [ 0.639507] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.639507] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.639507] rcu_init_tasks_generic+0xfe/0x120 [ 0.639507] do_one_initcall+0x6f/0x300 [ 0.639507] kernel_init_freeable+0x24b/0x2b0 [ 0.639507] ? __pfx_kernel_init+0x10/0x10 [ 0.639507] kernel_init+0x1a/0x130 [ 0.639507] ret_from_fork+0x2bd/0x370 [ 0.639507] ? __pfx_kernel_init+0x10/0x10 [ 0.639507] ret_from_fork_asm+0x1a/0x30 [ 0.639507] </TASK> [ 0.639507] irq event stamp: 6418 [ 0.639507] hardirqs last enabled at (6417): [<ffffffffb2017e0b>] _raw_spin_unlock_irqrestore+0x4b/0x70 [ 0.639507] hardirqs last disabled at (6418): [<ffffffffb20013fe>] sysvec_irq_work+0xe/0x80 [ 0.639507] softirqs last enabled at (6406): [<ffffffffb11ce7b6>] __irq_exit_rcu+0x96/0xc0 [ 0.639507] softirqs last disabled at (6401): [<ffffffffb11ce7b6>] __irq_exit_rcu+0x96/0xc0 [ 0.639507] ---[ end trace 0000000000000000 ]---Thanks,
-Andrea
Re: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 46 lines · Boqun Feng
Quoted 23 lines · Andrea Righi
Hi Boqun,
Quoted 20 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.Quoted 8 lines
Quoted 3 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.I'm getting this at boot with this patch applied (testing directly from Joel's branch rcu/dev):
[ 0.639477] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context())My bad, this is missing:
kernel/rcu/srcutree.c +1
-0@@ -1993,13 +1993,14 @@ static void srcu_irq_work(struct irq_work *work)struct srcu_struct *ssp;struct srcu_usage *sup;unsigned long delay; +unsigned long flags; sup = container_of(work, struct srcu_usage, irq_work);
kernel/rcu/srcutree.c static void srcu_irq_work(struct irq_work *work) · line 2006
Quoted 10 lines
kernel/rcu/srcutree.c +2
-2ssp = sup->srcu_ssp; -raw_spin_lock_irq_rcu_node (ssp->srcu_sup); +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); delay =srcu_get_delay (ssp); -raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags);queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); }
Ah yes, much better with this one. :) And I confirm that it fixes the initial locking issue that I reported.
Thanks!
-Andrea
Andrea Righi
Tested-byRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 55 lines · Andrea Righi
Quoted 54 lines · Boqun Feng
Quoted 23 lines · Andrea Righi
Hi Boqun,
Quoted 20 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.Quoted 8 lines
Quoted 3 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.I'm getting this at boot with this patch applied (testing directly from Joel's branch rcu/dev):
[ 0.639477] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context())My bad, this is missing:
kernel/rcu/srcutree.c +3
-2@@ -1993,13 +1993,14 @@ static void srcu_irq_work(struct irq_work *work)struct srcu_struct *ssp;struct srcu_usage *sup;unsigned long delay; +unsigned long flags; sup = container_of(work, struct srcu_usage, irq_work); ssp = sup->srcu_ssp; -raw_spin_lock_irq_rcu_node (ssp->srcu_sup); +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); delay =srcu_get_delay (ssp); -raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags);
Quoted 5 lines
kernel/rcu/srcutree.c static void srcu_irq_work(struct irq_work *work) · line 2006
Quoted 2 lines
kernel/rcu/srcutree.c +0
-0queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); }Ah yes, much better with this one. :) And I confirm that it fixes the initial locking issue that I reported.
Forgot to add my:
-Andrea
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 62 lines · Andrea Righi
Quoted 55 lines · Andrea Righi
Quoted 54 lines · Boqun Feng
Quoted 23 lines · Andrea Righi
Hi Boqun,
Quoted 20 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.Quoted 8 lines
Quoted 3 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.I'm getting this at boot with this patch applied (testing directly from Joel's branch rcu/dev):
[ 0.639477] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context())My bad, this is missing:
kernel/rcu/srcutree.c +3
-2@@ -1993,13 +1993,14 @@ static void srcu_irq_work(struct irq_work *work)struct srcu_struct *ssp;struct srcu_usage *sup;unsigned long delay; +unsigned long flags; sup = container_of(work, struct srcu_usage, irq_work); ssp = sup->srcu_ssp; -raw_spin_lock_irq_rcu_node (ssp->srcu_sup); +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); delay =srcu_get_delay (ssp); -raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags);Quoted 5 lines
kernel/rcu/srcutree.c static void srcu_irq_work(struct irq_work *work) · line 2006
Quoted 2 lines
kernel/rcu/srcutree.c +0
-0queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); }Ah yes, much better with this one. :) And I confirm that it fixes the initial locking issue that I reported.
Quoted 4 lines
Forgot to add my:
Tested-by Andrea Righi <[email protected]>
Thank you ;-)
Regards,
Boqun
Quoted 1 line
-Andrea
Boqun Feng
maintainerPATCH v2 1/1 rcu: Use an intermediate irq_work to start process_srcu()
In reply to Andrea RighiSince commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held), call_srcu() now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using an irq_work to delay the queuing of the work to start process_srcu().
[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]
--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-)
include/linux/srcutree.h +1 -0
@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };
kernel/rcu/srcutree.c +28 -2
@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h>
@@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/*
@@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);
@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);
@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
@@ -1979,6 +1988,23 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; +unsigned long flags; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags); + +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]
Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
I have the following in the shared rcu tree rcu/dev branch, but if you're sending it for 7.0 -rc cycle I will drop them:
998608c o rcu: Use an intermediate irq_work to start process_srcu() 15d921a o rcutorture: Test call_srcu() with preemption disabled and not
thanks,
Signature · 1 line
Joel Fernandes
Quoted 94 lines
--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +28
-2@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,23 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; +unsigned long flags; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irqsave_rcu_node (ssp->srcu_sup, flags); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irqrestore_rcu_node (ssp->srcu_sup, flags); + +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {
Boqun Feng
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 22 lines · Joel Fernandes
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 8 lines
Tested-by Joel Fernandes <[email protected]>I have the following in the shared rcu tree rcu/dev branch, but if you're sending it for 7.0 -rc cycle I will drop them:
998608c o rcu: Use an intermediate
irq_workto startprocess_srcu()15d921a o rcutorture: Testcall_srcu()with preemption disabled and not
Thank you. I think Paul has another one we need for v7.0:
https://lore.kernel.org/rcu/ad67e723-7f7d-4350-b886-c04e56c0b78d@paulmck-laptop/
I've made an fixes.v7.0-rc4 branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux.git fixes.v7.0-rc4
with these commits on top of -rc4:
d0f816d5e872 rcu: Use an intermediate irq_work to start process_srcu() 6b7fc20ab878 srcu: Push srcu_node allocation to GP when non-preemptible f627bbab8fd0 srcu: Use raw spinlocks so call_srcu() can be used under preempt_disable()
I will send a PR at Wednesday if I don't hear any objection. Thanks!
Regards,
Boqun
Quoted 5 lines
thanks,
Signature · 1 line
Joel Fernandes
[..]
Joel Fernandes
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 40 lines · Boqun Feng
Quoted 22 lines · Joel Fernandes
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 8 lines
Tested-by Joel Fernandes <[email protected]>I have the following in the shared rcu tree rcu/dev branch, but if you're sending it for 7.0 -rc cycle I will drop them:
998608c o rcu: Use an intermediate
irq_workto startprocess_srcu()15d921a o rcutorture: Testcall_srcu()with preemption disabled and notThank you. I think Paul has another one we need for v7.0:
https://lore.kernel.org/rcu/ad67e723-7f7d-4350-b886-c04e56c0b78d@paulmck-laptop/I've made an fixes.v7.0-rc4 branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux.git fixes.v7.0-rc4
Quoted 8 lines
with these commits on top of -rc4:
d0f816d5e872rcu: Use an intermediateirq_workto startprocess_srcu()6b7fc20ab878srcu: Pushsrcu_nodeallocation to GP when non-preemptiblef627bbab8fd0srcu: Use raw spinlocks socall_srcu()can be used underpreempt_disable()I will send a PR at Wednesday if I don't hear any objection. Thanks!
Btw, I am getting lockdep splats on SRCU-T now for some reason.
rcu_gp_start_if_needed() calls schedule_work() acquiring pool->lock
I believe this is because of Paul's rcutorture patch. I will debug it more and send a patch but all other tests scenarios are looking good.
--
Joel Fernandes
Frederic Weisbecker
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengQuoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]
Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
Thanks.
Signature · 2 lines
Frederic Weisbecker SUSE Labs
Joel Fernandes
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 20 lines · Frederic Weisbecker
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 8 lines
I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
Sure, but there is a valid point I think by those who say that "This was working before the RCU change". So in that sense, we ought to have this (possibly short-term fix).
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Frederic WeisbeckerQuoted 21 lines · Frederic Weisbecker
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 8 lines
I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
You all are still missing that rcu_tasks_trace was developed exclusively for bpf with bpf requirements.
Then srcu_fast was introduced and then it looked like that task_trace can be replaced with srcu_fast and that's where the problems discovered. So either task_trace need to be resurrected
or srcu_fast needs to be fixed.
Let's punt to bpf subsystem isn't an option.
At this rate we will have rcu_bpf. Which rcu_tasks_trace effectively was.
Boqun Feng
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 26 lines · Alexei Starovoitov
Quoted 25 lines · Frederic Weisbecker
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
Quoted 7 lines
Quoted 4 lines
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
You all are still missing that
rcu_tasks_tracewas developed exclusively for bpf with bpf requirements.
I'm missing this for sure. But what would be a better design?
BPF is also calling normal RCU (via call_rcu()) as well, and I don't think we can say normal call_rcu() was designed exclusively for BPF. Plus BPF heavily uses irq_work to avoid deadlocks but irq_work_queue() itself has a tracepoint in it (trace_ipi_send_cpu()), so in theory you could hit a deadlock there too.
Quoted 5 lines
Then
srcu_fastwas introduced and then it looked like thattask_tracecan be replaced withsrcu_fastand that's where the problems discovered. So eithertask_traceneed to be resurrected
orsrcu_fastneeds to be fixed.
Let's punt to bpf subsystem isn't an option.
I don't think we are suggesting that, i.e. "BPF should fix its own issue", at least myself was hoping that we can redesign the APIs that BPF relies on and make it clear that it's for BPF and we can in theory avoid all the deadlocks (we will probably have to make some primitives non-traceable) and BPF can use it combined with other general synchronization primitives.
The current approach seems to me that we just whack-a-mole when an issue happens, and it's not a systematic solution.
(It doesn't have to be a problem, it could be an opportunity ;-))
Regards,
Boqun
Quoted 1 line
At this rate we will have
rcu_bpf. Whichrcu_tasks_traceeffectively was.
Joel Fernandes
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 56 lines · Boqun Feng
Quoted 26 lines · Alexei Starovoitov
Quoted 25 lines · Frederic Weisbecker
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
Quoted 7 lines
Quoted 4 lines
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
You all are still missing that
rcu_tasks_tracewas developed exclusively for bpf with bpf requirements.I'm missing this for sure. But what would be a better design?
BPF is also calling normal RCU (via
call_rcu()) as well, and I don't think we can say normalcall_rcu()was designed exclusively for BPF. Plus BPF heavily usesirq_workto avoid deadlocks butirq_work_queue()itself has a tracepoint in it (trace_ipi_send_cpu()), so in theory you could hit a deadlock there too.Quoted 5 lines
Then
srcu_fastwas introduced and then it looked like thattask_tracecan be replaced withsrcu_fastand that's where the problems discovered. So eithertask_traceneed to be resurrected
orsrcu_fastneeds to be fixed.
Let's punt to bpf subsystem isn't an option.I don't think we are suggesting that, i.e. "BPF should fix its own issue", at least myself was hoping that we can redesign the APIs that BPF relies on and make it clear that it's for BPF and we can in theory avoid all the deadlocks (we will probably have to make some primitives non-traceable) and BPF can use it combined with other general synchronization primitives.
Quoted 4 lines
The current approach seems to me that we just whack-a-mole when an issue happens, and it's not a systematic solution.
(It doesn't have to be a problem, it could be an opportunity ;-))
The advantage of the "whack-a-mole" approach is perhaps totally benign BPF usecases (non-tracing related even) where not using irq_work might be just ok seems to be a win (no self-IPIs pointless, other irq_work overhead, low latency). Probably for the best trade-offs, we need to probably deal with it on a case-by-case basis that irq-work'ing everything randomly (?). That said, I'm not seeing like 20 reports or something of this so perhaps for now "case by case" is winning.
One argument could be BPF is supposed to be SAFE so anything it does like map operations that relies on kernel APIs that take locks etc, should be probably be done with a lot of care and extra precautions... simply because you can insert a BPF program at any tracepoint.
Not sure where the line is, BPF is kind of an interesting usecase as in it wants to be powerful (run in kernel context) but also be safe/verified at the same time.
my 2 c, thanks,
--
Joel Fernandes
Paul E. McKenney
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengQuoted 35 lines · Boqun Feng
Quoted 26 lines · Alexei Starovoitov
Quoted 25 lines · Frederic Weisbecker
Quoted 11 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>I have the feeling that this problem should be solved at the BPF level. Tracepoints can fire at any time, in that sense they are like NMIs, and NMIs shouldn't acquire locks, let alone call call_rcu_*()
Quoted 7 lines
Quoted 4 lines
BPF should arrange for delaying such operations to more appropriate contexts.
I understand this is a regression trigerred by an RCU change but to me it rather reveals a hidden design issue rather than an API breakage.
You all are still missing that
rcu_tasks_tracewas developed exclusively for bpf with bpf requirements.
Quoted 7 lines
I'm missing this for sure. But what would be a better design?
BPF is also calling normal RCU (via
call_rcu()) as well, and I don't think we can say normalcall_rcu()was designed exclusively for BPF. Plus BPF heavily usesirq_workto avoid deadlocks butirq_work_queue()itself has a tracepoint in it (trace_ipi_send_cpu()), so in theory you could hit a deadlock there too.
My fault, I should have seen this one coming. But here I am.
Quoted 13 lines
Quoted 5 lines
Then
srcu_fastwas introduced and then it looked like thattask_tracecan be replaced withsrcu_fastand that's where the problems discovered. So eithertask_traceneed to be resurrected
orsrcu_fastneeds to be fixed.
Let's punt to bpf subsystem isn't an option.I don't think we are suggesting that, i.e. "BPF should fix its own issue", at least myself was hoping that we can redesign the APIs that BPF relies on and make it clear that it's for BPF and we can in theory avoid all the deadlocks (we will probably have to make some primitives non-traceable) and BPF can use it combined with other general synchronization primitives.
Quoted 4 lines
The current approach seems to me that we just whack-a-mole when an issue happens, and it's not a systematic solution.
(It doesn't have to be a problem, it could be an opportunity ;-))
I am hoping that we don't have too many more moles to whack. Famous last words... ;-)
Thanx, Paul
Quoted 4 lines
Regards,
BoqunQuoted 1 line
At this rate we will have
rcu_bpf. Whichrcu_tasks_traceeffectively was.
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengThis patch was applied to netdev/net.git (main) by Boqun Feng <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Boqun Feng <[email protected]>:
Quoted 9 lines · On Fri, 20 Mar 2026 15:29:16 -0700 you wrote:
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[...]
Here is the summary with links:
- [v2] rcu: Use an intermediate irq_work to start process_srcu()
https://git.kernel.org/netdev/net/c/7c405fb3279b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengQuoting Boqun Feng (2026-03-20 23:29:16)
Quoted 11 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]
Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Thanks for the patch, which is now upstream as7c405fb3279b ("rcu: Use an intermediate irq_work to start process_srcu()")
Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
https://esmil.dk/d1-7.0.txt
https://esmil.dk/d1-7.1.txt
Reverting this patch seems to fix the issue although it then breaks when loading modules which is can be fixed by reverting:d6e152d905bd ("clockevents: Prevent timer interrupt starvation")
This might be a side-effect of reverting this patch though.
We'd really like to continue support for this SoC on the 7.0 kernel, but since this patch is a bugfix just shippping the revert doesn't sound appealing. So some guidance would be much appreciated, thanks!
/Emil
Boqun Feng
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 20 lines · Emil Renner Berthing
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 11 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Quoted 7 lines
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18
I will guess for some reasons the irq_work was missed or the IPI never happened. Is it possible for you to enable trace points ipi_send_cpu and ipi_entry to get more information?
Quoted 6 lines
Reverting this patch seems to fix the issue although it then breaks when loading modules which is can be fixed by reverting:
d6e152d905bd("clockevents: Prevent timer interrupt starvation")This might be a side-effect of reverting this patch though.
I'm not so sure about this, i.e. you might have *two* problems :(
Regards,
Boqun
Quoted 5 lines
We'd really like to continue support for this SoC on the 7.0 kernel, but since this patch is a bugfix just shippping the revert doesn't sound appealing. So some guidance would be much appreciated, thanks!
/Emil
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?
I have to admit I've not used tracepoints before, but it seems like only ipi_send_cpu and ipi_send_cpumask is available on RISC-V.
I've now added trace_event=ipi:* and tp_printk to the command line, and this is what I get:
https://esmil.dk/d1-7.0-2.txt
Let me know if there is something I'm missing or something else I can do to help find the bug.
/Emil
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 2 lines · Emil Renner Berthing
Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
I can confirm boot failures on Allwinner D1 (Lichee RV Dock) starting from v7.1-rc1. My bisect points to:
ff1c0c5d07028 ("Merge branch 'timers/urgent' into timers/core")
[1] https://lore.kernel.org/linux-riscv/CA+fTLhgLmTY+exGujKf8OYYQvcEW5X5NJ_5sLq2AYL6zER2c0A@mail.gmail.com/
[2] https://lore.kernel.org/regressions/[email protected]/
Best regards,
Indrek
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Boqun Feng
maintainerRe: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Emil Renner BerthingQuoted 61 lines · Emil Renner Berthing
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18
Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and this
Thank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txt
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58
Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
The ipi_send_cpu message means RCU was able to send an IPI, now if there is no ipi_handler between the send and the hung task, that would mean the IPI was missed.
Regards,
Boqun
Quoted 4 lines
Let me know if there is something I'm missing or something else I can do to help find the bug.
/Emil
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoting Boqun Feng (2026-06-22 17:38:10)
Quoted 77 lines · Emil Renner Berthing
Quoted 61 lines
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and thisThank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txt
Quoted 6 lines
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
Yes, sorry for not being clear about that. This is the exact same binary booted without the two extra command line parametrs:
https://esmil.dk/d1-7.0-3.txt
But with the two parameters added the board reboots before getting to the hung task messages. The bootloader enables the watchdog, so I think what happens is that the kernel halts earlier with the tracepoints enabled, and doesn't get to load the watchdog driver to keep the machine from rebooting.
The same happens with just trace_event=ipi:* added, just without the last message above.
Quoted 12 lines
The
ipi_send_cpumessage means RCU was able to send an IPI, now if there is noipi_handlerbetween the send and the hung task, that would mean the IPI was missed.Regards,
BoqunQuoted 4 lines
Let me know if there is something I'm missing or something else I can do to help find the bug.
/Emil
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Hi Emil,
Quoted 89 lines · Emil Renner Berthing
Quoting Boqun Feng (2026-06-22 17:38:10)
Quoted 77 lines · Emil Renner Berthing
Quoted 61 lines
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and thisThank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txtQuoted 6 lines
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
Yes, sorry for not being clear about that. This is the exact same binary booted without the two extra command line parametrs:
https://esmil.dk/d1-7.0-3.txt
Quoted 12 lines
But with the two parameters added the board reboots before getting to the hung task messages. The bootloader enables the watchdog, so I think what happens is that the kernel halts earlier with the tracepoints enabled, and doesn't get to load the watchdog driver to keep the machine from rebooting.
The same happens with just trace_event=ipi:* added, just without the last message above.
Quoted 4 lines
The
ipi_send_cpumessage means RCU was able to send an IPI, now if there is noipi_handlerbetween the send and the hung task, that would mean the IPI was missed.
Assuming that your OpenSBI version is exactly v1.3 per the boot log, and not "v1.3 + patches", then you would indeed not be receiving IPIs. You need at least this commit: https://github.com/riscv-software-src/opensbi/commit/446fa65eb579
(included in v1.4) or alternatively to add the CLINT to the M-mode devicetree.
Regards,
Samuel
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoting Samuel Holland (2026-06-23 17:53:19)
Quoted 101 lines
Hi Emil,
Quoted 98 lines · Emil Renner Berthing
Quoting Boqun Feng (2026-06-22 17:38:10)
Quoted 77 lines · Emil Renner Berthing
Quoted 61 lines
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and thisThank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txtQuoted 6 lines
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
Yes, sorry for not being clear about that. This is the exact same binary booted without the two extra command line parametrs:
https://esmil.dk/d1-7.0-3.txtBut with the two parameters added the board reboots before getting to the hung task messages. The bootloader enables the watchdog, so I think what happens is that the kernel halts earlier with the tracepoints enabled, and doesn't get to load the watchdog driver to keep the machine from rebooting.
The same happens with just trace_event=ipi:* added, just without the last message above.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
The
ipi_send_cpumessage means RCU was able to send an IPI, now if there is noipi_handlerbetween the send and the hung task, that would mean the IPI was missed.Assuming that your OpenSBI version is exactly v1.3 per the boot log, and not "v1.3 + patches", then you would indeed not be receiving IPIs. You need at least this commit: https://github.com/riscv-software-src/opensbi/commit/446fa65eb579
(included in v1.4) or alternatively to add the CLINT to the M-mode devicetree.
So then we're in a situation similar to [1], where upgrading the kernel from 6.19 to 7.0 requires you to update the firmware first. To me and from the thread that seems like a really obvious regression. So the question is, how can we make the current kernel work like < 7.0 kernels worked?
[1]: https://lore.kernel.org/all/87jzgjnh9z.ffs@tglx/#t
/Emil
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 104 lines · Emil Renner Berthing
Quoting Samuel Holland (2026-06-23 17:53:19)
Quoted 103 lines · Emil Renner Berthing
Quoted 101 lines
Quoting Boqun Feng (2026-06-22 17:38:10)
Quoted 77 lines · Emil Renner Berthing
Quoted 61 lines
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and thisThank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txtQuoted 6 lines
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
Yes, sorry for not being clear about that. This is the exact same binary booted without the two extra command line parametrs:
https://esmil.dk/d1-7.0-3.txtBut with the two parameters added the board reboots before getting to the hung task messages. The bootloader enables the watchdog, so I think what happens is that the kernel halts earlier with the tracepoints enabled, and doesn't get to load the watchdog driver to keep the machine from rebooting.
The same happens with just trace_event=ipi:* added, just without the last message above.
Quoted 4 lines
The
ipi_send_cpumessage means RCU was able to send an IPI, now if there is noipi_handlerbetween the send and the hung task, that would mean the IPI was missed.
Quoted 7 lines
Quoted 4 lines
Assuming that your OpenSBI version is exactly v1.3 per the boot log, and not "v1.3 + patches", then you would indeed not be receiving IPIs. You need at least this commit: https://github.com/riscv-software-src/opensbi/commit/446fa65eb579
(included in v1.4) or alternatively to add the CLINT to the M-mode devicetree.So then we're in a situation similar to [1], where upgrading the kernel from 6.19 to 7.0 requires you to update the firmware first.
Which normally should never happen to ensure users feel save to update the kernel. But I wonder if that is relevant, as Indrek Kruusa reported problems with that board, too -- and there is a fix that fixes it:
https://lore.kernel.org/linux-riscv/[email protected]/
Does that maybe fix your problem, too (even if it was bisected to a different commit, it might be related somehow, that's why I'm asking)?
Ciao, Thorsten
Quoted 5 lines
To me and from the thread
that seems like a really obvious regression. So the question is, how can we make the current kernel work like < 7.0 kernels worked?
Re: [PATCH v2] rcu: Use an intermediate irq_work to start process_srcu()
Kontakt Thorsten Leemhuis (<[email protected]>) kirjutas kuupäeval E, 6. juuli 2026 kell 14:33:
Quoted 119 lines · Emil Renner Berthing
Quoted 104 lines
Quoting Samuel Holland (2026-06-23 17:53:19)
Quoted 103 lines · Emil Renner Berthing
Quoted 101 lines
Quoting Boqun Feng (2026-06-22 17:38:10)
Quoted 77 lines · Emil Renner Berthing
Quoted 61 lines
Quoting Boqun Feng (2026-06-18 17:30:10)
Quoted 21 lines · Emil Renner Berthing
Quoted 20 lines
Quoting Boqun Feng (2026-03-20 23:29:16)
Quoted 18 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
[boqun: Apply Andrea's test feedback]Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Tested-by Andrea Righi <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 12 lines
Quoted 6 lines
Thanks for the patch, which is now upstream as
7c405fb3279b("rcu: Use an intermediateirq_workto startprocess_srcu()")Unfortunately it seems to halt booting on the Allwinner D1 single-core RISC-V SoC both on the 7.0 and 7.1 kernels:
By "single-core", is it only one CPU in that system?
Quoted 3 lines
Yes, the SoC only has one CPU core capable of running Linux at least.
Quoted 24 lines
From the callstack,
[ 243.002818] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ 243.010681] task:kworker/0:0 state:D stack:0 pid:9 tgid:9 ppid:2 task_flags:0x4208060 flags:0x00000000 [ 243.021858] Workqueue: device_link_wq device_link_release_fn [ 243.027587] Call Trace: [ 243.030079] [<ffffffff80745b66>] __schedule+0x232/0x530 [ 243.035365] [<ffffffff80745e82>] schedule+0x1e/0x94 [ 243.040298] [<ffffffff8074aa7a>] schedule_timeout+0x6e/0xa8 [ 243.045929] [<ffffffff8004d6a0>] wakeup_preempt+0x8c/0x98 [ 243.051380] [<ffffffff80746aee>] wait_for_completion+0x3a/0xb0 [ 243.057267] [<ffffffff80087226>] __synchronize_srcu.part.0+0x4e/0x60 [ 243.063712] [<ffffffff80084414>] rcu_tasks_get_gp_data+0xc/0x10 [ 243.069699] [<ffffffff80490898>] device_link_release_fn+0x14/0x80 [ 243.075850] [<ffffffff8003dbd0>] process_one_work+0xf8/0x1c8 [ 243.081583] [<ffffffff8003e282>] worker_thread+0x11a/0x254 [ 243.087127] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.092755] [<ffffffff8003e164>] rescuer_thread+0x3a0/0x3a4 [ 243.098381] [<ffffffff8004499e>] kthread+0xbe/0xe4 [ 243.103231] [<ffffffff8001349e>] ret_from_fork_kernel+0x6/0xd0 [ 243.109127] [<ffffffff800517a8>] schedule_tail+0x8/0xac [ 243.114410] [<ffffffff800448dc>] kthreads_online_cpu+0x0/0x4 [ 243.120121] [<ffffffff8074be0a>] ret_from_fork_kernel_asm+0x12/0x18Quoted 7 lines
Quoted 3 lines
I will guess for some reasons the
irq_workwas missed or the IPI never happened. Is it possible for you to enable trace pointsipi_send_cpuandipi_entryto get more information?I have to admit I've not used tracepoints before, but it seems like only
ipi_send_cpuandipi_send_cpumaskis available on RISC-V.
I've now added trace_event=ipi:* andtp_printkto the command line, and thisThank you! Yeah, this is what I meant ;-)
Quoted 3 lines
is what I get:
https://esmil.dk/d1-7.0-2.txtQuoted 6 lines
[ 0.071132] rcu: Max phase no-delay instances is 1000. [ 0.077837] ipi_send_cpu: cpu=0 callsite=irq_work_queue+0x22/0x4c callback=srcu_irq_work+0x0/0x58Is this the last line you can see from your (serial?) console, or we are missing a few more lines? Maybe it'll should the same hung task messages?
Yes, sorry for not being clear about that. This is the exact same binary booted without the two extra command line parametrs:
https://esmil.dk/d1-7.0-3.txtBut with the two parameters added the board reboots before getting to the hung task messages. The bootloader enables the watchdog, so I think what happens is that the kernel halts earlier with the tracepoints enabled, and doesn't get to load the watchdog driver to keep the machine from rebooting.
The same happens with just trace_event=ipi:* added, just without the last message above.
Quoted 4 lines
The
ipi_send_cpumessage means RCU was able to send an IPI, now if there is noipi_handlerbetween the send and the hung task, that would mean the IPI was missed.Quoted 7 lines
Quoted 4 lines
Assuming that your OpenSBI version is exactly v1.3 per the boot log, and not "v1.3 + patches", then you would indeed not be receiving IPIs. You need at least this commit: https://github.com/riscv-software-src/opensbi/commit/446fa65eb579
(included in v1.4) or alternatively to add the CLINT to the M-mode devicetree.So then we're in a situation similar to [1], where upgrading the kernel from 6.19 to 7.0 requires you to update the firmware first.
Which normally should never happen to ensure users feel save to update the kernel. But I wonder if that is relevant, as Indrek Kruusa reported problems with that board, too -- and there is a fix that fixes it:
https://lore.kernel.org/linux-riscv/[email protected]/
Quoted 5 lines
Does that maybe fix your problem, too (even if it was bisected to a different commit, it might be related somehow, that's why I'm asking)?
Ciao, Thorsten
I tend to think we have two different situations here. I am using newer OpenSBI (v1.8) and an experimental u-boot based on newer v2026.07-rc1 [1].
So, my firmware is different, also the context Emil is pointing to is different.
Best regards,
Indrek
[1] https://github.com/ikruusa/u-boot/tree/v2026-07-rc1-thead-base-b1
Quoted 7 lines
Quoted 5 lines
To me and from the thread
that seems like a really obvious regression. So the question is, how can we make the current kernel work like < 7.0 kernels worked?
Zqiang
reviewerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengQuoted 17 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 3 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.
Thanks Boqun add me to Suggested-by :) .
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,
Quoted 59 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +5
-0@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,
The following should also be replaced, although under normal situation, we wouldn't go here:
if (snp == snp_leaf && snp_seq != s) {
srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0);
return;
}Thanks
Zqiang
Quoted 41 lines
kernel/rcu/srcutree.c +22
-2// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); + +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 21 lines · Zqiang
Quoted 17 lines
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 3 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.
Quoted 2 lines
Thanks Boqun add me to Suggested-by :) .
No problem.
Quoted 64 lines
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,
Quoted 59 lines
@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +5
-0@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,The following should also be replaced, although under normal situation, we wouldn't go here:
Quoted 5 lines
if (snp == snp_leaf && snp_seq != s) {
srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0);
return;
}Sigh, another mole to whack... this one is less fatal since we don't call it with rcu node lock:
raw_spin_unlock_irqrestore_rcu_node(snp, flags);
if (snp == snp_leaf && snp_seq != s) {
srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0);
return;
}but the operation is per srcu_data, so we may need per srcu_data (a hacky way is that we compare with rcu_tasks_trace_srcu_struct and have only one percpu irq_work for rcu_tasks_trace_srcu_struct).
Note that if we may the delay always >0, then we can dodge the pi->lock (or the pool->lock as we recently discovered). But we will still have a timer base lock in call_srcu(). Depending on whether it's considered as a bug per BPF (we have the issue in v6.19 as well, see [1]). If [1] is not considered as a bug, then I think we can just fix the issue by an always positive delay. Otherwise, bring your mallet, we may have more moles to whack. ;-)
[1]: https://lore.kernel.org/rcu/[email protected]/
Regards,
Boqun
Quoted 47 lines
Thanks
ZqiangQuoted 41 lines
kernel/rcu/srcutree.c +22
-2// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup); + +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
In reply to Boqun FengQuoted 8 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().
Quoted 8 lines
[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>
First, thank you all for putting this together!
If I enable both early boot RCU testing and lockdep, for example, by running the RUDE01 rcutorture scenario, I get the following splat, which suggests that the raw_spin_unlock_irq_rcu_node() in srcu_irq_work() might need help (see inline below):
[ 0.872594] ------------[ cut here ]------------ [ 0.873550] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) [ 0.873550] WARNING: kernel/locking/lockdep.c:4404 at lockdep_hardirqs_on_prepare+0x150/0x190, CPU#0: swapper/0/1 [ 0.873550] Modules linked in: [ 0.873550] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-00039-g35d354b6cd0f-dirty #8217 PREEMPT(full) [ 0.873550] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 [ 0.873550] RIP: 0010:lockdep_hardirqs_on_prepare+0x157/0x190 [ 0.873550] Code: 01 90 e8 ec c7 54 00 85 c0 74 0a 8b 35 12 c4 e0 01 85 f6 74 31 90 5d c3 cc cc cc cc 48 8d 3d 20 cf e1 01 48 c7 c6 ec c1 87 9f <67> 48 0f b9 3a eb ac 48 8d 3d 1b cf e1 01 48 c7 c6 87 be 87 9f 67 [ 0.873550] RSP: 0000:ffff9ff3c0003f50 EFLAGS: 00010046 [ 0.873550] RAX: 0000000000000001 RBX: ffffffff9fb608f8 RCX: 0000000000000001 [ 0.873550] RDX: 0000000000000000 RSI: ffffffff9f87c1ec RDI: ffffffff9fd44120 [ 0.873550] RBP: ffffffff9f00bae3 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000 [ 0.873550] R13: ffff9e1bc11e4bc0 R14: 0000000000000000 R15: 0000000000000000 [ 0.873550] FS: 0000000000000000(0000) GS:ffff9e1c3ed9b000(0000) knlGS:0000000000000000 [ 0.873550] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.873550] CR2: ffff9e1bcf3d8000 CR3: 000000000dc4e000 CR4: 00000000000006f0 [ 0.873550] Call Trace: [ 0.873550] <IRQ> [ 0.873550] ? _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] trace_hardirqs_on+0x16/0xe0 [ 0.873550] _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] srcu_irq_work+0x5e/0x90 [ 0.873550] irq_work_single+0x42/0x90 [ 0.873550] irq_work_run_list+0x26/0x40 [ 0.873550] irq_work_run+0x18/0x30 [ 0.873550] __sysvec_irq_work+0x30/0x180 [ 0.873550] sysvec_irq_work+0x6a/0x80 [ 0.873550] </IRQ> [ 0.873550] <TASK> [ 0.873550] asm_sysvec_irq_work+0x1a/0x20 [ 0.873550] RIP: 0010:_raw_spin_unlock_irqrestore+0x34/0x50 [ 0.873550] Code: c7 18 53 48 89 f3 48 8b 74 24 10 e8 06 d4 f1 fe 48 89 ef e8 2e 0c f2 fe 80 e7 02 74 06 e8 74 86 01 ff fb 65 ff 0d ec d4 66 01 <74> 07 5b 5d e9 53 1b 00 00 e8 5e 94 df fe 5b 5d e9 47 1b 00 00 0f [ 0.873550] RSP: 0000:ffff9ff3c0013d50 EFLAGS: 00000286 [ 0.873550] RAX: 0000000000001417 RBX: 0000000000000297 RCX: 0000000000000000 [ 0.873550] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff9f00bb3c [ 0.873550] RBP: ffffffff9fb60630 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000001 R12: fffffffffffffe74 [ 0.873550] R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001 [ 0.873550] ? _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] srcu_gp_start_if_needed+0x354/0x530 [ 0.873550] __synchronize_srcu+0xd1/0x180 [ 0.873550] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.873550] ? synchronize_srcu+0x3f/0x170 [ 0.873550] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.873550] rcu_init_tasks_generic+0x10c/0x130 [ 0.873550] do_one_initcall+0x59/0x2e0 [ 0.873550] ? _printk+0x56/0x70 [ 0.873550] kernel_init_freeable+0x227/0x440 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] kernel_init+0x15/0x1c0 [ 0.873550] ret_from_fork+0x2ac/0x330 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] ret_from_fork_asm+0x1a/0x30 [ 0.873550] </TASK> [ 0.873550] irq event stamp: 5144 [ 0.873550] hardirqs last enabled at (5143): [<ffffffff9f00bb3c>] _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] hardirqs last disabled at (5144): [<ffffffff9eff7c9f>] sysvec_irq_work+0xf/0x80 [ 0.873550] softirqs last enabled at (5132): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] softirqs last disabled at (5127): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] ---[ end trace 0000000000000000 ]--- [ 0.873574] ------------[ cut here ]------------
Quoted 83 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +13
-2@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{
kernel/rcu/srcutree.c static void process_srcu(struct work_struct *work) · line 2002
Quoted 10 lines
kernel/rcu/srcutree.c +10
-0+struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup);
Removing the "_irq" from both avoids the lockdep splat in my test setup, which makes sense given that interrupts are disabled in irq_work handlers. Or at least it looks to me that they are. ;-)
Like this:
+ raw_spin_lock_rcu_node(ssp->srcu_sup);
+ delay = srcu_get_delay(ssp);
+ raw_spin_unlock_rcu_node(ssp->srcu_sup);
Thanx, Paul
Quoted 10 lines
kernel/rcu/srcutree.c +4
-0+ +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 18 lines · Paul E. McKenney
Quoted 8 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().Quoted 8 lines
[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>
Quoted 6 lines
First, thank you all for putting this together!
If I enable both early boot RCU testing and lockdep, for example, by running the RUDE01 rcutorture scenario, I get the following splat, which suggests that the
raw_spin_unlock_irq_rcu_node()insrcu_irq_work()might need help (see inline below):
Yes, Andrea reported a similar issue:
https://lore.kernel.org/rcu/ab2yd35rm6OgZUmb@gpd4/
Quoted 164 lines
[ 0.872594] ------------[ cut here ]------------ [ 0.873550] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) [ 0.873550] WARNING: kernel/locking/lockdep.c:4404 at lockdep_hardirqs_on_prepare+0x150/0x190, CPU#0: swapper/0/1 [ 0.873550] Modules linked in: [ 0.873550] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-00039-g35d354b6cd0f-dirty #8217 PREEMPT(full) [ 0.873550] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 [ 0.873550] RIP: 0010:lockdep_hardirqs_on_prepare+0x157/0x190 [ 0.873550] Code: 01 90 e8 ec c7 54 00 85 c0 74 0a 8b 35 12 c4 e0 01 85 f6 74 31 90 5d c3 cc cc cc cc 48 8d 3d 20 cf e1 01 48 c7 c6 ec c1 87 9f <67> 48 0f b9 3a eb ac 48 8d 3d 1b cf e1 01 48 c7 c6 87 be 87 9f 67 [ 0.873550] RSP: 0000:ffff9ff3c0003f50 EFLAGS: 00010046 [ 0.873550] RAX: 0000000000000001 RBX: ffffffff9fb608f8 RCX: 0000000000000001 [ 0.873550] RDX: 0000000000000000 RSI: ffffffff9f87c1ec RDI: ffffffff9fd44120 [ 0.873550] RBP: ffffffff9f00bae3 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000 [ 0.873550] R13: ffff9e1bc11e4bc0 R14: 0000000000000000 R15: 0000000000000000 [ 0.873550] FS: 0000000000000000(0000) GS:ffff9e1c3ed9b000(0000) knlGS:0000000000000000 [ 0.873550] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.873550] CR2: ffff9e1bcf3d8000 CR3: 000000000dc4e000 CR4: 00000000000006f0 [ 0.873550] Call Trace: [ 0.873550] <IRQ> [ 0.873550] ? _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] trace_hardirqs_on+0x16/0xe0 [ 0.873550] _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] srcu_irq_work+0x5e/0x90 [ 0.873550] irq_work_single+0x42/0x90 [ 0.873550] irq_work_run_list+0x26/0x40 [ 0.873550] irq_work_run+0x18/0x30 [ 0.873550] __sysvec_irq_work+0x30/0x180 [ 0.873550] sysvec_irq_work+0x6a/0x80 [ 0.873550] </IRQ> [ 0.873550] <TASK> [ 0.873550] asm_sysvec_irq_work+0x1a/0x20 [ 0.873550] RIP: 0010:_raw_spin_unlock_irqrestore+0x34/0x50 [ 0.873550] Code: c7 18 53 48 89 f3 48 8b 74 24 10 e8 06 d4 f1 fe 48 89 ef e8 2e 0c f2 fe 80 e7 02 74 06 e8 74 86 01 ff fb 65 ff 0d ec d4 66 01 <74> 07 5b 5d e9 53 1b 00 00 e8 5e 94 df fe 5b 5d e9 47 1b 00 00 0f [ 0.873550] RSP: 0000:ffff9ff3c0013d50 EFLAGS: 00000286 [ 0.873550] RAX: 0000000000001417 RBX: 0000000000000297 RCX: 0000000000000000 [ 0.873550] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff9f00bb3c [ 0.873550] RBP: ffffffff9fb60630 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000001 R12: fffffffffffffe74 [ 0.873550] R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001 [ 0.873550] ? _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] srcu_gp_start_if_needed+0x354/0x530 [ 0.873550] __synchronize_srcu+0xd1/0x180 [ 0.873550] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.873550] ? synchronize_srcu+0x3f/0x170 [ 0.873550] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.873550] rcu_init_tasks_generic+0x10c/0x130 [ 0.873550] do_one_initcall+0x59/0x2e0 [ 0.873550] ? _printk+0x56/0x70 [ 0.873550] kernel_init_freeable+0x227/0x440 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] kernel_init+0x15/0x1c0 [ 0.873550] ret_from_fork+0x2ac/0x330 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] ret_from_fork_asm+0x1a/0x30 [ 0.873550] </TASK> [ 0.873550] irq event stamp: 5144 [ 0.873550] hardirqs last enabled at (5143): [<ffffffff9f00bb3c>] _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] hardirqs last disabled at (5144): [<ffffffff9eff7c9f>] sysvec_irq_work+0xf/0x80 [ 0.873550] softirqs last enabled at (5132): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] softirqs last disabled at (5127): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] ---[ end trace 0000000000000000 ]--- [ 0.873574] ------------[ cut here ]------------Quoted 83 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +13
-2@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{kernel/rcu/srcutree.c static void process_srcu(struct work_struct *work) · line 2002
Quoted 10 lines
kernel/rcu/srcutree.c +10
-0+struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup);Removing the "
_irq" from both avoids the lockdep splat in my test setup, which makes sense given that interrupts are disabled inirq_workhandlers. Or at least it looks to me that they are. ;-)Like this:
Review
Quoted 3 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);
It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/
I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Thanks for the testing and feedback.
Regards,
Boqun
Quoted 12 lines
Thanx, Paul
Quoted 10 lines
kernel/rcu/srcutree.c +4
-0+ +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 200 lines · Boqun Feng
Quoted 18 lines · Paul E. McKenney
Quoted 8 lines · Boqun Feng
Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().Quoted 8 lines
[boqun: Apply Joel's feedback]
Reported-by Andrea Righi <[email protected]>Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Suggested-by Zqiang <[email protected]>Signed-off-by Boqun Feng <[email protected]>Quoted 6 lines
First, thank you all for putting this together!
If I enable both early boot RCU testing and lockdep, for example, by running the RUDE01 rcutorture scenario, I get the following splat, which suggests that the
raw_spin_unlock_irq_rcu_node()insrcu_irq_work()might need help (see inline below):Yes, Andrea reported a similar issue:
https://lore.kernel.org/rcu/ab2yd35rm6OgZUmb@gpd4/Quoted 164 lines
[ 0.872594] ------------[ cut here ]------------ [ 0.873550] DEBUG_LOCKS_WARN_ON(lockdep_hardirq_context()) [ 0.873550] WARNING: kernel/locking/lockdep.c:4404 at lockdep_hardirqs_on_prepare+0x150/0x190, CPU#0: swapper/0/1 [ 0.873550] Modules linked in: [ 0.873550] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-00039-g35d354b6cd0f-dirty #8217 PREEMPT(full) [ 0.873550] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014 [ 0.873550] RIP: 0010:lockdep_hardirqs_on_prepare+0x157/0x190 [ 0.873550] Code: 01 90 e8 ec c7 54 00 85 c0 74 0a 8b 35 12 c4 e0 01 85 f6 74 31 90 5d c3 cc cc cc cc 48 8d 3d 20 cf e1 01 48 c7 c6 ec c1 87 9f <67> 48 0f b9 3a eb ac 48 8d 3d 1b cf e1 01 48 c7 c6 87 be 87 9f 67 [ 0.873550] RSP: 0000:ffff9ff3c0003f50 EFLAGS: 00010046 [ 0.873550] RAX: 0000000000000001 RBX: ffffffff9fb608f8 RCX: 0000000000000001 [ 0.873550] RDX: 0000000000000000 RSI: ffffffff9f87c1ec RDI: ffffffff9fd44120 [ 0.873550] RBP: ffffffff9f00bae3 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000000000 [ 0.873550] R13: ffff9e1bc11e4bc0 R14: 0000000000000000 R15: 0000000000000000 [ 0.873550] FS: 0000000000000000(0000) GS:ffff9e1c3ed9b000(0000) knlGS:0000000000000000 [ 0.873550] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.873550] CR2: ffff9e1bcf3d8000 CR3: 000000000dc4e000 CR4: 00000000000006f0 [ 0.873550] Call Trace: [ 0.873550] <IRQ> [ 0.873550] ? _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] trace_hardirqs_on+0x16/0xe0 [ 0.873550] _raw_spin_unlock_irq+0x23/0x40 [ 0.873550] srcu_irq_work+0x5e/0x90 [ 0.873550] irq_work_single+0x42/0x90 [ 0.873550] irq_work_run_list+0x26/0x40 [ 0.873550] irq_work_run+0x18/0x30 [ 0.873550] __sysvec_irq_work+0x30/0x180 [ 0.873550] sysvec_irq_work+0x6a/0x80 [ 0.873550] </IRQ> [ 0.873550] <TASK> [ 0.873550] asm_sysvec_irq_work+0x1a/0x20 [ 0.873550] RIP: 0010:_raw_spin_unlock_irqrestore+0x34/0x50 [ 0.873550] Code: c7 18 53 48 89 f3 48 8b 74 24 10 e8 06 d4 f1 fe 48 89 ef e8 2e 0c f2 fe 80 e7 02 74 06 e8 74 86 01 ff fb 65 ff 0d ec d4 66 01 <74> 07 5b 5d e9 53 1b 00 00 e8 5e 94 df fe 5b 5d e9 47 1b 00 00 0f [ 0.873550] RSP: 0000:ffff9ff3c0013d50 EFLAGS: 00000286 [ 0.873550] RAX: 0000000000001417 RBX: 0000000000000297 RCX: 0000000000000000 [ 0.873550] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffff9f00bb3c [ 0.873550] RBP: ffffffff9fb60630 R08: 0000000000000001 R09: 0000000000000000 [ 0.873550] R10: 0000000000000001 R11: 0000000000000001 R12: fffffffffffffe74 [ 0.873550] R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000001 [ 0.873550] ? _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] srcu_gp_start_if_needed+0x354/0x530 [ 0.873550] __synchronize_srcu+0xd1/0x180 [ 0.873550] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.873550] ? synchronize_srcu+0x3f/0x170 [ 0.873550] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.873550] rcu_init_tasks_generic+0x10c/0x130 [ 0.873550] do_one_initcall+0x59/0x2e0 [ 0.873550] ? _printk+0x56/0x70 [ 0.873550] kernel_init_freeable+0x227/0x440 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] kernel_init+0x15/0x1c0 [ 0.873550] ret_from_fork+0x2ac/0x330 [ 0.873550] ? __pfx_kernel_init+0x10/0x10 [ 0.873550] ret_from_fork_asm+0x1a/0x30 [ 0.873550] </TASK> [ 0.873550] irq event stamp: 5144 [ 0.873550] hardirqs last enabled at (5143): [<ffffffff9f00bb3c>] _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.873550] hardirqs last disabled at (5144): [<ffffffff9eff7c9f>] sysvec_irq_work+0xf/0x80 [ 0.873550] softirqs last enabled at (5132): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] softirqs last disabled at (5127): [<ffffffff9dea2501>] __irq_exit_rcu+0xa1/0xc0 [ 0.873550] ---[ end trace 0000000000000000 ]--- [ 0.873574] ------------[ cut here ]------------Quoted 83 lines
---
@Zqiang, I put your name as Suggested-by because you proposed the same idea, let me know if you rather not have it.@Joel, I did two updates (including your test feedback, other one is call
irq_work_sync()when we clean thesrcu_struct), please give it a try.include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +13
-2@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -713,6 +716,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)return ;/* Just leak it! */ if (WARN_ON (srcu_readers_active (ssp)))return ;/* Just leak it! */ +/* Wait for irq_work to finish first as it may queue a new work. */ +irq_work_sync (&sup->irq_work);flush_delayed_work (&sup->work);for_each_possible_cpu (cpu) {struct srcu_data *sdp =per_cpu_ptr (ssp->sda, cpu);@@ -1118,9 +1123,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1988,22 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{kernel/rcu/srcutree.c static void process_srcu(struct work_struct *work) · line 2002
Quoted 10 lines
kernel/rcu/srcutree.c +10
-0+struct srcu_struct *ssp; +struct srcu_usage *sup; +unsigned long delay; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +raw_spin_lock_irq_rcu_node (ssp->srcu_sup); + delay =srcu_get_delay (ssp); +raw_spin_unlock_irq_rcu_node (ssp->srcu_sup);Removing the "
_irq" from both avoids the lockdep splat in my test setup, which makes sense given that interrupts are disabled inirq_workhandlers. Or at least it looks to me that they are. ;-)Like this:
Review
Quoted 3 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
Quoted 6 lines
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
Thanx, Paul
Quoted 15 lines
Regards,
BoqunQuoted 12 lines
Thanx, Paul
Quoted 10 lines
kernel/rcu/srcutree.c +4
-0+ +queue_delayed_work (rcu_gp_wq, &sup->work, !!delay); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]
Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/
We have a queue_work_on() in srcu_schedule_cbs_sdp(), so
srcu_torture_deferred_free():
raw_spin_lock_irqsave(->pi_lock,...);
call_srcu():
if (snp == snp_leaf && snp_seq != s) {
srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0):
if (!delay)
queue_work_on(...)I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per srcu_data work ;-) NR_CPUS x irq_work incoming.
Regards,
Boqun
Quoted 2 lines
Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)
Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.
Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Thanx, Paul
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 39 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)
Quoted 7 lines
Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
I see, there is a schedule_work() in srcutiny's srcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?
Regards,
Boqun
Quoted 1 line
Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 44 lines · Boqun Feng
Quoted 43 lines · Paul E. McKenney
Quoted 41 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.
Quoted 7 lines
Quoted 2 lines
Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?
Like this, you mean? I will give it a shot tomorrow.
Thanx, Paul
------------------------------------------------------------------------
kernel/rcu/rcutorture.c +1 -1
@@ -843,7 +843,7 @@ static unsigned long srcu_torture_completed(void)static void srcu_torture_deferred_free (struct rcu_torture *rp) {unsigned long flags; -bool lockit = jiffies &0x1 ; +bool lockit =IS_ENABLED (CONFIG_SMP ) && (jiffies &0x1 );if (lockit)raw_spin_lock_irqsave (¤t->pi_lock, flags);
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 7 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
Regards,
Boqun
Quoted 17 lines
Thanx, Paul
------------------------------------------------------------------------
kernel/rcu/rcutorture.c +1
-1@@ -843,7 +843,7 @@ static unsigned long srcu_torture_completed(void)static void srcu_torture_deferred_free (struct rcu_torture *rp) {unsigned long flags; -bool lockit = jiffies &0x1 ; +bool lockit =IS_ENABLED (CONFIG_SMP ) && (jiffies &0x1 );if (lockit)raw_spin_lock_irqsave (¤t->pi_lock, flags);
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 49 lines · Boqun Feng
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
OK, the previous patch did fine on short rcutorture testing aside from the !SMP lockdep splat, so I have started the test without pi_lock.
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Thanx, Paul
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 62 lines · Paul E. McKenney
Quoted 49 lines · Boqun Feng
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
OK, the previous patch did fine on short rcutorture testing aside from the !SMP lockdep splat, so I have started the test without
pi_lock.
Quoted 8 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect PREEMPT_RT locking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.
Regards,
Boqun
Quoted 1 line
Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 71 lines · Boqun Feng
Quoted 62 lines · Paul E. McKenney
Quoted 49 lines · Boqun Feng
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
OK, the previous patch did fine on short rcutorture testing aside from the !SMP lockdep splat, so I have started the test without
pi_lock.Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.
But lockdep *does* know when it is running in a CONFIG_SMP=n kernel, correct? In which case all the code paths are UP-only.
The situation with CONFIG_PREEMPT_RT=y is quite different: The motivation was for people running lockdep on CONFIG_PREEMPT_RT=n kernels to detect and fix locking issues that would otherwise only show up in CONFIG_PREEMPT_RT=y kernels.
And of course, CONFIG_SMP=n kernels still need deadlock detection for mutexes and the like.
Thanx, Paul
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 72 lines · Paul E. McKenney
Quoted 71 lines · Boqun Feng
Quoted 69 lines · Paul E. McKenney
Quoted 49 lines · Boqun Feng
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
OK, the previous patch did fine on short rcutorture testing aside from the !SMP lockdep splat, so I have started the test without
pi_lock.Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 8 lines
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.
Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
Quoted 5 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.
I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
Regards,
Boqun
Quoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 78 lines · Boqun Feng
Quoted 77 lines · Paul E. McKenney
Quoted 75 lines · Boqun Feng
Quoted 62 lines · Paul E. McKenney
Quoted 49 lines · Boqun Feng
Quoted 48 lines · Paul E. McKenney
Quoted 47 lines · Boqun Feng
Quoted 45 lines · Paul E. McKenney
Quoted 38 lines · Boqun Feng
On Sat, Mar 21, 2026 at 10:41:47AM -0700, Paul E. McKenney wrote:
[...]Quoted 12 lines
Quoted 12 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ raw_spin_lock_rcu_node(ssp->srcu_sup); + delay = srcu_get_delay(ssp); + raw_spin_unlock_rcu_node(ssp->srcu_sup);It was fixed differently in v2:
https://lore.kernel.org/rcu/[email protected]/I used _irqsave/_irqrestore just in case. Given it's an urgent fix, overly careful code is probably fine ;-)
Quoted 8 lines
Quoted 1 line
Thanks for the testing and feedback.
OK, I will try that one, thank you!
FYI, with my change on your earlier version, SRCU-T got deadlocks between the pi-lock and the workqueue pool lock. Which might or might not be particularly urgent.
I just checked my run yesterday, I also hit it. It's probably what Zqiang has found:
https://lore.kernel.org/rcu/[email protected]/We have a
queue_work_on()insrcu_schedule_cbs_sdp(), sosrcu_torture_deferred_free(): raw_spin_lock_irqsave(->pi_lock,...); call_srcu(): if (snp == snp_leaf && snp_seq != s) { srcu_schedule_cbs_sdp(sdp, do_norm ? SRCU_INTERVAL : 0): if (!delay) queue_work_on(...)Quoted 3 lines
I was about to reply to Zqiang, fixing that could be a touch design decision. Since it's a per
srcu_datawork ;-)NR_CPUSxirq_workincoming.Just to be clear, SRCU-T is Tiny SRCU rather than Tree SRCU. So perhaps lower priority, though perhaps not lower irritation. ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I see, there is a
schedule_work()in srcutiny'ssrcu_gp_start_if_needed(). But it couldn't cause deadlock on UP since locks are (almost) no-op. Maybe we can make RCU torture only test it on SMP?Like this, you mean? I will give it a shot tomorrow.
Yes, thanks!
OK, the previous patch did fine on short rcutorture testing aside from the !SMP lockdep splat, so I have started the test without
pi_lock.Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.
Quoted 8 lines
Quoted 2 lines
But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
I know that this is what lockdep is doing. I am instead saying that what lockdep is doing is not a good thing. ;-)
Quoted 8 lines
Quoted 4 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
It is very different.
There were very few people developing and running PREEMPT_RT, so it was quite difficult for them to clean up the lock-context issues that everyone else was creating. Making lockdep check for PREEMPT_RT issues in !PREEMPT_RT kernels was therefore very helpful, at least to the PREEMPT_RT guys.
In contrast (and unlike 20 years ago), almost everyone runs SMP, so there is no harm in !SMP lockdep ignoring things that would be deadlocks in SMP kernels. The ample SMP lockdep testing will catch those issues, so there is no need for extra help from UP lockdep testing.
Thanx, Paul
Quoted 7 lines
Regards,
BoqunQuoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
On Sun, Mar 22, 2026 at 10:44:58AM -0700, Paul E. McKenney wrote:
[...]
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.
Quoted 9 lines
Quoted 5 lines
Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
I know that this is what lockdep is doing. I am instead saying that what lockdep is doing is not a good thing. ;-)
I see.
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
It is very different.
Quoted 7 lines
There were very few people developing and running
PREEMPT_RT, so it was quite difficult for them to clean up the lock-context issues that everyone else was creating. Making lockdep check forPREEMPT_RTissues in !PREEMPT_RT kernels was therefore very helpful, at least to thePREEMPT_RTguys.In contrast (and unlike 20 years ago), almost everyone runs SMP, so there
(It also means the people who cares UP is almost none ;-))
Quoted 4 lines
is no harm in !SMP lockdep ignoring things that would be deadlocks in SMP kernels. The ample SMP lockdep testing will catch those issues, so there is no need for extra help from UP lockdep testing.
Fair point. If anyone cares UP enough to submit a patch in lockdep, I'm happy to take a look.
Regards,
Boqun
Quoted 9 lines
Thanx, Paul
Quoted 7 lines
Regards,
BoqunQuoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Paul E. McKenney
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 46 lines · Boqun Feng
On Sun, Mar 22, 2026 at 10:44:58AM -0700, Paul E. McKenney wrote:
[...]Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.Quoted 8 lines
Quoted 5 lines
Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
I know that this is what lockdep is doing. I am instead saying that what lockdep is doing is not a good thing. ;-)
I see.
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
It is very different.
There were very few people developing and running
PREEMPT_RT, so it was quite difficult for them to clean up the lock-context issues that everyone else was creating. Making lockdep check forPREEMPT_RTissues in !PREEMPT_RT kernels was therefore very helpful, at least to thePREEMPT_RTguys.
Quoted 3 lines
Quoted 1 line
In contrast (and unlike 20 years ago), almost everyone runs SMP, so there
(It also means the people who cares UP is almost none ;-))
I don't know about that, given that the sets of people who run SMP and who care about UP are not necessarily disjoint. But those who care *only* about UP definitely are no longer the vast majority. ;-)
Quoted 6 lines
Quoted 3 lines
is no harm in !SMP lockdep ignoring things that would be deadlocks in SMP kernels. The ample SMP lockdep testing will catch those issues, so there is no need for extra help from UP lockdep testing.
Fair point. If anyone cares UP enough to submit a patch in lockdep, I'm happy to take a look.
Fair enough.
In other news, the SMP-check hack to rcutorture does suppress this lockdep issue, at least in my testing. But I applied that change to my -rcu tree, which reverted me back to v1 of your patch and re-introduced the earlier lockdep issue.
So I am restarting the tests.
Thanx, Paul
Quoted 12 lines
Regards,
BoqunQuoted 9 lines
Thanx, Paul
Quoted 7 lines
Regards,
BoqunQuoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Boqun Feng
maintainerRe: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 47 lines · Paul E. McKenney
Quoted 46 lines · Boqun Feng
On Sun, Mar 22, 2026 at 10:44:58AM -0700, Paul E. McKenney wrote:
[...]Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.Quoted 8 lines
Quoted 5 lines
Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
I know that this is what lockdep is doing. I am instead saying that what lockdep is doing is not a good thing. ;-)
I see.
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
It is very different.
There were very few people developing and running
PREEMPT_RT, so it was quite difficult for them to clean up the lock-context issues that everyone else was creating. Making lockdep check forPREEMPT_RTissues in !PREEMPT_RT kernels was therefore very helpful, at least to thePREEMPT_RTguys.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
In contrast (and unlike 20 years ago), almost everyone runs SMP, so there
(It also means the people who cares UP is almost none ;-))
I don't know about that, given that the sets of people who run SMP and who care about UP are not necessarily disjoint. But those who care *only* about UP definitely are no longer the vast majority. ;-)
You're right, I should have said "UP-only". And I *think* the reality is that most of the sub-systems share the code path between UP and SMP, and it works fine for them, because UP tests help them find SMP deadlock as well. That's probably why lockdep has been doing this "not a good thing" for a while.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
is no harm in !SMP lockdep ignoring things that would be deadlocks in SMP kernels. The ample SMP lockdep testing will catch those issues, so there is no need for extra help from UP lockdep testing.
Fair point. If anyone cares UP enough to submit a patch in lockdep, I'm happy to take a look.
Quoted 9 lines
Fair enough.
In other news, the SMP-check hack to rcutorture does suppress this lockdep issue, at least in my testing. But I applied that change to my -rcu tree, which reverted me back to v1 of your patch and re-introduced the earlier lockdep issue.
So I am restarting the tests.
Thank you!
Regards,
Boqun
Quoted 14 lines
Thanx, Paul
Quoted 12 lines
Regards,
BoqunQuoted 9 lines
Thanx, Paul
Quoted 7 lines
Regards,
BoqunQuoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Re: [PATCH] rcu: Use an intermediate irq_work to start process_srcu()
Quoted 56 lines · Boqun Feng
Quoted 47 lines · Paul E. McKenney
Quoted 46 lines · Boqun Feng
On Sun, Mar 22, 2026 at 10:44:58AM -0700, Paul E. McKenney wrote:
[...]Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Longer term, shouldn't lockdep take into account the fact that on !SMP, the disabling of preemption (or interrupts or...) is essentially the same as acquiring a global lock? This means that only one task at a time can be acquiring a raw spinlock on !SMP, so that the order of acquisition of raw spinlocks on !SMP is irrelevant? (Aside from self-deadlocking double acquisitions, perhaps.) In other words, shouldn't lockdep leave raw spinlocks out of lockdep's cycle-detection data structure?
Quoted 4 lines
Lockdep doesn't know whether a code path is UP-only, so it'll apply the general locking rule to check. Similar as lockdep still detect
PREEMPT_RTlocking issue for !PREEMPT_RT kernel. Maybe we can add a separate kconfig to narrow down lockdep detection for UP-only if UP=y.But lockdep *does* know when it is running in a
CONFIG_SMP=nkernel, correct? In which case all the code paths are UP-only.Quoted 8 lines
Quoted 5 lines
Why? UP and SMP can share the same code path, no? Just because lockdep is running in UP and see a code path, doesn't mean that code path is UP-only, right? What I was trying to say is Lockdep detects generel locking rule violation, so even when it's running in UP kernel, it'll use rules that SMP uses.
I know that this is what lockdep is doing. I am instead saying that what lockdep is doing is not a good thing. ;-)
I see.
Quoted 17 lines
Quoted 8 lines
Quoted 4 lines
The situation with
CONFIG_PREEMPT_RT=yis quite different: The motivation was for people running lockdep onCONFIG_PREEMPT_RT=nkernels to detect and fix locking issues that would otherwise only show up inCONFIG_PREEMPT_RT=ykernels.I'm not sure how it's different than people wanted to detect SMP=y locking issues when running UP kernel. Of course, I didn't know whether that's the intention because I wasn't there ;-)
It is very different.
There were very few people developing and running
PREEMPT_RT, so it was quite difficult for them to clean up the lock-context issues that everyone else was creating. Making lockdep check forPREEMPT_RTissues in !PREEMPT_RT kernels was therefore very helpful, at least to thePREEMPT_RTguys.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
In contrast (and unlike 20 years ago), almost everyone runs SMP, so there
(It also means the people who cares UP is almost none ;-))
I don't know about that, given that the sets of people who run SMP and who care about UP are not necessarily disjoint. But those who care *only* about UP definitely are no longer the vast majority. ;-)
Quoted 5 lines
You're right, I should have said "UP-only". And I *think* the reality is that most of the sub-systems share the code path between UP and SMP, and it works fine for them, because UP tests help them find SMP deadlock as well. That's probably why lockdep has been doing this "not a good thing" for a while.
There are many instances of "#ifdef CONFIG_SMP", too many to avoid activating my laziness.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
is no harm in !SMP lockdep ignoring things that would be deadlocks in SMP kernels. The ample SMP lockdep testing will catch those issues, so there is no need for extra help from UP lockdep testing.
Fair point. If anyone cares UP enough to submit a patch in lockdep, I'm happy to take a look.
Fair enough.
Quoted 8 lines
Quoted 6 lines
In other news, the SMP-check hack to rcutorture does suppress this lockdep issue, at least in my testing. But I applied that change to my -rcu tree, which reverted me back to v1 of your patch and re-introduced the earlier lockdep issue.
So I am restarting the tests.
Thank you!
With these commits in addition:
79e15e57059e ("rcutorture: Test call_srcu() with pi_lock held only for SMP")
(from my -rcu tree)ca174c705db5 ("cgroup/cpuset: Call rebuild_sched_domains() directly in hotplug")
(from mainline)
Thanx, Paul
Quoted 17 lines
Regards,
BoqunQuoted 14 lines
Thanx, Paul
Quoted 12 lines
Regards,
BoqunQuoted 9 lines
Thanx, Paul
Quoted 7 lines
Regards,
BoqunQuoted 4 lines
And of course,
CONFIG_SMP=nkernels still need deadlock detection for mutexes and the like.Thanx, Paul
Boqun Feng
maintainerQuoted 17 lines · Joel Fernandes
Quoted 14 lines · Boqun Feng
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
So we really do need to make some variant of
call_srcu()that deals with this.Quoted 8 lines
Quoted 7 lines
We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.Within the RCU scope, I prefer the second option.
Works for me!
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Would you guys like to implement this, or would you prefer that I do so?
I feel I don't have cycles for it soon, I have a big backlog (including making
preempt_count64bit on 64bit x86). But I will send the fix in the currentcall_srcu()for v7.0 and work with Joel to get into Linus' tree.Boqun, I get a splat as below with your
irq_workpatch on rcutorture:
Thank you, I fixed that in the new version [1]. Please give it a go.
[1]: https://lore.kernel.org/rcu/[email protected]/
Regards,
Boqun
Quoted 67 lines
Maybe the
srcu_get_delaycall needs:raw_spin_lock_irqsave_rcu_node(ssp->srcu_sup, flags); delay = srcu_get_delay(ssp); raw_spin_unlock_irqrestore_rcu_node(ssp->srcu_sup, flags);can you check?
[ 0.459781] ------------[ cut here ]------------ [ 0.460401] WARNING: kernel/rcu/srcutree.c:681 at srcu_get_delay+0xb4/0xd0, CPU#0: swapper/0/1 [ 0.460751] Modules linked in: [ 0.460751] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc3-00020-gc18a9e13ce7f #96 PREEMPTLAZY [ 0.460751] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 0.460751] RIP: 0010:srcu_get_delay+0xb4/0xd0 [ 0.460751] Code: 00 00 00 5b 5d 48 39 d0 48 0f 47 c2 e9 45 b0 0b 01 48 89 fd be ff ff ff ff 48 8d bb d0 00 00 00 e8 e1 86 0a 01 85 c0 75 0d 90 <0f> 0b 90 48 8b 55 40 e9 57 ff ff ff 48 8b 55 40 e9 4e ff ff ff 0f [ 0.460751] RSP: 0000:ffffb4ba80003f80 EFLAGS: 00010046 [ 0.460751] RAX: 0000000000000000 RBX: ffffffffac1604c0 RCX: 0000000000000001 [ 0.460751] RDX: 0000000000000000 RSI: 00000000ffffffff RDI: ffffffffac160590 [ 0.460751] RBP: ffffffffac160460 R08: 0000000000000000 R09: 0000000000000000 [ 0.460751] R10: 0000000000000000 R11: ffffb4ba80003ff8 R12: 0000000000000023 [ 0.460751] R13: ffff9de181214b00 R14: 0000000000000000 R15: 0000000000000000 [ 0.460751] FS: 0000000000000000(0000) GS:ffff9de1f2799000(0000) knlGS:0000000000000000 [ 0.460751] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 0.460751] CR2: ffff9de18ddda000 CR3: 000000000c64e000 CR4: 00000000000006f0 [ 0.460751] Call Trace: [ 0.460751] <IRQ> [ 0.460751] srcu_irq_work+0x11/0x40 [ 0.460751] irq_work_single+0x42/0x90 [ 0.460751] irq_work_run_list+0x26/0x40 [ 0.460751] irq_work_run+0x18/0x30 [ 0.460751] __sysvec_irq_work+0x30/0x180 [ 0.460751] sysvec_irq_work+0x6a/0x80 [ 0.460751] </IRQ> [ 0.460751] <TASK> [ 0.460751] asm_sysvec_irq_work+0x1a/0x20 [ 0.460751] RIP: 0010:_raw_spin_unlock_irqrestore+0x34/0x50 [ 0.460751] Code: c7 18 53 48 89 f3 48 8b 74 24 10 e8 e6 58 f1 fe 48 89 ef e8 2e 92 f1 fe 80 e7 02 74 06 e8 e4 c0 00 ff fb 65 ff 0d fc 63 66 01 <74> 07 5b 5d c3 cc cc cc cc e8 7e 03 df fe 5b 5d e9 57 1b 00 00 0f [ 0.460751] RSP: 0000:ffffb4ba80013d50 EFLAGS: 00000286 [ 0.460751] RAX: 0000000000001c8b RBX: 0000000000000297 RCX: 0000000000000000 [ 0.460751] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffab614c2c [ 0.460751] RBP: ffffffffac160578 R08: 0000000000000001 R09: 0000000000000000 [ 0.460751] R10: 0000000000000001 R11: 0000000000000000 R12: fffffffffffffe74 [ 0.460751] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000001 [ 0.460751] ? _raw_spin_unlock_irqrestore+0x2c/0x50 [ 0.460751] srcu_gp_start_if_needed+0x354/0x530 [ 0.460751] __synchronize_srcu+0xcc/0x180 [ 0.460751] ? __pfx_wakeme_after_rcu+0x10/0x10 [ 0.460751] ? synchronize_srcu+0x3f/0x170 [ 0.460751] ? __pfx_rcu_init_tasks_generic+0x10/0x10 [ 0.460751] rcu_init_tasks_generic+0x104/0x150 [ 0.460751] do_one_initcall+0x59/0x2e0 [ 0.460751] ? _printk+0x56/0x70 [ 0.460751] kernel_init_freeable+0x227/0x440 [ 0.460751] ? __pfx_kernel_init+0x10/0x10 [ 0.460751] kernel_init+0x15/0x1c0 [ 0.460751] ret_from_fork+0x2ac/0x330 [ 0.460751] ? __pfx_kernel_init+0x10/0x10 [ 0.460751] ret_from_fork_asm+0x1a/0x30 [ 0.460751] </TASK>
Paul E. McKenney
maintainerQuoted 35 lines · Boqun Feng
On Fri, Mar 20, 2026 at 09:24:15AM -0700, Paul E. McKenney wrote:
[...]Quoted 33 lines
Quoted 32 lines
Quoted 9 lines
Quoted 6 lines
In an alternative universe, BPF has a defer mechanism, and BPF core would just call (for example):
bpf_defer(call_srcu, ...); // <- a lockless deferso the issue won't happen.
In theory, this is quite true.
Quoted 10 lines
In practice, unfortunately for keeping this part of RCU as simple as we might wish, when a BPF program gets attached to some function in the kernel, it does not know whether or not that function holds a given scheduler lock. For example, there are any number of utility functions that can be (and are) called both with and without those scheduler locks held. Worse yet, it might be attached to a function that is *never* invoked with a scheduler lock held -- until some out-of-tree module is loaded. Which means that this module might well be loaded after BPF has JIT-ed the BPF program.
Hmm.. maybe I failed to make myself more clear. I was suggesting we treat BPF as a special context, and you cannot do everything, if there is any
call_srcu()needed, switch it tobpf_defer(). We should have the same result as either 1)call_srcu()locklessly defer itself or 2) acall_srcu_lockless().Certainly we can
call_srcu()do locklessly defer, but if it's only for BPF, that looks like a whack-a-mole approach to me. Say later on we want to usecall_hazptr()in BPF for some reason (there is hoping!), then we need to make it locklessly defer as well. Now we have two lockless logic in bothcall_srcu()andcall_hazptr(), if there is a third one, we need to do that as well. So where's the end?
Quoted 6 lines
Quoted 3 lines
Except that by the same line of reasoning, how do the BPF guys figure out exactly which function calls they need to defer and under what conditions they need to defer them? Keeping in mind that the list of functions and
Can't they just defer anything that is deferrable? If it's deferrable, then what's the actual cost for BPF to defer it?
I believe that there are overhead issues with unconditional deferral, but I must defer to the BPF guys.
Quoted 29 lines
Quoted 29 lines
corresponding conditions is subject to change as the kernel continues to change.
Quoted 4 lines
The lockless defer request comes from BPF being special, a proper way to deal with it IMO would be BPF has a general defer mechanism. Whether
call_srcu()orcall_srcu_lockless()can do lockless defer is orthogonal.Fair point, and for the general defer mechanism, I hereby nominate the
irq_work_queue()function. We can use this both for RCU and for hazard pointers. The code to make acall_srcu_lockless()andcall_hazptr_lockless()that includes the relevant checks and that does the deferral will not be large, complex, or slow. Especially assuming that we consolidate common checks.Quoted 13 lines
BTW, an example to my point, I think we have a deadlock even with the old
call_rcu_tasks_trace(), because at:https://elixir.bootlin.com/linux/v6.19.8/source/kernel/rcu/tasks.h#L384
We do a:
mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp));which means
call_rcu_tasks_trace()may acquire timer base lock, and that means if BPF was to trace a point where timer base lock is held, then we may have a deadlock. So Now I wonder whether you had any magic to avoid the deadlock pre-7.0 or we are just lucky ;-)
Quoted 4 lines
Quoted 1 line
Test it and see! ;-)
"Program testing can be used to show the presence of bugs, but never to show their absence!" ;-)
But with the exceptions of trivial programs, and I assert that the Linux kernel is non-trivial, there will always be bugs. We therefore need not concern ourselves with showing their absence. ;-)
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
See, without a general defer mechanism, we will have a lot of fun auditing all the primitives that BPF may use.
No, *we* only audit the primitives in our subsystem that BPF actually uses when BPF starts using them. We let the *other* subsystems worry about *their* interactions with BPF.
Quoted 6 lines
As an RCU mainatainer: fine
As a LOCKING maintainer: shake my head, because for every primitive that BPF uses, now there could be a normal version and a _bpf/lockless() version. That could create more maintenance issues, but only time can tell.
One might be surprised by no-lock locking primitives, but you are right that there is always trylock and release.
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines
So we really do need to make some variant of
call_srcu()that deals with this.We do have some options. First, we could make
call_srcu()deal with it directly, or second, we could create something likecall_srcu_lockless()orcall_srcu_nolock()or whatever that can safely be invoked from any context, including NMI handlers, and that invokescall_srcu()directly when it determines that it is safe to do so. The advantage of the second approach is that it avoids incurring the overhead of checking in the common case.Quoted 1 line
Within the RCU scope, I prefer the second option.
Works for me!
Quoted 7 lines
Quoted 1 line
Would you guys like to implement this, or would you prefer that I do so?
I feel I don't have cycles for it soon, I have a big backlog (including making
preempt_count64bit on 64bit x86). But I will send the fix in the currentcall_srcu()for v7.0 and work with Joel to get into Linus' tree.I will definitely review it if you beat me to it ;-)
I am sure that further adjustments will be required. ;-)
Thanx, Paul
Paul E. McKenney
maintainerQuoted 2 lines · Paul E. McKenney
Quoted 1 line · Boqun Feng
On Fri, Mar 20, 2026 at 09:24:15AM -0700, Paul E. McKenney wrote:
[ . . . ]
Quoted 3 lines
Quoted 1 line
I will definitely review it if you beat me to it ;-)
I am sure that further adjustments will be required. ;-)
And speaking of further adjustments, heavier rcutorture testing found the bug allegedly fixed by the following.
I will be testing the stack over the weekend.
Thanx, Paul
------------------------------------------------------------------------
commit a717ba6b919d1be6d13e3ce13ca70e2afd3c24d0
Author: Paul E. McKenney <[email protected]> Date: Fri Mar 20 20:06:22 2026 -0700
srcu: Push srcu_node allocation to GP when non-preemptible
When the srcutree.convert_to_big and srcutree.big_cpu_lim kernel boot parameters specify initialization-time allocation of the srcu_node tree for statically allocated srcu_struct structures (for example, in DEFINE_SRCU() at build time instead of init_srcu_struct() at runtime), init_srcu_struct_nodes() will attempt to dynamically allocate this tree at the first run-time update-side use of this srcu_struct structure, but while holding a raw spinlock. Because the memory allocator can acquire non-raw spinlocks, this can result in lockdep splats.
This commit therefore uses the same SRCU_SIZE_ALLOC trick that is used when the first run-time update-side use of this srcu_struct structure happens before srcu_init() is called. The actual allocation then takes place from workqueue context at the ends of upcoming SRCU grace periods.
kernel/rcu/srcutree.c +5 -2
@@ -227,9 +227,12 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static) ssp->srcu_sup->srcu_gp_seq_needed_exp =SRCU_GP_SEQ_INITIAL_VAL ; ssp->srcu_sup->srcu_last_gp_end =ktime_get_mono_fast_ns ();if (READ_ONCE (ssp->srcu_sup->srcu_size_state) ==SRCU_SIZE_SMALL &&SRCU_SIZING_IS_INIT ()) { -if (!init_srcu_struct_nodes (ssp, is_static ?GFP_ATOMIC :GFP_KERNEL )) +if (!preemptible ()) +WRITE_ONCE (ssp->srcu_sup->srcu_size_state,SRCU_SIZE_ALLOC ); +else if (init_srcu_struct_nodes (ssp,GFP_KERNEL )) +WRITE_ONCE (ssp->srcu_sup->srcu_size_state,SRCU_SIZE_BIG ); +else goto err_free_sda; -WRITE_ONCE (ssp->srcu_sup->srcu_size_state,SRCU_SIZE_BIG ); } ssp->srcu_sup->srcu_ssp = ssp; smp_store_release(&ssp->srcu_sup->srcu_gp_seq_needed,
Boqun Feng
maintainerRFC PATCH 1/1 rcu-tasks: Avoid using mod_timer() in call_rcu_tasks_generic()
In reply to Paul E. McKenneyThe following deadlock is possible:
__mod_timer()
lock_timer_base()
raw_spin_lock_irqsave(&base->lock) <- base->lock ACQUIRED
trace_timer_start() <- tp_btf/timer_start fires here
[probe_timer_start BPF program]
bpf_task_storage_delete()
bpf_selem_unlink(selem, false) <- reuse_now=false
bpf_selem_free(false)
call_rcu_tasks_trace()
call_rcu_tasks_generic()
raw_spin_trylock(rtpcp) <- succeeds (different lock)
mod_timer(lazy_timer) <- lazy_timer is on this CPU's base
lock_timer_base()
raw_spin_lock_irqsave(&base->lock) <- SAME LOCK -> DEADLOCK
because BPF can instrument a place while the timer base lock is held. Fix it by using an intermediate irq_work.
Further, because a "timer base->lock" to a "rtpcp lock" lock dependency can be establish in this way, we cannot mod_timer() with a rtpcp lock held. Fix that as well.
---
This is a follow-up of [1], and yes we can trigger a whole system deadlock freeze easily with (even non-recursively) tracing the timer_start tracepoint. I have a reproduce at:
https://github.com/fbq/rcu_tasks_deadlock
Be very careful, since it'll freeze your system when run it.
I've tested it on 6.17 and 6.19 and can confirm the deadlock could be triggered. So this is an old bug if it's a bug.
It's up to BPF whether this is a bug or not, because it has existed for a while and nobody seems to get hurt(?).
[1]: https://lore.kernel.org/rcu/2b3848e9-3b11-41b8-8c44-5de28d4a4433@paulmck-laptop/
kernel/rcu/tasks.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
kernel/rcu/tasks.h +23 -3
@@ -46,6 +46,7 @@ struct rcu_tasks_percpu {unsigned int urgent_gp;struct work_struct rtp_work;struct irq_work rtp_irq_work; +struct irq_work timer_irq_work;struct rcu_head barrier_q_head;struct list_head rtp_blkd_tasks;struct list_head rtp_exit_list;
@@ -134,6 +135,7 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp); static DEFINE_PER_CPU(struct rcu_tasks_percpu, rt_name ## __percpu) = { \ .lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name ## __percpu.cbs_pcpu_lock), \ .rtp_irq_work =IRQ_WORK_INIT_HARD (call_rcu_tasks_iw_wakeup), \ + .timer_irq_work =IRQ_WORK_INIT (call_rcu_tasks_mod_timer_lazy), \ }; \static struct rcu_tasks rt_name = \ { \
@@ -321,11 +323,19 @@ static void call_rcu_tasks_generic_timer(struct timer_list *tlp)if (!rtpcp->urgent_gp) rtpcp->urgent_gp =1 ; needwake = true; -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +/* +* We cannot mod_timer() here because "timer base lock -> +* rcu_node lock" lock dependencies can be establish by having +* a BPF instrument at timer_start(), and that means deadlock +* if we mod_timer() here. So delay the mod_timer() when we are +* out of the lock critical section. +*/ }raw_spin_unlock_irqrestore_rcu_node (rtpcp, flags); -if (needwake) +if (needwake) { +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp));rcuwait_wake_up (&rtp->cbs_wait); + } }// IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic().
@@ -338,6 +348,16 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp)rcuwait_wake_up (&rtp->cbs_wait); } +static void call_rcu_tasks_mod_timer_lazy (struct irq_work *iwp) +{ +struct rcu_tasks *rtp; + struct rcu_tasks_percpu *rtpcp = container_of(iwp, struct rcu_tasks_percpu, timer_irq_work); + rtp = rtpcp->rtpp; + +if (!timer_pending (&rtpcp->lazy_timer)) +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +} +// Enqueue a callback for the specified flavor of Tasks RCU. static void call_rcu_tasks_generic (struct rcu_head *rhp,rcu_callback_t func,struct rcu_tasks *rtp)
@@ -377,7 +397,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func, (rcu_segcblist_n_cbs (&rtpcp->cblist) == rcu_task_lazy_lim);if (havekthread && !needwake && !timer_pending (&rtpcp->lazy_timer)) {if (rtp->lazy_jiffies) -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +irq_work_queue (&rtpcp->timer_irq_work);else needwake =rcu_segcblist_empty (&rtpcp->cblist); }
Signature · 1 line
2.50.1 (Apple Git-155)
Boqun Feng
maintainerRe: [RFC PATCH] rcu-tasks: Avoid using mod_timer() in call_rcu_tasks_generic()
Quoted 34 lines · Boqun Feng
The following deadlock is possible:
__mod_timer()
lock_timer_base()raw_spin_lock_irqsave(&base->lock) <- base->lock ACQUIRED
trace_timer_start()<- tp_btf/timer_start fires here
[probe_timer_startBPF program]
bpf_task_storage_delete()
bpf_selem_unlink(selem, false)<- reuse_now=false
bpf_selem_free(false)
call_rcu_tasks_trace()
call_rcu_tasks_generic()
raw_spin_trylock(rtpcp)<- succeeds (different lock)
mod_timer(lazy_timer)<-lazy_timeris on this CPU's base
lock_timer_base()
raw_spin_lock_irqsave(&base->lock)<- SAME LOCK -> DEADLOCKbecause BPF can instrument a place while the timer base lock is held. Fix it by using an intermediate
irq_work.Further, because a "timer
base->lock" to a "rtpcp lock" lock dependency can be establish in this way, we cannotmod_timer()with a rtpcp lock held. Fix that as well.Fixes d119357d0743 ("rcu-tasks: Treat only synchronous grace periods urgently")Signed-off-by Boqun Feng <[email protected]>---
This is a follow-up of [1], and yes we can trigger a whole system deadlock freeze easily with (even non-recursively) tracing thetimer_starttracepoint. I have a reproduce at:
Quoted 8 lines
Be very careful, since it'll freeze your system when run it.
I've tested it on 6.17 and 6.19 and can confirm the deadlock could be triggered. So this is an old bug if it's a bug.
It's up to BPF whether this is a bug or not, because it has existed for a while and nobody seems to get hurt(?).
Ping BPF ;-) I know this was sent in a Saturday and only 2 days have passed, but we are at the decision point about how hard/urgent we should fix these "BPF deadlocks": As this patch shows, the deadlocks existed before v7.0 (i.e. before SRCU switches). And yes, ideally we should fix all of them, but given we are close to v7.0 release, I would like to focus the new issue that SRCU introduces, because that one would likely affect SCHED_EXT. Thoughts?
Regards,
Boqun
Quoted 76 lines
[1]: https://lore.kernel.org/rcu/2b3848e9-3b11-41b8-8c44-5de28d4a4433@paulmck-laptop/
kernel/rcu/tasks.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)kernel/rcu/tasks.h +23
-3@@ -46,6 +46,7 @@ struct rcu_tasks_percpu {unsigned int urgent_gp;struct work_struct rtp_work;struct irq_work rtp_irq_work; +struct irq_work timer_irq_work;struct rcu_head barrier_q_head;struct list_head rtp_blkd_tasks;struct list_head rtp_exit_list;@@ -134,6 +135,7 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp); static DEFINE_PER_CPU(struct rcu_tasks_percpu, rt_name ## __percpu) = { \ .lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name ## __percpu.cbs_pcpu_lock), \ .rtp_irq_work =IRQ_WORK_INIT_HARD (call_rcu_tasks_iw_wakeup), \ + .timer_irq_work =IRQ_WORK_INIT (call_rcu_tasks_mod_timer_lazy), \ }; \static struct rcu_tasks rt_name = \ { \@@ -321,11 +323,19 @@ static void call_rcu_tasks_generic_timer(struct timer_list *tlp)if (!rtpcp->urgent_gp) rtpcp->urgent_gp =1 ; needwake = true; -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +/* +* We cannot mod_timer() here because "timer base lock -> +* rcu_node lock" lock dependencies can be establish by having +* a BPF instrument at timer_start(), and that means deadlock +* if we mod_timer() here. So delay the mod_timer() when we are +* out of the lock critical section. +*/ }raw_spin_unlock_irqrestore_rcu_node (rtpcp, flags); -if (needwake) +if (needwake) { +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp));rcuwait_wake_up (&rtp->cbs_wait); + } }// IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic(). @@ -338,6 +348,16 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp)rcuwait_wake_up (&rtp->cbs_wait); } +static void call_rcu_tasks_mod_timer_lazy (struct irq_work *iwp) +{ +struct rcu_tasks *rtp; + struct rcu_tasks_percpu *rtpcp = container_of(iwp, struct rcu_tasks_percpu, timer_irq_work); + rtp = rtpcp->rtpp; + +if (!timer_pending (&rtpcp->lazy_timer)) +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +} +// Enqueue a callback for the specified flavor of Tasks RCU. static void call_rcu_tasks_generic (struct rcu_head *rhp,rcu_callback_t func,struct rcu_tasks *rtp)@@ -377,7 +397,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func, (rcu_segcblist_n_cbs (&rtpcp->cblist) == rcu_task_lazy_lim);if (havekthread && !needwake && !timer_pending (&rtpcp->lazy_timer)) {if (rtp->lazy_jiffies) -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +irq_work_queue (&rtpcp->timer_irq_work);else needwake =rcu_segcblist_empty (&rtpcp->cblist); }Signature · 1 line
2.50.1 (Apple Git-155)
Joel Fernandes
maintainerRe: [RFC PATCH] rcu-tasks: Avoid using mod_timer() in call_rcu_tasks_generic()
Quoted 44 lines · Boqun Feng
Quoted 34 lines · Boqun Feng
The following deadlock is possible:
__mod_timer()
lock_timer_base()raw_spin_lock_irqsave(&base->lock) <- base->lock ACQUIRED
trace_timer_start()<- tp_btf/timer_start fires here
[probe_timer_startBPF program]
bpf_task_storage_delete()
bpf_selem_unlink(selem, false)<- reuse_now=false
bpf_selem_free(false)
call_rcu_tasks_trace()
call_rcu_tasks_generic()
raw_spin_trylock(rtpcp)<- succeeds (different lock)
mod_timer(lazy_timer)<-lazy_timeris on this CPU's base
lock_timer_base()
raw_spin_lock_irqsave(&base->lock)<- SAME LOCK -> DEADLOCKbecause BPF can instrument a place while the timer base lock is held. Fix it by using an intermediate
irq_work.Further, because a "timer
base->lock" to a "rtpcp lock" lock dependency can be establish in this way, we cannotmod_timer()with a rtpcp lock held. Fix that as well.Fixes d119357d0743 ("rcu-tasks: Treat only synchronous grace periods urgently")Signed-off-by Boqun Feng <[email protected]>---
This is a follow-up of [1], and yes we can trigger a whole system deadlock freeze easily with (even non-recursively) tracing thetimer_starttracepoint. I have a reproduce at:Quoted 8 lines
Be very careful, since it'll freeze your system when run it.
I've tested it on 6.17 and 6.19 and can confirm the deadlock could be triggered. So this is an old bug if it's a bug.
It's up to BPF whether this is a bug or not, because it has existed for a while and nobody seems to get hurt(?).
Quoted 7 lines
Ping BPF ;-) I know this was sent in a Saturday and only 2 days have passed, but we are at the decision point about how hard/urgent we should fix these "BPF deadlocks": As this patch shows, the deadlocks existed before v7.0 (i.e. before SRCU switches). And yes, ideally we should fix all of them, but given we are close to v7.0 release, I would like to focus the new issue that SRCU introduces, because that one would likely affect
SCHED_EXT. Thoughts?
Yeah I think this deadlock is "lower priority" in the sense, I believe it existed even before 7.0. But the new SRCU ones are related to 7.0 where the RCU tasks trace implementation was switched to SRCU. So in that sense, yes I think the SRCU fix has to go in for 7.0 itself ideally, with the potential timer fix above moved to a later time.
I wonder also, could we (programmatically as a startup self-test) add a BPF tracepoint program to every trace point possible and see what blows up? I am pretty sure there are dragons in there too other than timers and workqueues. That would also make for a nice-selftest, where a test BPF program is hooked to all tracepoints and then busy-loop somework load is run. I'd brace for some fireworks but..;-)
Btw, I am testing the v2 of the irq_work srcu fix, so far so good. :-)
thanks,
--
Joel Fernandes
Quoted 80 lines
Regards,
BoqunQuoted 76 lines
[1]: https://lore.kernel.org/rcu/2b3848e9-3b11-41b8-8c44-5de28d4a4433@paulmck-laptop/
kernel/rcu/tasks.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)kernel/rcu/tasks.h +23
-3@@ -46,6 +46,7 @@ struct rcu_tasks_percpu {unsigned int urgent_gp;struct work_struct rtp_work;struct irq_work rtp_irq_work; +struct irq_work timer_irq_work;struct rcu_head barrier_q_head;struct list_head rtp_blkd_tasks;struct list_head rtp_exit_list;@@ -134,6 +135,7 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp); static DEFINE_PER_CPU(struct rcu_tasks_percpu, rt_name ## __percpu) = { \ .lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name ## __percpu.cbs_pcpu_lock), \ .rtp_irq_work =IRQ_WORK_INIT_HARD (call_rcu_tasks_iw_wakeup), \ + .timer_irq_work =IRQ_WORK_INIT (call_rcu_tasks_mod_timer_lazy), \ }; \static struct rcu_tasks rt_name = \ { \@@ -321,11 +323,19 @@ static void call_rcu_tasks_generic_timer(struct timer_list *tlp)if (!rtpcp->urgent_gp) rtpcp->urgent_gp =1 ; needwake = true; -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +/* +* We cannot mod_timer() here because "timer base lock -> +* rcu_node lock" lock dependencies can be establish by having +* a BPF instrument at timer_start(), and that means deadlock +* if we mod_timer() here. So delay the mod_timer() when we are +* out of the lock critical section. +*/ }raw_spin_unlock_irqrestore_rcu_node (rtpcp, flags); -if (needwake) +if (needwake) { +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp));rcuwait_wake_up (&rtp->cbs_wait); + } }// IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic(). @@ -338,6 +348,16 @@ static void call_rcu_tasks_iw_wakeup(struct irq_work *iwp)rcuwait_wake_up (&rtp->cbs_wait); } +static void call_rcu_tasks_mod_timer_lazy (struct irq_work *iwp) +{ +struct rcu_tasks *rtp; + struct rcu_tasks_percpu *rtpcp = container_of(iwp, struct rcu_tasks_percpu, timer_irq_work); + rtp = rtpcp->rtpp; + +if (!timer_pending (&rtpcp->lazy_timer)) +mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +} +// Enqueue a callback for the specified flavor of Tasks RCU. static void call_rcu_tasks_generic (struct rcu_head *rhp,rcu_callback_t func,struct rcu_tasks *rtp)@@ -377,7 +397,7 @@ static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func, (rcu_segcblist_n_cbs (&rtpcp->cblist) == rcu_task_lazy_lim);if (havekthread && !needwake && !timer_pending (&rtpcp->lazy_timer)) {if (rtp->lazy_jiffies) -mod_timer (&rtpcp->lazy_timer,rcu_tasks_lazy_time (rtp)); +irq_work_queue (&rtpcp->timer_irq_work);else needwake =rcu_segcblist_empty (&rtpcp->cblist); }Signature · 1 line
2.50.1 (Apple Git-155)
Signature · 1 line
Joel Fernandes
Kumar Kartikeya Dwivedi
maintainerRe: [RFC PATCH] rcu-tasks: Avoid using mod_timer() in call_rcu_tasks_generic()
In reply to Boqun FengQuoted 45 lines · Boqun Feng
Quoted 34 lines · Boqun Feng
The following deadlock is possible:
__mod_timer()
lock_timer_base()raw_spin_lock_irqsave(&base->lock) <- base->lock ACQUIRED
trace_timer_start()<- tp_btf/timer_start fires here
[probe_timer_startBPF program]
bpf_task_storage_delete()
bpf_selem_unlink(selem, false)<- reuse_now=false
bpf_selem_free(false)
call_rcu_tasks_trace()
call_rcu_tasks_generic()
raw_spin_trylock(rtpcp)<- succeeds (different lock)
mod_timer(lazy_timer)<-lazy_timeris on this CPU's base
lock_timer_base()
raw_spin_lock_irqsave(&base->lock)<- SAME LOCK -> DEADLOCKbecause BPF can instrument a place while the timer base lock is held. Fix it by using an intermediate
irq_work.Further, because a "timer
base->lock" to a "rtpcp lock" lock dependency can be establish in this way, we cannotmod_timer()with a rtpcp lock held. Fix that as well.Fixes d119357d0743 ("rcu-tasks: Treat only synchronous grace periods urgently")Signed-off-by Boqun Feng <[email protected]>---
This is a follow-up of [1], and yes we can trigger a whole system deadlock freeze easily with (even non-recursively) tracing thetimer_starttracepoint. I have a reproduce at:Quoted 8 lines
Be very careful, since it'll freeze your system when run it.
I've tested it on 6.17 and 6.19 and can confirm the deadlock could be triggered. So this is an old bug if it's a bug.
It's up to BPF whether this is a bug or not, because it has existed for a while and nobody seems to get hurt(?).
Quoted 7 lines
Ping BPF ;-) I know this was sent in a Saturday and only 2 days have passed, but we are at the decision point about how hard/urgent we should fix these "BPF deadlocks": As this patch shows, the deadlocks existed before v7.0 (i.e. before SRCU switches). And yes, ideally we should fix all of them, but given we are close to v7.0 release, I would like to focus the new issue that SRCU introduces, because that one would likely affect
SCHED_EXT. Thoughts?
I tried both of your changes, thanks for working on these. I agree the one reported by Andrea is more important, so that should be the first priority and should be sent as a fix for 7.0.
It would be good to make the timer-related fix too, but it doesn't need to be rushed for 7.0. We're aware of the issue being fixed by this patch in timer tracepoints [0].
It's a corner case which no one has hit thus far. We already made similar fixes where we could, e.g. [1], but it's difficult to make a similar change for local storage.
Given Paul said he plans into looking into call_{s,}rcu_nolock() anyway, the guard can be dropped once call_{s,}rcu_nolock() materializes.
Something like what you did in this patch would be prerequisite for the call_{s,}rcu_nolock() anyway, the assumption will be that it could be invoked from NMI, so reentrancy can happen anywhere, it doesn't matter much then whether it happens in the same context when the lock is held and we end up invoking the same path through call_srcu(), or when an NMI prog interrupts when the timer lock is held.
[0]: https://lore.kernel.org/bpf/CAP01T76xUCrDH4G2XikNvhPTn6ZbNTgQH59qt2Q_o0c9uudd8w@mail.gmail.com
[1]: https://lore.kernel.org/bpf/[email protected]
Quoted 2 lines
[...]
Boqun Feng
maintainerRe: [RFC PATCH] rcu-tasks: Avoid using mod_timer() in call_rcu_tasks_generic()
Quoted 54 lines · Kumar Kartikeya Dwivedi
Quoted 45 lines · Boqun Feng
Quoted 34 lines · Boqun Feng
The following deadlock is possible:
__mod_timer()
lock_timer_base()raw_spin_lock_irqsave(&base->lock) <- base->lock ACQUIRED
trace_timer_start()<- tp_btf/timer_start fires here
[probe_timer_startBPF program]
bpf_task_storage_delete()
bpf_selem_unlink(selem, false)<- reuse_now=false
bpf_selem_free(false)
call_rcu_tasks_trace()
call_rcu_tasks_generic()
raw_spin_trylock(rtpcp)<- succeeds (different lock)
mod_timer(lazy_timer)<-lazy_timeris on this CPU's base
lock_timer_base()
raw_spin_lock_irqsave(&base->lock)<- SAME LOCK -> DEADLOCKbecause BPF can instrument a place while the timer base lock is held. Fix it by using an intermediate
irq_work.Further, because a "timer
base->lock" to a "rtpcp lock" lock dependency can be establish in this way, we cannotmod_timer()with a rtpcp lock held. Fix that as well.Fixes d119357d0743 ("rcu-tasks: Treat only synchronous grace periods urgently")Signed-off-by Boqun Feng <[email protected]>---
This is a follow-up of [1], and yes we can trigger a whole system deadlock freeze easily with (even non-recursively) tracing thetimer_starttracepoint. I have a reproduce at:Quoted 8 lines
Be very careful, since it'll freeze your system when run it.
I've tested it on 6.17 and 6.19 and can confirm the deadlock could be triggered. So this is an old bug if it's a bug.
It's up to BPF whether this is a bug or not, because it has existed for a while and nobody seems to get hurt(?).
Quoted 7 lines
Ping BPF ;-) I know this was sent in a Saturday and only 2 days have passed, but we are at the decision point about how hard/urgent we should fix these "BPF deadlocks": As this patch shows, the deadlocks existed before v7.0 (i.e. before SRCU switches). And yes, ideally we should fix all of them, but given we are close to v7.0 release, I would like to focus the new issue that SRCU introduces, because that one would likely affect
SCHED_EXT. Thoughts?
Quoted 1 line
I tried both of your changes, thanks for working on these. I agree the
No problem. :)
Quoted 3 lines
one reported by Andrea is more important, so that should be the first priority and should be sent as a fix for 7.0.
Agreed. I will work with Joel to forward these fixes to Linus.
Quoted 7 lines
It would be good to make the timer-related fix too, but it doesn't need to be rushed for 7.0. We're aware of the issue being fixed by this patch in timer tracepoints [0].
It's a corner case which no one has hit thus far. We already made similar fixes where we could, e.g. [1], but it's difficult to make a similar change for local storage.
Right, we need more time to cover all the cases. For example, there is tracepoint inside irq_work_queue() where we can instrument it within BPF, that could open a lot of fun interactions. ;-)
Quoted 11 lines
Given Paul said he plans into looking into call_{s,}rcu_nolock() anyway, the guard can be dropped once call_{s,}rcu_nolock() materializes.
Something like what you did in this patch would be prerequisite for the call_{s,}rcu_nolock() anyway, the assumption will be that it could be invoked from NMI, so reentrancy can happen anywhere, it doesn't matter much then whether it happens in the same context when the lock is held and we end up invoking the same path through
call_srcu(), or when an NMI prog interrupts when the timer lock is held.
Sounds good, I will work with Paul on these.
Regards,
Boqun
Quoted 5 lines
[0]: https://lore.kernel.org/bpf/CAP01T76xUCrDH4G2XikNvhPTn6ZbNTgQH59qt2Q_o0c9uudd8w@mail.gmail.com
[1]: https://lore.kernel.org/bpf/[email protected]Quoted 2 lines
[...]
Boqun Feng
maintainerOn Thu, Mar 19, 2026 at 01:14:08PM -0700, Boqun Feng wrote:
[...]
Quoted 8 lines
Quoted 7 lines
Also, any unconditional deferral in the caller for APIs that can "hold locks" to avoid all this is not without its cost.
The implementation of RCU knows and can stay in sync with those conditions for when deferral is needed, and hide all that complexity from the caller. The cost should definitely be paid by the caller if we would break the API's broad contract, e.g., by trying to invoke it
Quoted 4 lines
The thing is, lots of the synchronization primitives existed before BPF, and they were not designed or implemented with "BPF safe" in mind, and they could be dragged into BPF core code path if we begin to use them. For example,
irq_workmay be just "happen-to-work" here, or there is a
Correction: irq_work is designed to be NMI safe (at least when queueing on the local CPU), so it's potential the bpf_defer() I proposed.
Regards,
Boqun
Quoted 15 lines
bug that we are missing. It would be rather easier or clearer if we design a dedicate defer mechanism with BPF core in mind, and then we use that for all the deferrable operations.
Regards,
BoqunQuoted 8 lines
in NMI which it is not supposed to run in yet, in that case we already handle things using
irq_work. Anything more complicated than that is hard to scale. All of this may also change in the future where we supportcall_rcu_nolock()to make it work everywhere, and only defer when we detect reentrancy (in the same or different context).
[..]
Paul E. McKenney
maintainerQuoted 10 lines · Boqun Feng
On Thu, Mar 19, 2026 at 01:14:08PM -0700, Boqun Feng wrote:
[...]Quoted 8 lines
Quoted 7 lines
Also, any unconditional deferral in the caller for APIs that can "hold locks" to avoid all this is not without its cost.
The implementation of RCU knows and can stay in sync with those conditions for when deferral is needed, and hide all that complexity from the caller. The cost should definitely be paid by the caller if we would break the API's broad contract, e.g., by trying to invoke it
Quoted 7 lines
Quoted 4 lines
The thing is, lots of the synchronization primitives existed before BPF, and they were not designed or implemented with "BPF safe" in mind, and they could be dragged into BPF core code path if we begin to use them. For example,
irq_workmay be just "happen-to-work" here, or there is aCorrection:
irq_workis designed to be NMI safe (at least when queueing on the local CPU), so it's potential thebpf_defer()I proposed.
Completely agreed!
Thanx, Paul
Quoted 19 lines
Regards,
BoqunQuoted 15 lines
bug that we are missing. It would be rather easier or clearer if we design a dedicate defer mechanism with BPF core in mind, and then we use that for all the deferrable operations.
Regards,
BoqunQuoted 8 lines
in NMI which it is not supposed to run in yet, in that case we already handle things using
irq_work. Anything more complicated than that is hard to scale. All of this may also change in the future where we supportcall_rcu_nolock()to make it work everywhere, and only defer when we detect reentrancy (in the same or different context).[..]
Quoted 1 line · Boqun Feng
I agree it's not RCU's fault ;-)
I never claimed it is anyone's fault. I just see that BPF should be able to do things which kgdb would not be allowed to.
Quoted 7 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).But we need to fix this in v7.0, so this short-term fix is still needed.
I would prefer something substantial before we rush to get a quick fix and move on.
If we could get that irq_work() part only for BPF where it is required then it would be already a step forward.
Long term it would be nice if we could avoid calling this while locks are held. I think call_rcu() can't be used under rq/pi lock, but timers should be fine.
Is this rq/pi locking originating from "regular" BPF code or sched_ext?
Quoted 5 lines
Regars,
BoqunQuoted 2 lines
Quoted 2 lines
Regards,
Boqun
Sebastian
Boqun Feng
maintainerQuoted 12 lines · Sebastian Andrzej Siewior
Quoted 1 line · Boqun Feng
I agree it's not RCU's fault ;-)
I never claimed it is anyone's fault. I just see that BPF should be able to do things which kgdb would not be allowed to.
Quoted 6 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).
Quoted 5 lines
Quoted 1 line
But we need to fix this in v7.0, so this short-term fix is still needed.
I would prefer something substantial before we rush to get a quick fix and move on.
The quick fix here is really "restore the previous behavior of call_rcu_tasks_trace() in call_srcu()", and the future work will naturally happen: if the extra irq_work layer turns out calling issues to other SRCU users, then we need to fix them as well. Otherwise, there is no real need to avoid the extra irq_work hop. So I *think* it's OK ;-)
Cleaning up all the ad-hoc irq_work usages in BPF is another thing, which can happen if we learn about all the cases and have a good design.
Quoted 3 lines
If we could get that
irq_work()part only for BPF where it is required then it would be already a step forward.
I'm happy to include that (i.e. using Qiang's suggestion) if Joel also agrees.
Quoted 6 lines
Long term it would be nice if we could avoid calling this while locks are held. I think
call_rcu()can't be used under rq/pi lock, but timers should be fine.Is this rq/pi locking originating from "regular" BPF code or
sched_ext?
I think if you have any tracepoint (include traceable functions) under rq/pi locking, then potentially BPF can call call_srcu() there.
The root cause of the issues is that BPF is actually like a NMI unless the code is noinstr (There is a rabit hole about BPF calling call_srcu() while it's instrumenting call_srcu() itself). And the right way to solve all the issues is to have a general defer mechanism for BPF.
Regards,
Boqun
Quoted 7 lines
Quoted 5 lines
Regars,
BoqunQuoted 2 lines
Quoted 2 lines
Regards,
BoqunSebastian
Joel Fernandes
maintainerQuoted 13 lines · Boqun Feng
Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 1 line · Boqun Feng
I agree it's not RCU's fault ;-)
I never claimed it is anyone's fault. I just see that BPF should be able to do things which kgdb would not be allowed to.
Quoted 6 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
But we need to fix this in v7.0, so this short-term fix is still needed.
I would prefer something substantial before we rush to get a quick fix and move on.
The quick fix here is really "restore the previous behavior of
call_rcu_tasks_trace()incall_srcu()", and the future work will
Unfortunately reverting c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") is tricky since the original body of RCU Tasks Trace code is deleted. Perhaps we should have added an easier escape-hatch, lesson learnt:)
Quoted 8 lines
naturally happen: if the extra
irq_worklayer turns out calling issues to other SRCU users, then we need to fix them as well. Otherwise, there is no real need to avoid the extrairq_workhop. So I *think* it's OK ;-)Cleaning up all the ad-hoc
irq_workusages in BPF is another thing, which can happen if we learn about all the cases and have a good design.
Quoted 6 lines
Quoted 3 lines
If we could get that
irq_work()part only for BPF where it is required then it would be already a step forward.I'm happy to include that (i.e. using Qiang's suggestion) if Joel also agrees.
Sure, I am Ok with sort of short-term fix, but I worry that it still does not the issues due to the tasks-trace conversion. In particular, it doesn't fix the issue Andrea reported AFAICS, because there is a dependency on pool->lock? see:
https://lore.kernel.org/all/abjzvz_tL_siV17s@gpd4/
That happens precisely because of the queue_delayed_work() happening from the SRCU tasks-trace specific BPF right?
This looks something like this, due to combination of SRCU, scheduler and WQ:
srcu_usage.lock -> pool->lock -> pi_lock -> rq->__lock
^ |
| |
+----------- DEADLOCK CYCLE ------------+Quoted 11 lines
Quoted 6 lines
Long term it would be nice if we could avoid calling this while locks are held. I think
call_rcu()can't be used under rq/pi lock, but timers should be fine.Is this rq/pi locking originating from "regular" BPF code or
sched_ext?I think if you have any tracepoint (include traceable functions) under rq/pi locking, then potentially BPF can call
call_srcu()there.
Quoted 5 lines
The root cause of the issues is that BPF is actually like a NMI unless the code is noinstr (There is a rabit hole about BPF calling
call_srcu()while it's instrumentingcall_srcu()itself). And the right way to solve all the issues is to have a general defer mechanism for BPF.
Will that really solve the above mentioned issue though that Andrea reported?
+Andrea, +Steve as well.
thanks,
--
Joel Fernandes
Boqun Feng
maintainerQuoted 68 lines · Joel Fernandes
Quoted 13 lines · Boqun Feng
Quoted 12 lines · Sebastian Andrzej Siewior
Quoted 1 line · Boqun Feng
I agree it's not RCU's fault ;-)
I never claimed it is anyone's fault. I just see that BPF should be able to do things which kgdb would not be allowed to.
Quoted 6 lines
I guess it'll be difficult to restrict BPF, however maybe BPF can call
call_srcu()inirq_workinstead? Or a more systematic defer mechanism that allows BPF to defer any lock holding functions to a different context. (We have a similar issue that BPF cannot callkfree_rcu()in some cases IIRC).Quoted 8 lines
Quoted 5 lines
Quoted 1 line
But we need to fix this in v7.0, so this short-term fix is still needed.
I would prefer something substantial before we rush to get a quick fix and move on.
The quick fix here is really "restore the previous behavior of
call_rcu_tasks_trace()incall_srcu()", and the future work willUnfortunately reverting
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") is tricky since the original body of RCU Tasks Trace code is deleted. Perhaps we should have added an easier escape-hatch, lesson learnt:)Quoted 8 lines
naturally happen: if the extra
irq_worklayer turns out calling issues to other SRCU users, then we need to fix them as well. Otherwise, there is no real need to avoid the extrairq_workhop. So I *think* it's OK ;-)Cleaning up all the ad-hoc
irq_workusages in BPF is another thing, which can happen if we learn about all the cases and have a good design.Quoted 6 lines
Quoted 3 lines
If we could get that
irq_work()part only for BPF where it is required then it would be already a step forward.I'm happy to include that (i.e. using Qiang's suggestion) if Joel also agrees.
Sure, I am Ok with sort of short-term fix, but I worry that it still does not the issues due to the tasks-trace conversion. In particular, it doesn't fix the issue Andrea reported AFAICS, because there is a dependency on
pool->lock? see:
https://lore.kernel.org/all/abjzvz_tL_siV17s@gpd4/That happens precisely because of the
queue_delayed_work()happening from the SRCU tasks-trace specific BPF right?This looks something like this, due to combination of SRCU, scheduler and WQ:
srcu_usage.lock ->
pool->lock->pi_lock->rq->__lock^ | | | +----------- DEADLOCK CYCLE ------------+Quoted 11 lines
Quoted 6 lines
Long term it would be nice if we could avoid calling this while locks are held. I think
call_rcu()can't be used under rq/pi lock, but timers should be fine.Is this rq/pi locking originating from "regular" BPF code or
sched_ext?I think if you have any tracepoint (include traceable functions) under rq/pi locking, then potentially BPF can call
call_srcu()there.
Quoted 7 lines
Quoted 5 lines
The root cause of the issues is that BPF is actually like a NMI unless the code is noinstr (There is a rabit hole about BPF calling
call_srcu()while it's instrumentingcall_srcu()itself). And the right way to solve all the issues is to have a general defer mechanism for BPF.Will that really solve the above mentioned issue though that Andrea reported?
It should, since we call irq_work to queue_work instead queue_work directly, so we break the srcu_usage.lock -> pool->lock dependency. But yes, some tests would be good, the code is at:
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
related commits are:
78dcdc35d85f rcu: Use an intermediate irq_work to start process_srcu() 0490fe4b5c39 srcu: Use raw spinlocks so call_srcu() can be used under preempt_disable()
One fixes the raw spinlock vs spinlock issue, the other fixes the deadlock.
Regards,
Boqun
Quoted 7 lines
+Andrea, +Steve as well.
thanks,
--
Joel Fernandes
Joel Fernandes
maintainerQuoted 1 line · Boqun Feng
On Thu, Mar 19, 2026 at 02:42:56PM -0400, Joel Fernandes wrote:
[...]
Quoted 55 lines
Quoted 41 lines
Quoted 8 lines
naturally happen: if the extra
irq_worklayer turns out calling issues to other SRCU users, then we need to fix them as well. Otherwise, there is no real need to avoid the extrairq_workhop. So I *think* it's OK ;-)Cleaning up all the ad-hoc
irq_workusages in BPF is another thing, which can happen if we learn about all the cases and have a good design.Quoted 6 lines
Quoted 3 lines
If we could get that
irq_work()part only for BPF where it is required then it would be already a step forward.I'm happy to include that (i.e. using Qiang's suggestion) if Joel also agrees.
Sure, I am Ok with sort of short-term fix, but I worry that it still does not the issues due to the tasks-trace conversion. In particular, it doesn't fix the issue Andrea reported AFAICS, because there is a dependency on
pool->lock? see:
https://lore.kernel.org/all/abjzvz_tL_siV17s@gpd4/That happens precisely because of the
queue_delayed_work()happening from the SRCU tasks-trace specific BPF right?This looks something like this, due to combination of SRCU, scheduler and WQ:
srcu_usage.lock ->
pool->lock->pi_lock->rq->__lock^ | | | +----------- DEADLOCK CYCLE ------------+Quoted 11 lines
Quoted 6 lines
Long term it would be nice if we could avoid calling this while locks are held. I think
call_rcu()can't be used under rq/pi lock, but timers should be fine.Is this rq/pi locking originating from "regular" BPF code or
sched_ext?I think if you have any tracepoint (include traceable functions) under rq/pi locking, then potentially BPF can call
call_srcu()there.Quoted 7 lines
Quoted 5 lines
The root cause of the issues is that BPF is actually like a NMI unless the code is noinstr (There is a rabit hole about BPF calling
call_srcu()while it's instrumentingcall_srcu()itself). And the right way to solve all the issues is to have a general defer mechanism for BPF.Will that really solve the above mentioned issue though that Andrea reported?
It should, since we call
irq_worktoqueue_workinsteadqueue_workdirectly, so we break the srcu_usage.lock ->pool->lockdependency. But yes, some tests would be good, the code is at:https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
Quoted 7 lines
related commits are:
78dcdc35d85frcu: Use an intermediateirq_workto startprocess_srcu()0490fe4b5c39srcu: Use raw spinlocks socall_srcu()can be used underpreempt_disable()One fixes the raw spinlock vs spinlock issue, the other fixes the deadlock.
Ah yes, with the irq_work fix, indeed.
I'll try to queue the irq_work fix for 7.1 and run some tests. Appreciate if Andrea, Paul and Kumar can also check,
thanks,
--
Joel Fernandes
Joel Fernandes
maintainerQuoted 66 lines · Joel Fernandes
Quoted 1 line · Boqun Feng
On Thu, Mar 19, 2026 at 02:42:56PM -0400, Joel Fernandes wrote:
[...]
Quoted 60 lines
Quoted 41 lines
Quoted 8 lines
naturally happen: if the extra
irq_worklayer turns out calling issues to other SRCU users, then we need to fix them as well. Otherwise, there is no real need to avoid the extrairq_workhop. So I *think* it's OK ;-)Cleaning up all the ad-hoc
irq_workusages in BPF is another thing, which can happen if we learn about all the cases and have a good design.Quoted 6 lines
Quoted 3 lines
If we could get that
irq_work()part only for BPF where it is required then it would be already a step forward.I'm happy to include that (i.e. using Qiang's suggestion) if Joel also agrees.
Sure, I am Ok with sort of short-term fix, but I worry that it still does not the issues due to the tasks-trace conversion. In particular, it doesn't fix the issue Andrea reported AFAICS, because there is a dependency on
pool->lock? see:
https://lore.kernel.org/all/abjzvz_tL_siV17s@gpd4/That happens precisely because of the
queue_delayed_work()happening from the SRCU tasks-trace specific BPF right?This looks something like this, due to combination of SRCU, scheduler and WQ:
srcu_usage.lock ->
pool->lock->pi_lock->rq->__lock^ | | | +----------- DEADLOCK CYCLE ------------+Quoted 11 lines
Quoted 6 lines
Long term it would be nice if we could avoid calling this while locks are held. I think
call_rcu()can't be used under rq/pi lock, but timers should be fine.Is this rq/pi locking originating from "regular" BPF code or
sched_ext?I think if you have any tracepoint (include traceable functions) under rq/pi locking, then potentially BPF can call
call_srcu()there.Quoted 7 lines
Quoted 5 lines
The root cause of the issues is that BPF is actually like a NMI unless the code is noinstr (There is a rabit hole about BPF calling
call_srcu()while it's instrumentingcall_srcu()itself). And the right way to solve all the issues is to have a general defer mechanism for BPF.Will that really solve the above mentioned issue though that Andrea reported?
It should, since we call
irq_worktoqueue_workinsteadqueue_workdirectly, so we break the srcu_usage.lock ->pool->lockdependency. But yes, some tests would be good, the code is at:https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
related commits are:
78dcdc35d85frcu: Use an intermediateirq_workto startprocess_srcu()0490fe4b5c39srcu: Use raw spinlocks socall_srcu()can be used underpreempt_disable()
Quoted 6 lines
Quoted 2 lines
One fixes the raw spinlock vs spinlock issue, the other fixes the deadlock.
Ah yes, with the
irq_workfix, indeed.I'll try to queue the
irq_workfix for 7.1 and run some tests. Appreciate if Andrea, Paul and Kumar can also check,
Ah, but of course these should go through 7.0 (assuming they fix all open issues) since that's when the bug was introduced.
thanks,
--
Joel Fernandes
Paul E. McKenney
maintainerQuoted 179 lines · Boqun Feng
Quoted 104 lines · Boqun Feng
Quoted 87 lines · Joel Fernandes
Quoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);Nice, I wonder if it is better to do this in
__queue_delayed_work()itself. Do we havequeue_delayed_work()with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?Quoted 8 lines
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
I think all of these are probably a good point. However my fix is not complete :( It's missing the ABBA case in your example (it obviously could solve the self deadlock if my observation is correct), because we will still build
rcu_node::lock->runqueue::lockin some conditions, and BPF contributes therunqueue::lock->rcu_node::lockdependency. Hence we still have ABBA deadlock.Quoted 3 lines
To remove the
rcu_node::lock->runqueue::lockentirely, we need to always delay 1+ jiffies:Hmm.. or I can do as the old
call_rcu_tasks_trace()does: using anirq_work. I also pushed it at:https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
(based on Paul's fix on spinlock already, but only lightly build test).
Regards,
Boqun-------------------------->8
Subject: [PATCH] rcu: Use an intermediateirq_workto startprocess_srcu()Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Signed-off-by Boqun Feng <[email protected]>--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +3
-0@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1128
Quoted 8 lines
kernel/rcu/srcutree.c +5
-0@@ -1118,9 +1121,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here.
If I understand the lockdep splat, you need to bail out earlier on, prior to the first lock acquisition.
Thanx, Paul
Quoted 28 lines
kernel/rcu/srcutree.c +12
-2if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Boqun Feng
maintainerQuoted 183 lines · Paul E. McKenney
Quoted 182 lines · Boqun Feng
Quoted 104 lines · Boqun Feng
Quoted 87 lines · Joel Fernandes
Quoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);Nice, I wonder if it is better to do this in
__queue_delayed_work()itself. Do we havequeue_delayed_work()with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?Quoted 8 lines
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
I think all of these are probably a good point. However my fix is not complete :( It's missing the ABBA case in your example (it obviously could solve the self deadlock if my observation is correct), because we will still build
rcu_node::lock->runqueue::lockin some conditions, and BPF contributes therunqueue::lock->rcu_node::lockdependency. Hence we still have ABBA deadlock.Quoted 3 lines
To remove the
rcu_node::lock->runqueue::lockentirely, we need to always delay 1+ jiffies:Hmm.. or I can do as the old
call_rcu_tasks_trace()does: using anirq_work. I also pushed it at:https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
(based on Paul's fix on spinlock already, but only lightly build test).
Regards,
Boqun-------------------------->8
Subject: [PATCH] rcu: Use an intermediateirq_workto startprocess_srcu()Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Signed-off-by Boqun Feng <[email protected]>--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +3
-0@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -1118,9 +1121,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled.
Quoted 9 lines
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1128
Quoted 5 lines
kernel/rcu/srcutree.c +5
-0+// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. If I understand the lockdep splat, you need to bail out earlier on, prior to the first lock acquisition.
I think you're talking about another direction of the dependency ;-)
Joel's example shows both depenedencies clearly:
CPU A (BPF tracepoint) CPU B (concurrent call_srcu)
---------------------------- ------------------------------------
[1] holds &rq->__lock
[2]
-> call_srcu
-> srcu_gp_start_if_needed
-> srcu_funnel_gp_start
-> spin_lock_irqsave_ssp_content...
-> holds srcu locks [4] calls call_rcu_tasks_trace() [5] srcu_funnel_gp_start (cont..)
-> queue_delayed_work
-> call_srcu() -> __queue_work()
-> srcu_gp_start_if_needed() -> wake_up_worker()
-> srcu_funnel_gp_start() -> try_to_wake_up()
-> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock
-> WANTS srcu locksTo remove [1] -> [4], i.e. the dependency "&rq->__lock" -> "srcu locks", yes, you need to bail out earlier on. But to remove [2] -> [6], i.e. the dependency "srcu locks" -> "&rq->__lock", you just need to make sure call_srcu() won't call anything that need to acquire the rq lock.
In the old version of call_rcu_tasks_trace(), we were fine also because
[2] -> [6] didn't exist ([6] is rcu node lock in this case). [1] -> [4] ([4] being rcu node lock) existed in the RCU Tasks Trace version:
// Enqueue a callback for the specified flavor of Tasks RCU.
static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
struct rcu_tasks *rtp)
{
...
if (!raw_spin_trylock_rcu_node(rtpcp)) { // irqs already disabled.
raw_spin_lock_rcu_node(rtpcp); // irqs already disabled.
...
}
...
rcu_segcblist_enqueue(&rtpcp->cblist, rhp);
raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
...
/* We can't create the thread unless interrupts are enabled. */
if (needwake && READ_ONCE(rtp->kthread_ptr))
irq_work_queue(&rtpcp->rtp_irq_work);
}Hope it helps.
Regards,
Boqun
Quoted 30 lines
Thanx, Paul
Quoted 28 lines
kernel/rcu/srcutree.c +12
-2if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Paul E. McKenney
maintainerQuoted 244 lines · Boqun Feng
Quoted 183 lines · Paul E. McKenney
Quoted 182 lines · Boqun Feng
Quoted 104 lines · Boqun Feng
Quoted 87 lines · Joel Fernandes
Quoted 68 lines · Boqun Feng
Quoted 33 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 31 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Regards,
Boqun------>
kernel/rcu/srcutree.c +3
-0@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1132
Quoted 10 lines
kernel/rcu/srcutree.c +7
-1+// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);Nice, I wonder if it is better to do this in
__queue_delayed_work()itself. Do we havequeue_delayed_work()with zero delays that are in irq-disabled regions, and they depend on that zero-delay for correctness? Even with delay of 0 though, the work item doesn't execute right away anyway, the worker thread has to also be scheduler right?Quoted 8 lines
Also if IRQ is disabled, I'd think this is a critical path that is not wanting to run the work item right-away anyway since workqueue is more a bottom-half mechanism, than "run this immediately".
IOW, would be good to make the workqueue-layer more resilient to waking up the scheduler when a delay would have been totally ok. But maybe +Tejun can yell if that sounds insane.
I think all of these are probably a good point. However my fix is not complete :( It's missing the ABBA case in your example (it obviously could solve the self deadlock if my observation is correct), because we will still build
rcu_node::lock->runqueue::lockin some conditions, and BPF contributes therunqueue::lock->rcu_node::lockdependency. Hence we still have ABBA deadlock.Quoted 3 lines
To remove the
rcu_node::lock->runqueue::lockentirely, we need to always delay 1+ jiffies:Hmm.. or I can do as the old
call_rcu_tasks_trace()does: using anirq_work. I also pushed it at:https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/ srcu-fix
(based on Paul's fix on spinlock already, but only lightly build test).
Regards,
Boqun-------------------------->8
Subject: [PATCH] rcu: Use an intermediateirq_workto startprocess_srcu()Since commit
c27cea4416a3("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast") we switched to SRCU in BPF. However as BPF instrument can happen basically everywhere (including where a scheduler lock is held),call_srcu()now needs to avoid acquiring scheduler lock because otherwise it could cause deadlock [1]. Fix this by following what the previous RCU Tasks Trace did: using anirq_workto delay the queuing of the work to startprocess_srcu().Fixes commit c27cea4416a3 ("rcu: Re-implement RCU Tasks Trace in terms of SRCU-fast")Signed-off-by Boqun Feng <[email protected]>--- include/linux/srcutree.h | 1 + kernel/rcu/srcutree.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)include/linux/srcutree.h +1
-0@@ -95,6 +95,7 @@ struct srcu_usage {unsigned long reschedule_jiffies;unsigned long reschedule_count;struct delayed_work work; +struct irq_work irq_work;struct srcu_struct *srcu_ssp; };kernel/rcu/srcutree.c +3
-0@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/percpu.h> #include <linux/preempt.h> +#include <linux/irq_work.h> #include <linux/rcupdate_wait.h> #include <linux/sched.h> #include <linux/smp.h> @@ -75,6 +76,7 @@ static bool __read_mostly srcu_init_done;static void srcu_invoke_callbacks (struct work_struct *work);static void srcu_reschedule (struct srcu_struct *ssp,unsigned long delay);static void process_srcu (struct work_struct *work); +static void srcu_irq_work (struct irq_work *work);static void srcu_delay_timer (struct timer_list *t);/* @@ -216,6 +218,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); +init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);@@ -1118,9 +1121,13 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. Quoted 9 lines
kernel/rcu/srcutree.c static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp, · line 1128
Quoted 5 lines
kernel/rcu/srcutree.c +5
-0+// +// Use an irq_work here to avoid acquiring runqueue lock with +// srcu rcu_node::lock held. BPF instrument could introduce the +// opposite dependency, hence we need to break the possible +// locking dependency here. If I understand the lockdep splat, you need to bail out earlier on, prior to the first lock acquisition.
I think you're talking about another direction of the dependency ;-)
Joel's example shows both depenedencies clearly:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locks[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksTo remove [1] -> [4], i.e. the dependency "
&rq->__lock" -> "srcu locks", yes, you need to bail out earlier on. But to remove [2] -> [6], i.e. the dependency "srcu locks" -> "&rq->__lock", you just need to make surecall_srcu()won't call anything that need to acquire the rq lock.In the old version of
call_rcu_tasks_trace(), we were fine also because
[2] -> [6] didn't exist ([6] is rcu node lock in this case). [1] -> [4] ([4] being rcu node lock) existed in the RCU Tasks Trace version:// Enqueue a callback for the specified flavor of Tasks RCU. static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func, struct rcu_tasks *rtp) { ... if (!raw_spin_trylock_rcu_node(rtpcp)) { // irqs already disabled. raw_spin_lock_rcu_node(rtpcp); // irqs already disabled. ... } ... rcu_segcblist_enqueue(&rtpcp->cblist, rhp); raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags); ... /* We can't create the thread unless interrupts are enabled. */ if (needwake && READ_ONCE(rtp->kthread_ptr)) irq_work_queue(&rtpcp->rtp_irq_work); }
Quoted 1 line
Hope it helps.
Got it, thank you!
Thanx, Paul
Quoted 33 lines
Regards,
BoqunQuoted 30 lines
Thanx, Paul
Quoted 28 lines
kernel/rcu/srcutree.c +12
-2if (likely (srcu_init_done)) -queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); +irq_work_queue (&sup->irq_work);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }@@ -1979,6 +1986,17 @@ static void process_srcu(struct work_struct *work)srcu_reschedule (ssp, curdelay); } +static void srcu_irq_work (struct irq_work *work) +{ +struct srcu_struct *ssp; +struct srcu_usage *sup; + + sup = container_of(work, struct srcu_usage, irq_work); + ssp = sup->srcu_ssp; + +queue_delayed_work (rcu_gp_wq, &sup->work, !!srcu_get_delay (ssp)); +} +void srcutorture_get_gp_data (struct srcu_struct *ssp,int *flags,unsigned long *gp_seq) {Signature · 1 line
2.50.1 (Apple Git-155)
Kumar Kartikeya Dwivedi
maintainerQuoted 31 lines · Boqun Feng
Quoted 29 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 27 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu)
---------------------------- ------------------------------------
[1] holds&rq->__lock[2] -> call_srcu -> srcu_gp_start_if_needed -> srcu_funnel_gp_start -> spin_lock_irqsave_ssp_content... -> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..)-> queue_delayed_work -> call_srcu() -> __queue_work() -> srcu_gp_start_if_needed() -> wake_up_worker() -> srcu_funnel_gp_start() -> try_to_wake_up() -> spin_lock_irqsave_ssp_contention() [6] WANTS rq->__lock -> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Unfortunately it can be, there is at least one tracepoint that is invoked with hrtimer base lock held.
Alexei ended up fixing this in the recent past [0]. So I think this would cause trouble too.
hrtimer_start_range_ns() -> __hrtimer_start_range_ns() -> remove_timer() -> __remove_hrtimer() -> debug_deactivate() -> trace_hrtimer_cancel().
BPF can attach to such a tracepoint.
[0]: https://lore.kernel.org/bpf/[email protected]
Quoted 43 lines
Regards,
Boqun------>
kernel/rcu/srcutree.c +10
-1@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }
Zqiang
reviewerQuoted 48 lines · Boqun Feng
Quoted 32 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 27 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu) ---------------------------- ------------------------------------
[1] holds&rq->__lock
[2]
->call_srcu
->srcu_gp_start_if_needed
->srcu_funnel_gp_start
->spin_lock_irqsave_ssp_content...
-> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..) ->queue_delayed_work
->call_srcu()->__queue_work()
->srcu_gp_start_if_needed()->wake_up_worker()
->srcu_funnel_gp_start()->try_to_wake_up()
->spin_lock_irqsave_ssp_contention()[6] WANTSrq->__lock-> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.Quoted 9 lines
Quoted 4 lines
An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Unfortunately it can be, there is at least one tracepoint that is invoked with hrtimer base lock held.
Alexei ended up fixing this in the recent past [0]. So I think this would cause trouble too.
Quoted 4 lines
hrtimer_start_range_ns()->__hrtimer_start_range_ns()->remove_timer()->__remove_hrtimer()->debug_deactivate()->trace_hrtimer_cancel().
BPF can attach to such a tracepoint.
Is it possible to use irq_work_queue() to trigger queue_delay_work() by checking if ssp == &rcu_tasks_trace_srcu_struct ?
Thanks
Zqiang
Quoted 48 lines
[0]: https://lore.kernel.org/bpf/[email protected]
Quoted 44 lines
Regards,
Boqun------>
diff --gita/kernel/rcu/srcutree.cb/kernel/rcu/srcutree.c
index2328827f8775..a5d67264acb5100644
---a/kernel/rcu/srcutree.c
+++b/kernel/rcu/srcutree.c
@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp, structsrcu_node*snp_leaf;
unsigned longsnp_seq;
structsrcu_usage*sup =ssp->srcu_sup;
+ boolirqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */
if (smp_load_acquire(&sup->srcu_size_state)<SRCU_SIZE_WAIT_BARRIER)
@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp,/* Top of tree, must ensure the grace period will be started. */
raw_spin_lock_irqsave_ssp_contention(ssp, &flags);
+irqs_were_disabled=irqs_disabled_flags(flags);
if (ULONG_CMP_LT(sup->srcu_gp_seq_needed, s)) {
/*
* Record need for grace period s. Pair with load
@@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp, // it isn't. And it does not have to be. After all, it
// can only be executed during early boot when there is only
// the one boot CPU running with interrupts still disabled.
+ //
+ // If irq was disabled whencall_srcu()is called, then we
+ // could be in the scheduler path with a runqueue lock held,
+ // delay theprocess_srcu()work 1 more jiffies so we don't go
+ // through thekick_pool()->wake_up_process()path below, and
+ // we could avoid deadlock with runqueue lock.
if (likely(srcu_init_done))
queue_delayed_work(rcu_gp_wq,&sup->work,
- !!srcu_get_delay(ssp));
+ !!srcu_get_delay(ssp) +
+ !!irqs_were_disabled);
else if (list_empty(&sup->work.work.entry))
list_add(&sup->work.work.entry, &srcu_boot_list);
}
Boqun Feng
maintainerQuoted 48 lines · Zqiang
Quoted 48 lines · Boqun Feng
Quoted 32 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 27 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu) ---------------------------- ------------------------------------
[1] holds&rq->__lock
[2]
->call_srcu
->srcu_gp_start_if_needed
->srcu_funnel_gp_start
->spin_lock_irqsave_ssp_content...
-> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..) ->queue_delayed_work
->call_srcu()->__queue_work()
->srcu_gp_start_if_needed()->wake_up_worker()
->srcu_funnel_gp_start()->try_to_wake_up()
->spin_lock_irqsave_ssp_contention()[6] WANTSrq->__lock-> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.Quoted 9 lines
Quoted 4 lines
An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Unfortunately it can be, there is at least one tracepoint that is invoked with hrtimer base lock held.
Alexei ended up fixing this in the recent past [0]. So I think this would cause trouble too.
Quoted 8 lines
Quoted 4 lines
hrtimer_start_range_ns()->__hrtimer_start_range_ns()->remove_timer()->__remove_hrtimer()->debug_deactivate()->trace_hrtimer_cancel().
BPF can attach to such a tracepoint.Is it possible to use
irq_work_queue()to triggerqueue_delay_work()by checking if ssp ==&rcu_tasks_trace_srcu_struct?
Good call! I didn't do the exact == check, but close:
https://lore.kernel.org/rcu/[email protected]/
;-)
Regards,
Boqun
Quoted 52 lines
Thanks
ZqiangQuoted 48 lines
[0]: https://lore.kernel.org/bpf/[email protected]
Quoted 44 lines
Regards,
Boqun------>
diff --gita/kernel/rcu/srcutree.cb/kernel/rcu/srcutree.c
index2328827f8775..a5d67264acb5100644
---a/kernel/rcu/srcutree.c
+++b/kernel/rcu/srcutree.c
@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp, structsrcu_node*snp_leaf;
unsigned longsnp_seq;
structsrcu_usage*sup =ssp->srcu_sup;
+ boolirqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */
if (smp_load_acquire(&sup->srcu_size_state)<SRCU_SIZE_WAIT_BARRIER)
@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp,/* Top of tree, must ensure the grace period will be started. */
raw_spin_lock_irqsave_ssp_contention(ssp, &flags);
+irqs_were_disabled=irqs_disabled_flags(flags);
if (ULONG_CMP_LT(sup->srcu_gp_seq_needed, s)) {
/*
* Record need for grace period s. Pair with load
@@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(structsrcu_struct*ssp, structsrcu_data*sdp, // it isn't. And it does not have to be. After all, it
// can only be executed during early boot when there is only
// the one boot CPU running with interrupts still disabled.
+ //
+ // If irq was disabled whencall_srcu()is called, then we
+ // could be in the scheduler path with a runqueue lock held,
+ // delay theprocess_srcu()work 1 more jiffies so we don't go
+ // through thekick_pool()->wake_up_process()path below, and
+ // we could avoid deadlock with runqueue lock.
if (likely(srcu_init_done))
queue_delayed_work(rcu_gp_wq,&sup->work,
- !!srcu_get_delay(ssp));
+ !!srcu_get_delay(ssp) +
+ !!irqs_were_disabled);
else if (list_empty(&sup->work.work.entry))
list_add(&sup->work.work.entry, &srcu_boot_list);
}
Joel Fernandes
maintainerQuoted 62 lines · Boqun Feng
Quoted 48 lines · Zqiang
Quoted 48 lines
Quoted 34 lines · Boqun Feng
On Wed, Mar 18, 2026 at 02:55:48PM -0700, Boqun Feng wrote:
On Wed, Mar 18, 2026 at 02:52:48PM -0700, Boqun Feng wrote:
[...]Quoted 27 lines
Quoted 16 lines
Ah so it is an ABBA deadlock, not a ABA self-deadlock. I guess this is a different issue, from the NMI issue? It is more of an issue of calling
call_srcuAPI with scheduler locks held.Something like below I think:
CPU A (BPF tracepoint) CPU B (concurrent
call_srcu) ---------------------------- ------------------------------------
[1] holds&rq->__lock
[2]
->call_srcu
->srcu_gp_start_if_needed
->srcu_funnel_gp_start
->spin_lock_irqsave_ssp_content...
-> holds srcu locksQuoted 7 lines
[4] calls
call_rcu_tasks_trace()[5]srcu_funnel_gp_start(cont..) ->queue_delayed_work
->call_srcu()->__queue_work()
->srcu_gp_start_if_needed()->wake_up_worker()
->srcu_funnel_gp_start()->try_to_wake_up()
->spin_lock_irqsave_ssp_contention()[6] WANTSrq->__lock-> WANTS srcu locksI see, we can also have a self deadlock even without CPU B, when CPU A is going to
try_to_wake_up()the a worker on the same CPU.Quoted 9 lines
Quoted 4 lines
An interesting observation is that the deadlock can be avoided in
queue_delayed_work()uses a non-zero delay, that means a timer will be armed instead of acquiring the rq lock.If my observation is correct, then this can probably fix the deadlock issue with runqueue lock (untested though), but it won't work if BPF tracepoint can happen with timer base lock held.
Unfortunately it can be, there is at least one tracepoint that is invoked with hrtimer base lock held.
Alexei ended up fixing this in the recent past [0]. So I think this would cause trouble too.Quoted 8 lines
Quoted 4 lines
hrtimer_start_range_ns()->__hrtimer_start_range_ns()->remove_timer()->__remove_hrtimer()->debug_deactivate()->trace_hrtimer_cancel().
BPF can attach to such a tracepoint.Is it possible to use
irq_work_queue()to triggerqueue_delay_work()by checking if ssp ==&rcu_tasks_trace_srcu_struct?
Quoted 5 lines
Good call! I didn't do the exact == check, but close:
https://lore.kernel.org/rcu/[email protected]/
;-)
IMO I am ok with Boqun patch but I do not think the == check should be used. SRCU internals should not special case specific SRCU users, that is a hack :)
Thanks!
Quoted 56 lines
Regards,
BoqunQuoted 52 lines
Thanks
ZqiangQuoted 48 lines
[0]: https://lore.kernel.org/bpf/[email protected]
Quoted 44 lines
Regards,
Boqun------>
kernel/rcu/srcutree.c +10
-1@@ -1061,6 +1061,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,struct srcu_node *snp_leaf;unsigned long snp_seq;struct srcu_usage *sup = ssp->srcu_sup; +bool irqs_were_disabled;/* Ensure that snp node tree is fully initialized before traversing it */ if (smp_load_acquire (&sup->srcu_size_state) <SRCU_SIZE_WAIT_BARRIER )@@ -1098,6 +1099,7 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,/* Top of tree, must ensure the grace period will be started. */ raw_spin_lock_irqsave_ssp_contention (ssp, &flags); + irqs_were_disabled =irqs_disabled_flags (flags);if (ULONG_CMP_LT (sup->srcu_gp_seq_needed, s)) {/* * Record need for grace period s. Pair with load @@ -1118,9 +1120,16 @@ static void srcu_funnel_gp_start(struct srcu_struct *ssp, struct srcu_data *sdp,// it isn't. And it does not have to be. After all, it // can only be executed during early boot when there is only // the one boot CPU running with interrupts still disabled. +// +// If irq was disabled when call_srcu() is called, then we +// could be in the scheduler path with a runqueue lock held, +// delay the process_srcu() work 1 more jiffies so we don't go +// through the kick_pool() -> wake_up_process() path below, and +// we could avoid deadlock with runqueue lock. if (likely (srcu_init_done))queue_delayed_work (rcu_gp_wq, &sup->work, - !!srcu_get_delay (ssp)); + !!srcu_get_delay (ssp) + + !!irqs_were_disabled);else if (list_empty (&sup->work.work.entry))list_add (&sup->work.work.entry, &srcu_boot_list); }