Received: by 10.213.65.68 with SMTP id h4csp50568imn; Mon, 12 Mar 2018 06:25:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELujcYJdlC6DRO8VRZG+PrrUtTAb29hKX3CG4j74liW5PIHzJAORQXEVNm5aZs/7nKEbwJdK X-Received: by 10.98.185.11 with SMTP id z11mr7950866pfe.153.1520861147586; Mon, 12 Mar 2018 06:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520861147; cv=none; d=google.com; s=arc-20160816; b=zMXF8uyyyKLbi3KNLoXOB0+w0zTa91Q36EVDHCvNbkxak4nVWUIE5SIx3GTtzqSbom bc4XsrHd5IxA4yLDkCbiulgKWE8MxYpQcABofqbHU6YEeODT3g0MzNsPBGrb4C6YeJb8 emZ8NKG+vh7ndELAieaPA9PGNH6BdFEm+COHMcsYPVuNDsyYUBJc5kSvNbKJYHh5H8L6 DdkmMRXxe7JcrAUJOgGA2vxlVUVoJLYFikJWmgUoUbCfH+Qdt4teMldJRbQwCEGd83US muJrRWrDulpXNJqVRafaX2o70ANnLuYdaSCf5qY0GPtLjKTs5X0ib7C+0YrEhNGB7o0y o0eA== 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=fbL0iS/162Wq5P2x4iEYcBTx6S8XB+pK8UP4qvUPf2c=; b=0gylyJAc3xbtHQwhGpiqT5iJU+jVksDUjImJweDDPV8rKY8t2UcVwaIzma/djNSYa4 uvVJZhwcfLBnMbBo6bvDOM0veky2c+4yiA2yFrQ8eKph/zyp5uzOc9+KUyBJSa04H2Yn 5dXmrSJHnefB9nBwMc1yGUXULhJbtK7EWnVZYrJsD9vd+wjWBu3cO+t4yAk+e7UU83M+ mbBTpSbk/bHLBjDpQwkvXwoETfP4N9VQsJJeUeBYnmYteVz4m6lV9q9XZtVOHKIoCQ9r jy970YEyz3/r9HBBWLAjAaqOjB+aD+qHTtazIyM0T8D9rqz6uToSk5JZmqU2su/w1HCw sGZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lkEF5gfG; 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 x27si1689262pgc.4.2018.03.12.06.25.32; Mon, 12 Mar 2018 06:25:47 -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=@gmail.com header.s=20161025 header.b=lkEF5gfG; 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 S1751397AbeCLNYh (ORCPT + 99 others); Mon, 12 Mar 2018 09:24:37 -0400 Received: from mail-wr0-f179.google.com ([209.85.128.179]:36538 "EHLO mail-wr0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751247AbeCLNYf (ORCPT ); Mon, 12 Mar 2018 09:24:35 -0400 Received: by mail-wr0-f179.google.com with SMTP id d10so3208689wrf.3 for ; Mon, 12 Mar 2018 06:24:34 -0700 (PDT) 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=fbL0iS/162Wq5P2x4iEYcBTx6S8XB+pK8UP4qvUPf2c=; b=lkEF5gfGqT9FP9xN8pen5m88bTH+8o1gNlsh1qgns+r+DgWQzxBzNZAiP1XOM1mTV8 fLx7+U250GqjA28orT119gc/N8yo46tEfteAteOSCpgV0kCzAMBwjwVh8gufGPYro9K2 GnLBMbY3v0jleckB0nicpFERiqHaHkIngCcXEFgX0dZ2z5AsyZzls0u7RPmLHeBMp+xy PCPG572LZRc+ano8hn8ptX2GwVASEUO9e6jKTK0/RKgmWI/9XiS6RFiBowNhT+5xQpYN qig+qbuFHn5fAvSbFsCXUdpNJcpFG4QRY0SNIMQ3iUrTYSrqkB2YIrN9Ivf8fwTyN57+ 0+zA== 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=fbL0iS/162Wq5P2x4iEYcBTx6S8XB+pK8UP4qvUPf2c=; b=d8ll7phMIx+5Tmy89U6/67Zg+aFdlfmcOs2vwDFmWgz2Twj+p4exlgdrWFRXGvaOre QT/UNoEdUeCWVOsGXrUipilQU4LEHLzoAf83xSWE/Xu8HRQxj+jpIcRAajs3yQ2ghqgE C0eOvkGFXaiRb8+tEDAim2jR5YzmpnnRkEPViC5cqkLAzIMNRHGz0gCq2kRZNfXS7amV HXco8qUnZT7sRchMU1058do7VerXsBC4Hl1qEta+wOsbgAp9EYgO1NFeLlUlliuoOoCS JHrGfWhbWIcXOr11FfF+uX7+UszuavPnLetkd/oQu3n5Cg9uVV1ezRrp+QXf9AkS/6Ot 8I8Q== X-Gm-Message-State: AElRT7ETPUgPbi3fBIy5pxd/juEmMtC7F38wFpkpmsYSLeaOv1Lzj/MP cc9P7A85JqEMRnlozfboDAM= X-Received: by 10.223.172.167 with SMTP id o36mr6720294wrc.34.1520861073995; Mon, 12 Mar 2018 06:24:33 -0700 (PDT) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id x78sm15169627wmd.2.2018.03.12.06.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Mar 2018 06:24:33 -0700 (PDT) Date: Mon, 12 Mar 2018 14:24:27 +0100 From: Andrea Parri To: =?utf-8?B?54Sm5pmT5Yas?= Cc: Boqun Feng , linux-kernel@vger.kernel.org, peterz@infradead.org, Alan Stern , will.deacon@arm.com, torvalds@linux-foundation.org, npiggin@gmail.com, mingo@kernel.org, mpe@ellerman.id.au, oleg@redhat.com, benh@kernel.crashing.org, Paul McKenney Subject: Re: smp_mb__after_spinlock requirement too strong? Message-ID: <20180312132427.GA11222@andrea> References: <20180312054412.yqyde34ly3kjoajj@tardis> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi Trol, [...] > But this is just one special case that acquire-release chains promise us. > > A=B=0 as initial > > CPU0 CPU1 CPU2 CPU3 > write A=1 > read A=1 > write B=1 > release X > acquire X > read A=? > release Y > > acquire Y > > read B=? > > assurance 1: CPU3 will surely see B=1 writing by CPU1, and > assurance 2: CPU2 will also see A=1 writing by CPU0 as a special case > > The second assurance is both in theory and implemented by real hardware. > > As for theory, the C++11 memory model, which is a potential formal model > for kernel memory model as > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0124r4.html > descripes, states that: > > If a value computation A of an atomic object M happens before a value > computation B of M, and A takes its value from a side effect X on M, then > the value computed by B shall either be the value stored by X or the value > stored by a side effect Y on M, where Y follows X in the modification > order of M. A formal memory consistency model for the Linux kernel is now available at: git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git lkmm Commit 1c27b644c0fdbc61e113b8faee14baeb8df32486 ("Automate memory-barriers.txt; provide Linux-kernel memory model") provides some information (and references) on the development of this work. --- You can check the above observation against this model: unless I mis-typed your snippet, andrea@andrea:~/linux-rcu/tools/memory-model$ cat trol0.litmus C trol0 {} P0(int *a) { WRITE_ONCE(*a, 1); } P1(int *a, int *b, int *x) { int r0; r0 = READ_ONCE(*a); WRITE_ONCE(*b, 1); smp_store_release(x, 1); } P2(int *a, int *x, int *y) { int r0; int r1; r0 = smp_load_acquire(x); r1 = READ_ONCE(*a); smp_store_release(y, 1); } P3(int *b, int *y) { int r0; int r1; r0 = smp_load_acquire(y); r1 = READ_ONCE(*b); } exists (1:r0=1 /\ 2:r0=1 /\ 3:r0=1 /\ (2:r1=0 \/ 3:r1=0)) andrea@andrea:~/linux-rcu/tools/memory-model$ herd7 -conf linux-kernel.cfg trol0.litmus Test trol0 Allowed States 25 1:r0=0; 2:r0=0; 2:r1=0; 3:r0=0; 3:r1=0; 1:r0=0; 2:r0=0; 2:r1=0; 3:r0=0; 3:r1=1; 1:r0=0; 2:r0=0; 2:r1=0; 3:r0=1; 3:r1=0; 1:r0=0; 2:r0=0; 2:r1=0; 3:r0=1; 3:r1=1; 1:r0=0; 2:r0=0; 2:r1=1; 3:r0=0; 3:r1=0; 1:r0=0; 2:r0=0; 2:r1=1; 3:r0=0; 3:r1=1; 1:r0=0; 2:r0=0; 2:r1=1; 3:r0=1; 3:r1=0; 1:r0=0; 2:r0=0; 2:r1=1; 3:r0=1; 3:r1=1; 1:r0=0; 2:r0=1; 2:r1=0; 3:r0=0; 3:r1=0; 1:r0=0; 2:r0=1; 2:r1=0; 3:r0=0; 3:r1=1; 1:r0=0; 2:r0=1; 2:r1=0; 3:r0=1; 3:r1=1; 1:r0=0; 2:r0=1; 2:r1=1; 3:r0=0; 3:r1=0; 1:r0=0; 2:r0=1; 2:r1=1; 3:r0=0; 3:r1=1; 1:r0=0; 2:r0=1; 2:r1=1; 3:r0=1; 3:r1=1; 1:r0=1; 2:r0=0; 2:r1=0; 3:r0=0; 3:r1=0; 1:r0=1; 2:r0=0; 2:r1=0; 3:r0=0; 3:r1=1; 1:r0=1; 2:r0=0; 2:r1=0; 3:r0=1; 3:r1=0; 1:r0=1; 2:r0=0; 2:r1=0; 3:r0=1; 3:r1=1; 1:r0=1; 2:r0=0; 2:r1=1; 3:r0=0; 3:r1=0; 1:r0=1; 2:r0=0; 2:r1=1; 3:r0=0; 3:r1=1; 1:r0=1; 2:r0=0; 2:r1=1; 3:r0=1; 3:r1=0; 1:r0=1; 2:r0=0; 2:r1=1; 3:r0=1; 3:r1=1; 1:r0=1; 2:r0=1; 2:r1=1; 3:r0=0; 3:r1=0; 1:r0=1; 2:r0=1; 2:r1=1; 3:r0=0; 3:r1=1; 1:r0=1; 2:r0=1; 2:r1=1; 3:r0=1; 3:r1=1; No Witnesses Positive: 0 Negative: 25 Condition exists (1:r0=1 /\ 2:r0=1 /\ 3:r0=1 /\ (2:r1=0 \/ 3:r1=0)) Observation trol0 Never 0 25 Time trol0 0.03 Hash=21369772c98e442dd382bd84b43067ee Please see "tools/memory-model/README" or "tools/memory-model/Documentation/" for further information about these tools/model. Best, Andrea > > at > $1.10 rule 18, on page 14 > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf > > As for real hardware, Luc provided detailed test and explanation on > ARM and POWER in 5.1 Cumulative Barriers for WRC on page 19 > in this paper: > > A Tutorial Introduction to the ARM and POWER Relaxed Memory Models > https://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test7.pdf > > So, I think we may remove RCsc from smp_mb__after_spinlock which is > really confusing. > > Best Regards, > Trol > > > > >> And for stopped tasks, > >> > >> CPU0 CPU1 CPU2 > >> > >> > >> > >> lock(rq0) > >> schedule out A > >> remove A from rq0 > >> store-release(A->on_cpu) > >> unock(rq0) > >> > >> load_acquire(A->on_cpu) > >> set_task_cpu(A, 2) > >> > >> lock(rq2) > >> add A into rq2 > >> unlock(rq2) > >> > >> lock(rq2) > >> schedule in A > >> unlock(rq2) > >> > >> > >> > >> happens-before > >> store-release(A->on_cpu) happens-before > >> load_acquire(A->on_cpu) happens-before > >> unlock(rq2) happens-before > >> lock(rq2) happens-before > >> > >> > >> So, I think the only requirement to smp_mb__after_spinlock is > >> to guarantee a STORE before the spin_lock() is ordered > >> against a LOAD after it. So we could remove the RCsc requirement > >> to allow more efficient implementation. > >> > >> Did I miss something or this RCsc requirement does not really matter?