Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1022856yba; Thu, 4 Apr 2019 02:38:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqyC1Y6rG5EbIfow/6rpBiLdaMqx63S2F7+BuadyUfnI7TpGUBKetoKCflsjfCJchcOXWpwP X-Received: by 2002:a63:3dca:: with SMTP id k193mr4726531pga.146.1554370723716; Thu, 04 Apr 2019 02:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370723; cv=none; d=google.com; s=arc-20160816; b=DJyksXtWfgvT4YN/uzvWrlWh/G9a5HSbmbKM9Onf1Y6o5e+Dh6zU/Le1qsgmtEzY2Z WGKTYgqSnPNPuNLDhgg+KpsooMYnJliLnPkr4ijSJ06Et7mBx2EDNcFjA2KF26+gwK1O Bj415wFvMM0Lu0CLAC+a73ZkbbXnR8xbrnp4g3s0cg8y8vQiv3BgNAFUJ61kJ9OQ193z AyYlRJvo4JXjWuvlSrxp23vtwutSHHSHc+iQUdu/jgjeZjNampVFoCvuG8JAIAA3oayh Fr32ht6NpcLORVviBIQizuGmvSCD0UIVaN2fPYwE+jF+ALML+r36K3CbSKD8LfJzWJUd 2MYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xk8shUFBfHfcsHV5kXsJ2mFalTvQip4BgpRpFlTPbK0=; b=LFZ00yZzg8mR+MQi9W05hrvxYaEhQvfBDVsu0orhDUunF2624uxpaWz8LI3AA/LdaG CQv9Lg8g2I8JZt/riQP9kRhjWjNSDFv1qcJzWEG8lE78ueBIrrqkOo2wAYEsh7aqQSdB wmSKGKVWrPYWL1zJnEG1e49QBsmjMmEyiNgVCZ7O5iCdYBhnVw/f5PyChIbIQ1fMP/cL uFdN11vsWsqGYxN9QTgN5u1KIUmf7gy1ox7ZaN6GzjxChmt67jYGfJAsBx/9H/n0GTMA l6hrYut+K25W3UegE0Mjotg6OdijLyEScWWNhvW2ECzre0G/w0nJ2kTgJwT935s6ZEbo 7ugQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Zd9QcPWI; 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 l33si16284355pld.309.2019.04.04.02.38.28; Thu, 04 Apr 2019 02:38:43 -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=@kernel.org header.s=default header.b=Zd9QcPWI; 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 S1732301AbfDDJhc (ORCPT + 99 others); Thu, 4 Apr 2019 05:37:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:42810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731812AbfDDJEy (ORCPT ); Thu, 4 Apr 2019 05:04:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7E2F2183E; Thu, 4 Apr 2019 09:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368693; bh=+99nPX0BD/OKqi6HTdELshrGt916SX9sHcTiExDomOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zd9QcPWItKV6hANcw1YpsCiWkQwuAZARiY6leiUsggyQRyyIUGtSLBVNDNJs+qNkG SN1EOT3e7/UdxGkZycr2PH//Dy/EFNaVo1pdR0x8cTr+rEUbo3hQbXjRKpm9D2i+fO f4SnG56aRINyWXJyHS8oAD0MUpFgB/M9g57zCbb4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrea Parri , "Peter Zijlstra (Intel)" , Alan Stern , Linus Torvalds , Mike Galbraith , "Paul E. McKenney" , Thomas Gleixner , Will Deacon , Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 134/187] sched/core: Use READ_ONCE()/WRITE_ONCE() in move_queued_task()/task_rq_lock() Date: Thu, 4 Apr 2019 10:47:51 +0200 Message-Id: <20190404084609.508910932@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c546951d9c9300065bad253ecdf1ac59ce9d06c8 ] move_queued_task() synchronizes with task_rq_lock() as follows: 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 honor this address dependency. Also, mark the accesses to ->cpu and ->on_rq with READ_ONCE()/WRITE_ONCE() to comply with the LKMM. Signed-off-by: Andrea Parri Signed-off-by: Peter Zijlstra (Intel) Cc: Alan Stern Cc: Linus Torvalds Cc: Mike Galbraith Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Link: https://lkml.kernel.org/r/20190121155240.27173-1-andrea.parri@amarulasolutions.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- include/linux/sched.h | 4 ++-- kernel/sched/core.c | 9 +++++---- kernel/sched/sched.h | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 4abb5bd74b04..5dc024e28397 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1737,9 +1737,9 @@ static __always_inline bool need_resched(void) static inline unsigned int task_cpu(const struct task_struct *p) { #ifdef CONFIG_THREAD_INFO_IN_TASK - return p->cpu; + return READ_ONCE(p->cpu); #else - return task_thread_info(p)->cpu; + return READ_ONCE(task_thread_info(p)->cpu); #endif } diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 152a0b0c91bb..9a4f57d7e931 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -107,11 +107,12 @@ struct rq *task_rq_lock(struct task_struct *p, struct rq_flags *rf) * [L] ->on_rq * RELEASE (rq->lock) * - * If we observe the old CPU in task_rq_lock, the acquire of + * If we observe the old CPU in task_rq_lock(), the acquire of * the old rq->lock will fully serialize against the stores. * - * If we observe the new CPU in task_rq_lock, the acquire will - * pair with the WMB to ensure we must then also see migrating. + * If we observe the new CPU in task_rq_lock(), the address + * dependency headed by '[L] rq = task_rq()' and the acquire + * will pair with the WMB to ensure we then also see migrating. */ if (likely(rq == task_rq(p) && !task_on_rq_migrating(p))) { rq_pin_lock(rq, rf); @@ -910,7 +911,7 @@ static struct rq *move_queued_task(struct rq *rq, struct rq_flags *rf, { lockdep_assert_held(&rq->lock); - p->on_rq = TASK_ON_RQ_MIGRATING; + WRITE_ONCE(p->on_rq, TASK_ON_RQ_MIGRATING); dequeue_task(rq, p, DEQUEUE_NOCLOCK); set_task_cpu(p, new_cpu); rq_unlock(rq, rf); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index b63172288f7b..4c7a837d7c14 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1331,9 +1331,9 @@ static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu) */ smp_wmb(); #ifdef CONFIG_THREAD_INFO_IN_TASK - p->cpu = cpu; + WRITE_ONCE(p->cpu, cpu); #else - task_thread_info(p)->cpu = cpu; + WRITE_ONCE(task_thread_info(p)->cpu, cpu); #endif p->wake_cpu = cpu; #endif @@ -1434,7 +1434,7 @@ static inline int task_on_rq_queued(struct task_struct *p) static inline int task_on_rq_migrating(struct task_struct *p) { - return p->on_rq == TASK_ON_RQ_MIGRATING; + return READ_ONCE(p->on_rq) == TASK_ON_RQ_MIGRATING; } /* -- 2.19.1