Received: by 10.223.185.116 with SMTP id b49csp1970855wrg; Thu, 22 Feb 2018 06:14:35 -0800 (PST) X-Google-Smtp-Source: AH8x226l2z2pzNCONyM8n1Gsgzw9j+YZ3UCFoBhcq19kNj89TT5lMfRLniLKfJeJPplbiNbTitzM X-Received: by 2002:a17:902:694c:: with SMTP id k12-v6mr6591047plt.133.1519308875263; Thu, 22 Feb 2018 06:14:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519308875; cv=none; d=google.com; s=arc-20160816; b=REDK6+lkFF/mWhtrfEN5o4RGlA/BovPok4L40ExSKIghsl3tdm7qB9TMQ1BZrJ8noi YVTedwVlnY0WfVx2H6DqVOpjrZotQO8/jLqIjtwNNsf4EY7nMtdkp6n18xYie+Mr+f/3 dAvPHHtkxFmZiCNiLEz4R2VS0yXkYwtQeyYYMdu46RmsNgC89ZW7UXqKfT7xiKnSABES CogIFdlo3oSsf3Rk1SepGqnClpAHu+V6FNeXxUGONVCu6cQEwGcUSe2199b68YuXruM/ F6JStuXGROjKFwCfOvb6wO461TeW5tfapE0XWgOoAwGcOaRCq4PKSG6LhTxxqezTXYA4 yv7w== 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=x3n0fb2FxQzktWNZA68Ut1Nj1jRWegVwoEd3oYnOE3Y=; b=VPMNENSZ4hZEztKkrvFuJJdXLc9Phvh5cgJlC9BFnUV4PLqA0jxTbcHagLD9/hTOrj TScpysxLxjhJuJlXWMgE9VHCy/oOSaPOxGMKK7ZVcIAYkQpPbmFjGiwlpv+2XSeu0Qcg kMmsf2fQ2xkDYyEuk2VnZnBm+F9lr7Ox9GHyB0yNVCl/afdg6NpcuOWfUqwRl8Up4FEz SiCowvssPis4FztNGABGVq6E7G8sl+/Z/Vr1ApHtWWswYPYOkaYyrUOez0jZ89tXmKwJ eFvkiRyJalc8je3rNxRBRO/rhBhn+dZswbugouT4Kwb79Zc4ZpNQZOJ7oAJCr8kg67nX Fj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mnUBKB+V; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si117790pfj.61.2018.02.22.06.14.20; Thu, 22 Feb 2018 06:14:35 -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=pass header.i=@gmail.com header.s=20161025 header.b=mnUBKB+V; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932784AbeBVOM7 (ORCPT + 99 others); Thu, 22 Feb 2018 09:12:59 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:40080 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932664AbeBVOM5 (ORCPT ); Thu, 22 Feb 2018 09:12:57 -0500 Received: by mail-wm0-f66.google.com with SMTP id t82so3851789wmt.5 for ; Thu, 22 Feb 2018 06:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=x3n0fb2FxQzktWNZA68Ut1Nj1jRWegVwoEd3oYnOE3Y=; b=mnUBKB+VxiRvZn4s4LYU72exZtop7j7JntSP5W7LCjt30BT30K+SE9ZBTQFuJBKzNs vc+kigovF++XyMkcOA1NWAwMxdbCpiQZwVvHcGRg5L3evtnfDNHlknxbE4O7s5lE/fBg 3Jid2cxEczhL7NV1Eg6DloK7fg3OKYwCXjeFGoYIaSF9n5Yx4CzZyVkgy/6HalD/DpWR 8GdTaH/j48EYMl+Ss6d6bsnDkfIU4eRFugfu7cda7LQYYlwMxchnCbGaMGuWQYTNVQky kScEY5gHdWsIEVzUUZT45R92MjnJruwomNQKUjKatPMM1OA9TxGFM+PK07sgX3+c7Lgd 7MUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=x3n0fb2FxQzktWNZA68Ut1Nj1jRWegVwoEd3oYnOE3Y=; b=P/EX4WjPygb/ECcbNspwp6ptO6skZ1IXbk7V0QhJ5lc1FSb2dTqDlKpi5grZ/r3JQK 89vx7iftetkV+065m64dppalnCi4FLL2UBFyT1bDVgeVvX5Sqk2KXNZIF4RX5vu1ObMX nOvUw5br6g131kkZwL665WoF6xORx9ehEjd9dnP7rwma8iwizywv7kBSrzXrcv2uiFgM t2yrUZE12Fk0hIrtM8xwB2HLpblx5w5E4BdD2KWvQFKOFSxdJDMohWEA0HvlFqsQf96H 8Z8CDrCGu9Hzid0ZwDk+v5f582WbretJGTFcq0yTAOGM2OKre/n4d1jl180edayGwzWO 0LoA== X-Gm-Message-State: APf1xPA5pSO6zigYxyK9KTvcR8q/itihTRzqM5l7l4HSJvn52KT0+Ymt wRLZxP876Yh7Z3yNzmtyLQ4= X-Received: by 10.80.146.248 with SMTP id l53mr9448110eda.125.1519308775728; Thu, 22 Feb 2018 06:12:55 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id k9sm320735edh.34.2018.02.22.06.12.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 06:12:55 -0800 (PST) Date: Thu, 22 Feb 2018 15:12:49 +0100 From: Andrea Parri To: Peter Zijlstra 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: <20180222141249.GA14033@andrea> References: <1519301990-11766-1-git-send-email-parri.andrea@gmail.com> <20180222134004.GN25181@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180222134004.GN25181@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) 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 02:40:04PM +0100, Peter Zijlstra wrote: > 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? As mentioned in IRC, my understanding here is only based on the spec. referred below and on its (available) formalizations. I expect that RISC-V people will be able to provide more information. > > > 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. You're right: AFAICT, this can be remedied by inserting "beq x0,x5,FAIL00" right after amoswap.w.aq (and this label at the end of P0); this does not change the verdict of the available formalizations reported above however. (So, AFAICT, the above question remains valid/open.) Andrea > > (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. >