From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE526C43603 for ; Thu, 12 Dec 2019 17:16:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AED5321655 for ; Thu, 12 Dec 2019 17:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576170998; bh=hCIUUjoV9LDxYFfpfhgTZKOW9fzOYuAszkQqCpfyxqI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=DXJxLa3EEZOkhsTkimbCrusorx2NdeurVVFYOUyBFaE77h9K+iwJpTYA0oseTLQ+E OcIpWpVhnKsySdtIjhNNWNYH3jWTXeVlRVF5whmtTPWymglk9hCu4Cw4aOVzxqHQy1 iGBAERXbP7zmQwaakugfMUylI505VZ9SKrRQRdLA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730134AbfLLRQh (ORCPT ); Thu, 12 Dec 2019 12:16:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:57952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730040AbfLLRQh (ORCPT ); Thu, 12 Dec 2019 12:16:37 -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 93FE3205C9; Thu, 12 Dec 2019 17:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576170996; bh=hCIUUjoV9LDxYFfpfhgTZKOW9fzOYuAszkQqCpfyxqI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EWuay0I819XqGuvOSsknn0d9k75Vn8g4VG3BHr2E2DN4rsyF1Ff5RAOgMHPgzFwtc 8Na0syFuMwf74TW1Aod2SFGjufh5djkZ7Y9bO46PbSsdR7iP3IfPKFNvfs/9sqAhyU WdC0UAGaNcw5F5Lq+ZtVZ6pmlyL17XIKquJFBPPY= Date: Thu, 12 Dec 2019 17:16:31 +0000 From: Will Deacon To: Peter Zijlstra Cc: Michael Ellerman , Linus Torvalds , dja@axtens.net, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, christophe.leroy@c-s.fr, linux-arch@vger.kernel.org, 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: <20191212171630.GC16364@willie-the-truck> References: <87blslei5o.fsf@mpe.ellerman.id.au> <20191206131650.GM2827@hirez.programming.kicks-ass.net> <875zimp0ay.fsf@mpe.ellerman.id.au> <20191212080105.GV2844@hirez.programming.kicks-ass.net> <20191212100756.GA11317@willie-the-truck> <20191212104610.GW2827@hirez.programming.kicks-ass.net> <20191212170427.GA16364@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191212170427.GA16364@willie-the-truck> 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 Thu, Dec 12, 2019 at 05:04:27PM +0000, Will Deacon wrote: > On Thu, Dec 12, 2019 at 11:46:10AM +0100, Peter Zijlstra wrote: > > On Thu, Dec 12, 2019 at 10:07:56AM +0000, Will Deacon wrote: > > > > > > So your proposed change _should_ be fine. Will, I'm assuming you never > > > > saw this on your ARGH64 builds when you did this code ? > > > > > > I did see it, but (a) looking at the code out-of-line makes it look a lot > > > worse than it actually is (so the ext4 example is really helpful -- thanks > > > Michael!) and (b) I chalked it up to a crappy compiler. > > > > > > However, see this comment from Arnd on my READ_ONCE series from the other > > > day: > > > > > > https://lore.kernel.org/lkml/CAK8P3a0f=WvSQSBQ4t0FmEkcFE_mC3oARxaeTviTSkSa-D2qhg@mail.gmail.com > > > > > > In which case, I'm thinking that we should be doing better in READ_ONCE() > > > for non-buggy compilers which would also keep the KCSAN folks happy for this > > > code (and would help with [1] too). > > > > So something like this then? Although I suppose that should be moved > > into compiler-gcc.h and then guarded by #ifndef READ_ONCE or so. > > Ah wait, I think we've been looking at this wrong. The volatile pointer > argument is actually the problem here, not READ_ONCE()! The use of typeof() > means that the temporary variable to which __READ_ONCE_SIZE writes ends up > being a volatile store, so it can't be optimised away. This is why we get > a stack access and why stack protector then wrecks the codegen for us. Hmm, it's actually probably the volatile read which is causing the problem, since __READ_ONCE_SIZE has casted that away and just uses "void *", but you get the idea. Will From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BED40C43603 for ; Thu, 12 Dec 2019 17:18:33 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71BA6205C9 for ; Thu, 12 Dec 2019 17:18:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="EWuay0I8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71BA6205C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47YgVv3fHfzDq69 for ; Fri, 13 Dec 2019 04:18:31 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=will@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="EWuay0I8"; dkim-atps=neutral Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47YgSk5DyczDq69 for ; Fri, 13 Dec 2019 04:16:38 +1100 (AEDT) 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 93FE3205C9; Thu, 12 Dec 2019 17:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576170996; bh=hCIUUjoV9LDxYFfpfhgTZKOW9fzOYuAszkQqCpfyxqI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EWuay0I819XqGuvOSsknn0d9k75Vn8g4VG3BHr2E2DN4rsyF1Ff5RAOgMHPgzFwtc 8Na0syFuMwf74TW1Aod2SFGjufh5djkZ7Y9bO46PbSsdR7iP3IfPKFNvfs/9sqAhyU WdC0UAGaNcw5F5Lq+ZtVZ6pmlyL17XIKquJFBPPY= Date: Thu, 12 Dec 2019 17:16:31 +0000 From: Will Deacon To: Peter Zijlstra 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: <20191212171630.GC16364@willie-the-truck> References: <87blslei5o.fsf@mpe.ellerman.id.au> <20191206131650.GM2827@hirez.programming.kicks-ass.net> <875zimp0ay.fsf@mpe.ellerman.id.au> <20191212080105.GV2844@hirez.programming.kicks-ass.net> <20191212100756.GA11317@willie-the-truck> <20191212104610.GW2827@hirez.programming.kicks-ass.net> <20191212170427.GA16364@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191212170427.GA16364@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , Christian Borntraeger , linux-kernel@vger.kernel.org, Linus Torvalds , Mark Rutland , linuxppc-dev@lists.ozlabs.org, dja@axtens.net Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Dec 12, 2019 at 05:04:27PM +0000, Will Deacon wrote: > On Thu, Dec 12, 2019 at 11:46:10AM +0100, Peter Zijlstra wrote: > > On Thu, Dec 12, 2019 at 10:07:56AM +0000, Will Deacon wrote: > > > > > > So your proposed change _should_ be fine. Will, I'm assuming you never > > > > saw this on your ARGH64 builds when you did this code ? > > > > > > I did see it, but (a) looking at the code out-of-line makes it look a lot > > > worse than it actually is (so the ext4 example is really helpful -- thanks > > > Michael!) and (b) I chalked it up to a crappy compiler. > > > > > > However, see this comment from Arnd on my READ_ONCE series from the other > > > day: > > > > > > https://lore.kernel.org/lkml/CAK8P3a0f=WvSQSBQ4t0FmEkcFE_mC3oARxaeTviTSkSa-D2qhg@mail.gmail.com > > > > > > In which case, I'm thinking that we should be doing better in READ_ONCE() > > > for non-buggy compilers which would also keep the KCSAN folks happy for this > > > code (and would help with [1] too). > > > > So something like this then? Although I suppose that should be moved > > into compiler-gcc.h and then guarded by #ifndef READ_ONCE or so. > > Ah wait, I think we've been looking at this wrong. The volatile pointer > argument is actually the problem here, not READ_ONCE()! The use of typeof() > means that the temporary variable to which __READ_ONCE_SIZE writes ends up > being a volatile store, so it can't be optimised away. This is why we get > a stack access and why stack protector then wrecks the codegen for us. Hmm, it's actually probably the volatile read which is causing the problem, since __READ_ONCE_SIZE has casted that away and just uses "void *", but you get the idea. Will