Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1220153pxj; Fri, 4 Jun 2021 08:54:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzze/0vVVXCfwsJIa6X+/Dko87OejXEJwaKzWxAC9oGF1dXhrc6Gp9ekUBwI9UW8sFAdAi0 X-Received: by 2002:a17:906:bcd5:: with SMTP id lw21mr4691865ejb.346.1622822073807; Fri, 04 Jun 2021 08:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622822073; cv=none; d=google.com; s=arc-20160816; b=xlu1ByDdNXL0HK+qyW0l/EftlimzqIyTmoO1ETq3YtjS5ejOKIpO5t0JI+h7kBf0NK StcX7Jtlme2Ero9Pjkaye1Q5dCNb7haWX8aafSRt2jiFTGg9iuS9zPR+ocPi9UVwcSU/ 5ukCWqOLQ0zxO+xBJIEEPjiLOqVVtYuU+rNIFur/GnLM28TFiq20l+U9gwYydMtXNdTO f92JcQojTTvkOqkcU4UKlBfJ/n0alA4WDaKiJUzaj0VaU7FJdz+EyKo9e3DaCq8PxMdF NhnUA1EmvpxzHcPBs2FLLAkffqHt7wZAib9FGpv99v3O7Jvfkzb34kwqRfkFmpwyA/LM kkIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=34Zt94feNzGWCs+oGUVJ8jomtK36hBf2xTUU8DAWwJc=; b=prsIP8A+/h46ZgvNdi1kuHomH0jfqS+7mc4vdKQ25ppknjxQoHZOyx4s52AJIylyA1 cpGbiOSmdcykkUn+5t6c5fWZ9VfQzKn+YxamgEGiu9kcKt5lWJMTowA5s2txScUvMDUT Q13rzK2Z3EMo4lfDvjFCPt7da5cLEjoEbIsUfdFu+kMLKzGBtU45ZKYjTROZNZ3OiFmB vswx1T+R1IVdS0ZqHBCxBfB//wf6Mr1/5Ix24Qprmcaq+Zc85JN68yKmKQeb5wl1r2M4 oFQW6SOlWTQyknGTr0LIAVZX+QlxQA1yR4eTgQSG+i6bDWs2Wj2BxhFPKl1wOUBAxSis jF6Q== 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 k4si4969904eds.218.2021.06.04.08.54.10; Fri, 04 Jun 2021 08:54: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; 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 S231286AbhFDPxm (ORCPT + 99 others); Fri, 4 Jun 2021 11:53:42 -0400 Received: from netrider.rowland.org ([192.131.102.5]:37129 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229809AbhFDPxl (ORCPT ); Fri, 4 Jun 2021 11:53:41 -0400 Received: (qmail 1683583 invoked by uid 1000); 4 Jun 2021 11:51:54 -0400 Date: Fri, 4 Jun 2021 11:51:54 -0400 From: Alan Stern To: Peter Zijlstra Cc: Will Deacon , Linus Torvalds , paulmck@kernel.org, parri.andrea@gmail.com, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, linux-kernel@vger.kernel.org, linux-toolchains@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [RFC] LKMM: Add volatile_if() Message-ID: <20210604155154.GG1676809@rowland.harvard.edu> References: <20210604104359.GE2318@willie-the-truck> <20210604134422.GA2793@willie-the-truck> <20210604151356.GC2793@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 05:42:28PM +0200, Peter Zijlstra wrote: > On Fri, Jun 04, 2021 at 05:22:04PM +0200, Peter Zijlstra wrote: > > On Fri, Jun 04, 2021 at 04:13:57PM +0100, Will Deacon wrote: > > > > > In fact, maybe it's actually necessary to bundle the load and branch > > > together. I looked at some of the examples of compilers breaking control > > > dependencies from memory-barriers.txt and the "boolean short-circuit" > > > example seems to defeat volatile_if: > > > > > > void foo(int *x, int *y) > > > { > > > volatile_if (READ_ONCE(*x) || 1 > 0) > > > WRITE_ONCE(*y, 42); > > > } > > > > Yeah, I'm not too bothered about this. Broken is broken. > > > > If this were a compiler feature, the above would be a compile error. But > > alas, we're not there yet :/ and the best we get to say at this point > > is: don't do that then. > > Ha! Fixed it for you: > > #define volatile_if(cond) if (({ bool __t = (cond); BUILD_BUG_ON(__builtin_constant_p(__t)); volatile_cond(__t); })) That won't help with more complicated examples, such as: volatile_if (READ_ONCE(*x) * 0 + READ_ONCE(*y)) Alan