Re: [PATCH 3/8] srcu: Use local_lock() for per-CPU struct srcu_data access

From: Joel Fernandes
Date: Wed May 20 2020 - 15:00:07 EST


On Wed, May 20, 2020 at 08:28:00PM +0200, Sebastian Andrzej Siewior wrote:
> On 2020-05-20 13:42:59 [-0400], Joel Fernandes wrote:
> > Hi Sebastian,
> Hi Joel,
>
> > For pointer stability, can we just use get_local_ptr() and put_local_ptr()
> > instead of adding an extra lock? This keeps the pointer stable while keeping
> > the section preemptible on -rt. And we already have a lock in rcu_data, I
> > prefer not to add another lock if possible.
>
> What is this get_local_ptr() doing? I can't find it anywhereâ

I replied about it in the other thread.


> > > I remember Paul looked at that patch a few years ago and he said that
> > > that disabling interrupts here is important and matches the other part
> > > instance where the interrupts are disabled. Looking at it now, it seems
> > > that there is just pointer stability but I can't tell if
> > > rcu_segcblist_pend_cbs() needs more than just this.
> >
> > Which 'other part' are you referring to? Your patch removed local_irq_save()
> > from other places as well right?
>
> The patch converted hunks.
>

So then there are no other local_irq_save() to match with. Or may be I did
not understand your concern, could you share any threads from past
discussions about disabling interrupts in this code? You mentioned about a
discussion from few years ago.

> >
> > - Joel
> >
> > ---8<-----------------------
> >
> > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> > index 8ff71e5d0fe8b..5f49919205317 100644
> > --- a/kernel/rcu/srcutree.c
> > +++ b/kernel/rcu/srcutree.c
> > @@ -778,13 +778,17 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp)
> > unsigned long tlast;
> >
> > /* If the local srcu_data structure has callbacks, not idle. */
> > - local_irq_save(flags);
> > - sdp = this_cpu_ptr(ssp->sda);
> > + sdp = get_local_ptr(ssp->sda);
> > + spin_lock_irqsave_rcu_node(sdp, flags);
>
> You acquire the node lock which was not acquired before. Is that okay?
> How is get_local_ptr() different to raw_cpu_ptr()?

get_cpu_ptr() disables preemption which you might not want, right?

Most (all?) other paths are accessing the cblist under lock so I added it
here to be safe. This is anyway called from a slowpath. Do you see a problem?

thanks,

- Joel