Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1641062ybv; Fri, 21 Feb 2020 00:50:43 -0800 (PST) X-Google-Smtp-Source: APXvYqxSIa5sdXWLBJhU4FjiNS3zufb5okKPcYTLAmPMOLVu9NXII0kzjMi+a3stTZw4sApeNBIB X-Received: by 2002:aca:b703:: with SMTP id h3mr1083273oif.148.1582275043400; Fri, 21 Feb 2020 00:50:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582275043; cv=none; d=google.com; s=arc-20160816; b=YTsOIe1SLqsudnQdBkDkqW5xnJ3ajQ+/6ZAxGCCW81x1y5WG9s3ywaF5ePH4KiIVqq AYb2t1qyAYQUe/lIO7kVOWMF/wlyuagSf2Y4rB88VEJCTps1oBf16A3Jp2dWle50yh8u I6zCMV6UY5YUQK/TG32gXLxHNLTs8rFzAsJhQEReroWIdfo11gNUx4pZU5VA5LPZ6JZm ou06UKI00c1GgSR+WLjyOSgpLnNBItcgdjaCjXMNR+Nr7R+cdjnalR031OG5PaIKV93q WV1HcmxeexRWZH4q0mtupEerruprxHR3N1YejFDTjclkvERtvcQJemqyKcwhf9yPAgDx nK+w== 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=GvcL5WxkH8X6G0ZNzhoTPJnkeYzoZv3iTDCyTbnjSSM=; b=Aep8uj1PwoVKFc3o0sKOcbrzNPCqy/Gr5OwufgI+qvsWjaX6IT9h+KdNvnDzAX18f5 KHli4DkXQsRk6ivEqV2wJuYp8IAoi6DPvCRYTtLCCm4DiT9FzGF4zVx9IW5fhFUWaflb sNgkmJggrCeCtoHsT8E7F3lkVwMgjBcjmRA3P2kchXKNA+H6AMaRQTiGUBEgzmWlnCL1 zCI4Zw63aLR45Mmj2Umtlo7BQBsB95gxlgqysBdMXQO2aNIKLB3nUZuwxAowVJyMhqcI /hX6Ok2+9kGAQe9sZkSzHEcKLW6kP3E1qe2RsXJs4E06NTe0VwN/jMbMAIL6kR1d6Oo6 QuFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=usr6CPVe; 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 l139si505645oih.233.2020.02.21.00.50.31; Fri, 21 Feb 2020 00:50:43 -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=usr6CPVe; 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 S1727926AbgBUHoW (ORCPT + 99 others); Fri, 21 Feb 2020 02:44:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbgBUHoT (ORCPT ); Fri, 21 Feb 2020 02:44:19 -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 BFBA52465D; Fri, 21 Feb 2020 07:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271058; bh=2zzEizZPgz3jQw2F25+EGzqeylL8hud7mBY/PTOc2w4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usr6CPVeOwJnaaAWqMEgbTqEOXxqGWna/QDhUk4zldh4/L7ARdjJ6dkoBVvXNvmss mzowhHIag5kK5ZHPdcxy0K6WBaky7cL82N2jRn3/IbXEBDfBJRPKbCuLpahoFt/zUI +/rWqMCOn+0Myo+fVg0lJgtbKzNJbd6eIHRk0FKE= 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 5.5 023/399] cpu/hotplug, stop_machine: Fix stop_machine vs hotplug order Date: Fri, 21 Feb 2020 08:35:48 +0100 Message-Id: <20200221072404.603207525@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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 4dc279ed3b2d7..9c706af713fbc 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -525,8 +525,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); /* @@ -1089,8 +1088,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) { @@ -1100,6 +1099,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