Re: [PATCH 2/2] rcu: Robustify rcu_is_cpu_rrupt_from_idle()
From: Frederic Weisbecker
Date: Sun Mar 23 2025 - 18:31:49 EST
Le Sat, Mar 22, 2025 at 06:00:13PM +0100, Joel Fernandes a écrit :
>
>
> On 3/18/2025 2:56 PM, Frederic Weisbecker wrote:
> > RCU relies on the context tracking nesting counter in order to determine
> > if it is running in extended quiescent state.
> >
> > However the context tracking nesting counter is not completely
> > synchronized with the actual context tracking state:
> >
> > * The nesting counter is set to 1 or incremented further _after_ the
> > actual state is set to RCU not watching.
>
> I agree with patch, but this line is a bit confusing ->nesting is set to 1
> *after* the RCU state is set to "watching". Did you mean "watching" ?
>
> But I think you meant "After RCU transitions from a state of not-watching to
> watching' instead of 'actual state is set to RCU not watching'..
>
> ct_kernel_entry():
>
> // RCU is not watching here ...
> ct_kernel_enter_state(offset);
> // ... but is watching here.
> WRITE_ONCE(ct->nesting, 1);
Oh I completely inverted the thing in the changelog!
>
> > (then we know for sure we interrupted RCU not watching)
> >
> > * The nesting counter is set to 0 or decremented further _before_ the
> > actual state is set to RCU watching.
> >
> > Therefore it is safe to assume that if ct_nesting() > 0, RCU is not
> > watching. But if ct_nesting() <= 0, RCU is watching except for a tiny
> > window.
> >
> > This hasn't been a problem so far because rcu_is_cpu_rrupt_from_idle()
> > has only been called from interrupts. However the code is confusing
>
> Agreed, and I could also see the existing code's snippet:
> WARN_ON_ONCE(!nesting && !is_idle_task(current));
>
> .. not working if this function were to be called from non-interrupt kernel
> context.
Right.
I'll reissue that one.
Thanks!