From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932678AbcKPO01 (ORCPT ); Wed, 16 Nov 2016 09:26:27 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:50704 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932180AbcKPO0Y (ORCPT ); Wed, 16 Nov 2016 09:26:24 -0500 Date: Wed, 16 Nov 2016 06:26:19 -0800 From: "Paul E. McKenney" To: Mark Rutland Cc: linux-kernel@vger.kernel.org, Boqun Feng , Jonathan Corbet , Peter Zijlstra , Will Deacon , linux-doc@vger.kernel.org Subject: Re: [PATCH] Documentation: atomic_ops: use {READ,WRITE}_ONCE() Reply-To: paulmck@linux.vnet.ibm.com References: <1479294839-12811-1-git-send-email-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1479294839-12811-1-git-send-email-mark.rutland@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16111614-0020-0000-0000-00000A45BC5C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006088; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00781485; UDB=6.00376982; IPR=6.00558995; BA=6.00004886; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013345; XFM=3.00000011; UTC=2016-11-16 14:26:21 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16111614-0021-0000-0000-00005752135D Message-Id: <20161116142619.GD3612@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-16_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-1609300000 definitions=main-1611160233 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 16, 2016 at 11:13:59AM +0000, Mark Rutland wrote: > While the {READ,WRITE}_ONCE() macros should be used in preference to > ACCESS_ONCE(), the atomic documentation uses the latter exclusively. > > To point people in the right direction, and as a step towards the > eventual removal of ACCESS_ONCE(), update the documentation to use the > {READ,WRITE}_ONCE() macros as appropriate. > > Signed-off-by: Mark Rutland > Cc: Boqun Feng > Cc: Jonathan Corbet > Cc: Paul E. McKenney > Cc: Peter Zijlstra > Cc: Will Deacon > Cc: linux-doc@vger.kernel.org > Cc: linux-kernel@vger.kernel.org Acked-by: Paul E. McKenney > --- > Documentation/atomic_ops.txt | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/Documentation/atomic_ops.txt b/Documentation/atomic_ops.txt > index c9d1cac..a1b9a54 100644 > --- a/Documentation/atomic_ops.txt > +++ b/Documentation/atomic_ops.txt > @@ -90,10 +90,10 @@ compiler optimizes the section accessing atomic_t variables. > > Properly aligned pointers, longs, ints, and chars (and unsigned > equivalents) may be atomically loaded from and stored to in the same > -sense as described for atomic_read() and atomic_set(). The ACCESS_ONCE() > -macro should be used to prevent the compiler from using optimizations > -that might otherwise optimize accesses out of existence on the one hand, > -or that might create unsolicited accesses on the other. > +sense as described for atomic_read() and atomic_set(). The READ_ONCE() > +and WRITE_ONCE() macros should be used to prevent the compiler from using > +optimizations that might otherwise optimize accesses out of existence on > +the one hand, or that might create unsolicited accesses on the other. > > For example consider the following code: > > @@ -112,7 +112,7 @@ the following: > If you don't want the compiler to do this (and you probably don't), then > you should use something like the following: > > - while (ACCESS_ONCE(a) < 0) > + while (READ_ONCE(a) < 0) > do_something(); > > Alternatively, you could place a barrier() call in the loop. > @@ -141,7 +141,7 @@ of registers: reloading from variable a could save a flush to the > stack and later reload. To prevent the compiler from attacking your > code in this manner, write the following: > > - tmp_a = ACCESS_ONCE(a); > + tmp_a = READ_ONCE(a); > do_something_with(tmp_a); > do_something_else_with(tmp_a); > > @@ -166,14 +166,14 @@ that expected b to never have the value 42 if a was zero. To prevent > the compiler from doing this, write something like: > > if (a) > - ACCESS_ONCE(b) = 9; > + WRITE_ONCE(b, 9); > else > - ACCESS_ONCE(b) = 42; > + WRITE_ONCE(b, 42); > > Don't even -think- about doing this without proper use of memory barriers, > locks, or atomic operations if variable a can change at runtime! > > -*** WARNING: ACCESS_ONCE() DOES NOT IMPLY A BARRIER! *** > +*** WARNING: READ_ONCE() OR WRITE_ONCE() DO NOT IMPLY A BARRIER! *** > > Now, we move onto the atomic operation interfaces typically implemented with > the help of assembly code. > -- > 1.9.1 >