Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2003828pxj; Sat, 5 Jun 2021 09:28:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEpRjJ4PNoQ9GOf6yGpGYBuBxNAadpZHGf5dQanH+hkyAvZrxI3w/tg2eeczXdNl+0uURt X-Received: by 2002:a05:6402:1d06:: with SMTP id dg6mr10784999edb.132.1622910513569; Sat, 05 Jun 2021 09:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622910513; cv=none; d=google.com; s=arc-20160816; b=UQK73as1Y+k49FnrzcLicUuKMq4AlNVynCuZ1r6YoUv4fXqboNQskqxfbiK8X05Q16 j4hMNIiqOVb2tz4LLIknK6Sx2+4+l2B/qVctdoag8M9kjn7X9LAco7Gsn3euiKHRzxGb eScXGCErpaCsEpvZGJ4ciNrWM/kAzEu7lBpYDmD6ffFvfGQHFUHQAHsxxdaUU9BsIWUJ 7ynzV5/aptUJfpDF8YkCSSQkz2GtipqGGHexuZuXku+hu4CqrB3UIdrnUGlkaybYU92H YVVBAqtWIN7zemks7hasM0rjFXVFEPeJdRd7zvGAx72c/H6bQlRQBR/1QG18Vbu7r9fr +cGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GZa60s0glSdUWznibN+YHUgSL+wdhz/USRVQvcTkA3k=; b=H+mDc0Bo1X46XKiQxHt7C9ucc36TUtxXmbrXCOxkRlBbkbybOMO07Qg5ZlKfB5O+Rf 7n+xSQNyMAjRhB3bmwTgfRISsiXuDhEFFMEEkvcuKenrnR7PnDOqSUgiLzju8Lmn9px3 zLA0oC5tfRfHGFfO3yKPlm4zBxbDeeOXfGS5MpqFRdhhy90DOKhdc7HAUP/M5L0z0EDy 3+ODNPYQvQQDyfhtQQVKn7rih8alQSWNyvh1h2N4T45KKzLcmzi4XRlN5KbfMT8WwihX 7zn9MSfmbAmtLAVuW8lN0PW6OcOv7XaGWGXRITNa4QwbPaxhlijHKVn/qErIAp0LyFtJ ArxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=BQz+fRxw; 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 s24si1497940ejs.88.2021.06.05.09.27.57; Sat, 05 Jun 2021 09:28: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=@linux-foundation.org header.s=google header.b=BQz+fRxw; 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 S229959AbhFEQ1E (ORCPT + 99 others); Sat, 5 Jun 2021 12:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbhFEQ1E (ORCPT ); Sat, 5 Jun 2021 12:27:04 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87BADC061767 for ; Sat, 5 Jun 2021 09:25:15 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id n24so1514768lji.2 for ; Sat, 05 Jun 2021 09:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GZa60s0glSdUWznibN+YHUgSL+wdhz/USRVQvcTkA3k=; b=BQz+fRxwJrPzucEkOtxliKpTSWvi9EIwmF3SEXReAICeTz89zVE9OFvV9GV5MbYLsD QawgOFSMA9wi0wj0NsKxUp4FAEdi/eYMeMPeXWixE0CcQUC8xKaX/e2LoWw17Q6irdME KbDwe5zlt7LgNv46Z7UaR5DlXbYzZPGo7YHlM= 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=GZa60s0glSdUWznibN+YHUgSL+wdhz/USRVQvcTkA3k=; b=AmgwXbrRP/nhe07d4r4p66wcY81ueOX5Qy1FDjkyPb6GBgqgM/ZJByvcEMM0PcnnGL yJ6/iiIJQJhjDxm3Nozw6L1GFa19HIaeL9eWBaFVgaqbVuyX5bc/Vj2Que4r/6rwFYtf 2SZOXhXgxESNxsUoLyXjF6H25P31n/z1IK4sTYamTu/7XHlcV5ICJ/wokOX/u/Fj8Ue8 5uAhcF3/AZOsjy0l905obgWogKPkoqPYF5I029K0L68H8ta7+EQCUkLNnbC7kmwM9rb7 JnF7g3rc3rAQ5GmleoHtwaNdU9MFs36SHSKK5CrYSK002FJcJu9/nveab2SHKE9qfkPC bzZQ== X-Gm-Message-State: AOAM533AnYSX9bHXwZdgrRtuLgvplw446tsMTDhN0ZOBQSErefU+sbG8 GB5j0O3syYYrpXqApXimsS/hBIO1Prr4E+QZgxc= X-Received: by 2002:a2e:990:: with SMTP id 138mr7566543ljj.79.1622910312348; Sat, 05 Jun 2021 09:25:12 -0700 (PDT) Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com. [209.85.167.44]) by smtp.gmail.com with ESMTPSA id m18sm1070064ljc.105.2021.06.05.09.25.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Jun 2021 09:25:11 -0700 (PDT) Received: by mail-lf1-f44.google.com with SMTP id r5so18804449lfr.5 for ; Sat, 05 Jun 2021 09:25:10 -0700 (PDT) X-Received: by 2002:a05:6512:987:: with SMTP id w7mr6239078lft.41.1622910310532; Sat, 05 Jun 2021 09:25:10 -0700 (PDT) MIME-Version: 1.0 References: <20210604134422.GA2793@willie-the-truck> <20210604151356.GC2793@willie-the-truck> <20210604155154.GG1676809@rowland.harvard.edu> <20210604182708.GB1688170@rowland.harvard.edu> <20210605031403.GA1701165@rowland.harvard.edu> In-Reply-To: <20210605031403.GA1701165@rowland.harvard.edu> From: Linus Torvalds Date: Sat, 5 Jun 2021 09:24:54 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] LKMM: Add volatile_if() To: Alan Stern Cc: Peter Zijlstra , Will Deacon , "Paul E. McKenney" , Andrea Parri , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Linux Kernel Mailing List , linux-toolchains@vger.kernel.org, linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 4, 2021 at 8:14 PM Alan Stern wrote: > > > > > then I could in theory see teh compiler doing that WRITE_ONCE() as > > some kind of non-control dependency. > > This may be a minor point, but can that loophole be closed as follows? Note that it's actually entirely sufficient to have the barrier just on one side. I brought it up mainly as an oddity, and that it can result in the compiler generating different code for the two different directions. The reason that it is sufficient is that with the barrier in place (on either side), the compiler really can't do much. It can't join either of the sides, because it has to do that barrier on one side before any common code. In fact, even if the compiler decides to first do a conditional call just around the barrier, and then do any common code (and then do _another_ conditional branch), it still did that conditional branch first, and the problem is solved. The CPU doesn't care, it will have to resolve the branch before any subsequent stores are finalized. Of course, if the compiler creates a conditional call just around the barrier, and the barrier is empty (like we do now), and the compiler leaves no mark of it in the result (like it does seem to do for empty asm stataments), I could imagine some optimizing assembler (or linker) screwing things up for us, and saying "a conditional branch to the next instruction can just be removed). At that point, we've lost again, and it's a toolchain issue. I don't think that issue can currently happen, but it's an example of yet another really subtle problem that *could* happen even if *we* do everything right. I also do not believe that any of our code that has this pattern would have that situation where the compiler would generate a branch over just the barrier. It's kind of similar to Paul's example in that sense. When we use volatile_if(), the two sides are very very different entirely regardless of the barrier, so in practice I think this is all entirely moot. Linus