Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp143676pxb; Wed, 18 Nov 2020 00:07:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSvWlBbjmjS7W7phdCQplCDbDXI3Yy5HHQcES2+869xwcrj+ICuJphkBlwLW5670uI0+9p X-Received: by 2002:a17:906:57cc:: with SMTP id u12mr23501758ejr.163.1605686872308; Wed, 18 Nov 2020 00:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605686872; cv=none; d=google.com; s=arc-20160816; b=akBcw7DTNGiY24e6Rv8JOWIHQOeGEVblexPtL8UQEocHUHjAuXVFhk6Ge9NkAtsAXE f1AgIx6MuC9JU0Lq+wuaCUL1WJWt5Tc2M+sZWYB/Kl7XDaoI7mbWbwhTfZrRsLgu0UBp COzbhtwJOb2HCEh3m7/fiVUhO/YlV3D3GGAwxXGLIrbWSUoBQfkKGloKWLip5drHkWXP yR1rQs86Bku/Rn11uUoR3yRXCgz86kQSa5q1fwAP3qLQDpJERzLKMbtiUY0Wk5kQDhkR YUHgVj0ZBq1Qkfs9hgjoPqyIpPXHPqzgP4x+4O7Vzi39e9+QJl1UyotMpwgFRc+/7euL BdrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3YV100sViLRH3FnelBDRzH39rC5gys0VAUVXrzrueWQ=; b=EaefXM13InpSYHXn/4EdSro79NB28xQ1CI8hadDITTbA6eugxfrSbcEixN/MildbB6 kp/ni1WAfSDv9za1KQkX8lpWZcIZxWvm0bsagUgr76lzDSabscGOGlY+4lAAG2NCGnFi rcE4kpnrs8VQxUGn5eFtzW+VmT4LYkqxvg6BABnSPx/bMk0YsgK6gTp3vLs/+X4Q5shQ GT7RNQpE5AMVhzLCK9Ohqc7pQuuCNSnigYVnbauV79y7+qL9PgqoInehV1Z8f5fSSi/Q +Y9O3UpiYGLYdP/ASoof3G6EiJdKR9cpdlDLKOY+ftcEO6Dfmh0Y2JCwN6MdXeag/lla O8Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=JseLfYVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp30si11565797ejc.505.2020.11.18.00.07.28; Wed, 18 Nov 2020 00:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=JseLfYVB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726342AbgKRIF0 (ORCPT + 99 others); Wed, 18 Nov 2020 03:05:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbgKRIF0 (ORCPT ); Wed, 18 Nov 2020 03:05:26 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9137EC0613D4 for ; Wed, 18 Nov 2020 00:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=3YV100sViLRH3FnelBDRzH39rC5gys0VAUVXrzrueWQ=; b=JseLfYVBXlZAqzdoJk+VsN1VBh 1GBYMxovrTJt8hSBeQB4UEHxvPee8q2cyeXD5yqZebpoNXH0JD5MH9nEpFQyN1Fmr5+9Ml1HVyU7L 0RvBXfoVjaNsXU9fxqn2X/R58D9X9qeJ76HfDTXLUeej2lcnEs+sHmI8NufFzsom4hTgOK322E/z3 VO8UhxYaUpd9TLMb03652XSuvoux6yXsT0vCUu3uXn6QZDLHylkUdm/rWK8laABaQyLnJQOPxjgnn qEiVOlUEPjhtfYeCgyaHY+0iFAdmMBp3XTFy+ilU0aCeQPOPS2o+/nOQpoF65Twnv8NYD1vpn6hnE xUBHzGIA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfISt-0004Te-2Z; Wed, 18 Nov 2020 08:05:19 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3CA2B301959; Wed, 18 Nov 2020 09:05:15 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 178C8200E0A33; Wed, 18 Nov 2020 09:05:15 +0100 (CET) Date: Wed, 18 Nov 2020 09:05:15 +0100 From: Peter Zijlstra To: Valentin Schneider Cc: Will Deacon , Mel Gorman , Davidlohr Bueso , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched: Fix data-race in wakeup Message-ID: <20201118080515.GR3121392@hirez.programming.kicks-ass.net> References: <20201116142005.GE3121392@hirez.programming.kicks-ass.net> <20201116193149.GW3371@techsingularity.net> <20201117083016.GK3121392@hirez.programming.kicks-ass.net> <20201117091545.GA31837@willie-the-truck> <20201117092936.GA3121406@hirez.programming.kicks-ass.net> <20201117094621.GE3121429@hirez.programming.kicks-ass.net> <20201117161318.GP3121392@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 17, 2020 at 07:32:16PM +0000, Valentin Schneider wrote: > > On 17/11/20 16:13, Peter Zijlstra wrote: > > On Tue, Nov 17, 2020 at 03:37:24PM +0000, Valentin Schneider wrote: > > > >> >> + /* > >> >> + * This field must not be in the scheduler word above due to wakelist > >> >> + * queueing no longer being serialized by p->on_cpu. However: > >> >> + * > >> >> + * p->XXX = X; ttwu() > >> >> + * schedule() if (p->on_rq && ..) // false > >> >> + * smp_mb__after_spinlock(); if (smp_load_acquire(&p->on_cpu) && //true > >> >> + * deactivate_task() ttwu_queue_wakelist()) > >> >> + * p->on_rq = 0; p->sched_remote_wakeup = Y; > >> >> + * > >> >> + * guarantees all stores of 'current' are visible before > >> >> + * ->sched_remote_wakeup gets used, so it can be in this word. > >> >> + */ > >> > > >> > Isn't the control dep between that ttwu() p->on_rq read and > >> > p->sched_remote_wakeup write "sufficient"? > >> > >> smp_acquire__after_ctrl_dep() that is, since we need > >> ->on_rq load => 'current' bits load + store > > > > I don't think we need that extra barrier; after all, there will be a > > complete schedule() between waking the task and it actually becoming > > current. > > Apologies for the messy train of thought; what I was trying to say is that > we have already the following, which AIUI is sufficient: > > * p->XXX = X; ttwu() > * schedule() if (p->on_rq && ..) // false > * smp_mb__after_spinlock(); smp_acquire__after_ctrl_dep(); > * deactivate_task() ttwu_queue_wakelist() > * p->on_rq = 0; p->sched_remote_wakeup = Y; > Ah, you meant the existing smp_acquire__after_ctrl_dep(). Yeah, that's not required here either ;-) The reason I had the ->on_cpu thing in there is because it shows we violate the regular ->on_cpu handoff rules, not for the acquire. The only ordering that matters on the RHS of that thing is the ->on_rq load to p->sched_remote_wakeup store ctrl dep. That, combined with the LHS, guarantees there is a strict order on the stores. Makes sense?