Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp273759ybt; Mon, 6 Jul 2020 09:01:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1Pbu2GCkhAykWyc+xXKJ9jBrYbcBdY/aIUtA923gEKUdZbuNLO5GlnHY8Z4wi7PeeAHi0 X-Received: by 2002:aa7:db11:: with SMTP id t17mr54859155eds.365.1594051274023; Mon, 06 Jul 2020 09:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594051274; cv=none; d=google.com; s=arc-20160816; b=ve/5rbGjUc5LcPBnKVhLyyhGb6L/6Em7BUsWfu98V8r4Z+/aIAzFA9fGOYeMBlTJtm v5mzzE4AyjDf5AZAstvVW/AbnunC03soNpOK/LiFFELiPZu3Dha1KKH51aH41vofJlL5 gCjfDeKFTQ+Hd7GPOkj2seSzzezMtICawh5nV1TFfqN1RVZM6tJ5iH9wLZZMkCDybPYO d16zJJLovJeoxfOHf32cK/sW4SRgSPSdylEDODai1zUGlpO8dc8bEjVGzbSecVUwyzvb C7OrzmJ1SfewzjscP2Z/V2a7HXvwkvu4uHjJTXcchFRR6yFHgb3d32nuETYZDYALv/tF 4HiA== 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; bh=nMMkjr+6hRATeCXem8b03vBkXY7JB6Gee0kSGKnvrVs=; b=pk8u7TW1kB3i4seVTIwm5B97CfnJfd9twYw3EUqrmpS4pcOV3njNs50pUNk6vyN/M+ cQDjRRRfMo3T2iDB0BWI4gq8N87s4Z4tkhS15R2UG5cm/KPokP9v4EV9W3MZyAWQoVf4 YNVkFJ/It/U41R6qVYk+jTR4GM5cnki2NwbPwfqrf2tbna98zTRc4zBwF6OynvMTJtzB zJdArYNhpg9uYZQcxahMfl88TI0GjbfjFYIdGDkay3s7DIvjUROkMv/AjBpo3Llyx6d8 6KRwZ+n+B8l/MmPPNhbFm8admvd+bEde4Sar9r/i4zT6+3qM03WZydLxcD/5j4gFxX64 x6Ig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v12si13086562eje.201.2020.07.06.09.00.51; Mon, 06 Jul 2020 09:01:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbgGFQA3 (ORCPT + 99 others); Mon, 6 Jul 2020 12:00:29 -0400 Received: from foss.arm.com ([217.140.110.172]:52050 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729297AbgGFQA3 (ORCPT ); Mon, 6 Jul 2020 12:00:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 659CB1FB; Mon, 6 Jul 2020 09:00:28 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A61A23F68F; Mon, 6 Jul 2020 09:00:25 -0700 (PDT) Date: Mon, 6 Jul 2020 17:00:23 +0100 From: Dave Martin To: Will Deacon Cc: Mark Rutland , "Michael S. Tsirkin" , Peter Zijlstra , Catalin Marinas , Jason Wang , virtualization@lists.linux-foundation.org, Arnd Bergmann , Alan Stern , Sami Tolvanen , Matt Turner , kernel-team@android.com, Marco Elver , Kees Cook , "Paul E. McKenney" , Boqun Feng , Josh Triplett , Ivan Kokshaysky , linux-arm-kernel@lists.infradead.org, Richard Henderson , Nick Desaulniers , linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org Subject: Re: [PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y Message-ID: <20200706160023.GB10992@arm.com> References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> <20200701170722.4rte5ssnmrn2uqzg@bakewell.cambridge.arm.com> <20200702072301.GA15963@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200702072301.GA15963@willie-the-truck> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 02, 2020 at 08:23:02AM +0100, Will Deacon wrote: > On Wed, Jul 01, 2020 at 06:07:25PM +0100, Dave P Martin wrote: > > On Tue, Jun 30, 2020 at 06:37:34PM +0100, Will Deacon wrote: > > > When building with LTO, there is an increased risk of the compiler > > > converting an address dependency headed by a READ_ONCE() invocation > > > into a control dependency and consequently allowing for harmful > > > reordering by the CPU. > > > > > > Ensure that such transformations are harmless by overriding the generic > > > READ_ONCE() definition with one that provides acquire semantics when > > > building with LTO. > > > > > > Signed-off-by: Will Deacon > > > --- > > > arch/arm64/include/asm/rwonce.h | 63 +++++++++++++++++++++++++++++++ > > > arch/arm64/kernel/vdso/Makefile | 2 +- > > > arch/arm64/kernel/vdso32/Makefile | 2 +- > > > 3 files changed, 65 insertions(+), 2 deletions(-) > > > create mode 100644 arch/arm64/include/asm/rwonce.h > > > > > > diff --git a/arch/arm64/include/asm/rwonce.h b/arch/arm64/include/asm/rwonce.h > > > new file mode 100644 > > > index 000000000000..515e360b01a1 > > > --- /dev/null > > > +++ b/arch/arm64/include/asm/rwonce.h > > > @@ -0,0 +1,63 @@ > > > +/* SPDX-License-Identifier: GPL-2.0 */ > > > +/* > > > + * Copyright (C) 2020 Google LLC. > > > + */ > > > +#ifndef __ASM_RWONCE_H > > > +#define __ASM_RWONCE_H > > > + > > > +#ifdef CONFIG_CLANG_LTO > > > > Don't we have a generic option for LTO that's not specific to Clang. > > /me looks at the LTO series some more > > Oh yeah, there's CONFIG_LTO which is selected by CONFIG_LTO_CLANG, which is > the non-typoed version of the above. I can switch this to CONFIG_LTO. > > > Also, can you illustrate code that can only be unsafe with Clang LTO? > > I don't have a concrete example, but it's an ongoing concern over on the LTO > thread [1], so I cooked this to show one way we could deal with it. The main > concern is that the whole-program optimisations enabled by LTO may allow the > compiler to enumerate possible values for a pointer at link time and replace > an address dependency between two loads with a control dependency instead, > defeating the dependency ordering within the CPU. Why can't that happen without LTO? > We likely won't realise if/when this goes wrong, other than impossible to > debug, subtle breakage that crops up seemingly randomly. Ideally, we'd be > able to detect this sort of thing happening at build time, and perhaps > even prevent it with compiler options or annotations, but none of that is > close to being available and I'm keen to progress the LTO patches in the > meantime because they are a requirement for CFI. My concern was not so much why LTO makes things dangerous, as why !LTO makes things safe... Cheers ---Dave