Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp878140imm; Mon, 9 Jul 2018 12:20:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcIrm4sDvXUpwjEJAt1dV4UU5GQwI9P03Mceix13yvb+FURlIhofe7p/kxpIwDHgtqspNin X-Received: by 2002:a62:fd06:: with SMTP id p6-v6mr22159156pfh.167.1531164016391; Mon, 09 Jul 2018 12:20:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531164016; cv=none; d=google.com; s=arc-20160816; b=LJhrsnoOFd2BUmvTH4hJfFbMO6DFWFTYwy+6JDu4K4x430EG/U5HubeGN8VUC9guhz NcVziYJiOwpbRaWvz/d35Kd4XrCVIMn2Z47FEG1VUU7S0SCSDBdxWIdmtl/f23DlL4Qf fl3IygLkLpOkL48Io5O+kf+J/F9q/PyxCMic1Q9w9W61POkkzn9ezv/xF0wY7YfNuMZb aq8vKs2tMxWc6uHrjFOmSN9g76Rw39uSvMPmDmbW8vtHGAS5ZMWzFGwLr+EM8+lDA2yw ZKUkaa8HzjLuVc+yAbXwHHhmELdGWwEtoF2kRdvNOa1Os8IKw++zFS2j/Ih+sRNRQlZx JItQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date:arc-authentication-results; bh=oUzV2xv/1kbbUZAi7jtGha+0uRvh6cH+dnTMJIfu89o=; b=QX8VxgnKt1tbHpgXlEfIhYSXNIC/eZ9M45i1qIjp318WvFJgI/r01WUDTzAenak8ri iru01+QhhU2n5nyEtDYogJYF/v+GEc8Ft8vo8KaY+Vs2cyG+jM6ikFgzXGto0ylQlGto NeFLk5KFXAI3i3jKgRhcdUhcrwKNT0D9hlzfPZ3WPu+ebkmZJeOTGrVDdV/j2Ls7aBMX 94XxUg1SQ5yIP0ZHWZ2+Ht22jWyFiacPp+DO2B4jUSWq/n5Wjs7h23yLlBUSFDL1B2a3 Df/vtFvNeB0vBPLhmN/ZvnRIIVDvtAPXcsTKA5PrIjK5YU3PtVSlxvGjfL/pBRoZ/N+g sMhQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd5-v6si15562421plb.174.2018.07.09.12.20.01; Mon, 09 Jul 2018 12:20:16 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754657AbeGITSw (ORCPT + 99 others); Mon, 9 Jul 2018 15:18:52 -0400 Received: from iolanthe.rowland.org ([192.131.102.54]:54898 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754516AbeGITSv (ORCPT ); Mon, 9 Jul 2018 15:18:51 -0400 Received: (qmail 9862 invoked by uid 2102); 9 Jul 2018 15:18:50 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 9 Jul 2018 15:18:50 -0400 Date: Mon, 9 Jul 2018 15:18:50 -0400 (EDT) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Daniel Lustig cc: Will Deacon , "Paul E. McKenney" , Andrea Parri , LKMM Maintainers -- Akira Yokosawa , Boqun Feng , David Howells , Jade Alglave , Luc Maranget , Nicholas Piggin , Peter Zijlstra , Kernel development list Subject: Re: [PATCH 2/2] tools/memory-model: Add write ordering by release-acquire and by locks In-Reply-To: <01c35480-e207-c916-078b-de53df0e2645@nvidia.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 9 Jul 2018, Daniel Lustig wrote: > On 7/9/2018 9:52 AM, Will Deacon wrote: > > On Fri, Jul 06, 2018 at 02:10:55PM -0700, Paul E. McKenney wrote: > >> On Fri, Jul 06, 2018 at 04:37:21PM -0400, Alan Stern wrote: > >>> On Thu, 5 Jul 2018, Andrea Parri wrote: > >>> > >>>>> At any rate, it looks like instead of strengthening the relation, I > >>>>> should write a patch that removes it entirely. I also will add new, > >>>>> stronger relations for use with locking, essentially making spin_lock > >>>>> and spin_unlock be RCsc. > >>>> > >>>> Thank you. > >>>> > >>>> Ah let me put this forward: please keep an eye on the (generic) > >>>> > >>>> queued_spin_lock() > >>>> queued_spin_unlock() > >>>> > >>>> (just to point out an example). Their implementation (in part., > >>>> the fast-path) suggests that if we will stick to RCsc lock then > >>>> we should also stick to RCsc acq. load from RMW and rel. store. > > Just to be clear, this is "RCsc with W->R exception" again, right? Yes. I don't think any of these suggested names are really appropriate. (For instance, if I understood the original paper correctly, the "sc" in "RCsc" refers to the ordering properties of the acquire and release accesses themselves, not the accesses they protect.) I'm going to avoid using them. > >>> A very good point. The implementation of those routines uses > >>> atomic_cmpxchg_acquire() to acquire the lock. Unless this is > >>> implemented with an operation or fence that provides write-write > >>> ordering (in conjunction with a suitable release), qspinlocks won't > >>> have the ordering properties that we want. > >>> > >>> I'm going to assume that the release operations used for unlocking > >>> don't need to have any extra properties; only the lock-acquire > >>> operations need to be special (i.e., stronger than a normal > >>> smp_load_acquire). This suggests that atomic RMW functions with acquire > >>> semantics should also use this stronger form of acquire. > > It's not clear to me that the burden of enforcing "RCsc with W->R > ordering" should always be placed only on the acquire half. > RISC-V currently places some of the burden on the release half, as > we discussed last week. Specifically, there are a few cases where > fence.tso is used instead of fence rw,w on the release side. > > If we always use fence.tso here, following the current recommendation, > we'll still be fine. If LKMM introduces an RCpc vs. RCsc distinction > of some kind, though, I think we would want to distinguish the two > types of release accordingly as well. I wasn't talking about the burden in the implementation, just the modification to the memory model. In practice it shouldn't matter because real code should never intermix the two kinds of fences. That is, nobody will call smp_store_release() or cmpxchg_acquire() with an argument of type spinlock_t *, and nobody will call spin_unlock() with an argument that isn't of type spinlock_t *. > >>> Does anybody have a different suggestion? > >> > >> The approach you suggest makes sense to me. Will, Peter, Daniel, any > >> reasons why this approach would be a problem for you guys? > > > > qspinlock is very much opt-in per arch, so we can simply require that > > an architecture must have RCsc RmW atomics if they want to use qspinlock. > > Should an architecture arise where that isn't the case, then we could > > consider an arch hook in the qspinlock code, but I don't think we have > > to solve that yet. > > > > Will > > This sounds reasonable to me. Okay, I'll arrange the patch so that the new requirements apply only to lock and unlock accesses, not to RMW accesses in general. Alan