From patchwork Fri Apr 13 14:00:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 133376 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp762512ljb; Fri, 13 Apr 2018 07:02:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx49MKYVShta79CPdNa2Is0fp16BSukpBwS+WYyfM892M7fj4i28OvalIltbD2yXHolO/t1QP X-Received: by 2002:a17:902:7b96:: with SMTP id w22-v6mr5404024pll.116.1523628120666; Fri, 13 Apr 2018 07:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523628120; cv=none; d=google.com; s=arc-20160816; b=ihrL2FIVhl3b3qPJntHMr+YkPhVNaiYcTkCgktk1+MyjdvSRa9hulQi9AZ8ElhODVc nGOLKDjLyg5Cwq51O+4Z3DQDWWGOgKULZh4G2G7O/8nLjAtAaWdLVKvOGSc/Z0zUPUa+ pBJlQnN0v8/oSRtkHdnLT4VZ+n78txnyoZpHfgdFOzo41ZegBz7GVDLn9PKxKgO+HpId CFAASLTW4rVifWgFf5RvBclc00hsyQrQBPYJv+l9oKlUBXa5XPuwtNAiBRkXn9sC+221 kFTfx+RgiocG630bKuRdNDOU89S8CXETKfB/bKISDH1jzc4hnR07wdiNKpJdx5whZeDs FfnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=IeZtq7g5BLWixZlRKK1pjAf7jdj2HIGhqhr1ZsFIHvo=; b=qJ7MEoJOTiNPPJ2h1X2JWnH1tUeldQaux4jVc/TNTlDYC9d1l3Y9Vy8V3TCJx3PMgk FeTRPXi1E0rlSKAies8M2bm4+B3FNlyrjxrBIuhDvRWm+FKxzavHpZtuj6CRT3lKJNnz QgomvidSe4zk6eNTK9aAprVm6cRmr+0IZnJk+okY1UeWLk22AT8OBpHuBftpmTmLMiZs L5itNwWD/3eTYL+OZQHI0C1bARKtM6r969joDsaAT7xZ+97hrStVy9GHpEUyQ73lwztz nc51XMTtrtIEnEb/Ym7nB10Tp6K15b4bWRlQTL6Nhfk3uZVhc8FAIebvwFsWScHGwZEk 9QDw== 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 c4si195663pgu.282.2018.04.13.07.01.47; Fri, 13 Apr 2018 07:02:00 -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 S1754422AbeDMOBf (ORCPT + 29 others); Fri, 13 Apr 2018 10:01:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:53598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753859AbeDMOBc (ORCPT ); Fri, 13 Apr 2018 10:01:32 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3F9D217A6; Fri, 13 Apr 2018 14:01:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3F9D217A6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Mark Rutland , Arnaldo Carvalho de Melo Subject: [PATCH 02/17] tools headers: Restore READ_ONCE() C++ compatibility Date: Fri, 13 Apr 2018 11:00:56 -0300 Message-Id: <20180413140111.25313-3-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180413140111.25313-1-acme@kernel.org> References: <20180413140111.25313-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland 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 . Reported-by: Li Zhijian Reported-by: Sandipan Das Tested-by: Sandipan Das Signed-off-by: Mark Rutland Fixes: 6aa7de059173a986 ("locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()") Link: http://lkml.kernel.org/r/20180404163445.16492-1-mark.rutland@arm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/compiler.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.14.3 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