linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Mark Rutland <mark.rutland@arm.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 02/17] tools headers: Restore READ_ONCE() C++ compatibility
Date: Fri, 13 Apr 2018 11:00:56 -0300	[thread overview]
Message-ID: <20180413140111.25313-3-acme@kernel.org> (raw)
In-Reply-To: <20180413140111.25313-1-acme@kernel.org>

From: Mark Rutland <mark.rutland@arm.com>

Our userspace <linux/compiler.h> 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 <linux/compiler.h>.

Reported-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Reported-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
Tested-by: Sandipan Das <sandipan@linux.vnet.ibm.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
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 <acme@redhat.com>
---
 tools/include/linux/compiler.h | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

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.14.3

  parent reply	other threads:[~2018-04-13 14:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180413140111.25313-1-acme@kernel.org>
2018-04-13 14:00 ` [PATCH 01/17] perf stat: Enable 1ms interval for printing event counters values Arnaldo Carvalho de Melo
2018-04-13 14:00 ` Arnaldo Carvalho de Melo [this message]
2018-04-13 14:00 ` [PATCH 03/17] perf tests: Run dwarf unwind test on arm32 Arnaldo Carvalho de Melo
2018-04-13 14:00 ` [PATCH 04/17] perf annotate: Allow showing offsets in more than just jump targets Arnaldo Carvalho de Melo
2018-04-13 14:00 ` [PATCH 05/17] perf annotate browser: " Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 06/17] perf jvmti: Give hints about package names needed to build Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 07/17] perf tests bpf: Remove unused ptrace.h include from LLVM test Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 08/17] Revert "x86/asm: Allow again using asm.h when building for the 'bpf' clang target" Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 10/17] perf tools: Rename HAVE_SYSCALL_TABLE to HAVE_SYSCALL_TABLE_SUPPORT Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 11/17] perf version: Print status for syscall_table Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 12/17] perf sched: Fix documentation for timehist Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 13/17] perf tests: Disable breakpoint accounting test for powerpc Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 14/17] perf record: Change warning for missing sysfs entry to debug Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 15/17] perf report: Fix switching to another perf.data file Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 16/17] perf annotate: Allow setting the offset level in .perfconfig Arnaldo Carvalho de Melo
2018-04-13 14:01 ` [PATCH 17/17] perf annotate: Handle variables in 'sub', 'or' and many other instructions Arnaldo Carvalho de Melo
2018-04-13 16:20   ` Andi Kleen
2018-04-13 17:20     ` Arnaldo Carvalho de Melo
2018-04-13 17:39       ` Andi Kleen
2018-04-17  2:56         ` Namhyung Kim
2018-04-17 12:51           ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180413140111.25313-3-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).