From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9225C48BCD for ; Wed, 9 Jun 2021 12:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DFA1613B1 for ; Wed, 9 Jun 2021 12:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234992AbhFIMqQ (ORCPT ); Wed, 9 Jun 2021 08:46:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbhFIMqP (ORCPT ); Wed, 9 Jun 2021 08:46:15 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20275C061574 for ; Wed, 9 Jun 2021 05:44:21 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id j11-20020a9d738b0000b02903ea3c02ded8so10163898otk.5 for ; Wed, 09 Jun 2021 05:44:21 -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=3yJJiLIio1keCrN3sS6SLKCpX1mujUdD6B7dJpQDmZw=; b=ClaMFpHvFaLfrDBK3kLKjFrPN25oDeFJ8tj4sFgK8pktGD85GvHUBtvOEsfyTrqG+I X43sS+oC0NRnqBvv8fR1xouf7sOrSY40TyPaku3k/CIFeBOer4oWe3WdkZs3Y87sDPi1 nwgQ20qYboPzcGIJAvt5TjOrlRETQHfZEUR7OltE3NHxr3c9RcnfZ3cmaJf/dPCYX3ef fMHflwpyJCzqjK1hMUJMR9iwk1xuXRiFUVpKHGOUwyUgHq/A6y5pIbcT6NAUY4R14aqL ifxOAIMzLy60OeGyhY9jogUi7U8CrYZT4aUt6xV0uk0KViOaVef+3MfdSSup8dQZllAj 1xUw== 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=3yJJiLIio1keCrN3sS6SLKCpX1mujUdD6B7dJpQDmZw=; b=tduvD/ktQrtfKw6u/JS5ulVI3LyD5aaMGLpjrn0e2I/VwWN/x08r1deGBA9mygxoOX qZcrkZlRaxLVgbbt1uN7RjBvxtPSBvMcvwdb3/dFg+VWVQgYD6TAaVjHs5n2YtQn4SaO JsCHGU+Wlb5E4TkGC+ycB9WdNqXq7OwAp1aYcdSbnHV5ELCOi81JfTEVJanrNzYq9PA6 t0J/Bm88e5TG9UIt9BTEu41VuVmdxQiaEvkhcJatMojyx9svjHDbDwHXbqi/mN9QB6YB QzfTOTm5OFW78PqZ7tdKEqSRonFYUzGUIdpdXCPCA8bXuP0z177HFjHfwUjfsHy8+aEh q4+g== X-Gm-Message-State: AOAM531wv2ZhYO/QweZSFiZT5iew2b00XTCaHBnsJ7JfLC1Dzk+2Finr RHLIrED9W/Y2tdlKLKkjqSeaMsq3DyvSEilQul0x5g== X-Google-Smtp-Source: ABdhPJxBngznJ5I05L+XqEpGWWmBHExE9k9EYf3tqXEM9hX0sUuoP3RiU+g6XBrDr9Ttmz3Cfu1d39mD+4FznXHJW8c= X-Received: by 2002:a05:6830:1c7b:: with SMTP id s27mr8892653otg.233.1623242660230; Wed, 09 Jun 2021 05:44:20 -0700 (PDT) MIME-Version: 1.0 References: <20210606185922.GF7746@tucnak> <20210607152806.GS4397@paulmck-ThinkPad-P17-Gen-1> <20210608152851.GX18427@gate.crashing.org> In-Reply-To: <20210608152851.GX18427@gate.crashing.org> From: Marco Elver Date: Wed, 9 Jun 2021 14:44:08 +0200 Message-ID: Subject: Re: [RFC] LKMM: Add volatile_if() To: Segher Boessenkool Cc: Peter Zijlstra , "Paul E. McKenney" , Alexander Monakov , Linus Torvalds , Jakub Jelinek , Alan Stern , Will Deacon , 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-toolchains@vger.kernel.org On Tue, 8 Jun 2021 at 17:30, Segher Boessenkool wrote: > On Tue, Jun 08, 2021 at 01:22:58PM +0200, Peter Zijlstra wrote: > > Works for me; and note how it mirrors how we implemented volatile_if() > > in the first place, by doing an expression wrapper. > > > > __builtin_ctrl_depends(expr) would have to: > > > > - ensure !__builtin_const_p(expr) (A) > > Why would it be an error if __builtin_constant_p(expr)? In many > programs the compiler can figure out some expression does never change. > Having a control dependency on sometthing like that is not erroneous. > > > - imply an acquire compiler fence (B) > > - ensure cond-branch is emitted (C) > > (C) is almost impossible to do. This should be reformulated to talk > about the effect of the generated code, instead. > > > *OR* > > > > - ensure !__builtin_const_p(expr); (A) > > - upgrade the load in @expr to load-acquire (D) > > So that will only work if there is exactly one read from memory in expr? > That is problematic. > > This needs some work. There is a valid concern that something at the level of the memory model requires very precise specification in terms of language semantics and not generated code. Otherwise it seems difficult to get compiler folks onboard. And coming up with such a specification may take a while, especially if we have to venture in the realm of the C11/C++11 memory model while still trying to somehow make it work for the LKMM. That seems like a very tricky maze we may want to avoid. An alternative design would be to use a statement attribute to only enforce (C) ("__attribute__((mustcontrol))" ?). The rest can be composed through existing primitives I think (the compiler barriers need optimizing though), which should give us ctrl_depends(). At least for Clang, it should be doable: https://reviews.llvm.org/D103958 Thanks, -- Marco