Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3740409ybb; Mon, 23 Mar 2020 06:52:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuD6I0pNmVLFFt527WJSJWX+hymVzpw962d7DD5ntf+VY/CFyD+A453hyt3OpGa8oWJhYpz X-Received: by 2002:aca:c209:: with SMTP id s9mr2545742oif.131.1584971527447; Mon, 23 Mar 2020 06:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584971527; cv=none; d=google.com; s=arc-20160816; b=u1d15nLCJjTlRdpf7RdqHtHW5NnIejFtr2FSlgd7MxBRm/Usj4ZndeKoZor3drRvsX jFvhhqGM977SqtDAGqyJqG27+sCHEUQw99PVwhkEnx011SZ1GoO0FtOW1nDE4a41NjK1 B+BHy8D6+lgFDdzOkWu0Uy+OIvw5zfkRDGWAs2ewUIFmr+WVrdP01prDls7mpwZPOhmm 6OsABlnYGtb1XI+6ZYUZ06reiKDZ5DtpNlHO1yv1ATubL+jKI5sQ7M8ThqLjCmzjLZvK Snql6nK9U1bhev3Ajsp8YSP7lZcJgFkFjbV5shUn2OMRovD4EYGwLkVSXqQjOaE5VRz2 8H8Q== 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=oWouM1bKdUDyhL2sfNC3Z+IiBgF6THd6qTLF1+5p+l5D+eHlSbKE3w0N1IXuxRVaIJ gBelknIf7acih7xNdyVwEnXgaveBuxEPnuiqyNHBXkY4E96szB2M7cSDjIgwu43ynvvT hVi+bcHlilNalhsvbjjG5PykI3AIznECl2Tzd4hJwElnsB7f4UXvGKteNLexVJdZ/7D3 1Bud9pr3rh/IG4Rp1S2yc+Q5y1BZeULYfNtUzD+99bK3h+61vDGcoDT5dU7j1zfilIQv 16X0TfNZGWZmJOYtdVTeOQxnuoj9XMD5rYKBPGjuDzsDVWW3cg57EdDR1HyX3FAOshKd GTyw== 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 d8si8242193oti.306.2020.03.23.06.51.54; Mon, 23 Mar 2020 06:52:07 -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; 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 S1728578AbgCWNva (ORCPT + 99 others); Mon, 23 Mar 2020 09:51:30 -0400 Received: from foss.arm.com ([217.140.110.172]:49456 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728423AbgCWNv3 (ORCPT ); Mon, 23 Mar 2020 09:51:29 -0400 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 EDC941FB; Mon, 23 Mar 2020 06:51:28 -0700 (PDT) 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 6EFA53F52E; Mon, 23 Mar 2020 06:51:26 -0700 (PDT) From: Qais Yousef To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, 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 Subject: [PATCH v4 02/17] smp: Create a new function to shutdown nonboot cpus Date: Mon, 23 Mar 2020 13:50:55 +0000 Message-Id: <20200323135110.30522-3-qais.yousef@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323135110.30522-1-qais.yousef@arm.com> References: <20200323135110.30522-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