Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp801522ybl; Fri, 13 Dec 2019 04:57:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwSLZ0mNun7waUiV7ZqL/Lz4c10nZlzpURRdZjieA6QE6DNlnKO/f9YOdTdu0s3db6w8abH X-Received: by 2002:a05:6830:10a:: with SMTP id i10mr13889758otp.365.1576241873107; Fri, 13 Dec 2019 04:57:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576241873; cv=none; d=google.com; s=arc-20160816; b=m2NNKdhBMh7z/kasrrfIqy87R5q1Sp++8vXXV0b0w+6AIHVjlOZoRbnAE5xkm2V6FX fy1mDh+Xq49ppb0zg2Fz3vRIjmwzJQa8ZNu3Uv5QIXUUthVokVzlWMKhkZRRrGfjIlSJ MXit9JzX9uazI8qlPSgth0kgSlnssH3s0Do2uEeuKJfnpyrxm8mcaJTb+PmcJir0Gqno MVscBgRmbWy/E7Atg3ilgTk/d2D+o6o/Q1lAkh2BEWSoaWiusUZPA9uCTMb1bjJ8rp40 qxFGHahvAKNg4bFBCPTLXFitrmH+0yTEAwbQFo42E560NdfwsfOWq5Vunq0PtVU9wXP1 HXiw== 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:dkim-signature; bh=fWjlDQlwIoBg7I4Z9XSj9pI9UUWfLrkzsxAziGh6H/M=; b=A+NXyzRp9Cue8bFou9aVjkKXb0/gydg9HbVsXxoZOdD84RGu3EbavK3MUtHWCscSVl 6FqfG1eefOUrXPF/I7GVlcYU8e3YgA27LTfusBKwuu36/s13/RZy/p2ssokD/4tHKMQ8 XxArJ1MikUFXJJJAyEMlJbVeui5J6/gJHNreT/xnAzIO8b2vibfVYzBwYuYYJn9sQOME D9PjN4SF3G8w7Hfbwg8zfrlHIQiOE0K8Zc+YPjhe8iB6HkkUQTClJEcDim+hp1lvpEct Ydw21dayhsmIiTVEEk5GDIBs72rP2I1v3CUbivPoP8/xkEslr2qzmZc03eUZkb+vSfgj WIjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=iQu8Ss5C; 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 v7si7320403otr.44.2019.12.13.04.57.41; Fri, 13 Dec 2019 04:57:53 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=iQu8Ss5C; 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 S1727550AbfLMM4o (ORCPT + 99 others); Fri, 13 Dec 2019 07:56:44 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:46220 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727490AbfLMM4n (ORCPT ); Fri, 13 Dec 2019 07:56:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fWjlDQlwIoBg7I4Z9XSj9pI9UUWfLrkzsxAziGh6H/M=; b=iQu8Ss5CvIW0fiJBxMLgkD1jm yz+ajnmICV4TjIDDgyjd7PjqlmuUEvwzpxv4iI6JOc4i4t2KIec0epVoJTyvbUHEiqpxM6AJ+Xt05 sKMlHGiYwJk4ddTqnO404xiUWfpw8tXg1eqIYVKvSm4e0J/vOrP4MaT79qCHrwdyRKW34PUesKBVP u/FrqqKsWXFJr9rj6glrIgaha27VGjLLX/VvZx6keNKxpAzE9YM5ANFtm2gDn8hL2KCBjRWD1jabQ sRW9rFRq/ySsD5jIc8sZQIUccKV4JWAI1eusNTtWdFHf/Ti/SiaUpwv58KDQc+kuAmMRc9g/B9vAp wYyfUNA/g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ifkUX-0002Gq-OV; Fri, 13 Dec 2019 12:56:22 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 385E5305FFF; Fri, 13 Dec 2019 13:54:58 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EC16A20121961; Fri, 13 Dec 2019 13:56:18 +0100 (CET) Date: Fri, 13 Dec 2019 13:56:18 +0100 From: Peter Zijlstra To: Luc Van Oostenryck Cc: Will Deacon , Linus Torvalds , Michael Ellerman , dja@axtens.net, Linux Kernel Mailing List , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , linux-arch , Mark Rutland , Segher Boessenkool , Arnd Bergmann , Christian Borntraeger Subject: Re: READ_ONCE() + STACKPROTECTOR_STRONG == :/ (was Re: [GIT PULL] Please pull powerpc/linux.git powerpc-5.5-2 tag (topic/kasan-bitops)) Message-ID: <20191213125618.GD2844@hirez.programming.kicks-ass.net> References: <20191212080105.GV2844@hirez.programming.kicks-ass.net> <20191212100756.GA11317@willie-the-truck> <20191212104610.GW2827@hirez.programming.kicks-ass.net> <20191212180634.GA19020@willie-the-truck> <20191212193401.GB19020@willie-the-truck> <20191212202157.GD11457@worktop.programming.kicks-ass.net> <20191212205338.GB11802@worktop.programming.kicks-ass.net> <20191213104706.xnpqaehmtean3mkd@ltop.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191213104706.xnpqaehmtean3mkd@ltop.local> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 13, 2019 at 11:47:06AM +0100, Luc Van Oostenryck wrote: > On Thu, Dec 12, 2019 at 09:53:38PM +0100, Peter Zijlstra wrote: > > Now, looking at the current GCC source: > > > > https://github.com/gcc-mirror/gcc/blob/97d7270f894395e513667a031a0c309d1819d05e/gcc/c/c-parser.c#L3707 > > > > it seems that __typeof__() is supposed to strip all qualifiers from > > _Atomic types. That lead me to try: > > > > typeof(_Atomic typeof(p)) __p = (p); > > > > But alas, I still get the same junk you got for ool_store_release() :/ > > I was checking this to see if Sparse was ready to support this. > I was a bit surprised because at first sigth GCC was doing as > it claims (typeof striping const & volatile on _Atomic types) > but your exampe wasn't working. But it's working if an > intermediate var is used: > _Atomic typeof(p) tmp; > typeof(tmp) __p = (p); > or, uglier but probably more practical: > typeof(({_Atomic typeof(p) tmp; })) __p = (p); > > Go figure! Excellent! I had to change it to something like: #define unqual_typeof(x) typeof(({_Atomic typeof(x) ___x __maybe_unused; ___x; })) but that does indeed work! Now I suppose we should wrap that in a symbol that indicates our compiler does indeed support _Atomic, otherwise things will come apart. That is, my gcc-4.6 doesn't seem to have it, while gcc-4.8 does, which is exactly the range that needs the daft READ_ONCE() construct, how convenient :/ Something a little like this perhaps? --- diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h index 7d9cc5ec4971..c389af602da8 100644 --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -75,9 +75,9 @@ static inline unsigned long array_index_mask_nospec(unsigned long idx, #define __smp_store_release(p, v) \ do { \ - typeof(p) __p = (p); \ - union { typeof(*p) __val; char __c[1]; } __u = \ - { .__val = (__force typeof(*p)) (v) }; \ + unqual_typeof(p) __p = (p); \ + union { unqual_typeof(*p) __val; char __c[1]; } __u = \ + { .__val = (__force unqual_typeof(*p)) (v) }; \ compiletime_assert_atomic_type(*p); \ kasan_check_write(__p, sizeof(*p)); \ switch (sizeof(*p)) { \ @@ -110,8 +110,8 @@ do { \ #define __smp_load_acquire(p) \ ({ \ - union { typeof(*p) __val; char __c[1]; } __u; \ - typeof(p) __p = (p); \ + union { unqual_typeof(*p) __val; char __c[1]; } __u; \ + unqual_typeof(p) __p = (p); \ compiletime_assert_atomic_type(*p); \ kasan_check_read(__p, sizeof(*p)); \ switch (sizeof(*p)) { \ @@ -141,8 +141,8 @@ do { \ #define smp_cond_load_relaxed(ptr, cond_expr) \ ({ \ - typeof(ptr) __PTR = (ptr); \ - typeof(*ptr) VAL; \ + unqual_typeof(ptr) __PTR = (ptr); \ + unqual_typeof(*ptr) VAL; \ for (;;) { \ VAL = READ_ONCE(*__PTR); \ if (cond_expr) \ @@ -154,8 +154,8 @@ do { \ #define smp_cond_load_acquire(ptr, cond_expr) \ ({ \ - typeof(ptr) __PTR = (ptr); \ - typeof(*ptr) VAL; \ + unqual_typeof(ptr) __PTR = (ptr); \ + unqual_typeof(*ptr) VAL; \ for (;;) { \ VAL = smp_load_acquire(__PTR); \ if (cond_expr) \ diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h index 85b28eb80b11..dd5bb055f5ab 100644 --- a/include/asm-generic/barrier.h +++ b/include/asm-generic/barrier.h @@ -228,8 +228,8 @@ do { \ */ #ifndef smp_cond_load_relaxed #define smp_cond_load_relaxed(ptr, cond_expr) ({ \ - typeof(ptr) __PTR = (ptr); \ - typeof(*ptr) VAL; \ + unqual_typeof(ptr) __PTR = (ptr); \ + unqual_typeof(*ptr) VAL; \ for (;;) { \ VAL = READ_ONCE(*__PTR); \ if (cond_expr) \ @@ -250,7 +250,7 @@ do { \ */ #ifndef smp_cond_load_acquire #define smp_cond_load_acquire(ptr, cond_expr) ({ \ - typeof(*ptr) _val; \ + unqual_typeof(*ptr) _val; \ _val = smp_cond_load_relaxed(ptr, cond_expr); \ smp_acquire__after_ctrl_dep(); \ _val; \ diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 0eb2a1cc411d..15fd7ea3882a 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -179,3 +179,10 @@ #endif #define __no_fgcse __attribute__((optimize("-fno-gcse"))) + +#if GCC_VERSION < 40800 +/* + * GCC-4.6 doesn't support _Atomic, which is required to strip qualifiers. + */ +#define unqual_typeof(x) typeof(x) +#endif diff --git a/include/linux/compiler.h b/include/linux/compiler.h index ad8c76144a3c..9736993f2ba1 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -279,7 +279,7 @@ void __write_once_size(volatile void *p, void *res, int size) #define __READ_ONCE(x, check) \ ({ \ - union { typeof(x) __val; char __c[1]; } __u; \ + union { unqual_typeof(x) __val; char __c[1]; } __u; \ if (check) \ __read_once_size(&(x), __u.__c, sizeof(x)); \ else \ @@ -302,12 +302,12 @@ unsigned long read_word_at_a_time(const void *addr) return *(unsigned long *)addr; } -#define WRITE_ONCE(x, val) \ -({ \ - union { typeof(x) __val; char __c[1]; } __u = \ - { .__val = (__force typeof(x)) (val) }; \ - __write_once_size(&(x), __u.__c, sizeof(x)); \ - __u.__val; \ +#define WRITE_ONCE(x, val) \ +({ \ + union { unqual_typeof(x) __val; char __c[1]; } __u = \ + { .__val = (__force unqual_typeof(x)) (val) }; \ + __write_once_size(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ }) #include diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 72393a8c1a6c..fe8012c54251 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -243,4 +243,11 @@ struct ftrace_likely_data { #define __diag_error(compiler, version, option, comment) \ __diag_ ## compiler(version, error, option) +#ifndef unqual_typeof +/* + * GCC __typeof__() strips all qualifiers from _Atomic types. + */ +#define unqual_typeof(x) typeof(({_Atomic typeof(x) ___x __maybe_unused; ___x; })) +#endif + #endif /* __LINUX_COMPILER_TYPES_H */