Received: by 10.213.65.68 with SMTP id h4csp2866849imn; Mon, 9 Apr 2018 10:14:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx48gV5lG0RUnPAL0M9gS5ql/CKeUzddDQR6PkbawEfqLq6JJbH2+2ilaoHNL2XIHm2fbbcnZ X-Received: by 2002:a17:902:244:: with SMTP id 62-v6mr31182271plc.125.1523294052337; Mon, 09 Apr 2018 10:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523294052; cv=none; d=google.com; s=arc-20160816; b=wOSwYX5Pb1xQ7X76DaIJNAtMPhA21HtIQt0zkiFdj/CJCXHbeyc7LIrgdF2w4jOOL8 SukBvJPC477gFg7G0howIRSJViEoCjDrUJnY0SMZTHaFcWhANgWYM/yCchqSZMjT+/kl cEykwpaweVjny/+yGzipA1Qe3FE+qtPhuJt6G3bH3ELGFXAlcq6r4E+1eD5FIh50I1bF rsVopX6HazkJTJ7gbSejZIwagkwqIBE0nT5+yxAXCEymT9jFSsjUBC74WsTkt8BP//ZG c9qG5ennL9g+Q+1I4QBxAnjWyCe2yLuf4Ytmc7nPdih+rSozkMsd0+X+y1QvVGgH5L9Q +q6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=jYJl6gx0lrPL0DiUnv/UocC0m7nSJWFIQmEGG5vg1pI=; b=jNAlB/+fsZhmZKKt57sVYirlyyesdo3EJNxvdmybZ7RdKzXPwXws0Q0JCuIeuiGCk4 +tB/lwDTlAlw/+4PUZLf4F1a/sMCm763o6s1XAwtU1bV7iMXkrNXBYtLpIK5KDRxj2D6 1/4T/l7Y4LmWn6lR5MH48jH8DcT/QB6Vdk8MnIiDozT7gxqIx69+lcQk9ZKYEYMo1kvL tyXW2Z1t7ZWNOp8veCk5nSzaimj1suECFzDicifsjL2Yj2QXSY6NTZI73Gka73Flm+9H Yr2qnDyf0c8URWa8PN/0GX9FcOVMARZpyLFQeDc6WTMog3CNm+v/eyy5EFdaTfy9+qRV T+5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s198si438833pgc.151.2018.04.09.10.13.35; Mon, 09 Apr 2018 10:14:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752351AbeDIRKt (ORCPT + 99 others); Mon, 9 Apr 2018 13:10:49 -0400 Received: from foss.arm.com ([217.140.101.70]:58730 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752202AbeDIRKs (ORCPT ); Mon, 9 Apr 2018 13:10:48 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55AA01529; Mon, 9 Apr 2018 10:10:48 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AD053F592; Mon, 9 Apr 2018 10:10:47 -0700 (PDT) Date: Mon, 9 Apr 2018 18:10:41 +0100 From: Mark Rutland To: linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo Cc: lizhijian@cn.fujitsu.com, sandipan@linux.vnet.ibm.com Subject: Re: [PATCH] tools: restore READ_ONCE() C++ compatibility Message-ID: <20180409171041.6qfabrccsqu4bdlc@lakrids.cambridge.arm.com> References: <20180404163445.16492-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180404163445.16492-1-mark.rutland@arm.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnaldo, As Sandipan gave a Tested-by for this, are you happy to pick it up as a fix for v4.17? Or would you prefer that I resend this? Thanks, Mark. On Wed, Apr 04, 2018 at 05:34:45PM +0100, Mark Rutland wrote: > Our userspace defines READ_ONCE() in a way that clang > doesn't like, as we have an anonymous union in which neither field is > initialized. > > WRITE_ONCE() is fine since it initializes the __val field. For > READ_ONCE() we can keep clang and GCC happy with a dummy initialization > of the __c field, so let's do that. > > At the same time, let's split READ_ONCE() and WRITE_ONCE() over several > lines for legibility, as we do in the in-kernel . > > Signed-off-by: Mark Rutland > Fixes: 6aa7de059173a986 ("locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()") > Reported-by: Li Zhijian > Reported-by: Sandipan Das > Cc: Arnaldo Carvalho de Melo > --- > tools/include/linux/compiler.h | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > Hi, > > This is fallout from my automated ACCESS_ONCE() removal, and I'm not that > familiar with using clang for perf. > > In local testing, this fixes READ_ONCE() when compiling with clang, but I > subsequently hit some other issues which I believe are down to LLVM API > changes. > > Zhijian, Sandipan, does this patch work for you? > > Thanks, > Mark. > > diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h > index 04e32f965ad7..1827c2f973f9 100644 > --- a/tools/include/linux/compiler.h > +++ b/tools/include/linux/compiler.h > @@ -151,11 +151,21 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > * required ordering. > */ > > -#define READ_ONCE(x) \ > - ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > - > -#define WRITE_ONCE(x, val) \ > - ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > +#define READ_ONCE(x) \ > +({ \ > + union { typeof(x) __val; char __c[1]; } __u = \ > + { .__c = { 0 } }; \ > + __read_once_size(&(x), __u.__c, sizeof(x)); \ > + __u.__val; \ > +}) > + > +#define WRITE_ONCE(x, val) \ > +({ \ > + union { typeof(x) __val; char __c[1]; } __u = \ > + { .__val = (val) }; \ > + __write_once_size(&(x), __u.__c, sizeof(x)); \ > + __u.__val; \ > +}) > > > #ifndef __fallthrough > -- > 2.11.0 >