Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6361484imu; Mon, 21 Jan 2019 07:37:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN5lf0OEoV2oCTK2bq7cPsIXvr5ITgw/qx4sNpmnwmtDbGJbEAGQ91oxjH/Zs7s7nOVQxS1N X-Received: by 2002:a62:1112:: with SMTP id z18mr29826636pfi.173.1548085048372; Mon, 21 Jan 2019 07:37:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548085048; cv=none; d=google.com; s=arc-20160816; b=mBM/2hC1B7fuyu2lLYTddjzNgR3q8VtMs4KWgFH7WXeLm0k+gRm/jVZNGEJP+LWrdF w8OuJZqsFLJkKeT+Edkmwvoa29u1FbVWuyw9TbwUeHvRMcg2MqNQNJVcsIHE4M/kamH1 YAKw7y9Ev2yOWTCnBp7z1rhWE/A0wMmz8T2U37pehETKtH+F7yTEEbrD8ZMbkVMt/GjI eR6W3jJ8lInGaC4GYWgc0jEnEZdzPJKa+IRWRUcvXnjW6MSJORo4nOJwqFgCpJCRo7dV 5wlMKhIJpeB2JzXjnq60wSOA7u7fv+1zrDq6Kj6UYBvyhjP1bYN2F3nXXCtOGBU3y4Os U6gQ== 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; bh=KlyrB5n5ya2HRdFoSG/ZicyJjS++CBBS44KKM+5uUG4=; b=BAU/WJKJ27GAg4587bTnfPjZ6Ii4Kx25sg16b2csvpodgNdQ1WdwW03kfQ+YjTtz91 CuOTNIFFDrpNtG/CE8OLPrCYeJPXDGRAXFMlp1q+MkmSTTErDytNqpJRZ3wpA+3rfn/j UVWS6/xWrU9dw1vMDPhRa5SSpOLO2pE3DVM7m8Ke4KN6gjf+W+yNfQ1FyG8eSG6dIaBe j3I4+JrNgwQy7f0Qs/7Lrg46cmHcqzJyfTm2w7mj/0xsWFeMed/bKLJ4p7YGLaSlcmqP svM/Wj4/PHLEX+3aBqfFeHcuxT0Zg3QTPecJULVcDTeuJbk8nGYqF9gyjrUqU/j0CRX5 7igQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oug2GetC; 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 w12si12068506pfn.212.2019.01.21.07.37.12; Mon, 21 Jan 2019 07:37:28 -0800 (PST) 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=oug2GetC; 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 S1730526AbfAUPew (ORCPT + 99 others); Mon, 21 Jan 2019 10:34:52 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:42091 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730440AbfAUPer (ORCPT ); Mon, 21 Jan 2019 10:34:47 -0500 Received: by mail-ed1-f65.google.com with SMTP id y20so16876361edw.9 for ; Mon, 21 Jan 2019 07:34:46 -0800 (PST) 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=KlyrB5n5ya2HRdFoSG/ZicyJjS++CBBS44KKM+5uUG4=; b=oug2GetC1HER1Wuh3Dc28fvOQtTvAbMGpPHPCtqqe9lokfFVxRPh68RXS9qfvvj8ek kyhPUajIgaEAadEZBxOOOGPyTET4TIlzGxXmGOMXAQgPVZ9qO3SomuwcfJY9d0a5zGHb ZbjXMBcAmRIQSijOOA19ElKDEkgMpJ/m2v62g= 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=KlyrB5n5ya2HRdFoSG/ZicyJjS++CBBS44KKM+5uUG4=; b=eajQfNDPCjkXJLFR/ThpzQeTSvD/1M5Mbhl1DreogSE9/DJRmhpDDvy+6F5ZhYV4j1 tbfpjClVTRilfogqVEy7ZOLlLTEkzNVZjJ2IrrkTuIEbgaCURZRLH1CJ2HiBDGYANhHe Ido5ubm4IVm19ZNkXeSlid3cu8RfA11nauhlMSMUGyzciW5hJH5aEf8FR8Cb1DkicyE9 s/brH1SgJ3wOYeTuZLcAbiPuFlxhdV5lY7vQCgVr+hX+WZ1JmRA/RC57TWSdewSDZTPl IWAb4v3dT0wMOIgNB7ka+BsghN7Ggq07dayfdmFH7oVehwyMS0137Ls7HQvIWUyVKQmk /VOA== X-Gm-Message-State: AJcUukdbDloU4aFqrfYOMyr0k1+BMYGSfnV5jQw3ByJsTMMNCOP2IX+q KJvrYvhQLJ37zmNdIQ2Y5hvm/d6yA0cDPg== X-Received: by 2002:a50:afa3:: with SMTP id h32mr27223730edd.150.1548084885349; Mon, 21 Jan 2019 07:34:45 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id a27sm9661964eda.65.2019.01.21.07.34.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 07:34:44 -0800 (PST) Date: Mon, 21 Jan 2019 16:34:39 +0100 From: Andrea Parri To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Ingo Molnar , "Paul E. McKenney" , Alan Stern , Will Deacon Subject: Re: [PATCH] sched: Use READ_ONCE()/WRITE_ONCE() in task_cpu()/__set_task_cpu() Message-ID: <20190121153439.GA12623@andrea> References: <20190116184218.13757-1-andrea.parri@amarulasolutions.com> <20190121104707.GA5883@andrea> <20190121122526.GA13777@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190121122526.GA13777@hirez.programming.kicks-ass.net> 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 Mon, Jan 21, 2019 at 01:25:26PM +0100, Peter Zijlstra wrote: > On Mon, Jan 21, 2019 at 11:51:21AM +0100, Andrea Parri wrote: > > On Wed, Jan 16, 2019 at 07:42:18PM +0100, Andrea Parri wrote: > > > The smp_wmb() in move_queued_task() (c.f., __set_task_cpu()) pairs with > > > the composition of the dependency and the ACQUIRE in task_rq_lock(): > > > > > > move_queued_task() task_rq_lock() > > > > > > [S] ->on_rq = MIGRATING [L] rq = task_rq() > > > WMB (__set_task_cpu()) ACQUIRE (rq->lock); > > > [S] ->cpu = new_cpu [L] ->on_rq > > > > > > where "[L] rq = task_rq()" is ordered before "ACQUIRE (rq->lock)" by an > > > address dependency and, in turn, "ACQUIRE (rq->lock)" is ordered before > > > "[L] ->on_rq" by the ACQUIRE itself. > > > > > > Use READ_ONCE() to load ->cpu in task_rq() (c.f., task_cpu()) to honour > > > this address dependency between loads; also, mark the store to ->cpu in > > > __set_task_cpu() by using WRITE_ONCE() in order to tell the compiler to > > > not mess/tear this (synchronizing) memory access. > > > > In the light of the recent discussion about the integration of plain > > accesses in the LKMM (c.f., e.g., [1] and discussion thereof), I was > > considering even further changes to this in order to "reinforce" the > > above smp_wmb(). Here's two approaches (one of): > > > > 1) replace this smp_wmb()+WRITE_ONCE() with an smp_store_release(); > > > > 2) or keep this smp_wmb()+WRITE_ONCE(), but use {WRITE,READ}_ONCE() > > also for the accesses to ->on_rq. > > That should be the least painful I think. Note that we never store a > value larger than a single byte in that word, so tearing shouldn't be a > problem, but yes, that makes it all neat and tidy. Thank you for the suggestion; I'll send the revisited patch shortly. Andrea