Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp193740pxb; Wed, 18 Nov 2020 01:54:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZImur/vXE7dzEdbE7ypGBimT2ZGw/iSuNY1xY1DNk7z3FNqQ+SRtwof91j5PJUeZoa96f X-Received: by 2002:a17:906:2747:: with SMTP id a7mr11657139ejd.58.1605693267500; Wed, 18 Nov 2020 01:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605693267; cv=none; d=google.com; s=arc-20160816; b=c5tX/bmRE3Yw5oBx3yHtLo2LdAH0U2k4HA1WGCd3IjnqsGvAr86acwlKx34TOcp7pT Vl3w9Gycpddv5wCcmvfYoQw/XbEuUhkH2leLB2lKPt056axgi6ERXDLAmRSO5sVGoKBK bUNUPTErq7fTidRhhwe0zTnO/h1t1CoS5K9iCyY8OkLKA5wwzhlH2HF/V6lKfWjZ+W82 sN6HqtuBdxNAYzUJWRhnffSSJf2iTd+2H72QTOcib4AJXKLgYcUXj/vIcuKpbNgy5+6L 1WdEHJoGVZIwB3y7OpXqsu/sTvRhZRDVgwgMpKLvs5Yem/B09r3adaf5wigAjHz6OQQI F0Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:from:user-agent:references; bh=TVY+apzUB1N9B155FwpQDF6R5swLntH7ANa9GMwpiDs=; b=ILxcOxLFpaf71QqZnJmdPkEAOdG/3GJj8c1S2xbChBuLbHjkzBS3RxA1uIr/cdKK4p CzZRikoG/o2/hz53uP2YtrXbMEcNsLNAeOq/TJEs35YKch+kUbx6a04UjPrA+siGQQ59 FSc5f8K0RblfkWCrDvRLpsKBJUEKl99Qa0mTskO9lzE6LMvgrSXPsWEGg3cIbCykwG5q MmuR+sTd7jjUZTnlC/DlcBu2tVAClMJbVULOHsxZ8momlb3u3IOIGw4XK0Ps8ivI+pHb 3N9vhbBsKIg8ECdopbmkCqBcOgssz4jy0/jHxRmMrHVmnZeyUsNVkBSN38erykY0/db0 4s5Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw3si823354ejb.656.2020.11.18.01.54.05; Wed, 18 Nov 2020 01:54:27 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727499AbgKRJvl (ORCPT + 99 others); Wed, 18 Nov 2020 04:51:41 -0500 Received: from foss.arm.com ([217.140.110.172]:49980 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbgKRJvl (ORCPT ); Wed, 18 Nov 2020 04:51:41 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B255111D4; Wed, 18 Nov 2020 01:51:40 -0800 (PST) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C91653F719; Wed, 18 Nov 2020 01:51:39 -0800 (PST) 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> <20201118080515.GR3121392@hirez.programming.kicks-ass.net> User-agent: mu4e 0.9.17; emacs 26.3 From: Valentin Schneider To: Peter Zijlstra 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 In-reply-to: <20201118080515.GR3121392@hirez.programming.kicks-ass.net> Date: Wed, 18 Nov 2020 09:51:33 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/11/20 08:05, Peter Zijlstra wrote: > 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. > Gotcha > 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? Yep, thanks!