Received: by 10.213.65.68 with SMTP id h4csp74968imn; Mon, 12 Mar 2018 07:11:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELuBB2P6zqDZbnKy69jzMiB08U2AWUtpMOOYPGATIjsipxxO3v7lf0PMnZFSm9MGVBrYn7q8 X-Received: by 10.98.246.16 with SMTP id x16mr8106394pfh.81.1520863894968; Mon, 12 Mar 2018 07:11:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520863894; cv=none; d=google.com; s=arc-20160816; b=SLc4nUKwSUQ/XOeGw+6bX0Y9StyFEsF7R88+09x4IDewcT74WFgoBh2pcTrZBb1wMg pSvmlbwax+8RMu82Ed7vTWmljMQ9nfilGFOLVKFmQQEOLVlvPofPjkame4xirUTX83+N dy35l5l6SIe1zL0DjmD7RlPty9101waUG0IFFW9vkJNr106QwpLci1g2u0RHeeEfEvrv t695JzMQcbssIhQ6ijBNHjajVwlO3LrjmEUjlbB9c5L271Jm9wUiNqIcPWwP/Q8P22YU eUAcGTJUzaTlxEoY7D6Jd3yeX7jbxts9EA5Gfq1DFZYQM1DW7zfDkOOF0n3gjpwx7sLe kpeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3SWOIBtodKFyLAXibiyWFXMQZV6ZxmYhNFFdpnoPARo=; b=06Jm4Q8kK3nCFm7t5LUIwG5OsCoeuv+4cSXOO/eW8P+6AsMcqjuC4pHMOOEGZoKwPO 4+KEnoRtUFhQwn5MgL4/coaCv2rvkLq4+hfrflVM8Ffc/xCy/bgii4xskpTmT8FtRb00 6jWu+G10kBa/j1SVlsV+7c7JKWLS3TQKrzVSrnNJHmzxAHFfXxUtebTUrQQOSV5cLUrB W6PsD2BRUywrgIRBKEFjxK1DX45tsRwy0Hm+DK7grO6wu/PE3nPqcQ8WTzGXLzfJCYWa 12yps9wm5+uaFfyse+9NP4z3Y+WtRlbyM3Y1tTu8SPZSPtaYXXDOhK+Fx/IF8N92/zQO wCSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fA/94XOa; 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 c14si5081201pgn.681.2018.03.12.07.11.20; Mon, 12 Mar 2018 07:11:34 -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=fA/94XOa; 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 S932399AbeCLOKa (ORCPT + 99 others); Mon, 12 Mar 2018 10:10:30 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:45313 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932331AbeCLOK3 (ORCPT ); Mon, 12 Mar 2018 10:10:29 -0400 Received: by mail-oi0-f68.google.com with SMTP id j79so12382507oib.12 for ; Mon, 12 Mar 2018 07:10:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3SWOIBtodKFyLAXibiyWFXMQZV6ZxmYhNFFdpnoPARo=; b=fA/94XOay1poZn15HPaUGd4bik7PtVuPjWcOnS/OEKuXFWw0cf/neWro0RQNuO0mmu 0vgn467hnzww3Z5SWRWwKTyIeYTgMXBjVYMAQ864vG+EEx/LL4jH/EQJk1wUvywpBJtS SPHO0umhjdt+/a/oJFPt1rpvYqDrY8XrJy9ZbBghKMPs0xyh3/hkNIWf617WiWN+Og6a 04S3FedTT6sE8sqhWTItwmi6VfFWhJDo5/xcJo0yFxqJonAdkf3c0lcL4lLFPY7ce3AJ 5JbYsV//k+CaoH0slBCw/IQRkg48Ws1UHXOISnCyY7WbShfuAgLwDwWye9zlKhPbJ0C/ tnRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3SWOIBtodKFyLAXibiyWFXMQZV6ZxmYhNFFdpnoPARo=; b=B0KV/aO52Ts09N4kxMVniA81x4Qc/FGrYgXtj6pSDPyXyQ93bOCsnAZOvnjydyQPju In+cSebJkY2kFEDPUGfJ8NfDY3egYzrGVbP2EWJL6bi21sif6uhyheQr+OZdMCFvNpMh UL4wm8VHXvZCD9yfc7Fo618J9JyFgQywIb1eY7bOlaRuj6e/64j1S/Xfcmps6G9TSPSo gNL3VZ1jySYgJSP2PVVWlYo/0hpZmSpGwj/bqb2SnCfrzVWR6HMmZsGOAKjLibbWXGv4 NtbQICkY6TGkzgltjq0iJ9+TIBXwmTy7XoDLheu9Q2/eCttRzE5ThM8z++aZURYps5r2 +s0A== X-Gm-Message-State: AElRT7GNtE+/r/nTziRHAt8n4NGCxSwa6GPcrYe5OQtV3B8u5eUSRPo+ CFK95S688KqoPtO4CL/vapf0FV7ZHVrA4jOcWkMVbA== X-Received: by 10.202.74.148 with SMTP id x142mr5310113oia.157.1520863828414; Mon, 12 Mar 2018 07:10:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.151.230 with HTTP; Mon, 12 Mar 2018 07:10:27 -0700 (PDT) In-Reply-To: <20180312132427.GA11222@andrea> References: <20180312054412.yqyde34ly3kjoajj@tardis> <20180312132427.GA11222@andrea> From: =?UTF-8?B?54Sm5pmT5Yas?= Date: Mon, 12 Mar 2018 22:10:27 +0800 Message-ID: Subject: Re: smp_mb__after_spinlock requirement too strong? To: Andrea Parri 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 12, 2018 at 9:24 PM, Andrea Parri wrote: > 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 > This work is amazingly great, Andrea. I'd like to study on it. > >> >> 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?