Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp704528imm; Fri, 31 Aug 2018 10:57:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbzHqVOVHs5JOztf8wnx0DWnwKrG7hKlkN5bymbHMeIaNItJ2v0oDqaxC2zPXuUMTzhsiiZ X-Received: by 2002:a62:e008:: with SMTP id f8-v6mr17115374pfh.208.1535738259944; Fri, 31 Aug 2018 10:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535738259; cv=none; d=google.com; s=arc-20160816; b=iPqPbP+ovuNHkeA7MVaAG/LtzG4JI0BxlKzGzMMpDav5gvlnKuR0wetvgXdRVqcqGR c9OA9KkPAGqmNSIhq+25TCTZdY/lMIAPHRoXjqK0ZJ5RIfOj9vdcYbvvask+phdnn9Vs A6gPIYEWAEJgLSygGtLQ3FxFjE/s+WAj/iyA3+Q4On8gzXoXn6cVYXjqw2OYRj+EIwB1 RdQhaNiDdLmnNnDGciYkKbkmxqgp85hpjPoBtCEBcq0IWhORmRxVAdUontY1rdlXVTBO zPU8thUyzbVrnrje0MmCUV6k/4LykaUREsGCiDk336spLyFLhpBMjphuyy9RDx8GU7Ux VhwQ== 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=l9+UeNtS7la9WoqV1GxEFoPXF/KlYJquyqTSE1HhhRg=; b=WlqjCccmbwgfV4lJ0l8T55RsI32YtCYcQbxGa9ZhMxdGFQQ1Ww7/cVm5CT0hHvNq4o nJPjXDBVRpMbjAYGNgz2WNzb38L6NMFrYf5Ljl52QJ+iny6o9GmOxaVI+OORmgmLocjE fwuvEnOjfRTgqUu8hXq/GgqLUfs4DvgZO+DOdG+STQDFHFzfJ9Mfj1iVmLKR3opmbCve LTm7GhZzn3ylOE6MzAMzMwCZZWj3W1XY3ASVqv05JY6Oalfws0CV5QLKHFJLAPaXPntn kJT52hMUHObhr946EwpYnCzkYfQ64YvgADlUXPSVqpxc+cNCqEbw8Ip/WqHoJ/7raSGU 0fFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Eu2nNt19; 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 a18-v6si9948542pfn.317.2018.08.31.10.57.24; Fri, 31 Aug 2018 10:57:39 -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=Eu2nNt19; 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 S1727352AbeHaWED (ORCPT + 99 others); Fri, 31 Aug 2018 18:04:03 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:38136 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbeHaWEC (ORCPT ); Fri, 31 Aug 2018 18:04:02 -0400 Received: by mail-wm0-f67.google.com with SMTP id t25-v6so6101798wmi.3 for ; Fri, 31 Aug 2018 10:55:25 -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=l9+UeNtS7la9WoqV1GxEFoPXF/KlYJquyqTSE1HhhRg=; b=Eu2nNt19eWRZP35klLM0iSYNHLvhE7zOeuCba6zNSNRBd+5XcENjGMWpE7bDFruqG/ r450maY9AOCaMvxhNW9tazqfXqZ8xIOi9d4DaqrzOSDBeg5KozJvan+Z5ZdHFiV6zpjA GtWPiO0chX5wtKKk8tT3WKLN5KkDEygAwIw24= 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=l9+UeNtS7la9WoqV1GxEFoPXF/KlYJquyqTSE1HhhRg=; b=mQds2UMphY9qHYx8XV7O2yXveO18wfX+Kw2MLgJ9BIDmA81h+GwPf2Fx3gUgUQG1m0 M3KZsjD/aXuxDuAgULgRc3xh5opAliLGAL5uyiyCIyc8VAzcjgJklz0QfQGVpds3U1I7 jRynQo+n1o/c0Sj4aAFSIn3CkNyN7ju9K0hfXGnR4nlM+hRhY23jvVZGHDbIpig2ZCkN aziehZCaiQQsTopn+ic+wItj5vm/R/RX5X4KD7K7onT9THCOtTRrFIwzJxObKzuph5GP Qr2vyXNlE+p2SnR7Vtv4ZXTK9QNe2UC5qJYPaWyDbGGDGAPdnESU9uAXqLK5LOtAet/q TG+A== X-Gm-Message-State: APzg51Cl81boOsxutBhzYqhpzeYNB01JRA2qUotrRIwBhLv1bD8y+pou y9EcB/ScDRUTpxBKyy4xZGRmZg== X-Received: by 2002:a1c:ae94:: with SMTP id x142-v6mr5749528wme.125.1535738125215; Fri, 31 Aug 2018 10:55:25 -0700 (PDT) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id e141-v6sm6173716wmd.32.2018.08.31.10.55.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 10:55:24 -0700 (PDT) Date: Fri, 31 Aug 2018 19:55:12 +0200 From: Andrea Parri To: Alan Stern Cc: Andrea Parri , "Paul E. McKenney" , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, mingo@kernel.org, will.deacon@arm.com, peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com Subject: Re: [PATCH RFC LKMM 1/7] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire Message-ID: <20180831175512.GA3121@andrea> References: <20180831091641.GA3634@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 10:52:54AM -0400, Alan Stern wrote: > On Fri, 31 Aug 2018, Andrea Parri wrote: > > > On Thu, Aug 30, 2018 at 05:31:32PM -0400, Alan Stern wrote: > > > On Thu, 30 Aug 2018, Andrea Parri wrote: > > > > > > > > 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 > > > > > Signed-off-by: Paul E. McKenney > > > > > Reviewed-by: Will Deacon > > > > > Acked-by: Peter Zijlstra (Intel) > > > > > > > > Round 2 ;-), I guess... Let me start from the uncontroversial points: > > > > > > > > 1) being able to use the LKMM to reason about generic locking code > > > > is useful and desirable (paraphrasing Peter in [1]); > > > > > > > > 2) strengthening the ordering requirements of such code isn't going > > > > to boost performance (that's "real maths"). > > > > > > > > This patch is taking (1) away from us and it is formalizing (2), with > > > > almost _no_ reason (no reason at all, if we stick to the commit msg.). > > > > > > That's not quite fair. Generic code isn't always universally > > > applicable; some of it is opt-in -- meant only for the architectures > > > that can support it. In general, the LKMM allows us to reason about > > > higher abstractions (such as locking) at a higher level, without > > > necessarily being able to verify the architecture-specific details of > > > the implementations. > > > > No, generic code is "universally applicable" by definition; see below > > for more on this point. > > Then perhaps we should be talking about "partially generic" code; i.e., > code that applies to many but not all architectures. Perhaps. I call this "non-generic". ;-) > > > > > In [2], Will wrote: > > > > > > > > "[...] having them [the RMWs] closer to RCsc[/to the semantics of > > > > locks] would make it easier to implement and reason about generic > > > > locking implementations (i.e. reduce the number of special ordering > > > > cases and/or magic barrier macros)" > > > > > > > > "magic barrier macros" as in "mmh, if we accept this patch, we _should_ > > > > be auditing the various implementations/code to decide where to place a > > > > > > > > smp_barrier_promote_ordinary_release_acquire_to_unlock_lock()" ;-) > > > > > > > > or the like, and "special ordering cases" as in "arrgh, (otherwise) we > > > > are forced to reason on a per-arch basis while looking at generic code". > > > > > > Currently the LKMM does not permit architecture-specific reasoning. It > > > would have to be extended (in a different way for each architecture) > > > first. > > > > Completely agreed; that's why I said that this patch is detrimental to > > the applicability of the LKMM... > > This ignores the attitude of the kernel developers who want locking to > have the stronger RCtso semantics. From their point of view, the patch > enhances the LKMM's applicability. Please stop. We spent weeks discussing how to make such a transition properly, and I suggested ways to do this above and in other threads. (Again, your commit message says nothing about that "enhancement"...) > > > > For example, one could use herd's POWER model combined with the POWER > > > compilation scheme and the POWER-specific implementation of spinlocks > > > for such reasoning. The LKMM alone is not sufficient. > > > > > > Sure, programming and reasoning about the kernel would be easier if all > > > architectures were the same. Unfortunately, we (and the kernel) have > > > to live in the real world. > > > > > > > (Remark: ordinary release/acquire are building blocks for code such as > > > > qspinlock, (q)rwlock, mutex, rwsem, ... and what else??). > > > > > > But are these building blocks used the same way for all architectures? > > > > The more, the better! (because then we have the LKMM tools) > > > > We already discussed the "fast path" example: the fast paths of the > > above all resemble: > > > > *_lock(s): atomic_cmpxchg_acquire(&s->val, UNLOCKED_VAL, LOCKED_VAL) ... > > *_unlock(s): ... atomic_set_release(&s->val, UNLOCKED_VAL) > > > > When I read this code, I think "Of course." (unless some arch. has > > messed the implementation of cmpxchg_* up, which can happen...); but > > then I read the subject line of this patch and I think "Wait, what?". > > > > You can argue that this is not generic code, sure; but why on Earth > > would you like to do so?! > > Because the code might not work! On RISC-V, for example, the > implementation of ordinary release/acquire is currently not as strong > as atomic release/acquire. No doubt it "might not work". ;-) Concerning the RISC-V implementation, I almost (re)did that, so at least you know who to blame if what you are saying turned out to be correct. > > Yes, it's true that implementing locks with atomic_cmpxchg_acquire > should be correct on all existing architectures. And Paul has invited > a patch to modify the LKMM accordingly. If you feel that such a change > would be a useful enhancement to the LKMM's applicability, please write > it. Hey, it's your patch that is introducing concerns! "my patch" would partially _but_ substantially revert yours (see earlier discussions): I'm still hoping that we'll be able to find an agreement... Andrea > > Alan >