From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753531AbbIRL2T (ORCPT ); Fri, 18 Sep 2015 07:28:19 -0400 Received: from casper.infradead.org ([85.118.1.10]:42423 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752400AbbIRL2R (ORCPT ); Fri, 18 Sep 2015 07:28:17 -0400 Date: Fri, 18 Sep 2015 13:22:52 +0200 From: Peter Zijlstra To: Will Deacon 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: <20150918112252.GT3816@twins.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150918092820.GA27377@arm.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. *