[Linux-kernel-mentees] [PATCH 2/2] events: callchain: Use RCU API to access RCU pointer

Amol Grover frextrite at gmail.com
Thu Jan 30 10:14:51 UTC 2020


On Thu, Jan 30, 2020 at 09:23:21AM +0100, Peter Zijlstra wrote:
> On Wed, Jan 29, 2020 at 05:19:09PM -0500, Joel Fernandes wrote:
> > On Wed, Jan 29, 2020 at 09:38:13PM +0530, Amol Grover wrote:
> > > callchain_cpus_entries is annotated as an RCU pointer.
> > > Hence rcu_dereference_protected or similar RCU API is
> > > required to dereference the pointer.
> > > 
> > > This fixes the following sparse warning
> > > kernel/events/callchain.c:65:17: warning: incorrect type in assignment
> 
> Seems silly to have this two patches; the first introduces the second
> issue, might as well fix it all in one go.
> 

Got it. I'll combine them into a single patch and re-send.

> Also look at the output of:
> 
>   git log --oneline kernel/events/
> 
> and then at your $subject.
> 
> > > Signed-off-by: Amol Grover <frextrite at gmail.com>
> > > ---
> > >  kernel/events/callchain.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> > > index f91e1f41d25d..a672d02a1b3a 100644
> > > --- a/kernel/events/callchain.c
> > > +++ b/kernel/events/callchain.c
> > > @@ -62,7 +62,8 @@ static void release_callchain_buffers(void)
> > >  {
> > >  	struct callchain_cpus_entries *entries;
> > >  
> > > -	entries = callchain_cpus_entries;
> > > +	entries = rcu_dereference_protected(callchain_cpus_entries,
> > > +					    lockdep_is_held(&callchain_mutex));
> > 
> > 
> > Reviewed-by: Joel Fernandes (Google) <joel at joelfernandes.org>
> 
> Do we really need that smp_read_barrier_depends() here? Then again, I
> don't suppose this is a fast path.
> 

rcu_dereference_protected is actually a lightweight API and IIRC it
omits the READ_ONCE() and hence the memory barriers.

Thanks
Amol

> IIRC even Alpha got the dependent write ordering right.
> 
> > >  	RCU_INIT_POINTER(callchain_cpus_entries, NULL);
> > >  	call_rcu(&entries->rcu_head, release_callchain_buffers_rcu);
> > >  }
> > > -- 
> > > 2.24.1
> > > 


More information about the Linux-kernel-mentees mailing list