Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4041891pxb; Wed, 13 Oct 2021 19:17:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW9Nu5K1kqrT/W29ylKMVIUp0JJe0n33le1y0llZQNXJ6a2YScAVOxspn7/xu+HcbOz4WQ X-Received: by 2002:a17:906:cc89:: with SMTP id oq9mr582934ejb.70.1634177868567; Wed, 13 Oct 2021 19:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634177868; cv=none; d=google.com; s=arc-20160816; b=Bd88sqNALunhRzL0P8sydTSNFTow+Ss/11T2Z5nQhZspwPkpe3d0DD48x64fz2oLur 3uuwk2fxmhlZXGJUCj9UlsPvr+5IdNISd3GbzCcQlJ5bOh+l8UmFwmIWFBfpb18Bhcwl g2dw9lag5QD9jjDqFCiUMWdxRvq8cum0JrH772dCpfmYKbj4tMILjagzt7KW18I341by p1M2msbfmQIXyroOhz51QlQ20ROV7tZKmcJTMdCnuuXnqGMqNaUbNK2w/65Fz/kgDJDp Xi0f6FocPXImYa54DDUTF/M0VBO/Hr4KwWuBwvIoZOuUXpRAkdQP+vbP3Ebe9+hbaq7E Bwlw== 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=kjesq4BZlLn17eQ5D02Y4QMdtRvbjcTSfzWWUPYXaNY=; b=QStPLeDWlihcMFfYFK7gG9e1+Kio6IwS5PST7YeSUw5/lHiVDz0xtCAeEG9mn170FO W4SgJVjWtKDAeP3jqoyXTdBIcPdfE88kkmxJfdXVCqSbocm2BsfJmJcLuUvyyH/GzWbC k8zYtrVJC3Wqv+dFMkPLTR9NrdEjjkNGGn9QYZW3fb6su9qWMoVC+0q6pdV0vaS4D2RJ 7rl1Vj20X3nuvWl+PdUbnQN7e1ouLUAP2swQFPW55cka5RncaTJHcPbo3c0+wCwHxje4 X4l7uTfyumDePCu9+vTjigx6FT7CB/spHBmPlSKpdwhjzo39z0OfKrCkVLLnHwgv+/3J drDA== 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 i2si2924438edc.582.2021.10.13.19.17.13; Wed, 13 Oct 2021 19:17:48 -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 S229798AbhJNCQh (ORCPT + 99 others); Wed, 13 Oct 2021 22:16:37 -0400 Received: from netrider.rowland.org ([192.131.102.5]:35509 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S229660AbhJNCQh (ORCPT ); Wed, 13 Oct 2021 22:16:37 -0400 Received: (qmail 910485 invoked by uid 1000); 13 Oct 2021 22:14:31 -0400 Date: Wed, 13 Oct 2021 22:14:31 -0400 From: Alan Stern To: "Paul E. McKenney" Cc: Florian Weimer , Linus Torvalds , Mathieu Desnoyers , Segher Boessenkool , Will Deacon , Peter Zijlstra , linux-kernel , Andrea Parri , Boqun Feng , Nicholas Piggin , David Howells , j alglave , luc maranget , akiyks , linux-toolchains , linux-arch Subject: Re: [RFC PATCH] LKMM: Add ctrl_dep() macro for control dependency Message-ID: <20211014021431.GA910341@rowland.harvard.edu> References: <20210928211507.20335-1-mathieu.desnoyers@efficios.com> <87lf3f7eh6.fsf@oldenburg.str.redhat.com> <20210929174146.GF22689@gate.crashing.org> <2088260319.47978.1633104808220.JavaMail.zimbra@efficios.com> <871r54ww2k.fsf@oldenburg.str.redhat.com> <87y271yo4l.fsf@mid.deneb.enyo.de> <20211014000104.GX880162@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211014000104.GX880162@paulmck-ThinkPad-P17-Gen-1> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 05:01:04PM -0700, Paul E. McKenney wrote: > On Sun, Oct 10, 2021 at 04:02:02PM +0200, Florian Weimer wrote: > > * Linus Torvalds: > > > > > On Fri, Oct 1, 2021 at 9:26 AM Florian Weimer wrote: > > >> > > >> Will any conditional branch do, or is it necessary that it depends in > > >> some way on the data read? > > > > > > The condition needs to be dependent on the read. > > > > > > (Easy way to see it: if the read isn't related to the conditional or > > > write data/address, the read could just be delayed to after the > > > condition and the store had been done). > > > > That entirely depends on how the hardware is specified to work. And > > the hardware could recognize certain patterns as always producing the > > same condition codes, e.g., AND with zero. Do such tests still count? > > It depends on what the specification says. > > > > What I really dislike about this: Operators like & and < now have side > > effects, and is no longer possible to reason about arithmetic > > expressions in isolation. > > Is there a reasonable syntax that might help with these issues? > > Yes, I know, we for sure have conflicting constraints on "reasonable" > on copy on this email. What else is new? ;-) > > I could imagine a tag of some sort on the load and store, linking the > operations that needed to be ordered. You would also want that same > tag on any conditional operators along the way? Or would the presence > of the tags on the load and store suffice? Here's a easy cop-out. Imagine a version of READ_ONCE that is equivalent to: a normal READ_ONCE on TSO architectures, a load-acquire on more weakly ordered architectures. Call it READ_ONCE_FOR_COND, for the sake of argument. Then as long as people are careful to use READ_ONCE_FOR_COND when loading the values that a conditional expression depends on, and WRITE_ONCE for the important stores in the branches of the "if" statement, all architectures will have the desired ordering. (In fact, if there are multiple loads involved in the condition then only the last one has to be READ_ONCE_FOR_COND; the others can just be READ_ONCE.) Of course, this is not optimal on non-TSO archictecture. That's why I called it a cop-out. But at least it is simple and easy. Alan Stern