Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1644071ybv; Sun, 23 Feb 2020 11:31:40 -0800 (PST) X-Google-Smtp-Source: APXvYqy3TgJc/0TDxFNHb+AJ9blffDCJdVzljvzRSWHL0A5UTvTYBrz3Og2ee/RXXtTNpkccZm8+ X-Received: by 2002:aca:cf07:: with SMTP id f7mr10177097oig.5.1582486300300; Sun, 23 Feb 2020 11:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582486300; cv=none; d=google.com; s=arc-20160816; b=vopFOpSJ1k7KGd1WDEy91vGaxNfz+4h0oaz+XZVOOKm0RbrY2UnVCHxWeM0IqrgwFx LOgNFLt0ibLCZT8DvZDRR53VC5VXPAkYDNEq1kWw8Q4NTjUui/iBkzs4nPPVVwikP6Ed W7p2UBPAAz15ZycpHPd27PYGelG9giB2nL2yQlHYbjhUPkb9WG7aRbji150BpEXXlURH Ii7GvIxyO3GNzxbkiXn3e6HIFZpNmxD86Kz4jTSGqcx++V1lSq3KOlO/iQrLQe323ANq F01FrZN3virZWyMctJ5CNP7gEmRHLVo3z+J25j0YvmzmcacD/6kR3c8OlNXxNuFm7L+6 CNZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=uZByXQ6lh/bFRWYWwNlP7ohBD8PMBB2p9x3kgpURzjk=; b=phm5NSs3FEIi19cAqzmJTwewelXjQ1qDlKmhMEOuUFFADisFXhEHTc2/mqeTnudT30 RQP9gEKfaiHemY8OxFCWMPCvoSU+r08z+FmUO9xfvRMmX4UpKKqvAy33n0kySxALV9hF 6KL0rh3hnhpngh12nS/8e8wRq14Lw6l1RxHi/j4vskonmaK3zWpIK5vAcoultb2CPlEJ JQ5ZFIa+ci1yXtzLNACdRPwYCzuBSBwYqLZHGfZgZC5dUlLxr8F7fqqZQfnpZPWinXk2 aCXuPEDG+0JpSuvNquLPzVNps7agv1GiwSH8xDLDMIAuC5CLhnl8+TP/30hF4iHtdQ09 Kw+g== ARC-Authentication-Results: i=1; mx.google.com; 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 193si3643595oie.51.2020.02.23.11.31.28; Sun, 23 Feb 2020 11:31:40 -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; 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 S1727159AbgBWT36 (ORCPT + 99 others); Sun, 23 Feb 2020 14:29:58 -0500 Received: from foss.arm.com ([217.140.110.172]:51280 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgBWT36 (ORCPT ); Sun, 23 Feb 2020 14:29:58 -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 19161106F; Sun, 23 Feb 2020 11:29:57 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 739D33F6CF; Sun, 23 Feb 2020 11:29:54 -0800 (PST) From: Qais Yousef To: Thomas Gleixner Cc: "Paul E . McKenney" , Qais Yousef , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Jiri Kosina , Nicholas Piggin , Daniel Lezcano , Ingo Molnar , Eiichi Tsukata , Zhenzhong Duan , Nadav Amit , Greg Kroah-Hartman , "Rafael J. Wysocki" , Tony Luck , Fenghua Yu , Russell King , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/15] smp: Create a new function to shutdown nonboot cpus Date: Sun, 23 Feb 2020 19:29:29 +0000 Message-Id: <20200223192942.18420-3-qais.yousef@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200223192942.18420-1-qais.yousef@arm.com> References: <20200223192942.18420-1-qais.yousef@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function will be used later in machine_shutdown() for some archs. disable_nonboot_cpus() is not safe to use when doing machine_down(), because it relies on freeze_secondary_cpus() which in turn is a suspend/resume related freeze and could abort if the logic detects any pending activities that can prevent finishing the offlining process. Signed-off-by: Qais Yousef CC: Thomas Gleixner CC: Josh Poimboeuf CC: "Peter Zijlstra (Intel)" CC: Jiri Kosina CC: Nicholas Piggin CC: Daniel Lezcano CC: Ingo Molnar CC: Eiichi Tsukata CC: Zhenzhong Duan CC: Nadav Amit CC: Greg Kroah-Hartman CC: "Rafael J. Wysocki" CC: Tony Luck CC: Fenghua Yu CC: Russell King CC: Catalin Marinas CC: Will Deacon CC: linux-arm-kernel@lists.infradead.org CC: linux-ia64@vger.kernel.org CC: linux-kernel@vger.kernel.org --- include/linux/cpu.h | 2 ++ kernel/cpu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/linux/cpu.h b/include/linux/cpu.h index cf8cf38dca43..64a246e9c8db 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -120,6 +120,7 @@ extern void cpu_hotplug_enable(void); void clear_tasks_mm_cpumask(int cpu); int cpu_down(unsigned int cpu); int remove_cpu(unsigned int cpu); +extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu); #else /* CONFIG_HOTPLUG_CPU */ @@ -131,6 +132,7 @@ static inline int cpus_read_trylock(void) { return true; } static inline void lockdep_assert_cpus_held(void) { } static inline void cpu_hotplug_disable(void) { } static inline void cpu_hotplug_enable(void) { } +static inline void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { } #endif /* !CONFIG_HOTPLUG_CPU */ /* Wrappers which go away once all code is converted */ diff --git a/kernel/cpu.c b/kernel/cpu.c index 069802f7010f..03c727195b65 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1069,6 +1069,48 @@ int remove_cpu(unsigned int cpu) } EXPORT_SYMBOL_GPL(remove_cpu); +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) +{ + unsigned int cpu; + int error; + + cpu_maps_update_begin(); + + /* + * Make certain the cpu I'm about to reboot on is online. + * + * This is inline to what migrate_to_reboot_cpu() already do. + */ + if (!cpu_online(primary_cpu)) + primary_cpu = cpumask_first(cpu_online_mask); + + for_each_online_cpu(cpu) { + if (cpu == primary_cpu) + continue; + + error = cpu_down_maps_locked(cpu, CPUHP_OFFLINE); + if (error) { + pr_err("Failed to offline CPU%d - error=%d", + cpu, error); + break; + } + } + + /* + * Ensure all but the reboot CPU are offline. + */ + BUG_ON(num_online_cpus() > 1); + + /* + * Make sure the CPUs won't be enabled by someone else after this + * point. Kexec will reboot to a new kernel shortly resetting + * everything along the way. + */ + cpu_hotplug_disabled++; + + cpu_maps_update_done(); +} + #else #define takedown_cpu NULL #endif /*CONFIG_HOTPLUG_CPU*/ -- 2.17.1