From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755324AbdJITvQ (ORCPT ); Mon, 9 Oct 2017 15:51:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47150 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755183AbdJITvO (ORCPT ); Mon, 9 Oct 2017 15:51:14 -0400 Date: Mon, 9 Oct 2017 12:51:12 -0700 From: "Paul E. McKenney" To: Mark Rutland Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH 13/13] rcutorture: formal: prepare for ACCESS_ONCE() removal Reply-To: paulmck@linux.vnet.ibm.com References: <1507573730-8083-1-git-send-email-mark.rutland@arm.com> <1507573730-8083-14-git-send-email-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1507573730-8083-14-git-send-email-mark.rutland@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17100919-0036-0000-0000-000002791224 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007869; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000235; SDB=6.00928767; UDB=6.00467438; IPR=6.00709039; BA=6.00005631; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017463; XFM=3.00000015; UTC=2017-10-09 19:51:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100919-0037-0000-0000-000042064A48 Message-Id: <20171009195112.GL3521@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-09_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-1707230000 definitions=main-1710090288 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 09, 2017 at 07:28:50PM +0100, Mark Rutland wrote: > For several reasons, it is desirable to use {READ,WRITE}_ONCE() in > preference to ACCESS_ONCE(), and new code is expected to use one of the > former. So far, there's been no reason to change most existing uses of > ACCESS_ONCE(), as these aren't currently harmful. > > However, for some features it is necessary to instrument reads and > writes separately, which is not possible with ACCESS_ONCE(). This > distinction is critical to correct operation. > > The bulk of the kernel code can be transformed via Coccinelle to use > {READ,WRITE}_ONCE(), though this only modifies users of ACCESS_ONCE(), > and not the implementation itself. As such, it has the potential to > break homebrew ACCESS_ONCE() macros seen in some user code in the kernel > tree (e.g. the virtio code, as fixed in commit ea9156fb3b71d9f7). > > To avoid fragility if/when that transformation occurs, this patch > reworks the rcutorture formal tests to use an intermediate > __ACCESS_ONCE() helper, which will avoid {READ,WRITE}_ONCE() being > turned into tautological definitions. There should be no functional > change as a result of this patch. > > Cc: Paul E. McKenney > Signed-off-by: Mark Rutland > --- > tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h > index 6687acc..ee4e4f8 100644 > --- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h > +++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h > @@ -34,8 +34,9 @@ > #define rs_smp_mb() do {} while (0) > #endif > > -#define ACCESS_ONCE(x) (*(volatile typeof(x) *) &(x)) > -#define READ_ONCE(x) ACCESS_ONCE(x) > -#define WRITE_ONCE(x, val) (ACCESS_ONCE(x) = (val)) > +#define __ACCESS_ONCE(x) (*(volatile typeof(x) *) &(x)) > +#define ACCESS_ONCE(x) __ACCESS_ONCE(x) > +#define READ_ONCE(x) __ACCESS_ONCE(x) > +#define WRITE_ONCE(x, val) (__ACCESS_ONCE(x) = (val)) How about something like the following? #define READ_ONCE(x) (*(volatile typeof(x) *) &(x)) #define WRITE_ONCE(x) ((*(volatile typeof(x) *) &(x)) = (val)) Thanx, Paul