Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp905397ybt; Tue, 7 Jul 2020 03:13:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSqndj9dnhaVPy7GL/dGLURW/bzgCbaI8bvr4VfkiDM/ZckUCsGOubVuBQcRo86bSwi9w3 X-Received: by 2002:a50:fc88:: with SMTP id f8mr29453454edq.314.1594116795640; Tue, 07 Jul 2020 03:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594116795; cv=none; d=google.com; s=arc-20160816; b=tnQ9jfvrTWT7GT+uharfoHSos2qfTFdPyvLaFoVF8Vx51fdlG9V3kF7k6o2KN0tTCI ptfJV2ycfBXW4jS3knR9zmHO+MnWTfvUSlr9rnnZu4/clcA25c/TQZ5pSbbbq8oFx4st 4ChDSQeoSbxKo56SXlncjjd3YZnJTHguHCX14sEALzfI6K54ViUy7d+1fxwxD5phOyTF eLEZsyso8tmUBIy5zJ3ljmOjTLEWTjFtl4asuOchr8VoaynEz1HItjZM/jczMj0rY8ms 8H/VMkAJl35K5h0Hh21blIW7WZInbfE40XNwNhjQ0ztr4xtJugxHOOpuq+XB13gfPryr i01g== 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=/Mcju1+tMSfNhmoB4FzONgclRJ9ke1O8ONnTDlyYkRg=; b=DHEYvrKd/vYy6nJ9OXBjJT8aAY0j+oPA1/yD69MeTi1atWEYX7VXzjo/StykOEUK9k n1Ux2oWv0MVTFYa1fZ6KkrFVIkCY/5Tw75F5/TUenNQtYSImNc+seTnArNUNovJ1YR4F rPovEp7wesaR/uYEh3DRdGJqdb3lNG2jxtznY5Yzy2XGf5umnPVFANfX9Cf1RY0GXXwB dN6eK+FRIBjdUny8xaE+kER5RrHdcQ6u6e3oRrIC6YJV8jPGLY89/0UO3+pE3f1aBpeX gFxmSEsRhTXpN5LCKdejfFIhFfE588Y222ZV2zkaoYLUyGhoq1etNHArXxnKKIQt66C+ 7BGA== 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 t19si13659187eju.562.2020.07.07.03.12.50; Tue, 07 Jul 2020 03:13:15 -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 S1727895AbgGGKKY (ORCPT + 99 others); Tue, 7 Jul 2020 06:10:24 -0400 Received: from foss.arm.com ([217.140.110.172]:36564 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgGGKKX (ORCPT ); Tue, 7 Jul 2020 06:10:23 -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 87A21C0A; Tue, 7 Jul 2020 03:10:22 -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 C4C603F71E; Tue, 7 Jul 2020 03:10:19 -0700 (PDT) Date: Tue, 7 Jul 2020 11:10:17 +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: <20200707101015.GH10992@arm.com> References: <20200630173734.14057-1-will@kernel.org> <20200630173734.14057-19-will@kernel.org> <20200706160820.GC10992@arm.com> <20200706183510.GA23766@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200706183510.GA23766@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 Mon, Jul 06, 2020 at 07:35:11PM +0100, Will Deacon wrote: > On Mon, Jul 06, 2020 at 05:08:20PM +0100, Dave Martin wrote: > > On Tue, Jun 30, 2020 at 06:37:34PM +0100, Will Deacon wrote: > > > 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. > > It's patched at runtime, so it's either LDAR or LDAPR. Agh ignore me, I somehow failed to sport the ALTERNATIVE(). For my understanding -- my background here is a bit shaky -- the LDAPR gives us load-to-load order even if there is just a control dependency? If so (possibly dumb question): why can't we just turn this on unconditionally? Is there a significant performance impact? I'm still confused (or ignorant) though. If both loads are READ_ONCE() then switching to LDAPR presumably helps, but otherwise, once the compiler has reduced the address dependency to a control dependency can't it then go one step further and reverse the order of the loads? LDAPR wouldn't rescue us from that. Or does the "memory" clobber in READ_ONCE() fix that for all important cases? I can't see this mattering for local variables (where it definitely won't work), but I wonder whether static variables might not count as "memory" in some situations. Discounting ridiculous things like static register variables, I think the only way for a static variable not to count as memory would be if there are no writes to it that are reachable from any translation unit entry point (possibly after dead code removal). If so, maybe that's enough. > > 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? > > Sure, although like I say, this is more about helping to progress that > conversation. That's fair enough, but when there is a consensus it would be good to see it documented in the code _especially_ if we know that the fix won't address all instances of the problem and in any case works partly by accident. That doesn't mean it's not a good practical compromise, but it could be very confusing to unpick later on. Cheers ---Dave