From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755959AbdKNWWK (ORCPT ); Tue, 14 Nov 2017 17:22:10 -0500 Received: from smtprelay0126.hostedemail.com ([216.40.44.126]:44439 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751233AbdKNWWA (ORCPT ); Tue, 14 Nov 2017 17:22:00 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:1:2:41:69:355:379:541:599:800:960:968:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1431:1437:1515:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:2197:2198:2199:2200:2393:2553:2559:2562:2693:2828:2918:3138:3139:3140:3141:3142:3622:3653:3865:3866:3867:3868:3870:3871:3874:4052:4321:4605:5007:7904:8603:8957:9040:9592:10004:10226:10848:11026:11232:11473:11658:11914:12043:12295:12296:12438:12555:12683:12740:12760:12895:12986:13141:13200:13229:13230:13439:14096:14097:14659:21080:21221:21433:21434:21451:21627:30012:30054:30070:30079:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: smoke11_113c422f25040 X-Filterd-Recvd-Size: 10190 Message-ID: <1510698116.2006.27.camel@perches.com> Subject: Re: [PATCH] perf mmap: Convert ACCESS_ONCE() to READ_ONCE() From: Joe Perches To: paulmck@linux.vnet.ibm.com, Mark Rutland Cc: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Ingo Molnar , Peter Zijlstra Date: Tue, 14 Nov 2017 14:21:56 -0800 In-Reply-To: <20171114220855.GE3624@linux.vnet.ibm.com> References: <20171114103138.9931-1-mark.rutland@arm.com> <20171114220855.GE3624@linux.vnet.ibm.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 $ 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,