Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3831720pxb; Tue, 17 Nov 2020 04:55:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWtAqAUMeNMlDCNeO1oZRAZx46W+U7ElziBBs2eFAdgBQh0vuHXcjoWXvTY8wOOITNaRhj X-Received: by 2002:a17:906:2454:: with SMTP id a20mr1203009ejb.208.1605617735207; Tue, 17 Nov 2020 04:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605617735; cv=none; d=google.com; s=arc-20160816; b=GA/lmVnsnEz9FQlV4vTp9XxxhLg/gXmjG3VhuKtJjEeHKD59iOGNKKcvMzb9/6nPwf WEr7lDYPQI9L0aI1jPDr1IIt8EHwpObFCWVzu+MY78jcp0vowtjvJgJ85U9qCWXI4EwG C3TKaaNIIZKeURCmfApIg7q9Tzci53nA5EKySYa8iUO/ce+rjqttqpO9jdPPlMS9wWxe unsS9W+idqITxW0gIPdpuv+QdDlBMQcLQDDRgE9jabOxRV9drqAj6RjJCv35xdKaOhPK +UFlONargN01yxAvwJDgn0R9pg96jkH4pDtqOJ5s0ar08bfEzJm3ZLmMceaY1jZu2824 lmNQ== 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=9rNmrT17BIg5CueYB7dhl8Zr0I0Mh+gLit4mWGwAzKY=; b=VFSuJ4065KMtjFKIMjdw4OhLSop3G1aCQR2cg1jd22/UvV4kAyJ2RntyMnQ3ci0/fs edgvDIpTjdL0gMGPI9VtrqlGVbj+hWeEPWN3NOEDes7qqGv5fbJcXFYFgB6VnYQJf3lh 4CFY5wBDsay692HyOYSfLsYTh3JyOS9nZnC5shdcud5TDW383zKCJKisyWjozg7an+5r jQb/NUzQAkvosYfrOnJH6c3vQqhnUcKNHzifi/qxG53oNK7o9L84SbxVnbSA4VU/uQ5O q3yrjG7IRQdkhC8/0aNU2Hwxz3CPYukGXGGlnbqEfZ2Y+ttnPXArjCdkrTqBeoUnsGeU GkpQ== 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 z7si10451629eja.279.2020.11.17.04.54.49; Tue, 17 Nov 2020 04:55:35 -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 S1728293AbgKQMwQ (ORCPT + 99 others); Tue, 17 Nov 2020 07:52:16 -0500 Received: from foss.arm.com ([217.140.110.172]:55768 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgKQMwQ (ORCPT ); Tue, 17 Nov 2020 07:52:16 -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 989AC101E; Tue, 17 Nov 2020 04:52:15 -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 B29AF3F719; Tue, 17 Nov 2020 04:52:14 -0800 (PST) References: <20201116091054.GL3371@techsingularity.net> <20201116131102.GA29992@willie-the-truck> <20201116133721.GQ3371@techsingularity.net> <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> 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: <20201117094621.GE3121429@hirez.programming.kicks-ass.net> Date: Tue, 17 Nov 2020 12:52:12 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/11/20 09:46, Peter Zijlstra wrote: > How's this then? It still doesn't explicitly call out the specific race, > but does mention the more fundamental issue that wakelist queueing > doesn't respect the regular rules anymore. > > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -775,7 +775,6 @@ struct task_struct { > unsigned sched_reset_on_fork:1; > unsigned sched_contributes_to_load:1; > unsigned sched_migrated:1; > - unsigned sched_remote_wakeup:1; > #ifdef CONFIG_PSI > unsigned sched_psi_wake_requeue:1; > #endif > @@ -785,6 +784,21 @@ struct task_struct { > > /* Unserialized, strictly 'current' */ > > + /* > + * 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"? That should be giving the right ordering for the rest of ttwu() wrt. those 'current' bits, considering they are written before that smp_mb__after_spinlock(). In any case, consider me convinced: Reviewed-by: Valentin Schneider > + unsigned sched_remote_wakeup:1; > + > /* Bit to tell LSMs we're in execve(): */ > unsigned in_execve:1; > unsigned in_iowait:1;