From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753566AbbIRLaL (ORCPT ); Fri, 18 Sep 2015 07:30:11 -0400 Received: from foss.arm.com ([217.140.101.70]:45839 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753153AbbIRLaI (ORCPT ); Fri, 18 Sep 2015 07:30:08 -0400 Date: Fri, 18 Sep 2015 12:30:09 +0100 From: Will Deacon To: Peter Zijlstra Cc: Dmitry Vyukov , Oleg Nesterov , "ebiederm@xmission.com" , Al Viro , Andrew Morton , Ingo Molnar , Paul McKenney , "mhocko@suse.cz" , LKML , "ktsan@googlegroups.com" , Kostya Serebryany , Andrey Konovalov , Alexander Potapenko , Hans Boehm Subject: Re: [PATCH] kernel: fix data race in put_pid Message-ID: <20150918113009.GD27377@arm.com> References: <1442496268-47803-1-git-send-email-dvyukov@google.com> <20150917160837.GA26050@redhat.com> <20150917174456.GA30178@redhat.com> <20150917180919.GA32116@redhat.com> <20150918085156.GS3816@twins.programming.kicks-ass.net> <20150918092820.GA27377@arm.com> <20150918112252.GT3816@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150918112252.GT3816@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2015 at 12:22:52PM +0100, Peter Zijlstra wrote: > On Fri, Sep 18, 2015 at 10:28:20AM +0100, Will Deacon wrote: > > On Fri, Sep 18, 2015 at 10:06:46AM +0100, Dmitry Vyukov wrote: > > > > Can we have something along the lines of: > > > > > > #define atomic_read_ctrl(v) READ_ONCE_CTRL(&(v)->counter) > > > > Funnily enough, I had this exact same discussion off-list yesterday > > afternoon, since I wrote some code relying on a ctrl dependency from > > an atomic_read to an atomic_xchg_relaxed. > > Something a little like so should work fine I suppose. > > --- > Subject: atomic: Implement atomic_read_ctrl() > > Provide atomic_read_ctrl() to mirror READ_ONCE_CTRL(), such that we can > more conveniently use atomics in control dependencies. > > Since we can assume atomic_read() implies a READ_ONCE(), we must only > emit an extra smp_read_barrier_depends() in order to upgrade to > READ_ONCE_CTRL() semantics. > > Requested-by: Dmitry Vyukov > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/atomic.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/include/linux/atomic.h b/include/linux/atomic.h > index 00a5763e850e..c4072421ea7f 100644 > --- a/include/linux/atomic.h > +++ b/include/linux/atomic.h > @@ -4,6 +4,15 @@ > #include > #include > > +#ifndef atomic_read_ctrl > +static inline int atomic_read_ctrl(atomic_t *v) > +{ > + int val = atomic_read(v); > + smp_read_barrier_depends(); /* Enforce control dependency. */ > + return val; > +} > +#endif > + > /* > * Relaxed variants of xchg, cmpxchg and some atomic operations. > * Works for me: Acked-by: Will Deacon Will