Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp435629pxb; Wed, 8 Sep 2021 04:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygC5Cu0Th/jNWsUpc6095StNP+wdtICWa6aWWprwJS4/VFuA4Uxxhg/O1w47HKDB1iwAB8 X-Received: by 2002:a17:906:d94:: with SMTP id m20mr3617035eji.445.1631101605440; Wed, 08 Sep 2021 04:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631101605; cv=none; d=google.com; s=arc-20160816; b=zDZ2b3l3gVQKiLBzVYJNZHpU8Iy4NKBjeRs4z3wX2YeiFyJ3SZxe72PdM2Z3fsGil9 kjHP87drOyT2s1iPzA9mtwTz3u18qRN4U3HI13+ja+dKiEdI6Ell3EbwieNhNEfRE63X QpRFAVSDUXZXsJLAHvKkCNNc5NDUt9TIpm8rDjhYxnl6FDGniEaYW8N+Xns6ojHwyIjA OYcJsrOQSzzg8u4D1hhT081HtWBrw9fEk/qo9tbFkbzQsK0fkNvjIM95jcnE42vJpdlB JPwcyuftqgkvpd7G4vQqJBqF82UnSbzRCTJN/LKTDz3wKTXq4FY6S+TnC1YAsY6d+UHB uKPQ== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=KkbVfC2NQ37cQ9a9pfkaXbYDmV13hjbW4DGEU3FEM8g=; b=exiMEW/SnU/RDZFwyPvKzLp/KuCkvJg2C8GBZN1n4By0c3/pDahgv1pXyKFltmnSkc 4+TuHp7zJ1DwzZJnVYWZedLre+16r5VdZbowPalsdLct0Afw+UcGvaCLGvmS4QE+EX48 brnfdguUadP3zX72dVzzAyKn+WfAS8Xf4irnANmkVivj1X14F3jtIv7wnwKC4Sk5UmEa hi/9BmYvGsC7jn9sgDugZiC9kbRPhlGNJXc6tryDNmwW1pXw0UxOtk3URu0XewFxDSAJ co/qzmQVNdJ4K5xCCj+Igo2N7AVpKuuQOFIaVLJiBA39mqlsHTBIValiXhlTqqEw+CiW 3uOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=cgldSu7j; 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 m7si2324039edq.520.2021.09.08.04.46.11; Wed, 08 Sep 2021 04:46:45 -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=@infradead.org header.s=desiato.20200630 header.b=cgldSu7j; 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 S1351550AbhIHLpg (ORCPT + 99 others); Wed, 8 Sep 2021 07:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349176AbhIHLpc (ORCPT ); Wed, 8 Sep 2021 07:45:32 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1583EC061575; Wed, 8 Sep 2021 04:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KkbVfC2NQ37cQ9a9pfkaXbYDmV13hjbW4DGEU3FEM8g=; b=cgldSu7jeycIUIEkvccbPhxMpL isZsXa+GOmeyES61HptJTl2+pBZ6PXUcZfiMqXCesR4WlhrFtw8AEFX82Ov3Wx35XGhAIVbxp7Ccb yRz4x0FR81Kou2PY5yryoFvE/vaR+SX+xj3dBQbjcdvkztvqOsFT0QmKCbBJ+hi7yoZVJLAeSWPqp k2a34E2vNIZfi0TKY0Hze1VwJdoxDZC5TFk8kSWiBz6DLezTvrWRE87RQ8MXUrzatj2cfyzUccj+/ m4VydFJQuamYB/tglrmSaXfyWu7fd9PMn67+l+mzfK3iP3cvFwXw9Tr4Sn8VhnVgXADicnd4sTs3M zzMUKBEQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNvzx-001dJI-53; Wed, 08 Sep 2021 11:44:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 91163300362; Wed, 8 Sep 2021 13:44:11 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6FEA92067E687; Wed, 8 Sep 2021 13:44:11 +0200 (CEST) Date: Wed, 8 Sep 2021 13:44:11 +0200 From: Peter Zijlstra To: stern@rowland.harvard.edu, alexander.shishkin@linux.intel.com, hpa@zytor.com, parri.andrea@gmail.com, mingo@kernel.org, paulmck@kernel.org, vincent.weaver@maine.edu, tglx@linutronix.de, jolsa@redhat.com, acme@redhat.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, eranian@google.com, will@kernel.org Cc: linux-tip-commits@vger.kernel.org Subject: Re: [tip:locking/core] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire Message-ID: References: <20180926182920.27644-2-paulmck@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 08, 2021 at 01:00:26PM +0200, Peter Zijlstra wrote: > On Tue, Oct 02, 2018 at 03:11:10AM -0700, tip-bot for Alan Stern wrote: > > Commit-ID: 6e89e831a90172bc3d34ecbba52af5b9c4a447d1 > > Gitweb: https://git.kernel.org/tip/6e89e831a90172bc3d34ecbba52af5b9c4a447d1 > > Author: Alan Stern > > AuthorDate: Wed, 26 Sep 2018 11:29:17 -0700 > > Committer: Ingo Molnar > > CommitDate: Tue, 2 Oct 2018 10:28:01 +0200 > > > > tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire > > > > More than one kernel developer has expressed the opinion that the LKMM > > should enforce ordering of writes by locking. In other words, given > > the following code: > > > > WRITE_ONCE(x, 1); > > spin_unlock(&s): > > spin_lock(&s); > > WRITE_ONCE(y, 1); > > > > the stores to x and y should be propagated in order to all other CPUs, > > even though those other CPUs might not access the lock s. In terms of > > the memory model, this means expanding the cumul-fence relation. > > Let me revive this old thread... recently we ran into the case: > > WRITE_ONCE(x, 1); > spin_unlock(&s): > spin_lock(&r); > WRITE_ONCE(y, 1); > > which is distinct from the original in that UNLOCK and LOCK are not on > the same variable. > > I'm arguing this should still be RCtso by reason of: > > spin_lock() requires an atomic-acquire which: > > TSO-arch) implies smp_mb() > ARM64) is RCsc for any stlr/ldar > Power) LWSYNC > Risc-V) fence r , rw > *) explicitly has smp_mb() > > > However, Boqun points out that the memory model disagrees, per: > > https://lkml.kernel.org/r/YTI2UjKy+C7LeIf+@boqun-archlinux > > Is this an error/oversight of the memory model, or did I miss a subtlety > somewhere? Hmm.. that argument isn't strong enough for Risc-V if I read that FENCE thing right. That's just R->RW ordering, which doesn't constrain the first WRITE_ONCE(). However, that spin_unlock has "fence rw, w" with a subsequent write. So the whole thing then becomes something like: WRITE_ONCE(x, 1); FENCE RW, W WRITE_ONCE(s.lock, 0); AMOSWAP %0, 1, r.lock FENCE R, WR WRITE_ONCE(y, 1); Which I think is still sufficient, irrespective of the whole s!=r thing.