Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1615061ybv; Fri, 21 Feb 2020 00:19:42 -0800 (PST) X-Google-Smtp-Source: APXvYqyrToKGEiRJilwbvqZcqJ3SZZFaTbHO/NLVn5Oww2/aWZFfJPJvXA5QvcXpCl3Z4+5r9rvv X-Received: by 2002:a54:488d:: with SMTP id r13mr944267oic.115.1582273182443; Fri, 21 Feb 2020 00:19:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273182; cv=none; d=google.com; s=arc-20160816; b=pM/PG3F+lDYKLZRmNt7UZTSj432xaBeKnhotYJpQ+NA1GnJc0wItWV9wWUFEFWN1W/ SaAMPR6YK2cFIwpWfS2Q7SiaBfpcOcoOh6BahyyQ9l4mR34+AnGbH3s3uYf2b3TBpcbM 8Vj8GiSOVzBaGgVMDvRBd3/B1Fq2m3v7SM3LyQzQremjkxLUrZpL5Ct6qf7BZBW2fs5D 9LndftYJNePkxZyNI1AnHnyQN8JvAGoQu8QuZ7Nnm/Hu7KyBEsn/YK5o87+5JcFXTq0A gOJCOq3VD5EUcRke1RXxv+fEiRyPCiGJzsP6UG/bq3O8KwttSFB775wr/CHqDH/WOvRq 9UYw== 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=p9k8meQFE3RhTLoDY9e4kZEjkwreBKLU95yaFE5Vrz4=; b=g7nzO/9s7ZyGmrKnlrIWQ4VM2GwqmN+LH0kk8wKDM//HbtdxjhZajxbpF1Hx16Ox3T oYgS8btJ14fOPbPlGy8362U8GlhiMoz6V6VSbkqXq/62FPTyCuZnfuMJXv/HTNE0b8j4 OEeJBRg2fADMvo70hBtmtSzfM5w+BiHUxQKeHtvPCG66GFVLT8b3Eo0xa1u2XGE8qYdz BtBdBH8Q5eb06OFw+U47of+PG7GVncsUqZ0b0FhjjEc5fSc9aRGG/MlZuVV4+hxImcTv 8SwVpGjnOHS9nipu7XZrMXiCn6BO/fYRAUUjSp5KpB3a6/LGeyuwMi9+8FuKoYyUEAyA 4C7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VeYCXwnu; 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 g25si1126260otp.20.2020.02.21.00.19.30; Fri, 21 Feb 2020 00:19:42 -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=@kernel.org header.s=default header.b=VeYCXwnu; 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 S2387833AbgBUIS1 (ORCPT + 99 others); Fri, 21 Feb 2020 03:18:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:56334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387488AbgBUISY (ORCPT ); Fri, 21 Feb 2020 03:18:24 -0500 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 93C8D24694; Fri, 21 Feb 2020 08:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273104; bh=+2u6VCYeEc6ZE9pvV3ZpiM8JNxbrXYBB8tjL4aeEA3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VeYCXwnulq670N5lbuMsNACyrNqRQNrn/Z2Us/cV9RCEpkKWmLl1+tQM+3UzkapmI AAf0cemT2ObkpsM5l7fC2ht3xNhe4+7z+q+YG84rsDOs25eZqocUIU8FGQdgCPQtw9 WBSnvYjUNgtFatX2Hodh1ZTNjfj9YFRea7911FiQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Paul E. McKenney" , "Peter Zijlstra (Intel)" , Sasha Levin , Tejun Heo Subject: [PATCH 4.19 013/191] cpu/hotplug, stop_machine: Fix stop_machine vs hotplug order Date: Fri, 21 Feb 2020 08:39:46 +0100 Message-Id: <20200221072252.751035068@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Peter Zijlstra [ Upstream commit 45178ac0cea853fe0e405bf11e101bdebea57b15 ] Paul reported a very sporadic, rcutorture induced, workqueue failure. When the planets align, the workqueue rescuer's self-migrate fails and then triggers a WARN for running a work on the wrong CPU. Tejun then figured that set_cpus_allowed_ptr()'s stop_one_cpu() call could be ignored! When stopper->enabled is false, stop_machine will insta complete the work, without actually doing the work. Worse, it will not WARN about this (we really should fix this). It turns out there is a small window where a freshly online'ed CPU is marked 'online' but doesn't yet have the stopper task running: BP AP bringup_cpu() __cpu_up(cpu, idle) --> start_secondary() ... cpu_startup_entry() bringup_wait_for_ap() wait_for_ap_thread() <-- cpuhp_online_idle() while (1) do_idle() ... available to run kthreads ... stop_machine_unpark() stopper->enable = true; Close this by moving the stop_machine_unpark() into cpuhp_online_idle(), such that the stopper thread is ready before we start the idle loop and schedule. Reported-by: "Paul E. McKenney" Debugged-by: Tejun Heo Signed-off-by: Peter Zijlstra (Intel) Tested-by: "Paul E. McKenney" Signed-off-by: Sasha Levin --- kernel/cpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 8d6b8b5493f9f..2d850eaaf82e3 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -493,8 +493,7 @@ static int bringup_wait_for_ap(unsigned int cpu) if (WARN_ON_ONCE((!cpu_online(cpu)))) return -ECANCELED; - /* Unpark the stopper thread and the hotplug thread of the target cpu */ - stop_machine_unpark(cpu); + /* Unpark the hotplug thread of the target cpu */ kthread_unpark(st->thread); /* @@ -1048,8 +1047,8 @@ void notify_cpu_starting(unsigned int cpu) /* * Called from the idle task. Wake up the controlling task which brings the - * stopper and the hotplug thread of the upcoming CPU up and then delegates - * the rest of the online bringup to the hotplug thread. + * hotplug thread of the upcoming CPU up and then delegates the rest of the + * online bringup to the hotplug thread. */ void cpuhp_online_idle(enum cpuhp_state state) { @@ -1059,6 +1058,12 @@ void cpuhp_online_idle(enum cpuhp_state state) if (state != CPUHP_AP_ONLINE_IDLE) return; + /* + * Unpart the stopper thread before we start the idle loop (and start + * scheduling); this ensures the stopper task is always available. + */ + stop_machine_unpark(smp_processor_id()); + st->state = CPUHP_AP_ONLINE_IDLE; complete_ap_thread(st, true); } -- 2.20.1