Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp413095ybt; Mon, 6 Jul 2020 12:24:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztdzGeX+8Rd8RssYGOfLHlkBHFklofg3bI/aaHq9lsG3dbZV3qXa5bafKSsa/pQJaAShWd X-Received: by 2002:a17:906:3945:: with SMTP id g5mr47295610eje.549.1594063452030; Mon, 06 Jul 2020 12:24:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594063452; cv=none; d=google.com; s=arc-20160816; b=lyUq6psJJBFchaJp7WqZGuDLYtvJQD6kkc6MzEFIewmF9IEzF5VcSZtJjJPCHU/Buy nwAtmgNVFqp6covz+XoJ6Dj7gZkSWnHZ84uKGquXVMraGGttoGeTt8+0UcHgPPQLMzji fYzCftmiK1m5zKh8AQCIcMPdniriSryvlhjJ/78URfeRNvFh3BfU5VnFovLxsBtcI1WA 5JIdLGVyEEBmbV++ObhAF4JUPVB3C+im34mHnXciIxK1swzyLMdyExT6E63CU8Gh454G oEbWvMKqO8nmpwbbvS5uBCdR8I4DY5LnWIIx2hBTWHwrz72l+mhGmQGdf7ExhTiYuMrw q8Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7rVviAD5LzlDObQk5Wo1OIPXX0O0i14V8Y9kck3sGsA=; b=g4ePUv+QqtPaoVf7NCMGu6uyRrx0T+fypC8A5Ty4Q1kvZYzUMsFivwvdESFwSoSOt6 8jOR5q96tVtEOtkpV+2sQkPYiWF/5yrtRdB+nXu4B1GMDt4H2O8fLEjEPROoKCnQkAxD 6/7RuFbez++/cprgFWZ8V9Lv3wUxTdioKmv9h8o+aENuKOzGLkO8vFcmZZUnrzByMuRr dN2jqBlwcE7CwcljRDeaV0EgdNefEIJgdYSGHwRZLA8ixJ+9QvjDZ5CbH6rkrZsdu3M6 PIbl8EtRNxuh0ee2Lu/HUNrawFvksQLqKJXshM6azHw2yekS7BhRwuO+BV/pniOQbtQs h7tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kktLS6II; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm22si9428913edb.499.2020.07.06.12.23.48; Mon, 06 Jul 2020 12:24:12 -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=@google.com header.s=20161025 header.b=kktLS6II; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgGFTXj (ORCPT + 99 others); Mon, 6 Jul 2020 15:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725901AbgGFTXi (ORCPT ); Mon, 6 Jul 2020 15:23:38 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAFCFC061755 for ; Mon, 6 Jul 2020 12:23:38 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id k22so21581812oib.0 for ; Mon, 06 Jul 2020 12:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7rVviAD5LzlDObQk5Wo1OIPXX0O0i14V8Y9kck3sGsA=; b=kktLS6II7R90NPohUeMToqXFTW9/KTTxKsvR9z6CQOtuYiA+UR1ubootJAzBto7yuJ AbRvCe66+Tt8q+e7CaqjBO/+BqOggtYUZd94QOOMy3P6tdZbgMFUX2kKcMpO2rBMAiQV 5P3zf0HiGPY4b0db3+VWxD2tkv5CY7XEZlXVtx3qjIKDMVpq9AFvxZ2W+5yyNFj3mHWq KzP6T0h5FK7Z0GIwe04akbYFIG6ZBAT1RiOTM/kh1P3VhD+BMpi4H6OFelIwdriMLqyW CZAxAVAwkoGHY7q2qlbqV+rOUxl6ESs/jNfXniEGzfMGnS5htYM2u2lyMprNvZeKvtN3 U91Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7rVviAD5LzlDObQk5Wo1OIPXX0O0i14V8Y9kck3sGsA=; b=V2vdFn91+DSXM+NkPI5b2yBF1VYw6xfOoWcuqpM0RsCoOqgLcdSHhd5G8g98gGaTLK AhIr5jHAfjNu8xTYF+F/yLVFOj3UML7SyC2a0GreBE39Wqirt2qy0OutmtjAu5J/Pl51 oCcLlfWLo02aDEIObR4y3e++qACvkjqSBj/WHgJ+ItIcAy4qv326mFnERjnji9VrmBjn HHIBE1nS4ekj/RyPeBxe7D3gYEmfzIabzPDmXcJneSeaqzdJZpf2ji1GwDhMVBrFpdfl wfvNXhjt2f6cXrS7NvdEC6zvaMdYWM6dxvxCmzdRROa0rM8ByqnT+7lTyfy+PBEunl6X Swqg== X-Gm-Message-State: AOAM533DtOR6tqCv/tZtVRfkhpIeNg7ANf1uGfNMHZYkLtypY8TQ7+PJ 44mmm9f/XZAG/fHYyEhWun+w6db00QfBHNlQVIJ/cQ== X-Received: by 2002:aca:5007:: with SMTP id e7mr682320oib.70.1594063417791; Mon, 06 Jul 2020 12:23:37 -0700 (PDT) MIME-Version: 1.0 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> <20200706183542.GB23766@willie-the-truck> In-Reply-To: <20200706183542.GB23766@willie-the-truck> From: Marco Elver Date: Mon, 6 Jul 2020 21:23:26 +0200 Message-ID: Subject: Re: [PATCH 18/18] arm64: lto: Strengthen READ_ONCE() to acquire when CLANG_LTO=y To: Will Deacon Cc: Dave Martin , Mark Rutland , "Michael S. Tsirkin" , Peter Zijlstra , Catalin Marinas , Jason Wang , virtualization@lists.linux-foundation.org, Arnd Bergmann , Alan Stern , Sami Tolvanen , Matt Turner , Android Kernel Team , Kees Cook , "Paul E. McKenney" , Boqun Feng , Josh Triplett , Ivan Kokshaysky , Linux ARM , Richard Henderson , Nick Desaulniers , LKML , linux-alpha@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 6 Jul 2020 at 20:35, Will Deacon wrote: > 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: > > > > 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? > > It could, but I'd argue that it's considerably less likely because there > is less information available to the compiler to perform these sorts of > optimisations. It also doesn't appear to be happening in practice. > > The current state of affairs is that, if/when we catch the compiler > performing harmful optimistations, we look for a way to disable them. > However, there are good reasons to enable LTO, so this is one way to > do that without having to worry about the potential impact on dependency > ordering. If it's of any help, I'll see if we can implement that warning in LLVM if data dependencies somehow disappear (although I don't have any cycles to pursue right now myself). Until then, short of manual inspection or encountering a bug in the wild, there is no proof any of this happens or doesn't happen. Also, as some anecdotal evidence it's extremely unlikely, even with LTO: looking at the passes that LLVM runs, there are a number of passes that seem to want to eliminate basic blocks, thereby getting rid of branches. Intuitively, it makes sense, because branches are expensive on most architectures (for GPU targets, I think it tries even harder to get rid of branches). If we extend our reasoning and assumptions of LTO's aggressiveness in that direction, we might actually end up with fewer branches. That might be beneficial for the data dependencies we worry about (but not so much for control dependencies we want to keep). Still, no point in speculating (no pun intended) until we have hard data what actually happens. :-) Thanks, -- Marco