Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp116909imm; Fri, 13 Jul 2018 18:53:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdnBO1vo1auYG/t0kcQIZkD/C/K4gHpQyxxVMiW5PcIc6wFIUiG5YkXW4FqSABJ40Z+Koz2 X-Received: by 2002:a17:902:1127:: with SMTP id d36-v6mr8657065pla.267.1531533211607; Fri, 13 Jul 2018 18:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531533211; cv=none; d=google.com; s=arc-20160816; b=tN8qjxAhzKzIV5sNiJ4Gb55YL8hxxPsflMpwu0c2VMCym22faprqf3WNukJUmMmBKo w+y7XjSaB4gaDAkIGpLvQHA7VMJyYnFgnE/4uSxQawvZ2FnF9rm+LvblCEw8b87fU00U b8ui702c9UAp38iT4ngCqrAPirD2WiSG8GJ/DJqNyD+QdjhL5iBpngQO9M20eLqfhq9Z hkz4S1LSEiHEYYSV6skVVA5wrgHVP51liBUGxB0T+LxyZie2hGUxSX136h1XpwXr04SV iilgU1NlhMT3Kb9E976d3oK/0DXH5m+rT+3UrTX4np50p3GZoprs3ckKqHh9WCCaBqlm +QvQ== 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=wpQdo7VAq3FsrRJyCrFEL2fhuOS4oHqlnyPfLsmfJ/I=; b=hx9JskQl7GL74iAHXPT7ChE4/Cthnoze1jQCV+vPYRTsWCYgw09DnU39ByJV3uhXMc RkavpGVQXTDXBI1I819QIaryrIYurW/XeLwBeAJJzvgYbt2NnTSfnFHyU3jO+te/phK6 yLERxq4TC7UAXp2YLGvHs91NVIEGUe6ibc7qJeKA7I/PmD3xkiKVIqFqYCjxDRe+MmwP wTFdWv+xZc546DRGLpQ27qa0smCya3az/qIzLWjhiD3dW/OCaHWURzZsXH4ZVsLE5UNh OJ98CHvHUwVeuccqjS8Fs4sqXGu7T1TlkT8F+8M3p5JFIoThRDz1ajjydEf3NScxpbs3 vADQ== 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 b24-v6si21404228pff.192.2018.07.13.18.53.16; Fri, 13 Jul 2018 18:53:31 -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 S1731968AbeGNCIl (ORCPT + 99 others); Fri, 13 Jul 2018 22:08:41 -0400 Received: from netrider.rowland.org ([192.131.102.5]:35965 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1729771AbeGNCIl (ORCPT ); Fri, 13 Jul 2018 22:08:41 -0400 Received: (qmail 27370 invoked by uid 500); 13 Jul 2018 21:51:29 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 13 Jul 2018 21:51:29 -0400 Date: Fri, 13 Jul 2018 21:51:29 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Andrea Parri cc: Linus Torvalds , Will Deacon , Daniel Lustig , Peter Zijlstra , Paul McKenney , Akira Yokosawa , Boqun Feng , David Howells , Jade Alglave , Luc Maranget , Nick Piggin , Linux Kernel Mailing List Subject: Re: [PATCH v2] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire In-Reply-To: <20180713190638.GA4269@andrea> 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 Fri, 13 Jul 2018, Andrea Parri wrote: > On Fri, Jul 13, 2018 at 10:16:48AM -0700, Linus Torvalds wrote: > > On Fri, Jul 13, 2018 at 2:34 AM Will Deacon wrote: > > > > > > And, since we're stating preferences, I'll reiterate my preference towards: > > > > > > * RCsc unlock/lock > > > * RCpc release/acquire > > > > Yes, I think this would be best. We *used* to have pretty heavy-weight > > locking rules for various reasons, and we relaxed them for reasons > > that weren't perhaps always the right ones. > > > > Locking is pretty heavy-weight in general, and meant to be the "I > > don't really have to think about this very much" option. Then not > > being serializing enough to confuse people when it allows odd behavior > > (on _some_ architectures) does not sound like a great idea. > > > > In contrast, when you do release/acquire or any of the other "I know > > what I'm doing" things, I think we want the minimal serialization > > implied by the very specialized op. > > The changes under discussion are _not_ affecting uses such as: > > P0: > spin_lock(s); > UPDATE data_struct > spin_unlock(s); > > P1: > spin_lock(s); > UPDATE data_struct > spin_unlock(s); > > [...] > > (most common use case for locking?): these uses work just _fine_ with > the current implementations and in LKMM. > > OTOH, these changes are going to affect uses where threads interact by > "mixing" locking and _other_ synchronization primitives such as in: > > { x = 0; y = 0; } > > P0: > spin_lock(s); > WRITE_ONCE(x, 1); > spin_unlock(s); > > P1: > spin_lock(s); > r0 = READ_ONCE(x); > WRITE_ONCE(y, 1); > spin_unlock(s); > > P2: > r1 = smp_load_acquire(&y); > r2 = READ_ONCE(x); > > BUG_ON(r0 == 1 && r1 == 1 && r2 == 0) > > and > > { x = 0; y = 0; z = 0; } > > P0: > spin_lock(s); > WRITE_ONCE(x, 1); > r0 = READ_ONCE(y); > spin_unlock(s); > > P1: > spin_lock(s); > WRITE_ONCE(y, 1); > r1 = READ_ONCE(z); > spin_unlock(s); > > P2 > WRITE_ONCE(z, 1); > smp_mb(); > r2 = READ_ONCE(x); > > BUG_ON(r0 == 0 && r1 == 0 && r2 == 0) > > (inspired from __two__ uses in kernel/{sched,rcu}). Even if someone were > to tell me that locks serialize enough, I'd still be prompted to say "yes, > but do / can my BUG_ON()s fire?". The point being that the scenarios under discussion in this thread all fall most definitely into the "Non-standard usage; you'd better know exactly what you're doing" category. Which suggests, by Linus's reasoning, that locking should be as lightweight as possible while still being able to perform its basic job of defining critical sections. In other words, RCpc. And which would still leave smp_mb__after_unlock_lock available for more esoteric usages. Although it provides RCsc ordering, I assume the overhead wouldn't be prohibitive in situations where only RCtso ordering is needed. Alan > Actually, my very first reaction, before starting what does appear to be > indeed a long and complex conversation, would probably be to run/check the > above snippets against the (latest) LKMM, by using the associated tool. > > Once "checked" with both people and automated models, I'd probably remain > suspicious about my "magic" code so that I most likely will be prompted to > dig into each single arch. implementation / reference manual... > > ... Time's up! > > Andrea