Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4890052pxb; Thu, 14 Oct 2021 14:10:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvSX5U0zcVa2aVQ2Fb1s5wk00+aisNzSjCcjMhchSehFfSpirJdhbUQkKx8sRI8mW7daJ1 X-Received: by 2002:aa7:8bd4:0:b0:44c:f89d:7e72 with SMTP id s20-20020aa78bd4000000b0044cf89d7e72mr7649107pfd.71.1634245803685; Thu, 14 Oct 2021 14:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634245803; cv=none; d=google.com; s=arc-20160816; b=hP0khG9euQN4PT3JUqQYzbpE7ziwIFcQMtseme9TKhcpDjtlKzmOfDPA3mTGupVKYl nKIZLWv6Ts254knH5C1hvr4B5lxPMKnC6HNjXmUm/eGjqkfNSz2WjabHpmFM01rh0E/+ IUS9MOIUt6R+OyDtwzMPe0zJEmVJBD/XxRLIip0qicg9RbCIuO1k15zXbt4U4Vx70V4t EQPBCgxTPVNIk0apcxxOWQxuqWTJ+0DFEC3c5MffZCPbanxo+nByG8jIz5XLFwzsf46e qBE1ecyqpFjelPrnpV1Vo4JRLRNoV6WlfsiY3KzUkm7F5pLk7RydRv117Sgt8sSVHvAp 7Jsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=3C5J0Nq5Fo2CAp9xkbMzXSZWhIO8EUUchgLwLShCUyY=; b=OaXqa6hZMIC5i7HNFr8bbDCI7Pp4Kkp2qLb7id6rrWZtmu8ha2Ta7xOYRrC0hxrD1X LQMcqB64PHygwD62+1KdZG7MMHYvPqOM2bA1y5b/cck6CAsjsnoXPZ5Ssq5OOCq8zC59 KZMuDdmYhPQCH140W/n+v39rJy9fxqCjz5pl87Cs6P6lm3qqgJwL4m9K9qLyhuW84qMm 36qzS7U+FGCce/tNoH6Wc+o4FOwU4YF7PcD3aZgDOiojuSBRaXSwosALkIj2O+L4yMKU /O2xyw3KvAhhyL0zyi52p8ogrXXUZ/MSJah5pz2wxoeAfz0a9/uuHDJItfd6IOW8l/dx 5etQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IFU1s5a3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f15si5380193pgm.374.2021.10.14.14.09.48; Thu, 14 Oct 2021 14:10:03 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IFU1s5a3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232029AbhJNQZW (ORCPT + 99 others); Thu, 14 Oct 2021 12:25:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:54750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbhJNQZV (ORCPT ); Thu, 14 Oct 2021 12:25:21 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6D9F8610F9; Thu, 14 Oct 2021 16:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634228591; bh=fCvytSPcAeWo2Vds96eNy2fT0BcSOAO7bX73OXJ3ZDw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=IFU1s5a3z5Ekj2w0Y2WYmd0mqAHup0noJpoI07M4xq3w2OeC34TFrWMNrY47A0opP u5kjSp64z8dUyFT/erKNcZcvGkCGzbQ818e9jW44tzbGv+ZNAHdccv8GTw50ODk6yG uwElhmZHFVGJ1jt/ormdO88HltmoRpcv/RDha4gJxN69udTCLmYr7HK5Xsq8mKNKLy IMLhgAUql24WpHJxB9S9IbuyyIGFLEIjvjJNM7E7TlcsaxjDwlvmy/vr42ZeolpOK0 6XuKeF5N32eBlGLDS4fWsuvdhxEqqqth7FACn71BL2PelgoZluE+Vdydxi0VKlNyIa pK2QToiAjSoxA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 38B635C0AE9; Thu, 14 Oct 2021 09:23:11 -0700 (PDT) Date: Thu, 14 Oct 2021 09:23:11 -0700 From: "Paul E. McKenney" To: Florian Weimer Cc: Linus Torvalds , Mathieu Desnoyers , Segher Boessenkool , Will Deacon , Peter Zijlstra , linux-kernel , Alan Stern , 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: <20211014162311.GD880162@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org 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> <87lf2v61k7.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lf2v61k7.fsf@mid.deneb.enyo.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 14, 2021 at 05:58:16PM +0200, Florian Weimer wrote: > * Paul E. McKenney: > > > 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? > > Is this really a problem of syntax? No, but we seem to need some way to communicate the control-dependency's ordering intent to the compiler. ;-) > > 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? > > If the load is assigned to a local variable whose address is not taken > and which is only assigned this once, it could be used to label the > store. Then the compiler checks if all paths from the load to the > store feature a condition that depends on the local variable (where > qualifying conditions probably depend on the architecture). If it > can't prove that is the case, it emits a fake no-op condition that > triggers the hardware barrier. This formulation has the advantage > that it does not add side effects to operators like <. It even > generalizes to different barrier-implying instructions besides > conditional branches. So something like this? tagvar = READ_ONCE(a); if (tagvar) WRITE_ONCE_COND(b, 1, tagvar); (This seems to me to be an eminently reasonable syntax.) Or did I miss a turn in there somewhere? > But I'm not sure if all this complexity will be a tangible improvement > over just using that no-op condition all the time (whether implied by > READ_ONCE, or in a separate ctrl_dep macro). That is an excellent question. I have no idea what the answer is. ;-) Thanx, Paul