Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1854771ybl; Thu, 19 Dec 2019 04:12:38 -0800 (PST) X-Google-Smtp-Source: APXvYqzYCky431kpPdr5KqjAgwVV6m3jI0zjE9NVdGmc96TWueihVfjvSV0y1+ylqH8l5yyhz/6X X-Received: by 2002:a9d:6b06:: with SMTP id g6mr8487058otp.93.1576757558344; Thu, 19 Dec 2019 04:12:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576757558; cv=none; d=google.com; s=arc-20160816; b=gwEej/N/TETv+lMoY8HOcNXXWTxvCnkn8GMIy/fN1UAdOKmVOJ5EQvqzgGz8OSKN7o HNT7BBGmJjjplBe0lzrbLk5IxSfhnTuPYEAYZWdmsq12bLPXWbiyvon9e02OG8xt+Jj4 o+HCM7tFjewNPyjn8vI5wUpcYgG7hUZzdCU18WflVNsN4EZtzXPMVF4qj21XbycOtxg3 Te/Ev49sutKJVqFRjERGDCjZXsh2PPkvKqT+5l7g4maLo750sfMGmOIOsB4jEQbf+YuQ DLYR/ooPvfkjV3o7s1/qVM4JNLk+DgcEwLUhNyu6qpao47nLXpkHg7xzhCsQPZtJTVAx DPNw== 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=gg/FXrYuInNSvJ9nLwpzYjjCEZksSTQsLjtqCFW7lQ0=; b=w4fJxKBuAON3GDzuxx75qRid2xZpXEkOqDmPo75+3SZqtvjj6ovjJO7xHTUOi4Rogs mhRT90ThZMPXvpA8fR5+Rp+1VltSUwn+m8+UQQ6MUQudT1ep8cWRjy0hY2uAZQfyWxw7 liiK6/x178ArhzytVd7W8fOvCGwDYRiLTQzYTQcqRubdLQ2AIyHOnh6xVoDpf+bn05QJ 7VNBRRJ6leAHpHPhulbpiMY6wExc/yVxsNe+8Y3cRyeycvofW46XJ8iwJnejK8eDI4Bu HWodXHBDaa+N43ZcuKPYW62TzjHrN9L8eyb0Y/ex9NdqRnCQdDp4lt8J+doCxiEA9lag xdfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0ixnxT3u; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27si3455136otk.206.2019.12.19.04.12.26; Thu, 19 Dec 2019 04:12:38 -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=pass header.i=@kernel.org header.s=default header.b=0ixnxT3u; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726808AbfLSMLW (ORCPT + 99 others); Thu, 19 Dec 2019 07:11:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:39744 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfLSMLV (ORCPT ); Thu, 19 Dec 2019 07:11:21 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 1BEFF20716; Thu, 19 Dec 2019 12:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576757481; bh=RE2T76IU/lncwRrDRAlG+ju/T9yNzhZZa+kkSWXB+hk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0ixnxT3uqPi6FVe/deKUePFfnKx9P1IGOKn1P09zsr5cJF5tc+Lb/RinNJ6zRexCz d4w/YFMVv6noAYAo12vcpw9/xsADKJmW1JkRrwXaOXPOxbKCpRgXB/UF6b9ftaH2wF dIhF3//DAkyn3jnXauqEMxnnraV8I9v9EaclRVHs= Date: Thu, 19 Dec 2019 12:11:16 +0000 From: Will Deacon To: Linus Torvalds Cc: Peter Zijlstra , Michael Ellerman , Daniel Axtens , Linux Kernel Mailing List , linuxppc-dev , 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: <20191219121115.GB32361@willie-the-truck> References: <20191212100756.GA11317@willie-the-truck> <20191212104610.GW2827@hirez.programming.kicks-ass.net> <20191212180634.GA19020@willie-the-truck> <20191212193401.GB19020@willie-the-truck> <20191217170719.GA869@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Tue, Dec 17, 2019 at 10:32:35AM -0800, Linus Torvalds wrote: > On Tue, Dec 17, 2019 at 10:04 AM Linus Torvalds > wrote: > > > > Let me think about it. > > How about we just get rid of the union entirely, and just use > 'unsigned long' or 'unsigned long long' depending on the size. > > Something like the attached patch - it still requires that it be an > arithmetic type, but now because of the final cast. > > But it might still be a cast to a volatile type, of course. Then the > result will be volatile, but at least now READ_ONCE() won't be taking > the address of a volatile variable on the stack - does that at least > fix some of the horrible code generation. Hmm? Sounds like it according to mpe, but I'll confirm too for arm64. > This is untested, because I obviously still have the cases of > structures (page table entries) being accessed once.. > > Linus > include/linux/compiler.h | 33 +++++++++++++++++---------------- > 1 file changed, 17 insertions(+), 16 deletions(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 5e88e7e33abe..8b4282194f16 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -179,18 +179,18 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > > #include > > -#define __READ_ONCE_SIZE \ > -({ \ > - switch (size) { \ > - case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \ > - case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \ > - case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \ > - case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ > - default: \ > - barrier(); \ > - __builtin_memcpy((void *)res, (const void *)p, size); \ > - barrier(); \ > - } \ > +/* "unsigned long" or "unsigned long long" - make it fit in a register if possible */ > +#define __READ_ONCE_TYPE(size) \ > + __typeof__(__builtin_choose_expr(size > sizeof(0UL), 0ULL, 0UL)) Ha, I wondered when '__builtin_choose_expr()' would make an appearance in this thread! Nice trick. I'll try integrating this with what I have and see what I run into next. Back down the rabbit hole... Will