From nobody Sun May 10 09:53:42 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C7A7C433F5 for ; Mon, 9 May 2022 04:23:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbiEIE04 (ORCPT ); Mon, 9 May 2022 00:26:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234262AbiEIERW (ORCPT ); Mon, 9 May 2022 00:17:22 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFEEF119231 for ; Sun, 8 May 2022 21:13:28 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d22so12696656plr.9 for ; Sun, 08 May 2022 21:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1JuimxFJZooT8f2Q6NkZ9f5I0ZgYX0YbblE3FHMmMBk=; b=qIr3y8xaiABqjUdW/TFHLdQ/U+nIycklpviv7Lt2ehDkyuK+ZbETlYJTfeOWWmp/Bc sF/RZu0mx82VCh8FVJmlyWed5PhBjg3zicl3m02iClay6AqMJ4Sv3akZ8mKV1m12129P IwzdMz3q+IfnC8byavEccOp3FHYTuLuCMxF/DK8wS4pZ/JF/i+4tJ0/oADvbjRDX/ACc HjVW6fwR3ElhCgj5QCGSkNXnwuU22lqkBnXCrN8Wn85i1RlolIPU3D0RHSQkGyAC7Kup yh6ALWZ2VWYB8KNEzXT58SAjs5NwyqxWyvT0QbOlNhZsi2Ld2A6jErGFR31nQ4b3jEn6 sS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1JuimxFJZooT8f2Q6NkZ9f5I0ZgYX0YbblE3FHMmMBk=; b=5HYxDilvI3MAWDJ/SiWe+6BeqI07bUpjo+1okfmiOqr84U6zyIZ4jrgFJJF06srWrE maUlko2Y8BK5ZONwuMfLYvS9nG2SgSuUf/iOXUvJZFVhNgtxWHgj5bTdf94LiiduAuBS z2z59ej1lkho3nADX+JSLOvBK+7QWSS1zeYCOjhVV/zCt4Fa2lQxCHv7pSN9zt+mfeN9 hc/YGqejz3BUdHK7GJj+N0a5G6DJ+xwdlj9XVFr9j1k0505zkOcrWZ2/ZaNrPOVNYOao pYDN1S8kSdpT47C+dLG5cQyzPqN9GryrSCBhX5SsDEKAcs5AV1xvZtbIbZce3USjvBTZ Am/A== X-Gm-Message-State: AOAM5336pi8m5w7XZ91WN4SIr0B8rBH9n68r5KJzHMxNIrgA7Nj68CvE 9/+cLENTwc8MasK1BFmzzlZaAvQmZA== X-Google-Smtp-Source: ABdhPJxXBvvMk5ErpUETnMRmV2cb02nFaqWmb4dkcblP0/r/a8hqFiGGAhO1EPZVe8bfY2R62BNvww== X-Received: by 2002:a17:902:a585:b0:14d:58ef:65 with SMTP id az5-20020a170902a58500b0014d58ef0065mr14472907plb.139.1652069606480; Sun, 08 May 2022 21:13:26 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19-20020a17090a7f9300b001cd60246575sm11478545pjl.17.2022.05.08.21.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:13:25 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Eric Biederman , Peter Zijlstra , Thomas Gleixner , Valentin Schneider , Vincent Donnefort , Ingo Molnar , Mark Rutland , YueHaibing , Baokun Li , Randy Dunlap , Baoquan He , kexec@lists.infradead.org Subject: [PATCHv3 1/2] cpu/hotplug: Keep cpu hotplug disabled until the rebooting cpu is stable Date: Mon, 9 May 2022 12:13:04 +0800 Message-Id: <20220509041305.15056-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220509041305.15056-1-kernelfans@gmail.com> References: <20220509041305.15056-1-kernelfans@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The following code chunk repeats in both migrate_to_reboot_cpu() and smp_shutdown_nonboot_cpus(): if (!cpu_online(primary_cpu)) primary_cpu =3D cpumask_first(cpu_online_mask); This is due to a breakage like the following: kernel_kexec() migrate_to_reboot_cpu(); cpu_hotplug_enable(); -----------> comes a cpu_down(this_cpu) on other cpu machine_shutdown(); smp_shutdown_nonboot_cpus(); // re-check "if (!cpu_online(primary_cpu)= )" to protect against the former breakin Although the kexec-reboot task can get through a cpu_down() on its cpu, this code looks a little confusing. Make things straight forward by keeping cpu hotplug disabled until smp_shutdown_nonboot_cpus() holds cpu_add_remove_lock. By this way, the breakage is squashed out and the rebooting cpu can keep unchanged. Note: this patch only affects the kexec-reboot on arches(arm/arm64/ia64/ris= cv) , which rely on the cpu hot-removing mechanism. Signed-off-by: Pingfan Liu Cc: Eric Biederman Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Valentin Schneider Cc: Vincent Donnefort Cc: Ingo Molnar Cc: Mark Rutland Cc: YueHaibing Cc: Baokun Li Cc: Randy Dunlap Cc: Valentin Schneider Cc: Baoquan He Cc: kexec@lists.infradead.org To: linux-kernel@vger.kernel.org --- kernel/cpu.c | 16 ++++++++++------ kernel/kexec_core.c | 10 ++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index d0a9aa0b42e8..bf901fc90329 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1228,20 +1228,24 @@ int remove_cpu(unsigned int cpu) } EXPORT_SYMBOL_GPL(remove_cpu); =20 +/* primary_cpu keeps unchanged after migrate_to_reboot_cpu() */ void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { unsigned int cpu; int error; =20 + /* + * Block other cpu hotplug event, so primary_cpu is always online if + * it is not touched by us + */ 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. + * migrate_to_reboot_cpu() disables CPU hotplug assuming that + * no further code needs to use CPU hotplug (which is true in + * the reboot case). However, the kexec path depends on using + * CPU hotplug again; so re-enable it here. */ - if (!cpu_online(primary_cpu)) - primary_cpu =3D cpumask_first(cpu_online_mask); + __cpu_hotplug_enable(); =20 for_each_online_cpu(cpu) { if (cpu =3D=3D primary_cpu) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 68480f731192..db4fa6b174e3 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1168,14 +1168,12 @@ int kernel_kexec(void) kexec_in_progress =3D true; kernel_restart_prepare("kexec reboot"); migrate_to_reboot_cpu(); - /* - * migrate_to_reboot_cpu() disables CPU hotplug assuming that - * no further code needs to use CPU hotplug (which is true in - * the reboot case). However, the kexec path depends on using - * CPU hotplug again; so re-enable it here. + * migrate_to_reboot_cpu() disables CPU hotplug. If an arch + * relies on the cpu teardown to achieve reboot, it needs to + * re-enable CPU hotplug there. */ - cpu_hotplug_enable(); + pr_notice("Starting new kernel\n"); machine_shutdown(); } --=20 2.31.1 From nobody Sun May 10 09:53:42 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 080B8C433EF for ; Mon, 9 May 2022 04:23:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbiEIEZv (ORCPT ); Mon, 9 May 2022 00:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234349AbiEIER2 (ORCPT ); Mon, 9 May 2022 00:17:28 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34FD088F66; Sun, 8 May 2022 21:13:36 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id j10-20020a17090a94ca00b001dd2131159aso762638pjw.0; Sun, 08 May 2022 21:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yvzilvcidt0cy/+jVulM8s/ugqFP0eQunNYQSTfNZQQ=; b=VZlRW/We3EYhQtPGSwiA+/E8SQ9csMkZggbJQP8bDq93RAzZfEkKLiToa0CrYo2R6b Bw9GHO8xdQXPauGeSSZShZ6AcW0osz6zXk11mNUkJ7Zr22PeMHXZRYXR1A0AUoKsFmIG WRcIwZLmoMapXgqfsjRadkRfgdZ994AOY3pKiQ/LhphFBkKpGHvzrqGyFFNzacgFcgv9 uv40xCxir9ojG5hLanVpmtkP3lz5d+JtaVNDHwrsuyWt1ZCckRsmgry7staku/ADL/Bd 515bJtdiGHxIpP1ShGIxCTpusBl39fvK2BUfdMfgXmJOsqCL5A1sEiJGAp9grbq7gYln faZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yvzilvcidt0cy/+jVulM8s/ugqFP0eQunNYQSTfNZQQ=; b=FmzlQAfzplFU6tEFtYamjR9pXEChRGC/yKJRkpZprGAJygwRPKe58iG13nFPRtD3/B ASTwy7SQv2HSCTEewVuhpGt/89E6oRdn+f9HPp362+0YVd332TDAH8NHGye/BQDCYYFJ eNIEa0xb59t/CDdf2nIzj5a68OCz0oaJiCJywV0u+jnygAHgUht2g1sYFdnIhY2Zf2jQ pNaaP0HQiZRB3ckrsUz7LbebgcQMsW43uMkNJLruLxXKYQNol4dR6Cl8XaXcl73xYAro IPPqoY/5DigP05TlXArx4d4F9XrUa1Thah/laOlcAXkjCGrDAHf/XjS8DilR5xv71OVT KZbw== X-Gm-Message-State: AOAM5324V8Wl7PLeBcYjfdiHbUjTqBwrZPXi681uEvIbGPNyTHvDTHEr 5eMST2xlL3OXdGNuVFmZ4hVRWSloQg== X-Google-Smtp-Source: ABdhPJznFnzsSty9FB+peqx2+50gFD+ELmjTouVakza/raAO/f8MAY9hh3Kmuhr15ajevdFC9iJDXA== X-Received: by 2002:a17:902:d487:b0:15e:a0a4:69e3 with SMTP id c7-20020a170902d48700b0015ea0a469e3mr14746513plg.155.1652069613718; Sun, 08 May 2022 21:13:33 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19-20020a17090a7f9300b001cd60246575sm11478545pjl.17.2022.05.08.21.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:13:33 -0700 (PDT) From: Pingfan Liu To: linux-ia64@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Geert Uytterhoeven , Peter Zijlstra , Kees Cook , Jens Axboe , Russell King , Guenter Roeck , Arnd Bergmann , Wolfram Sang , Lee Jones , Catalin Marinas , Will Deacon , Mark Rutland , Peter Collingbourne , Marc Zyngier , linux-kernel@vger.kernel.org Subject: [PATCHv3 2/2] arm/arm64/ia64: kexec: fix the primary cpu passed to smp_shutdown_nonboot_cpus() Date: Mon, 9 May 2022 12:13:05 +0800 Message-Id: <20220509041305.15056-3-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220509041305.15056-1-kernelfans@gmail.com> References: <20220509041305.15056-1-kernelfans@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kernel_kexec()->migrate_to_reboot_cpu() has already pinned the reboot thread on a valid online cpu, either reboot_cpu or the first online cpu. So machine_shutdown() should pass smp_processor_id() of the pinned thread as the primary cpu to smp_shutdown_nonboot_cpus(). Signed-off-by: Pingfan Liu Cc: Geert Uytterhoeven Cc: Peter Zijlstra Cc: Kees Cook Cc: Jens Axboe To: linux-ia64@vger.kernel.org Cc: Russell King Cc: Guenter Roeck Cc: Arnd Bergmann Cc: Wolfram Sang Cc: Lee Jones Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Peter Zijlstra Cc: Peter Collingbourne Cc: Marc Zyngier To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- arch/arm/kernel/reboot.c | 2 +- arch/arm64/kernel/process.c | 2 +- arch/ia64/kernel/process.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/reboot.c b/arch/arm/kernel/reboot.c index 3044fcb8d073..898405682e08 100644 --- a/arch/arm/kernel/reboot.c +++ b/arch/arm/kernel/reboot.c @@ -91,7 +91,7 @@ void soft_restart(unsigned long addr) */ void machine_shutdown(void) { - smp_shutdown_nonboot_cpus(reboot_cpu); + smp_shutdown_nonboot_cpus(smp_processor_id()); } =20 /* diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 7fa97df55e3a..e5c130582cc6 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -86,7 +86,7 @@ void arch_cpu_idle_dead(void) */ void machine_shutdown(void) { - smp_shutdown_nonboot_cpus(reboot_cpu); + smp_shutdown_nonboot_cpus(smp_processor_id()); } =20 /* diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c index d7a256bd9d6b..ae732e35e7da 100644 --- a/arch/ia64/kernel/process.c +++ b/arch/ia64/kernel/process.c @@ -575,7 +575,7 @@ cpu_halt (void) =20 void machine_shutdown(void) { - smp_shutdown_nonboot_cpus(reboot_cpu); + smp_shutdown_nonboot_cpus(smp_processor_id()); =20 #ifdef CONFIG_KEXEC kexec_disable_iosapic(); --=20 2.31.1