Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751729AbdGaRpE (ORCPT ); Mon, 31 Jul 2017 13:45:04 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58740 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750905AbdGaRns (ORCPT ); Mon, 31 Jul 2017 13:43:48 -0400 Date: Mon, 31 Jul 2017 10:43:45 -0700 From: "Paul E. McKenney" To: Boqun Feng Cc: Peter Zijlstra , Will Deacon , linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner , Randy Dunlap Subject: Re: [RFC][PATCH v3]: documentation,atomic: Add new documents Reply-To: paulmck@linux.vnet.ibm.com References: <20170609092450.jwmldgtli57ozxgq@hirez.programming.kicks-ass.net> <20170609154442.GB9236@arm.com> <20170609193604.ncw3hhgvewzc3h5u@hirez.programming.kicks-ass.net> <20170611135632.sl72klbeklelupej@tardis> <20170612144929.3wiwtbqopsfpm3qk@hirez.programming.kicks-ass.net> <20170726115328.2sxiitivlnlq64dk@hirez.programming.kicks-ass.net> <20170726124750.vktrn5zi2gmpzfru@tardis> <20170731090535.rjgnoewqg7mhzr55@hirez.programming.kicks-ass.net> <20170731110403.ou3zqsp3uviqorkz@tardis> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170731110403.ou3zqsp3uviqorkz@tardis> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17073117-0040-0000-0000-000003887BE5 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007460; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000214; SDB=6.00895618; UDB=6.00447954; IPR=6.00675805; BA=6.00005503; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00016467; XFM=3.00000015; UTC=2017-07-31 17:43:45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17073117-0041-0000-0000-0000077CA4A4 Message-Id: <20170731174345.GL3730@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-07-31_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1706020000 definitions=main-1707310299 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2407 Lines: 79 On Mon, Jul 31, 2017 at 07:04:03PM +0800, Boqun Feng wrote: > On Mon, Jul 31, 2017 at 11:05:35AM +0200, Peter Zijlstra wrote: > > On Wed, Jul 26, 2017 at 08:47:50PM +0800, Boqun Feng wrote: > > > > > > + > > > > +Further, while something like: > > > > + > > > > + smp_mb__before_atomic(); > > > > + atomic_dec(&X); > > > > + > > > > +is a 'typical' RELEASE pattern, the barrier is strictly stronger than > > > > +a RELEASE. Similarly for something like: > > > > + > > > > > > .. at here. Maybe you planned to put stronger ACQUIRE pattern? > > > > Yes, although I struggled to find a sensible one. The problem is that > > ACQUIRE is on loads and value returning atomics have an ACQUIRE variant, > > so why would you ever want to use smp_mb__after_atomic() for this. > > > > > > That is, the best I could come up with is something like: > > > > val = atomic_fetch_or_relaxed(1, &var); > > smp_mb__after_atomic(); > > > > But in that case we should've just written: > > > > val = atomic_fetch_or_acquire(1, &var); > > > > Agreed. > > And besides, in memory-barriers.txt, the wording is: > > (*) smp_mb__before_atomic(); > (*) smp_mb__after_atomic(); > > These are for use with atomic (such as add, subtract, increment and > decrement) functions that don't return a value, especially when used for > reference counting. > > So actually, using smp_mb__after_atomic() for ACQUIRE is a misuse. You lost me on this one. Why wouldn't the following have ACQUIRE semantics? atomic_inc(&var); smp_mb__after_atomic(); Is the issue that there is no actual value returned or some such? > > Suggestions? > > As a result, I think it's better we say smp_mb__{before,after}_atomic() > are only for 1) non-value-returning RmW atomic ops, 2) > {set,clear,change}_bit and 3) internal use of atomic primitives(e.g. the > generic version of fully ordered atomics). > > 1) prevents people to use it for an ACQUIRE, but allows for a RELEASE. > 1) & 2) makes atomic_t.txt consistent with memory-barriers.txt > 3) explains our usage of those barriers internally. > > Thoughts? So if I have something like this, the assertion really can trigger? WRITE_ONCE(x, 1); atomic_inc(&y); r0 = xchg_release(&y, 5); smp_mb__after_atomic(); r1 = READ_ONCE(x); WARN_ON(r0 == 0 && r1 == 0); I must confess that I am not seeing why we would want to allow this outcome. Thanx, Paul