Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1596559pxj; Fri, 4 Jun 2021 20:15:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKggZuF8TvsktB6NR/DYZMM560H4vci7TxkE9MytaBmH2MhPHlI0OPmXi1MZtQaLes/4FZ X-Received: by 2002:a17:907:20f7:: with SMTP id rh23mr7487999ejb.414.1622862947816; Fri, 04 Jun 2021 20:15:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622862947; cv=none; d=google.com; s=arc-20160816; b=ksuCHcwbxFOL3Ti1W95Oiy4bFj4BWoNZUrqNiC+0YFYyvU8aOeklIfrqokbUu1vQ+R 04QtDSnlqNGBnpAkUwEjIhgF1skb/rdvXBhxWHOpzE+i3VAb6V5qqqtmbNglTw/rOZW/ BsNeJ4GRpGJ1ZvBrg7HwD3LjN37nAbCa1qi8q1nJm1kAnvRXhN7lDnbJNCd99/sI9UBk tMsCPFesDRoIdo95rzIt2176sBPIy+Fja6tv+iYtobW9p7nJaGwNK8yFAVu5Aekc2Uob IbeMCKF9fPM0X99+ICS+u9/lflhXTo8E0osvhvZpx7MtDFQy2Dv/S5npDB1msiYwro8h ZirA== 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=IVFwiCWvKeasby3/zUlHoU06yrGeMZqFzycI0URsMdE=; b=uVmLKTMHq4LAT8wkFHeqBFn1wUGXwZnfBE5OkClXA79ul98r3ZLWKhoLgjClPIwQ2m 3eg49z6jzYG8eCFV57icUd9pyyw0EHpuxE1z/omZ88JJobDTDwjTiQXIDMDJ6ZoOuyMd hnbh1/FR1I2hKn7GJX0yFuWbf8jfKYVF46W2A3UrMKphEXBl2lUUt7sIx24B4JTYTmNd LwbSE5pU88oE2fK9AG/08Hn3nkh+rSdRltO3tRbzkdbcuMnfXkjWQXBUfCOUeYJ2lK+F W4V+eFhJAnWiSeugd3lYg4NeW6benxTUd6pA651bpKXfUtAr38/bgrAHUEvx65sXHsWj AXbg== 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 c23si1985294ejc.734.2021.06.04.20.15.24; Fri, 04 Jun 2021 20:15:47 -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 S229998AbhFEDPw (ORCPT + 99 others); Fri, 4 Jun 2021 23:15:52 -0400 Received: from netrider.rowland.org ([192.131.102.5]:50509 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S231132AbhFEDPv (ORCPT ); Fri, 4 Jun 2021 23:15:51 -0400 Received: (qmail 1701512 invoked by uid 1000); 4 Jun 2021 23:14:03 -0400 Date: Fri, 4 Jun 2021 23:14:03 -0400 From: Alan Stern To: Linus Torvalds 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 Subject: Re: [RFC] LKMM: Add volatile_if() Message-ID: <20210605031403.GA1701165@rowland.harvard.edu> References: <20210604134422.GA2793@willie-the-truck> <20210604151356.GC2793@willie-the-truck> <20210604155154.GG1676809@rowland.harvard.edu> <20210604182708.GB1688170@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-kernel@vger.kernel.org On Fri, Jun 04, 2021 at 12:09:26PM -0700, Linus Torvalds wrote: > Side note: it is worth noting that my version of "volatile_if()" has > an added little quirk: it _ONLY_ orders the stuff inside the > if-statement. > > I do think it's worth not adding new special cases (especially that > "asm goto" hack that will generate worse code than the compiler could > do), but it means that > > x = READ_ONCE(ptr); > volatile_if (x > 0) > WRITE_ONCE(*z, 42); > > has an ordering, but if you write it as > > x = READ_ONCE(ptr); > volatile_if (x <= 0) > return; > WRITE_ONCE(*z, 42); > > 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? define volatile_if(x) \ if ((({ _Bool __x = (x); BUILD_BUG_ON(__builtin_constant_p(__x)); __x; }) && \ ({ barrier(); 1; })) || ({ barrier(); 0; })) (It's now a little later at night than when I usually think about this sort of thing, so my brain isn't firing on all its cylinders. Forgive me if this is a dumb question.) Alan