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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 1508DC4743E for ; Fri, 4 Jun 2021 18:27:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9857613F1 for ; Fri, 4 Jun 2021 18:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229982AbhFDS24 (ORCPT ); Fri, 4 Jun 2021 14:28:56 -0400 Received: from netrider.rowland.org ([192.131.102.5]:55385 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229913AbhFDS2z (ORCPT ); Fri, 4 Jun 2021 14:28:55 -0400 Received: (qmail 1689146 invoked by uid 1000); 4 Jun 2021 14:27:08 -0400 Date: Fri, 4 Jun 2021 14:27:08 -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: <20210604182708.GB1688170@rowland.harvard.edu> References: <20210604104359.GE2318@willie-the-truck> <20210604134422.GA2793@willie-the-truck> <20210604151356.GC2793@willie-the-truck> <20210604155154.GG1676809@rowland.harvard.edu> 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-toolchains@vger.kernel.org On Fri, Jun 04, 2021 at 06:17:20PM +0200, Peter Zijlstra wrote: > On Fri, Jun 04, 2021 at 11:51:54AM -0400, Alan Stern wrote: > > On Fri, Jun 04, 2021 at 05:42:28PM +0200, Peter Zijlstra wrote: > > > > #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)) > > That's effectively: > > volatile_if (READ_ONCE(*y)) > WRITE_ONCE(*y, 42); Sorry, what I meant to write was: volatile_if (READ_ONCE(*x) * 0 + READ_ONCE(*y)) WRITE_ONCE(*z, 42); where there is no ordering between *x and *z. It's not daft, and yes, a macro won't be able to warn about it. Alan > which is a valid, but daft, LOAD->STORE order, no? A compiler might > maybe be able to WARN on that, but that's definitely beyond what we can > do with macros.