Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4941381pxb; Thu, 14 Oct 2021 15:24:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIc4R0p6intEsyPY4Crgy2dTi6fnB7WPCZCGFyCKt+eqayfHAsZByip+cuqLVuaJXyjQKL X-Received: by 2002:a17:902:e743:b0:13f:18ba:c8a8 with SMTP id p3-20020a170902e74300b0013f18bac8a8mr7614218plf.72.1634250263319; Thu, 14 Oct 2021 15:24:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634250263; cv=none; d=google.com; s=arc-20160816; b=0Ajm9TnXbKOGDcvU9At/M81EqVPlmDXEEaJH1AKxZeSWHWDedJbp/zazVtp5C0aZIz ed3gXCndhwPGS0weUrkJGbySoBzuZqvgJ7YbZ9Hirf6yagoVdj9CNg/ghEGFvW/LEBas kop8Prcw5sA8bPYUZ+MTK/r8UOJ6RDKXqVcVCpTD3gYtBCng/LeVD2AgIXEXjq2uAUhc pC+PiYfdpn9EUjYctJ4HYWobeDgw54rpn9UmZHt9iFxC/rnKsn3aBqabDLG18aX8MKLX d7AABKQznjhnKUJcMi7KQbW7CEXrVlex6spC8kEGI7Qpj1FM4+RywHshYhdUofp+aso3 ftFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=wuOa9nPL4Nj+2R98FTVLVbL4EXpPka2okBzBYfAl02M=; b=tsddVr/ZQKol/m4ik8boTMlyswh8OKgU48muRYPcgmDoANJbr6ggp3xTCyM4Dag+oa 57Bx+rTNPH1q74vYXy/PNOwEC19mhV0MAm5M2Kx0abRLCB1IlVlz0rhhbcAF+OzgYVXb x18jAdchhzGHh03g8usypSFFOnjO/KYZo7CTWEXPgAnEB3knyBROBfXuTW0nUZXp0F88 v+YzrJHyR7YCr4B1vxwGlIQztuG/Ae/Q8JXm52x2a5Te1bpN1eyaDFoLzw2tFLlhPXY9 R2fpliN2hwOpjnb7ZBixFzCQLEWVbgpKX62pZM2XzG6a5he/ZJRXTISNlO55KogArAAq 98tw== 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 l9si13002528pjc.80.2021.10.14.15.24.02; Thu, 14 Oct 2021 15:24:23 -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 S233894AbhJNSWR (ORCPT + 99 others); Thu, 14 Oct 2021 14:22:17 -0400 Received: from albireo.enyo.de ([37.24.231.21]:44202 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbhJNSWQ (ORCPT ); Thu, 14 Oct 2021 14:22:16 -0400 Received: from [172.17.203.2] (port=43549 helo=deneb.enyo.de) by albireo.enyo.de ([172.17.140.2]) with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1mb5Kd-00012e-4b; Thu, 14 Oct 2021 18:19:55 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.94.2) (envelope-from ) id 1mb5Kc-000oEC-R6; Thu, 14 Oct 2021 20:19:54 +0200 From: Florian Weimer To: "Paul E. McKenney" 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 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> <20211014162311.GD880162@paulmck-ThinkPad-P17-Gen-1> Date: Thu, 14 Oct 2021 20:19:54 +0200 In-Reply-To: <20211014162311.GD880162@paulmck-ThinkPad-P17-Gen-1> (Paul E. McKenney's message of "Thu, 14 Oct 2021 09:23:11 -0700") Message-ID: <87o87r4gfp.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Paul E. McKenney: >> > 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); Yes, something like that. The syntax only makes sense if tagvar is assigned only once (statically). > (This seems to me to be an eminently reasonable syntax.) > > Or did I miss a turn in there somewhere? The important bit is that the compiler emits the extra condition when necessary, and the information in the snippet above seems to provide enough information to optimize it away in principle, when it's safe. This assumes that we can actually come up with a concrete model what triggers the hardware barrier, of course. For example, if tagvar is spilled to the stack, is it still possible to apply an effective condition to it after it is loaded from the stack? If not, then the compiler would have to put in a barrier before spilling tagvar if it is used in any WRITE_ONCE_COND statement.