Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp299183ybt; Mon, 6 Jul 2020 09:35:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLzkLZVrEFfsJCi+fKh2VhcXpiMJo128/5jErJ4uHwuFO7Pv/aVSsdVzXE9V0vaO0jiQmd X-Received: by 2002:a17:906:3f82:: with SMTP id b2mr127395ejj.240.1594053333377; Mon, 06 Jul 2020 09:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594053333; cv=none; d=google.com; s=arc-20160816; b=cmpzvtI9v7fRMwdf8dVADGY3khj38e9/yc/J1X6+T3ch/z1a5lmuuqo/ikfkKPHfAx wj5tTQSXvaaTYszPmNCHKH/+GCARQQToMdXkXDFzs42QMgscLBSRH59MOi9H9hS5oqIX QZc2ygzcVREr2oe5jXiowtVLDy90fOI4NvHIhikiUz77Qv7Ih6IleyKlCdMaRuGUCWP1 QswLtFIVDNdsgpxNEqxlLjroVlyJc78x5T71gbzh32i3LPw3exdNL9yvrPyfpG688IJ/ IwrCQ83ZPS9jwG6SQ5Ey5iPpdFJdffcw4GNVDY1PymVyscd8KOvddCXodyTlaKaBPtZ3 slsQ== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=CTWTpfgIfZrac5cn3EJUrwkgB4tsPW1TfTacvkOMe6c=; b=T8P4aJky+P+f6C0gcYgESZugTn6lLKRc2aitsVeZTxqEmHg81a93edm9pweudSN6aW wtkaEaIeIZvk/yF4o3oi70vOBxnKIV5JC9fSUIE08jVDzMqnNojBUgD8eZ/2JHYF192D w8Vv/UnTDef4KFuQvbqTz/tjzVFR8ZYGCuM+/s+GCxqxzSvuPH8ER6pcZZAuE9cDTqYU 9M+R4zNy+ABeYvLvp4KKSJJETrGBWrdO9a8lE7WBHElHKGKhzeMIOAUKjFNtZOrfMRGy YG0ymLFwh5bfYyxfCov8kB/P1jsctGelV+kzxQlAb3g8rddafofLaRpyrp9jFflkB5oF glHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CHLWFWDo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si13058832ejo.221.2020.07.06.09.35.10; Mon, 06 Jul 2020 09:35:33 -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; dkim=pass header.i=@kernel.org header.s=default header.b=CHLWFWDo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729429AbgGFQe4 (ORCPT + 99 others); Mon, 6 Jul 2020 12:34:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:34020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbgGFQe4 (ORCPT ); Mon, 6 Jul 2020 12:34:56 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-111-31.bvtn.or.frontiernet.net [50.39.111.31]) (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 7345420702; Mon, 6 Jul 2020 16:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594053295; bh=KGB5xCGGGIp9bGUY4wuMOuO+TBUq2UB1oRA8b9IjLnw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=CHLWFWDo8o64Xe0c2/fzvbWFaEMk6o22PbdfvrK7GELHs/X5AtEKtnN0BphATdwFR bSR78oZCcfnO+2bi4GnxLfEsTymAInrr8QncUPTgymdjH15TLfzhyj1g5NyiQAHmsh iJCvy6z1juiNZ95VKkAJqYjJOckCwB9Y2v97+7CI= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 592A13521502; Mon, 6 Jul 2020 09:34:55 -0700 (PDT) Date: Mon, 6 Jul 2020 09:34:55 -0700 From: "Paul E. McKenney" To: Dave Martin Cc: Will Deacon , 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 , 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: <20200706163455.GV9247@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> <20200701170722.4rte5ssnmrn2uqzg@bakewell.cambridge.arm.com> <20200702072301.GA15963@willie-the-truck> <20200706160023.GB10992@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200706160023.GB10992@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 06, 2020 at 05:00:23PM +0100, Dave Martin wrote: > 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? Because without LTO, the compiler cannot see all the pointers all at the same time due to their being in different translation units. But yes, if the compiler could see all the pointer values and further -know- that it was seeing all the pointer values, these optimizations could happen even without LTO. But it is quite easy to make sure that the compiler thinks that there are additional pointer values that it does not know about. > > 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... Because ignorant compilers are safe compilers! ;-) Thanx, Paul