Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1599340imm; Thu, 12 Jul 2018 04:53:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc4XELIl4vB+jqGajVC2prXUz3c5oCwLxGx1q5yEySPKeQfGeFtZwKvzM99lDiphLafzCmd X-Received: by 2002:a62:ed13:: with SMTP id u19-v6mr2062776pfh.125.1531396436313; Thu, 12 Jul 2018 04:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531396436; cv=none; d=google.com; s=arc-20160816; b=uHsbYE7TlgXrYJLwA9A9yavDvKdB7S2Hf+70dXNOnyZ5F7Rm+QWZ+SDK2t9FtTQKsk nIjJC9zsCk1ODtXAYnS4aLDuWipHsSYSIF/ZXnckqAUOFf0rqeG2e8t2WNxDF6tIhLKb OaSe9ABl0My/zQjajoqIvHhvxY7pFdFkR5ZPzsu8ytKRqh1279UG2Xzal+pOSTLeB1U7 QNEiCRqOkHd70zo5aPvnJmGJnqWyKxPeiy7U6g1JfPmypTk9Kszr4Uj3HEi+jWEqJzwC uO51j7pfbPrzoRW3z0V1clawykTcmdy9vrlmswKz84iWwv96osdHKxCqBjxOp9WUVZ3K obrg== 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=a/LCUiEnX3uEaaMOSWLWUdYucXE4PfnTNPKNqrCl+pI=; b=p8WY525RLZf8744py2msFRO02kmJzH0bWoUqgTTCne9j5kks+8WpQ6SIV0FeX+8QgD Ey0ysM6qjeX3i+zgyYde0p77LLQZzoiuRXwcYFYZ9oHTnwmJKwpvlP5+jeMutESKv9co ZGAvHjE8O1QM3L0IwIZJIzQDRCJZrHnbQuO+MhkGlZh7fkf2HRYR/wq9kt6ugoEii92l X5yXf9jJNFZTzHGbtY8MGjqY6yEcZocik0IjHObp+IkCmmkWymXwn1ckWuL48lMhSJ+J 7u1E+UeKQshkJby/LF7ERSGRmjh8lxNR/XR5oU1wTJ+hp/ZTyojhCh4DCviMxfPu/ErW LplA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XlnsNY2X; 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 c1-v6si5365781pfe.29.2018.07.12.04.53.40; Thu, 12 Jul 2018 04:53:56 -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; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XlnsNY2X; 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 S1726935AbeGLMCL (ORCPT + 99 others); Thu, 12 Jul 2018 08:02:11 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36889 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbeGLMCK (ORCPT ); Thu, 12 Jul 2018 08:02:10 -0400 Received: by mail-wm0-f65.google.com with SMTP id n17-v6so5751075wmh.2 for ; Thu, 12 Jul 2018 04:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=a/LCUiEnX3uEaaMOSWLWUdYucXE4PfnTNPKNqrCl+pI=; b=XlnsNY2Xx69bgK7+JkIQuBZA3FEBGGGSSJkEPTxnu9nVR3hX7rXelP9whNDF5d5gNM t7WFjwjm0iJij6ZyAXVeG+wX1vx1N37MMa+MohPMwFVdG/KNeV22nO02WVzmlnP+Jqge rRyzu/9pWkBhsv15nC2mUe3z20aqr1e1MBijQ= 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=a/LCUiEnX3uEaaMOSWLWUdYucXE4PfnTNPKNqrCl+pI=; b=Ogg/WAzhDG5e4jXEV5RRbe7WQgwzYSqxjfrzHNHW7NkVKugnGfBkGlvOqGFkzJFo8y pywb0iW/fcZAOQ/ZzJzTfq3MYUygipmJCTKvwDblyQlLMuPibSO6aImy6ROQG9gzoD+b 2X4C1MYUIUKLlfg6RyyuyMGSO4q32VzPInhxxZuKEW7DLcrNcRj6zFHiPmyg1xHxaavt xfsuhV5chBrgv+dzlAzO6z1sEACPYygWQq5dXjC5Jybz2fd18pOoTS1/tCFyUro4dmbh gZZAN0tyggUrkoHw3RdhMgD4MzmhNStp49osuegdQphHwngQwWK3a1T58mM2sZ6GLKpm 5NxQ== X-Gm-Message-State: AOUpUlFajhWbgGOaFI/M64DrfrkBPMaZrBVAYs7eLXhdes6aZKCTfdfd zESiLh81Fizfza1OyVZw6LN/7A== X-Received: by 2002:a1c:1d4d:: with SMTP id d74-v6mr1229601wmd.85.1531396376394; Thu, 12 Jul 2018 04:52:56 -0700 (PDT) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id f18-v6sm23515113wrt.64.2018.07.12.04.52.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 04:52:55 -0700 (PDT) Date: Thu, 12 Jul 2018 13:52:49 +0200 From: Andrea Parri To: Peter Zijlstra Cc: Will Deacon , Alan Stern , "Paul E. McKenney" , LKMM Maintainers -- Akira Yokosawa , Boqun Feng , Daniel Lustig , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Kernel development list Subject: Re: [PATCH v2] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire Message-ID: <20180712115249.GA6201@andrea> References: <20180710093821.GA5414@andrea> <20180711094310.GA13963@arm.com> <20180711123421.GA9673@andrea> <20180712074040.GA4920@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180712074040.GA4920@worktop.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, Jul 12, 2018 at 09:40:40AM +0200, Peter Zijlstra wrote: > On Wed, Jul 11, 2018 at 02:34:21PM +0200, Andrea Parri wrote: > > Simplicity is the eye of the beholder. From my POV (LKMM maintainer), the > > simplest solution would be to get rid of rfi-rel-acq and unlock-rf-lock-po > > (or its analogous in v3) all together: > > > > > Among other things, this would immediately: > > > > 1) Enable RISC-V to use their .aq/.rl annotations _without_ having to > > "worry" about tso or release/acquire fences; IOW, this will permit > > a partial revert of: > > > > 0123f4d76ca6 ("riscv/spinlock: Strengthen implementations with fences") > > 5ce6c1f3535f ("riscv/atomic: Strengthen implementations with fences") > > But I feel this goes in the wrong direction. This weakens the effective > memory model, where I feel we should strengthen it. > > Currently PowerPC is the weakest here, and the above RISC-V changes > (reverts) would make RISC-V weaker still. > > Any any effective weakening makes me very uncomfortable -- who knows > what will come apart this time. This memory ordering stuff causes > horrible subtle bugs at best. Indeed, what I was suggesting above is a weaking of the current model (and I agree: I wouldn't say that bugs in this context are nice ;-). These changes would affect a specific area: (IMO,) the examples we've been considering here aren't for the faint-hearted ;-) and as Daniel already suggested, everything would again be "nice and neat", if this was all about locking/if every thread used lock-synchronization. > > > 2) Resolve the above mentioned controversy (the inconsistency between > > - locking operations and atomic RMWs on one side, and their actual > > implementation in generic code on the other), thus enabling the use > > of LKMM _and_ its tools for the analysis/reviewing of the latter. > > This is a good point; so lets see if there is something we can do to > strengthen the model so it all works again. > > And I think if we raise atomic*_acquire() to require TSO (but ideally > raise it to RCsc) we're there. > > The TSO archs have RCpc load-acquire and store-release, but fully > ordered atomics. Most of the other archs have smp_mb() everything, with > the exception of PPC, ARM64 and now RISC-V. > > PPC has the RCpc TSO fence LWSYNC, ARM64 has the RCsc > load-acquire/store-release. And RISC-V has a gazillion of options IIRC. > > > So ideally atomic*_acquire() + smp_store_release() will be RCsc, and is > with the notable exception of PPC, and ideally RISC-V would be RCsc > here. But at the very least it should not be weaker than PPC. > > By increasing atomic*_acquire() to TSO we also immediately get the > proposed: > > P0() > { > WRITE_ONCE(X, 1); > spin_unlock(&s); > spin_lock(&s); > WRITE_ONCE(Y, 1); > } > > P1() > { > r1 = READ_ONCE(Y); > smp_rmb(); > r2 = READ_ONCE(X); > } > > behaviour under discussion; because the spin_lock() will imply the TSO > ordering. You mean: "when paired with a po-earlier release to the same memory location", right? I am afraid that neither arm64 nor riscv current implementations would ensure "(r1 == 1 && r2 == 0) forbidden" if we removed the po-earlier spin_unlock()... AFAICT, the current implementation would work with that release: as you remarked above, arm64 release->acquire is SC; riscv has an rw,w fence in its spin_unlock() (hence an w,w fence between the stores), or it could have a .tso fence ... But again, these are stuble patterns, and my guess is that several/ most kernel developers really won't care about such guarantees (and if some will do, they'll have the tools to figure out what they can actually rely on ...) OTOH (as I pointed out earlier) the strengthening we're configuring will prevent some arch. (riscv being just the example of today!) to go "full RCsc", and this will inevitably "complicate" both the LKMM and the reviewing process of related changes (atomics, locking, ...; c.f., this debate), apparently, just because you ;-) want to "care" about these guarantees. Not yet convinced ... :/ Andrea > > And note that this retains regular RCpc ACQUIRE for smp_load_acquire() > and associated primitives -- as they have had since their introduction > not too long ago.