Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1161677iob; Thu, 12 May 2022 12:35:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwuphLA6CMet3wnFpyfoXEArSQ/drRiH54+WpJY/Id2F597JhrSwALBGszWZwdNoPbqtoz X-Received: by 2002:a17:907:72d0:b0:6f5:108c:a34 with SMTP id du16-20020a17090772d000b006f5108c0a34mr1281638ejc.218.1652384115672; Thu, 12 May 2022 12:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652384115; cv=none; d=google.com; s=arc-20160816; b=UPeR8T61OD/tTbgG3csZnq0QQd8GC75/kv4pLylGngfIAcSwFWbn57bTO+GWyo7ptC WQavx2IUnc8AtqK+mwCAecUWqY4A795GvAoOSbqNVu2fQXSHdLNrEDFihqGzxQhww8UB nrGIEPJLrBEx5O9fFk7qRxhlPBQ7rj1axAOFmfCJ0JI/ngT80aGyK5HzLZHIzba7zz7W IAWBc4WuI5m+xl4xvOJ1i7ZUEuBNUfKmBgDitj9lfc7CqditCEGm4s5UVsuNLyr/DltL ZCKnbK5bRbJoS/WjvBxfWeAan+dTzSjxbETqRBCN9d9DcMn9ysjEbQtU9ZfvZzgKo6hw /65g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1zm77XuKLZiFKCTXff9/DZf2N76nza4knTVrJw3dY7k=; b=gpxOB/CLRGE+Lv4gyzSPx/GqUB1Htu0tGOEIbZCuB+G+bQwFesvGoYZwJ+fyz4YWlG Z+5J8zY1EU9rBO3NE/wGwkj+pqLGJCOovAEZ5C5pNDOY/pSTwYY5qAmeOBYDkx+gvrG7 jR9YELRhGX0Umb7Ig5uZI63nx7ajubzJwigvhwaRt8t/c33qkMexMBxtzxatGVO/oF+g HL870gVQ5c+aFLYV+LE6yXqB3dfj085zNyuoiIIyAc2InKQfnqwXxG5i5+Y8e7B32E7M NFv+rlQ4WSMeyggNdMHQzQ1CVWCQyguzPaibGpUP+jIQrifwfCK4SX+AfRZp1R0YWVnF ld+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=d6ZqPlGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji15-20020a170907980f00b006df76385d54si182733ejc.500.2022.05.12.12.34.47; Thu, 12 May 2022 12:35:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=d6ZqPlGq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244634AbiELDGo (ORCPT + 99 others); Wed, 11 May 2022 23:06:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244437AbiELDGn (ORCPT ); Wed, 11 May 2022 23:06:43 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 364FF37A9F for ; Wed, 11 May 2022 20:06:42 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id g8so3608450pfh.5 for ; Wed, 11 May 2022 20:06:42 -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=1zm77XuKLZiFKCTXff9/DZf2N76nza4knTVrJw3dY7k=; b=d6ZqPlGqZU64GDD4AaDMtWZonPd74O6ETXNgB4PxggKQxFnT45BAv3MNchxszSGq7j ZhgXTpXcrDwIeX426COYuKuBgM/U+tU3IZHjmnoLieyXRgAEgKOcfGPzuzD8RbXISyrB 82Pv0j/XIdHrQcdb32iFTjuE3h0ZSXGAE70DG3fpOdgp+OfwiYhxEUDaSLPLrq4lnt3Q Wq2TOJMTTlT0tBFZDbXRkdNJRYiCvheTmW131DugG073TzojAiGVGKX/RZWgrlu888Vr +LfMfKsgmleZ62f3O9ve2rXuyFTi/XbyEp80vqt4Ti/jOdPpFTaLUjOENmIBTfGI67Kh 18aA== 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=1zm77XuKLZiFKCTXff9/DZf2N76nza4knTVrJw3dY7k=; b=lmHVTNQnYYp1yg1GCUtSU1cW8Q0RSpL4+B6uwC45isS3kLpPNP6aL0IkgXtrsRn4zf LyhRv30vGTnzRtgKcZlwbwOE5ra3GoiNF971MU4ZXrnc1oox5bKLOkM2etj1vtN435JW cUfW/ozu83ReeXHyc6NM4uXslj+hQ8BndFsA2UynTCtwKjNwPOJ20WFUifZhxxWBV2qY GrQdxgJzoE3Mhd3ofmQdi/lCe+makLMKKV40zrryOmNo2Rtu0MROyCQbtpVvSyLjSyft W/vNkYRv2vXtapxU2KYDgxwEmvuvFs43Dc5kthQQUyW28+nMf5y2X6nFS5bfT+Bq3LR7 orIQ== X-Gm-Message-State: AOAM532PAZjG8c6CPIz1sKGXm0UFhT7LbPB35UY79f/ZOKds9NNqW3fv TWPkX9i++ed6BNjqI6/CHw== X-Received: by 2002:a62:7994:0:b0:4e1:58c4:ddfd with SMTP id u142-20020a627994000000b004e158c4ddfdmr9287569pfc.65.1652324801708; Wed, 11 May 2022 20:06:41 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e13-20020aa7980d000000b0050dc762815bsm2488162pfl.53.2022.05.11.20.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 20:06:41 -0700 (PDT) From: Pingfan Liu To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Eric Biederman , Peter Zijlstra , Thomas Gleixner , Vincent Donnefort , Ingo Molnar , Michael Ellerman , Mark Rutland , YueHaibing , Baokun Li , Randy Dunlap , Valentin Schneider , kexec@lists.infradead.org Subject: [PATCHv4 1/2] cpu/hotplug: Keep cpu hotplug disabled until the rebooting cpu is stable Date: Thu, 12 May 2022 11:06:18 +0800 Message-Id: <20220512030619.13426-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220512030619.13426-1-kernelfans@gmail.com> References: <20220512030619.13426-1-kernelfans@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org smp_shutdown_nonboot_cpus() repeats the same code chunk as migrate_to_reboot_cpu() to ensure that the rebooting happens on a valid cpu. if (!cpu_online(primary_cpu)) primary_cpu = cpumask_first(cpu_online_mask); This is due to an unexpected cpu-down event 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(); which needs to re-check "if (!cpu_online(primary_cpu))" Although the kexec-reboot task can get through a cpu_down() on its cpu, this code looks a little confusing. Tracing down the git history, the cpu_hotplug_enable() called by kernel_kexec() is introduced by commit 011e4b02f1da ("powerpc, kexec: Fix "Processor X is stuck" issue during kexec from ST mode"), which wakes up all offline cpu by cpu_up(cpu). Later, it is required by the architectures(arm/arm64/ia64/riscv) which resort to cpu hot-removing to achieve kexec-reboot by smp_shutdown_nonboot_cpus()->cpu_down_maps_locked(). Hence, the cpu_hotplug_enable() in kernel_kexec() is an architecture requirement. By deferring the cpu hotplug enable to a more proper point, where smp_shutdown_nonboot_cpus() holds cpu_add_remove_lock, the unexpected cpu-down event is squashed out and the rebooting cpu can keep unchanged. (For powerpc, no gains from this change.) As a result, the repeated code chunk can be removed and in [2/2], the callsites of smp_shutdown_nonboot_cpus() can be consistent. Signed-off-by: Pingfan Liu Cc: Eric Biederman Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Vincent Donnefort Cc: Ingo Molnar Cc: Michael Ellerman Cc: Mark Rutland Cc: YueHaibing Cc: Baokun Li Cc: Randy Dunlap Cc: Valentin Schneider Cc: kexec@lists.infradead.org To: linuxppc-dev@lists.ozlabs.org To: linux-kernel@vger.kernel.org --- arch/powerpc/kexec/core_64.c | 1 + kernel/cpu.c | 10 +++++----- kernel/kexec_core.c | 11 +++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c index 6cc7793b8420..8ccf22197f08 100644 --- a/arch/powerpc/kexec/core_64.c +++ b/arch/powerpc/kexec/core_64.c @@ -224,6 +224,7 @@ static void wake_offline_cpus(void) static void kexec_prepare_cpus(void) { + cpu_hotplug_enable(); wake_offline_cpus(); smp_call_function(kexec_smp_down, NULL, /* wait */0); local_irq_disable(); diff --git a/kernel/cpu.c b/kernel/cpu.c index d0a9aa0b42e8..4415370f0e91 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1236,12 +1236,12 @@ void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) 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. + * At this point, the cpu hotplug is still disabled by + * migrate_to_reboot_cpu() to guarantee that the rebooting happens on + * the selected CPU. But cpu_down_maps_locked() returns -EBUSY, if + * cpu_hotplug_disabled. So re-enable CPU hotplug here. */ - if (!cpu_online(primary_cpu)) - primary_cpu = cpumask_first(cpu_online_mask); + __cpu_hotplug_enable(); for_each_online_cpu(cpu) { if (cpu == primary_cpu) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 68480f731192..1bd5a8c95a20 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1168,14 +1168,13 @@ int kernel_kexec(void) kexec_in_progress = 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 and pin the + * rebooting thread on the selected CPU. If an architecture + * requires CPU hotplug to achieve kexec reboot, it should + * enable the hotplug in the architecture specific code */ - cpu_hotplug_enable(); + pr_notice("Starting new kernel\n"); machine_shutdown(); } -- 2.31.1