On Wed, Mar 18, 2026 at 03:43:05PM +0100, Sebastian Andrzej Siewior wrote:
> On 2026-03-18 04:49:52 [-0700], Paul E. McKenney wrote:
> > > > 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?
> > 
> > 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 ;)
> 
> > > > 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?
> > 
> > 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.

Almost ten years.  ;-)

> > > > 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!
> > > 
> > > 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?

Right, that patch fixes one lockdep problem, but another remains.

> > 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.

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.

> > > >                                                 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?
> > > 
> > > 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.

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

Reply via email to