Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1924046imm; Tue, 10 Jul 2018 10:04:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcb3NqyyCTLFW/c8bgUU1fI0LJXkvwL/oGlUIbc43gQaR9PnvOqumjZfZvpeV4SDlyEh9rV X-Received: by 2002:a17:902:8b8c:: with SMTP id ay12-v6mr25400414plb.74.1531242247906; Tue, 10 Jul 2018 10:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531242247; cv=none; d=google.com; s=arc-20160816; b=VkWclV7GQ5so8hUy6coGG54qhDWlrW2dYRxszP5BaTQcW61fHqDsog/qY+j4/IzYD9 OdxR0EruFwXqlhW4rwwp9CRz0alR+e3Dzt6fodqd+KOA3Rl+BYEcHQa3BE0ttrDK4qb9 etD6fKSpwnfEl/qd7TLcoaexdsqePWhz209KEZBydDpp2dSpYQZZXU5FsVuEhTJj360r S3BozxwWW7po3VwA8R1osElIG72PtGCTzLG0+vb6yNrAXR/V/rYDC2DwsFG/Ynpkhgbf h3+Mxs3nhqse0eTPs99ZhyS809V75sRpZcgV3bA5ympLjJOKqLGzn0IoRP1rv2AJFVdd WBFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=Rzic+XnKRM9LZeoSUC8+yjIOgecNEcvf15/Dotvra/k=; b=BjJHS6CYsizu3GGADNbKvxkcK9RxaRo0YKTSYfPPP40NDUxEUjJy5Mn1b1sJGOiE5c SgzGMjaz+nl6CZQ7ftxnf/JQcvuFJCW3HMM6esD6a26RAbFsV7ioGlQBDZs1CtQKTfHS 6gne1IxhALIQaSe760aNEs2sTbFraAn1dVFckIYuiL8x3ZtWth8niEitzAfqQMfsDQx7 3YEq2+3jWMnbhO2w7jQlr7RtlpinEfkoBApsA4sDlsUyEqeGHxVGBBUrOMs9W1n2Qv/e AU/6/iXkgWIVxTNX+wcoJQx2ODVi7f2ht4uj91YUNpKEcbe7IYFLcUiayzo4SCE7bshJ vNag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1-v6si18988530plj.474.2018.07.10.10.03.50; Tue, 10 Jul 2018 10:04:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933366AbeGJQ4i (ORCPT + 99 others); Tue, 10 Jul 2018 12:56:38 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:17986 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754260AbeGJQ4g (ORCPT ); Tue, 10 Jul 2018 12:56:36 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Tue, 10 Jul 2018 09:55:53 -0700 Received: from HQMAIL105.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 10 Jul 2018 09:56:33 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 10 Jul 2018 09:56:33 -0700 Received: from [10.110.39.62] (10.110.39.62) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 10 Jul 2018 16:56:35 +0000 Subject: Re: [PATCH v2] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire To: Alan Stern , "Paul E. McKenney" CC: LKMM Maintainers -- Akira Yokosawa , Andrea Parri , Boqun Feng , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Peter Zijlstra , Will Deacon , Kernel development list References: From: Daniel Lustig Message-ID: Date: Tue, 10 Jul 2018 09:56:14 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [10.110.39.62] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL105.nvidia.com (172.20.187.12) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/9/2018 1:01 PM, Alan Stern wrote: > 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. > > Locks should also provide read-read (and read-write) ordering in a > similar way. Given: > > READ_ONCE(x); > spin_unlock(&s); > spin_lock(&s); > READ_ONCE(y); // or WRITE_ONCE(y, 1); > > the load of x should be executed before the load of (or store to) y. > The LKMM already provides this ordering, but it provides it even in > the case where the two accesses are separated by a release/acquire > pair of fences rather than unlock/lock. This would prevent > architectures from using weakly ordered implementations of release and > acquire, which seems like an unnecessary restriction. The patch > therefore removes the ordering requirement from the LKMM for that > case. > > All the architectures supported by the Linux kernel (including RISC-V) > do provide this ordering for locks, albeit for varying reasons. > Therefore this patch changes the model in accordance with the > developers' wishes. > > Signed-off-by: Alan Stern > > --- > > v.2: Restrict the ordering to lock operations, not general release > and acquire fences. > > [as1871b] > > > tools/memory-model/Documentation/explanation.txt | 186 +++++++--- > tools/memory-model/linux-kernel.cat | 8 > tools/memory-model/litmus-tests/ISA2+pooncelock+pooncelock+pombonce.litmus | 5 > 3 files changed, 149 insertions(+), 50 deletions(-) > > Index: usb-4.x/tools/memory-model/linux-kernel.cat > =================================================================== > --- usb-4.x.orig/tools/memory-model/linux-kernel.cat > +++ usb-4.x/tools/memory-model/linux-kernel.cat > @@ -38,7 +38,7 @@ let strong-fence = mb | gp > (* Release Acquire *) > let acq-po = [Acquire] ; po ; [M] > let po-rel = [M] ; po ; [Release] > -let rfi-rel-acq = [Release] ; rfi ; [Acquire] > +let unlock-rf-lock-po = [UL] ; rf ; [LKR] ; po It feels slightly weird that unlock-rf-lock-po is asymmetrical. And in fact, I think the current RISC-V solution we've been discussing (namely, putting a fence.tso instead of a fence rw,w in front of the release) may not even technically respect that particular sequence. The fence.tso solution really enforces "po; [UL]; rf; [LKR]", right? Does something like "po; [UL]; rf; [LKR]; po" fit in with the rest of the model? If so, maybe that solves the asymmetry and also legalizes the approach of putting fence.tso in front? Or, other suggestions? Dan > (**********************************) > (* Fundamental coherence ordering *) > @@ -60,13 +60,13 @@ let dep = addr | data > let rwdep = (dep | ctrl) ; [W] > let overwrite = co | fr > let to-w = rwdep | (overwrite & int) > -let to-r = addr | (dep ; rfi) | rfi-rel-acq > +let to-r = addr | (dep ; rfi) > let fence = strong-fence | wmb | po-rel | rmb | acq-po > -let ppo = to-r | to-w | fence > +let ppo = to-r | to-w | fence | (unlock-rf-lock-po & int) > > (* Propagation: Ordering from release operations and strong fences. *) > let A-cumul(r) = rfe? ; r > -let cumul-fence = A-cumul(strong-fence | po-rel) | wmb > +let cumul-fence = A-cumul(strong-fence | po-rel) | wmb | unlock-rf-lock-po > let prop = (overwrite & ext)? ; cumul-fence* ; rfe?