Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1012710pxb; Wed, 29 Sep 2021 14:55:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPrD2nLIaArH3QdR2aIq9NRGgTSHzQ0aRawd9+2G4rZUfyszteV1Gd4jlTIUo25UnuHkTE X-Received: by 2002:a63:235f:: with SMTP id u31mr1892072pgm.248.1632952507258; Wed, 29 Sep 2021 14:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632952507; cv=none; d=google.com; s=arc-20160816; b=ItCIQ8wRcOBi3zdFFsuFrB0zJG4AcBDytuEzt6QcoryetgsONKFYT8NufDNEa7Hv/x 9ucV8F9I7DbrY0I+j/jD3IR4x30HDeusE64Gle8W9oUnmRCS+dJYvfOjq3/g9UZnW18a 9v453ppMv/C6qTmG2GJhPBGSUYezAlZ96qL5IaMIlRD1mbnuPS4GK8fwbfU/H+fMSDBm 2RWEiAlDWi/S/DVYcTCGdPqsvmb7wJmNcinTw2TXJAXLYILBGcZnYMqUis2CQGuKtnZO ezwEEtClcnt0zgWT+WOE0jgADcFqdA9T6zmvhxA96W04TG/7FRUwS1eVRwjtyTxJKOcE MByg== 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=tdzYGCnmK4Ef/ZqRFkVGD9RcWfiT/+hHCRmcEjdGENc=; b=1FVqvT9urSbbIY5b6CJ83e2Dns6b4UI+nHORRiv2LytO0IsB1I3XXgsCT555sEsmHe 6LkBkqHg2K706X3cKMgVbmGr82Hm9w9/zpOoglQ4+rqvWCN8SKlUZQk0F8ykNJ8C2hgP 10DNet5bZlSRAUC2kdEFql4yI1X/Wx8Bdj/xdh5urMLjEEZk0QGO1HjygbOHPlt5kJqU zsPkSehWEskTv6Jnf3p7P2ZVbnYv2Dd1etE630jiEKG6wsPrALwJjLaHs68A/yhmMdGE GeodAXkdJ+62tvZpzTBZ3RMy5QpQcAi34ZqR/f53A/iVK0a88NMESTa1+glpY83d3Kg4 CzkQ== 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 h3si1288895pgj.173.2021.09.29.14.54.53; Wed, 29 Sep 2021 14:55:07 -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 S1346689AbhI2Vys (ORCPT + 99 others); Wed, 29 Sep 2021 17:54:48 -0400 Received: from gate.crashing.org ([63.228.1.57]:53123 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346634AbhI2Vym (ORCPT ); Wed, 29 Sep 2021 17:54:42 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 18TLl6mK020560; Wed, 29 Sep 2021 16:47:06 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 18TLl3K9020545; Wed, 29 Sep 2021 16:47:03 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 29 Sep 2021 16:47:03 -0500 From: Segher Boessenkool To: Mathieu Desnoyers Cc: will@kernel.org, paulmck@kernel.org, Peter Zijlstra , linux-kernel@vger.kernel.org, Linus Torvalds , stern@rowland.harvard.edu, 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-toolchains@vger.kernel.org, linux-arch@vger.kernel.org Subject: Re: [RFC PATCH] LKMM: Add ctrl_dep() macro for control dependency Message-ID: <20210929214703.GG22689@gate.crashing.org> References: <20210928211507.20335-1-mathieu.desnoyers@efficios.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210928211507.20335-1-mathieu.desnoyers@efficios.com> User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On Tue, Sep 28, 2021 at 05:15:07PM -0400, Mathieu Desnoyers wrote: > C99 describes that accessing volatile objects are side-effects, and that > "at certain specified points in the execution sequence called sequence > points, all side effects of previous evaluations shall be complete > and no side effects of subsequent evaluations shall have taken > place". [2] But note that the kernel explicitly uses C89 (with GNU extensions). Side effects are largely equal there though. Also note that there may no place in the generated machine code that corresponds exactly to some sequence point. Sequence points are a concept that applies to the source program and how that executes on the abstract machine. > +Because ctrl_dep emits distinct asm volatile within each leg of the if > +statement, the compiler cannot transform the two writes to 'b' into a > +conditional-move (cmov) instruction, thus ensuring the presence of a > +conditional branch. Also because the ctrl_dep emits asm volatile within > +each leg of the if statement, the compiler cannot move the write to 'c' > +before the conditional branch. I think your reasoning here misses some things. So many that I don't know where to start to list them, every "because" and "thus" here does not follow, and even the statements of fact are not a given. Why do you want a conditional branch insn at all, anyway? You really want something else as far as I can see. It is essential here that there is a READ_ONCE and the WRITE_ONCE. Those things might make it work the way you want, but as Linus says this is all way too subtle. Can you include the *_ONCE into the primitive itself somehow? Segher