Re: [PATCH v2 3/6] rcu: limit PREEMPT_RCU configurations
From: Frederic Weisbecker
Date: Thu Nov 14 2024 - 06:36:17 EST
Le Thu, Nov 14, 2024 at 09:25:34AM +0100, Sebastian Andrzej Siewior a écrit :
> On 2024-11-13 16:23:03 [-0800], Ankur Arora wrote:
> > > But looking at !CONFIG_PREEMPT_RCU code on tree_plugin.h, I see
> > > some issues now that the code can be preemptible. Well I think
> > > it has always been preemptible but PREEMPTION && !PREEMPT_RCU
> > > has seldom been exerciced (or was it even possible?).
> > >
> > > For example rcu_read_unlock_strict() can be called with preemption
> > > enabled so we need the following otherwise the rdp is unstable, the
> > > norm value becomes racy
> >
> > I think I see your point about rdp being racy, but given that
> > rcu_read_unlock_strict() would always be called with a non-zero
> > preemption count (with CONFIG_PREEMPTION), wouldn't the preempt_count()
> > check defeat any calls to rcu_read_unlock_strict()?
> >
> > void rcu_read_unlock_strict(void)
> > {
> > struct rcu_data *rdp;
> >
> > if (irqs_disabled() || preempt_count() || !rcu_state.gp_kthread)
> > return;
> >
> > Or am I missing something?
Haha, right!
>
> This is indeed broken. By moving preempt_disable() as Frederic suggested
> then rcu_read_unlock_strict() becomes a NOP. Keeping this as-is results
> in spats due to this_cpu_ptr() in preemptible regions. Looking further
> we have "rdp->cpu != smp_processor_id()" as the next candidate.
>
> That preempt_disable() should go to rcu_read_unlock_strict() after the
> check.
Yeah that looks better ;-)
>
> > Ankur
>
> Sebastian