Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp282460ybt; Mon, 6 Jul 2020 09:11:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxz9tRlKUmnnRa5z8Edv4E0dXnVMiN9YNzYo9UJe002BTzdv0N8yq3JaQ6brWwm9dd+nFtY X-Received: by 2002:a17:906:50a:: with SMTP id j10mr31094254eja.113.1594051911965; Mon, 06 Jul 2020 09:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594051911; cv=none; d=google.com; s=arc-20160816; b=x1HDjHKB1emO/9j0CStYUA5g2m1k4VyXX9VMYGy7Dy7m0jh1TO5/UW+E+c8wc8l+48 /YvwPrZiRGn2/55rVLZhkJ1Dr0UMTjMLDq5bHjQy1+Cy3bFLUxCrDpcXgS/A9thMZkz7 gUiHg8srsJqUgFuHZY6HVic7WZ7QnfHQcxGJ67ytBKBq2MTepmgjD93tretE9tn6weNX Aq5GkZPTHk5wSAt6AI08VMIqBRYE4pUFOLJiW1cosjBJg5kCkASQ7eKDNyl2IcevuAYg P0YRFMZxGS4aMvD8RaUQqy+HE6mOhAfhnbwYnkKlWhmR/0fxoq9Bu+hEI4Oc/jQHvvr8 h8MQ== 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=OkqtH1t3W0skCB05p8+gC+tcFvYgw70LkQaMZftTlJ8=; b=T5sAmVWtlKV+5+TBadazE48142YiX17PSaRm1KDiYtrOghYCdiPJeWydhsYNzWVYSi 93RgBBw0ad/4/N5zPH5lDnN2LpsAAHj1Uok3D8t0RVBHtxOCk4DlOobMZPIc8HXKMcPW UCxiGhM0S2cT9YltM6hKxwMdLKg+GNeSdUx1fsi0X8tcSsqVO4CO+eudsIR4D+01CLW1 hnHlxrqwAf0Axv4IyfGHjVGP3/kFjHI5FjkB14jMPM2hjBAFJEsvIeihue8MWTI6NA/y IByiUBynbLx6QHBlHovIhvLNahuqvTUCH0dDzdnBP80RfMOakq19wPH7N0SYooicKSKL oS/Q== 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 qk1si12960622ejb.15.2020.07.06.09.11.28; Mon, 06 Jul 2020 09:11:51 -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 S1729535AbgGFQI0 (ORCPT + 99 others); Mon, 6 Jul 2020 12:08:26 -0400 Received: from foss.arm.com ([217.140.110.172]:52620 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729367AbgGFQI0 (ORCPT ); Mon, 6 Jul 2020 12:08:26 -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 89E3E1FB; Mon, 6 Jul 2020 09:08:25 -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 C6AF23F68F; Mon, 6 Jul 2020 09:08:22 -0700 (PDT) Date: Mon, 6 Jul 2020 17:08:20 +0100 From: Dave Martin To: Will Deacon Cc: linux-kernel@vger.kernel.org, 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-alpha@vger.kernel.org Subject: Re: [PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y Message-ID: <20200706160820.GC10992@arm.com> References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200630173734.14057-19-will@kernel.org> 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 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 > + > +#include > +#include > + > +#ifndef BUILD_VDSO > + > +#ifdef CONFIG_AS_HAS_LDAPR > +#define __LOAD_RCPC(sfx, regs...) \ > + ALTERNATIVE( \ > + "ldar" #sfx "\t" #regs, \ ^ Should this be here? It seems that READ_ONCE() will actually read twice... even if that doesn't actually conflict with the required semantics of READ_ONCE(), it looks odd. Making a direct link between LTO and the memory model also seems highly spurious (as discussed in the other subthread) so can we have a comment explaining the reasoning? > + ".arch_extension rcpc\n" \ > + "ldapr" #sfx "\t" #regs, \ > + ARM64_HAS_LDAPR) > +#else > +#define __LOAD_RCPC(sfx, regs...) "ldar" #sfx "\t" #regs > +#endif /* CONFIG_AS_HAS_LDAPR */ [...] Cheers ---Dave