Received: by 10.213.65.16 with SMTP id m16csp177175imf; Sun, 11 Mar 2018 22:41:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELtbB6TiYVZW2TKW1mo9GFibNa9BxkSPtJaMoE/5xGmY5lMaJFzVg7qkMcwhyrhzX3iuE/aM X-Received: by 2002:a17:902:6b81:: with SMTP id p1-v6mr7029075plk.181.1520833300033; Sun, 11 Mar 2018 22:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520833300; cv=none; d=google.com; s=arc-20160816; b=ooyxqpPXqbmFuMjKSffsHO0H9PrpJEO3dcSG5ETKFmCBlMtKgVlOB3BfRrUUCqrlRO UhWmkhH8CCW+yLaHdieA9/kvg3YvRCfu+UWFNANKL8Oc+IN5FWX/xoY1L12cLa8Fwc73 qqJzPtrz7umHTmWygc8eBtLZI52rxtNvyS409WKebk4nj6je0OVtOKsWXQjY1yxhESsA YamIGfk3Z1fzZURhHDgmHowW9F+jU+P9BZFKIqCP7zJBuA16ZE2dlOvoM+ooRZk7ZdM4 26awRorGIFhJWIQRddokhlvl7Gb3HwliXYQ+XfhzeRYPHK0bJAGXWz7ecGhDPn4ET7TQ dwbA== 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=GQTgfMbT51v64uekxveYVjBaQaI+5QvOWgt37EDP19U=; b=szZRdJ9nZHSb+aVhYlEkA24H113c6O2/qktAl0un3zNw96ie/WN2vWIfWCFFLRdNIc tJ424KXQuUrbFmP54zsIAcvkmlz/G6IzyrLhmzw9qlPv03m+C8DCRecR2BsFUqMjmkt8 Dm1aIKkCphCmykC1B3IYiyTVMjZZIDGBs2GGeabcIUZ5bAo6bSZKwLH0xtmMopGRSAiL eZBQM+NRa6Quiwe3dF0RfWmHLlwUoF/ksiddt8kThW30LIXElfq8Jlv+VGITw8hM9shH YsfpYJ0HSB1JOPh7fBNZBOhsYj+GucV1SuLWNyy0E1AYrJpLWZccByjQfPeCd3WDTvpb 1haA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=da935/+A; 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 2-v6si5489171plc.205.2018.03.11.22.41.24; Sun, 11 Mar 2018 22:41:40 -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=da935/+A; 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 S1751509AbeCLFkc (ORCPT + 99 others); Mon, 12 Mar 2018 01:40:32 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:50313 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbeCLFkb (ORCPT ); Mon, 12 Mar 2018 01:40:31 -0400 Received: by mail-wm0-f48.google.com with SMTP id w128so13991807wmw.0 for ; Sun, 11 Mar 2018 22:40:30 -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=GQTgfMbT51v64uekxveYVjBaQaI+5QvOWgt37EDP19U=; b=da935/+AADDYU6kzClWXm4wdyprAqJVYm0yCbsnQA1yNV2U/qg7NRHujr0SVa9ERWk 24dnbY3FCtI9OY+8UdcjwCCMYMbFfYNv6pQHO5O2OSou7LsuVSuJZ8kbcNNPo/6XsPmH /r54uVbiLurFs/AWbY/4Y0iRwx4akohUsDGcYVLo/hl5a2LMJJfBO4ZHEWj+Yxc6Hezd 6f1gpeNm7ZWrC0YikI9rhwIlLPdJQe6g2DCcaEewGl+k3hR+0IsgBesIYAk8tiD1ZOWR F4de3eAt+SeyZpIHlMzSmMciMqXI+ec9PI5QjfM/t8ATGg9cvvJPKDMQQCWYDi4+/XN4 CpUg== 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=GQTgfMbT51v64uekxveYVjBaQaI+5QvOWgt37EDP19U=; b=Dp+HI6mA2sIrg9I0+EaCYZ4nu25sZT6V7d/3y/pMK+Cn87JCcoEpMY2xUN6pTWy2WQ Fza6KNpoHt8+zYA9RFUTPmxNrpyobk1P1Be7qWX7hNnJ7nyMOvQVaY7IedKm/zpjs3ps 9Q6QUj7dKeuCBKDmMhl0Y0I4Jp4fcqghG4s3sRR+91K4RVchZ3gYO6Dr/JsgKZ2AZ9/S 3aFk4pl6pZhT/WZvd7kJJn5YKQFf+520BTsYdHafGs6SE+F0E21xappFVs/fm0JnSwXl NBeLrahFeWvcoXLeO12hQlKUqLUCefCuYqla18Q6C5StUFWOEl5nLYnPiSiqfFUD/CC0 flEA== X-Gm-Message-State: AElRT7GMfO1xxXQMfSxnEiNwY/mjPha6u/iRmyrZPtTNcduzkZY0miPL OrRviA0b479SpvtCJcfdrPhdNi9p X-Received: by 10.80.158.76 with SMTP id z70mr9275515ede.89.1520833230239; Sun, 11 Mar 2018 22:40:30 -0700 (PDT) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id c9sm1605470edl.23.2018.03.11.22.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 22:40:29 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id DA72520C79; Mon, 12 Mar 2018 01:40:26 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Mon, 12 Mar 2018 01:40:26 -0400 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 1C1367E13E; Mon, 12 Mar 2018 01:40:26 -0400 (EDT) Date: Mon, 12 Mar 2018 13:44:12 +0800 From: Boqun Feng To: =?utf-8?B?54Sm5pmT5Yas?= Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, stern@rowland.harvard.edu, 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, paulmck@linux.vnet.ibm.com Subject: Re: smp_mb__after_spinlock requirement too strong? Message-ID: <20180312054412.yqyde34ly3kjoajj@tardis> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wx2uzbtov5fnahj6" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --wx2uzbtov5fnahj6 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 11, 2018 at 03:55:41PM +0800, =E7=84=A6=E6=99=93=E5=86=AC wrote: > Peter pointed out in this patch https://patchwork.kernel.org/patch/977192= 1/ > that the spinning-lock used at __schedule() should be RCsc to ensure > visibility of writes prior to __schedule when the task is to be migrated = to > another CPU. >=20 > And this is emphasized at the comment of the newly introduced > smp_mb__after_spinlock(), >=20 > * This barrier must provide two things: > * > * - it must guarantee a STORE before the spin_lock() is ordered agains= t a > * LOAD after it, see the comments at its two usage sites. > * > * - it must ensure the critical section is RCsc. > * > * The latter is important for cases where we observe values written by o= ther > * CPUs in spin-loops, without barriers, while being subject to schedulin= g. > * > * CPU0 CPU1 CPU2 > * > * for (;;) { > * if (READ_ONCE(X)) > * break; > * } > * X=3D1 > * > * > * r =3D X; > * > * without transitivity it could be that CPU1 observes X!=3D0 breaks the = loop, > * we get migrated and CPU2 sees X=3D=3D0. >=20 > which is used at, >=20 > __schedule(bool preempt) { > ... > rq_lock(rq, &rf); > smp_mb__after_spinlock(); > ... > } > . >=20 > If I didn't miss something, I found this kind of visibility is __not__ > necessarily > depends on the spinning-lock at __schedule being RCsc. >=20 > In fact, as for runnable task A, the migration would be, >=20 > CPU0 CPU1 CPU2 >=20 > >=20 > lock(rq0) > schedule out A > unock(rq0) >=20 > lock(rq0) > remove A from rq0 > unlock(rq0) >=20 > lock(rq2) > add A into rq2 > unlock(rq2) > lock(rq2) > schedule in A > unlock(rq2) >=20 > >=20 > happens-before > unlock(rq0) happends-before > lock(rq0) happends-before > unlock(rq2) happens-before > lock(rq2) happens-before > >=20 But without RCsc lock, you cannot guarantee that a write propagates to CPU 0 and CPU 2 at the same time, so the same write may propagate to CPU0 before but propagate to CPU 2 after . So.. Regards, Boqun > And for stopped tasks, >=20 > CPU0 CPU1 CPU2 >=20 > >=20 > lock(rq0) > schedule out A > remove A from rq0 > store-release(A->on_cpu) > unock(rq0) >=20 > load_acquire(A->on_cpu) > set_task_cpu(A, 2) >=20 > lock(rq2) > add A into rq2 > unlock(rq2) >=20 > lock(rq2) > schedule in A > unlock(rq2) >=20 > >=20 > happens-before > store-release(A->on_cpu) happens-before > load_acquire(A->on_cpu) happens-before > unlock(rq2) happens-before > lock(rq2) happens-before > >=20 > 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. >=20 > Did I miss something or this RCsc requirement does not really matter? --wx2uzbtov5fnahj6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqmE6kACgkQSXnow7UH +rhz1Qf+MZCXL32i+z/Ca2k1MnPGka+FMuw0hbksH5L0BZrPdjeRSTKLtU+Qvj56 4F9VrFmvqg9nb8H2aPXRKGOBcM4fLmUykbkl2ZllspBAU0ZYUJCuX5FLAp8gKd93 K/TKfxoAvmMc9HH7XCwp7/5UDoQPp9XRjwHCqhvipdf15RbJ5rZJeOIxkf4SYx/N dyo8aSvwdz7Uk3VZ6nv1YSB0aB7Wd1PSQf1Ba1a3Jq6UTQENwc9OxV5BwWoDxe4I RRi9Q4qB/+iExGpfmnnYQr26HUNYUHdT7cYeKvNcTEFf7bBXn7rhir5c4Kvlr8W0 i/A2vgh9lvaNxoejGLxUG3qwgYJuuw== =M52O -----END PGP SIGNATURE----- --wx2uzbtov5fnahj6--