From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756053AbdKNW4T (ORCPT ); Tue, 14 Nov 2017 17:56:19 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48034 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751736AbdKNW4K (ORCPT ); Tue, 14 Nov 2017 17:56:10 -0500 Date: Tue, 14 Nov 2017 14:56:05 -0800 From: "Paul E. McKenney" To: Joe Perches Cc: Mark Rutland , linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra Subject: Re: [PATCH] perf mmap: Convert ACCESS_ONCE() to READ_ONCE() Reply-To: paulmck@linux.vnet.ibm.com References: <20171114103138.9931-1-mark.rutland@arm.com> <20171114220855.GE3624@linux.vnet.ibm.com> <1510698116.2006.27.camel@perches.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1510698116.2006.27.camel@perches.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17111422-0056-0000-0000-000003E9D90A X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008066; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00945935; UDB=6.00477437; IPR=6.00726232; BA=6.00005690; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018018; XFM=3.00000015; UTC=2017-11-14 22:56:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111422-0057-0000-0000-00000820F7DE Message-Id: <20171114225605.GG3624@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-14_12:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711140306 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 14, 2017 at 02:21:56PM -0800, Joe Perches wrote: > On Tue, 2017-11-14 at 14:08 -0800, Paul E. McKenney wrote: > > On Tue, Nov 14, 2017 at 10:31:38AM +0000, Mark Rutland wrote: > > > Recently there was a treewide conversion of ACCESS_ONCE() to > > > {READ,WRITE}_ONCE(), but a new use was introduced concurrently by > > > commit: > > > > > > 1695849735752d2a ("perf mmap: Move perf_mmap and methods to separate mmap.[ch] files") > > > > > > Let's convert this over to READ_ONCE() so that we can remove the > > > ACCESS_ONCE() definitions in subsequent patches. > > > > > > Signed-off-by: Mark Rutland > > > Cc: Arnaldo Carvalho de Melo > > > Cc: Ingo Molnar > > > Cc: Paul E. McKenney > > > Cc: Peter Zijlstra > > > > Reviewed-by: Paul E. McKenney > > > > Woo-hoo! Good to see that your Coccinelle script has already done > > its magic! ;-) > > Might be nice to remove all the other references too Agreed, and that is exactly what Mark was referring to in his "remove the ACCESS_ONCE() definitions in subsequent patches". ;-) Thanx, Paul > $ git grep -w ACCESS_ONCE > Documentation/RCU/RTFP.txt: ACCESS_ONCE(). > include/linux/compiler.h: * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the > include/linux/compiler.h: * WRITE_ONCE or ACCESS_ONCE() in different C statements. > include/linux/compiler.h: * In contrast to ACCESS_ONCE these two macros will also work on aggregate > include/linux/compiler.h: * is also forbidden from reordering successive instances of ACCESS_ONCE(), > include/linux/compiler.h: * ACCESS_ONCE() in different C statements. > include/linux/compiler.h: * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE > include/linux/compiler.h: * The major use cases of ACCESS_ONCE used to be (1) Mediating communication > include/linux/compiler.h:#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x)) > scripts/checkpatch.pl:# whine about ACCESS_ONCE > scripts/checkpatch.pl: "Prefer WRITE_ONCE(, ) over ACCESS_ONCE() = \n" . $herecurr) && > scripts/checkpatch.pl: "Prefer READ_ONCE() over ACCESS_ONCE()\n" . $herecurr) && > tools/include/linux/compiler.h:#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) > tools/include/linux/compiler.h: * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the > tools/include/linux/compiler.h: * WRITE_ONCE or ACCESS_ONCE() in different C statements. > tools/include/linux/compiler.h: * In contrast to ACCESS_ONCE these two macros will also work on aggregate > tools/perf/util/mmap.h: u64 head = ACCESS_ONCE(pc->data_head); > > --- > include/linux/compiler.h | 45 ++++++++++-------------------------------- > scripts/checkpatch.pl | 22 --------------------- > tools/include/linux/compiler.h | 19 ++++++++---------- > 3 files changed, 18 insertions(+), 68 deletions(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 3672353a0acd..f729154dae9b 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -215,17 +215,17 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > /* > * Prevent the compiler from merging or refetching reads or writes. The > * compiler is also forbidden from reordering successive instances of > - * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the > - * compiler is aware of some particular ordering. One way to make the > - * compiler aware of ordering is to put the two invocations of READ_ONCE, > - * WRITE_ONCE or ACCESS_ONCE() in different C statements. > + * READ_ONCE and WRITE_ONCE (see below), but only when the compiler is > + * aware of some particular ordering. One way to make the compiler aware > + * of ordering is to put the two invocations of READ_ONCE and WRITE_ONCE > + * in different C statements. > * > - * In contrast to ACCESS_ONCE these two macros will also work on aggregate > - * data types like structs or unions. If the size of the accessed data > - * type exceeds the word size of the machine (e.g., 32 bits or 64 bits) > - * READ_ONCE() and WRITE_ONCE() will fall back to memcpy(). There's at > - * least two memcpy()s: one for the __builtin_memcpy() and then one for > - * the macro doing the copy of variable - '__u' allocated on the stack. > + * These two macros will work on aggregate data types like structs or unions. > + * If the size of the accessed data type exceeds the word size of the machine > + * (e.g., 32 bits or 64 bits) READ_ONCE() and WRITE_ONCE() will fall back to > + * memcpy(). There are at least two memcpy()s: one for the __builtin_memcpy() > + * and then one for the macro doing the copy of variable - '__u' allocated on > + * the stack. > * > * Their two major use cases are: (1) Mediating communication between > * process-level code and irq/NMI handlers, all running on the same CPU, > @@ -322,29 +322,4 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > compiletime_assert(__native_word(t), \ > "Need native word sized stores/loads for atomicity.") > > -/* > - * Prevent the compiler from merging or refetching accesses. The compiler > - * is also forbidden from reordering successive instances of ACCESS_ONCE(), > - * but only when the compiler is aware of some particular ordering. One way > - * to make the compiler aware of ordering is to put the two invocations of > - * ACCESS_ONCE() in different C statements. > - * > - * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE > - * on a union member will work as long as the size of the member matches the > - * size of the union and the size is smaller than word size. > - * > - * The major use cases of ACCESS_ONCE used to be (1) Mediating communication > - * between process-level code and irq/NMI handlers, all running on the same CPU, > - * and (2) Ensuring that the compiler does not fold, spindle, or otherwise > - * mutilate accesses that either do not require ordering or that interact > - * with an explicit memory barrier or atomic instruction that provides the > - * required ordering. > - * > - * If possible use READ_ONCE()/WRITE_ONCE() instead. > - */ > -#define __ACCESS_ONCE(x) ({ \ > - __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \ > - (volatile typeof(x) *)&(x); }) > -#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x)) > - > #endif /* __LINUX_COMPILER_H */ > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 8b80bac055e4..fffe1e5895a2 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -6242,28 +6242,6 @@ sub process { > } > } > > -# whine about ACCESS_ONCE > - if ($^V && $^V ge 5.10.0 && > - $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) { > - my $par = $1; > - my $eq = $2; > - my $fun = $3; > - $par =~ s/^\(\s*(.*)\s*\)$/$1/; > - if (defined($eq)) { > - if (WARN("PREFER_WRITE_ONCE", > - "Prefer WRITE_ONCE(, ) over ACCESS_ONCE() = \n" . $herecurr) && > - $fix) { > - $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)\s*$eq\s*\Q$fun\E/WRITE_ONCE($par, $fun)/; > - } > - } else { > - if (WARN("PREFER_READ_ONCE", > - "Prefer READ_ONCE() over ACCESS_ONCE()\n" . $herecurr) && > - $fix) { > - $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)/READ_ONCE($par)/; > - } > - } > - } > - > # check for mutex_trylock_recursive usage > if ($line =~ /mutex_trylock_recursive/) { > ERROR("LOCKING", > diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h > index 07fd03c74a77..cb77706af769 100644 > --- a/tools/include/linux/compiler.h > +++ b/tools/include/linux/compiler.h > @@ -84,8 +84,6 @@ > > #define uninitialized_var(x) x = *(&(x)) > > -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) > - > #include > > /* > @@ -135,16 +133,15 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > /* > * Prevent the compiler from merging or refetching reads or writes. The > * compiler is also forbidden from reordering successive instances of > - * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the > - * compiler is aware of some particular ordering. One way to make the > - * compiler aware of ordering is to put the two invocations of READ_ONCE, > - * WRITE_ONCE or ACCESS_ONCE() in different C statements. > + * READ_ONCE and WRITE_ONCE, but only when the compiler is aware of some > + * particular ordering. One way to make the compiler aware of ordering is > + * to put the two invocations of READ_ONCE or WRITE_ONCE in different C > + * statements. > * > - * In contrast to ACCESS_ONCE these two macros will also work on aggregate > - * data types like structs or unions. If the size of the accessed data > - * type exceeds the word size of the machine (e.g., 32 bits or 64 bits) > - * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a > - * compile-time warning. > + * These two macros will also work on aggregate data types like structs or > + * unions. If the size of the accessed data type exceeds the word size of the > + * machine (e.g., 32 bits or 64 bits) READ_ONCE() and WRITE_ONCE() will fall > + * back to memcpy and print a compile-time warning. > * > * Their two major use cases are: (1) Mediating communication between > * process-level code and irq/NMI handlers, all running on the same CPU, >