Received: by 10.223.185.116 with SMTP id b49csp1935075wrg; Thu, 22 Feb 2018 05:41:27 -0800 (PST) X-Google-Smtp-Source: AH8x225mNZeJ53XCIilqnt8O71Sq+5KNng3MxxCiYTty76NBfWGL72tLI79O2Y4Wxj9eAgUAuHXL X-Received: by 2002:a17:902:7485:: with SMTP id h5-v6mr6785180pll.236.1519306886927; Thu, 22 Feb 2018 05:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519306886; cv=none; d=google.com; s=arc-20160816; b=nqEczweIoKmhuB238D2gpf4J5KSjI/kNcRDcN63zH//2gETvU0R2rJvHXONiuUg75M Ue/3AVGYrt59a4CQgvu/NTEJlV7/TVKSAKd7KEUkX1vbU5o3cgOjuCFwYggNl05bW+cz lRmlthDcI4PWjVH6y3EGjKu+bYnCkMYBYZec9AGvgjcb8g9mIKJBBaXEUSFnFg5a3EH5 XcgRBnIBmxaRf7V+8z8WVeizLArnEcrlVtXzWzkfK6npd4xd+vm6bLuklT+fKfOcyZ8u Oeb7OGEWqQCIpRQ6K/0xCDp2dopXesDc/I9LvbRUfBTtW6DE3hSr6PqgVdAyFMT7chkw /R1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=74X91CWYyE1iekJz/WWZDA5876wTk2PgqeA98MM+9O8=; b=lyGZakrtCF+piioBs/grIlPFcWQVOXxweqzFvBS+l15zDi6UxDnl5LxZrZx15lEPlQ h55xIrRRdVNpQVuwJucx/ZS+KtsgYnoo2jv5NQ7pbByEVzCximF7gvrLj0iFMwoMzV25 IAg/BRFUtIDEC6GXFn96EZSYlO7UFiRjcKGv+mWVjNIBYwdYJiXTi9N5Jefan2iEAFln JjnBwbJpd+ORJFeeiRPC/d6/Btot08tscxEAGoOn/kHmsO4usarU4+8HFHywy/NDkMUs RhdDGmQ0x7cIvh9DOpnGZYHYCJyA55mDnBQoE3gCbD/VeTJeN6Ei9vatR8YLH9g66TNN HXfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=RANqMHYD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si26005pgp.788.2018.02.22.05.41.12; Thu, 22 Feb 2018 05:41:26 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=RANqMHYD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932591AbeBVNk2 (ORCPT + 99 others); Thu, 22 Feb 2018 08:40:28 -0500 Received: from merlin.infradead.org ([205.233.59.134]:52288 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932414AbeBVNk0 (ORCPT ); Thu, 22 Feb 2018 08:40:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; 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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=74X91CWYyE1iekJz/WWZDA5876wTk2PgqeA98MM+9O8=; b=RANqMHYDeOr75GA685cNFOP4x /mfNUpg9KgGWYkkEEyYGE5zUe8dAxMa+ZGvTuNU9s2cpmqmt9DlSGokSq723iq5ZxPaShUZFUa09C /vTtcZSZnx1PlkQ0ErTnEwn60dqHW1+i2fuDPcSIGNlTIac0w5+kgXipeGtJ2kyvGgk4mgqs1JfZm KJfiL0oqRmockMiymRB9LN9m24mKVLZkTGs2xRHZhT75Y3Hx+oAb+3a3827UuY31n8Ov8C11uxYsB xfQX6i8YArBKqvg+7laLzARkYWaMyicrmqvcbTOL4+wjVBDXEhm3reMtQMVVJj/gps9wIc9NvnBRE JMOdbGDaQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eor6V-0004u2-MA; Thu, 22 Feb 2018 13:40:08 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 58D372029F9F9; Thu, 22 Feb 2018 14:40:04 +0100 (CET) Date: Thu, 22 Feb 2018 14:40:04 +0100 From: Peter Zijlstra To: Andrea Parri Cc: linux-kernel@vger.kernel.org, Palmer Dabbelt , Albert Ou , Daniel Lustig , Alan Stern , Will Deacon , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Ingo Molnar , Linus Torvalds , linux-riscv@lists.infradead.org Subject: Re: [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock() Message-ID: <20180222134004.GN25181@hirez.programming.kicks-ass.net> References: <1519301990-11766-1-git-send-email-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1519301990-11766-1-git-send-email-parri.andrea@gmail.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 22, 2018 at 01:19:50PM +0100, Andrea Parri wrote: > C unlock-lock-read-ordering > > {} > /* s initially owned by P1 */ > > P0(int *x, int *y) > { > WRITE_ONCE(*x, 1); > smp_wmb(); > WRITE_ONCE(*y, 1); > } > > P1(int *x, int *y, spinlock_t *s) > { > int r0; > int r1; > > r0 = READ_ONCE(*y); > spin_unlock(s); > spin_lock(s); > r1 = READ_ONCE(*y); > } > > exists (1:r0=1 /\ 1:r1=0) > > RISCV RISCV-unlock-lock-read-ordering > { > 0:x2=x; 0:x4=y; > 1:x2=y; 1:x4=x; 1:x6=s; > s=1; > } > P0 | P1 ; > ori x1,x0,1 | lw x1,0(x2) ; > sw x1,0(x2) | amoswap.w.rl x0,x0,(x6) ; > fence w,w | ori x5,x0,1 ; > ori x3,x0,1 | amoswap.w.aq x0,x5,(x6) ; > sw x3,0(x4) | lw x3,0(x4) ; > exists > (1:x1=1 /\ 1:x3=0) So I would indeed expect this to be forbidden. Could someone please explain how this could be allowed? > C unlock-lock-write-ordering > > {} > /* s initially owned by P0 */ > > P0(int *x, int *y, spinlock_t *s) > { > WRITE_ONCE(*x, 1); > spin_unlock(s); > spin_lock(s); > WRITE_ONCE(*y, 1); > } > > P1(int *x, int *y) > { > int r0; > int r1; > > r0 = READ_ONCE(*y); > smp_rmb(); > r1 = READ_ONCE(*y); > } > > exists (1:r0=1 /\ 1:r1=0) > > RISCV RISCV-unlock-lock-write-ordering > { > 0:x2=x; 0:x4=y; 0:x6=s; > 1:x2=y; 1:x4=x; > s=1; > } > P0 | P1 ; > ori x1,x0,1 | lw x1,0(x2) ; > sw x1,0(x2) | fence r,r ; > amoswap.w.rl x0,x0,(x6) | lw x3,0(x4) ; > ori x5,x0,1 | ; > amoswap.w.aq x0,x5,(x6) | ; > ori x3,x0,1 | ; > sw x3,0(x4) | ; > exists > (1:x1=1 /\ 1:x3=0) And here I think the RISCV conversion is flawed, there should be a ctrl dependency. The second store-word in P0 should depend on the result of amoswap.w.aq being 0. (strictly speaking there should be a ctrl-dep in the read example too, except it'd be pointless for ordering reads, so I accept it being left out) Again, I cannot see how this could be allowed.