From nobody Fri Apr 10 17:13:29 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 4F2BCC00140 for ; Mon, 22 Aug 2022 02:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbiHVCPx (ORCPT ); Sun, 21 Aug 2022 22:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232345AbiHVCPi (ORCPT ); Sun, 21 Aug 2022 22:15:38 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E84BF1ADB4 for ; Sun, 21 Aug 2022 19:15:37 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id f4so6336403pgc.12 for ; Sun, 21 Aug 2022 19:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=x9NaAeROHZ7LhGtDm+xAwRDta8yhQJ2bsdPkhebtaWw=; b=pMEHVg3KR0sN9NGoqjvIgRr6fD7XlQcRjsdBCXfbEFn4iPueTdqI39iongNLewhgZm 5Yl9Ix74qU/T2+HSYgmP5ZGBWOXYyxLBrBu/xr5O+ZfIQm1eBlhkQmCqNc5pRV4+iFec qJ/j5OCOCVKJbTmJm3l+1277BSCQ1B35i6/jvE+1S7o8WcZSHxPZRsHogWF7JqhkWXXJ kwdXYEX5ialtSx7SQgWrrvKOqG+XKcs+0ERhl9H0ViTXR+skSQfZPfFfjMLGFZikdL1L XIsyCNvBBYDIx+nQJy5sBAx6RMg4PzcXHRgdEoGcBARFp0TViruF7MiMk/KeO5nLndT/ ne1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=x9NaAeROHZ7LhGtDm+xAwRDta8yhQJ2bsdPkhebtaWw=; b=yYNP05iGrF+p3oUK9EOavAht8vwSPj9B2128O+ic9Z2BXF1fZkg8sOISmumhLUTaRf fU2bJeoDKX3l8BQ88/S34UOuEmwG3GZMDLF8dqLps1gy+MCzP6Sjde2+sH1mNaKnWZ0i eDDS/d4G0KKrcDDKq2TWI26lYhELRhsLPkHYcnt7UUWfJaa+7BXAwXxv5psCz+C/cfBk JLelQboHY1pt/knUun7rZ2D2aHpZMVZ4D3VkaiAZ7UStSXG3pEz0l0AOu7gEPHnXugyw QDLfN9VhVmOyX6Cnv6KpBYM6IgkJoxQuWRdRYQ6LDRM2avTc5xfMoNiky5MmbVk3hnuR uf2w== X-Gm-Message-State: ACgBeo2DGuGKwnSytE1EhkvywG4fX76flTqLK1iqajNqFWVl1fmlVMOn 7AM/7QXefUex7khI+AbTBWPpE79j8g== X-Google-Smtp-Source: AA6agR7RX6fx2qhb0rc0+ZwauaxrA5pmHSuMao+E6pjhPa0oIdQZg0lPlRAGozGxhe9QjxOTvIsKcA== X-Received: by 2002:a63:4d65:0:b0:419:d6ae:27df with SMTP id n37-20020a634d65000000b00419d6ae27dfmr15477909pgl.179.1661134537236; Sun, 21 Aug 2022 19:15:37 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:15:36 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Thomas Gleixner , Steven Price , Andi Kleen , Frederic Weisbecker , "Jason A. Donenfeld" , Mark Rutland Subject: [RFC 01/10] cpu/hotplug: Make __cpuhp_kick_ap() ready for async Date: Mon, 22 Aug 2022 10:15:11 +0800 Message-Id: <20220822021520.6996-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" At present, during the kexec reboot, the teardown of cpus can not run in parallel. As the first step towards the parallel, it demands the initiator to kick ap thread one by one instead of waiting for each ap thread completion. Change the prototype of __cpuhp_kick_ap() to cope with this demand. Signed-off-by: Pingfan Liu Cc: Thomas Gleixner Cc: Steven Price Cc: "Peter Zijlstra Cc: Andi Kleen Cc: Frederic Weisbecker Cc: "Jason A. Donenfeld" Cc: Mark Rutland To: linux-kernel@vger.kernel.org --- kernel/cpu.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index bbad5e375d3b..338e1d426c7e 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -526,7 +526,7 @@ cpuhp_reset_state(int cpu, struct cpuhp_cpu_state *st, } =20 /* Regular hotplug invocation of the AP hotplug thread */ -static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st) +static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st, bool sync) { if (!st->single && st->state =3D=3D st->target) return; @@ -539,20 +539,22 @@ static void __cpuhp_kick_ap(struct cpuhp_cpu_state *s= t) smp_mb(); st->should_run =3D true; wake_up_process(st->thread); - wait_for_ap_thread(st, st->bringup); + if (sync) + wait_for_ap_thread(st, st->bringup); } =20 static int cpuhp_kick_ap(int cpu, struct cpuhp_cpu_state *st, - enum cpuhp_state target) + enum cpuhp_state target, bool sync) { enum cpuhp_state prev_state; int ret; =20 prev_state =3D cpuhp_set_state(cpu, st, target); - __cpuhp_kick_ap(st); - if ((ret =3D st->result)) { + __cpuhp_kick_ap(st, sync); + ret =3D st->result; + if (sync && ret) { cpuhp_reset_state(cpu, st, prev_state); - __cpuhp_kick_ap(st); + __cpuhp_kick_ap(st, true); } =20 return ret; @@ -583,7 +585,7 @@ static int bringup_wait_for_ap(unsigned int cpu) if (st->target <=3D CPUHP_AP_ONLINE_IDLE) return 0; =20 - return cpuhp_kick_ap(cpu, st, st->target); + return cpuhp_kick_ap(cpu, st, st->target, true); } =20 static int bringup_cpu(unsigned int cpu) @@ -835,7 +837,7 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state stat= e, bool bringup, st->cb_state =3D state; st->single =3D true; =20 - __cpuhp_kick_ap(st); + __cpuhp_kick_ap(st, true); =20 /* * If we failed and did a partial, do a rollback. @@ -844,7 +846,7 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state stat= e, bool bringup, st->rollback =3D true; st->bringup =3D !bringup; =20 - __cpuhp_kick_ap(st); + __cpuhp_kick_ap(st, true); } =20 /* @@ -868,12 +870,29 @@ static int cpuhp_kick_ap_work(unsigned int cpu) cpuhp_lock_release(true); =20 trace_cpuhp_enter(cpu, st->target, prev_state, cpuhp_kick_ap_work); - ret =3D cpuhp_kick_ap(cpu, st, st->target); + ret =3D cpuhp_kick_ap(cpu, st, st->target, true); trace_cpuhp_exit(cpu, st->state, prev_state, ret); =20 return ret; } =20 +/* In the async case, trace is meaningless since ret value is not availabl= e */ +static int cpuhp_kick_ap_work_async(unsigned int cpu) +{ + struct cpuhp_cpu_state *st =3D per_cpu_ptr(&cpuhp_state, cpu); + int ret; + + cpuhp_lock_acquire(false); + cpuhp_lock_release(false); + + cpuhp_lock_acquire(true); + cpuhp_lock_release(true); + + ret =3D cpuhp_kick_ap(cpu, st, st->target, false); + + return ret; +} + static struct smp_hotplug_thread cpuhp_threads =3D { .store =3D &cpuhp_state.thread, .thread_should_run =3D cpuhp_should_run, @@ -1171,7 +1190,7 @@ static int __ref _cpu_down(unsigned int cpu, int task= s_frozen, if (ret && st->state < prev_state) { if (st->state =3D=3D CPUHP_TEARDOWN_CPU) { cpuhp_reset_state(cpu, st, prev_state); - __cpuhp_kick_ap(st); + __cpuhp_kick_ap(st, true); } else { WARN(1, "DEAD callback error for CPU%d", cpu); } --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 55B69C00140 for ; Mon, 22 Aug 2022 02:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbiHVCP7 (ORCPT ); Sun, 21 Aug 2022 22:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiHVCPu (ORCPT ); Sun, 21 Aug 2022 22:15:50 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB562183E; Sun, 21 Aug 2022 19:15:48 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id f17so2876063pfk.11; Sun, 21 Aug 2022 19:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=1iHPy2MJm6s7J5XdJO/siHoKhzaKKWD/EXtuZwe5/AE=; b=mKi9In1cguwoEOIvsqd6r243Uwmb97pem6sMmVbQ/lX7DKmHGQ4Cz8u7NaUAMolab3 HmdgTa5cqnb+GfgxLAPvRC2VcgnhWhU/izaXxri5eH+EgDoV+6M0er9uK9apm/9k6Wa+ O6vWMuPgbVirYyTOwBORRtmkCs2pdpI1E3AlnfMY1g6INcFNsiY5OxCc+eK21YnW41W/ 9gNulkHUPIkdHnMs5921OdcrPwHgoXozCfdiUiIdwYospQ2cvraEremg4xnjuFFKYkFu gDjp9ye/aSfYYNx/jRfdI/eCYmQuHZst3at0UYKdKX8Agaty19wI93E6qRscBDPMtYU4 QtCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=1iHPy2MJm6s7J5XdJO/siHoKhzaKKWD/EXtuZwe5/AE=; b=gQurD7zt8PVEr+NP3mGn/+6k0tXJ5MoscnXNzSMiKmZmjLvPObX9wj+HlnsJ6trjLk OX41ToE2aDZVKgGEs3bys+Hg2aTOPMHl2zzs6mWB7gNN4q6AQwKhvS6RI90tJD9R0SeF ow9N0Ca1QaVm8epRdoPzpNIQWxKV8QHX7gTmFeENE/nZVTTLYI0cIp6zG6mCtBGVcEE8 dPhqmxExnHHPCP4976yoMkVwRqS+KP9/xMjAyqos5Z28PJk+KfND+aJGvNT5PQ5ih2oZ yPS+MDVl2R25+2orxw8XNxw3toaDZp6kCH1GJT5zRY49/bRq9T9F6A1Qmr9ReEzJt7iX X2tQ== X-Gm-Message-State: ACgBeo2kJuEgLbiLz49ddHiLK8xN8QT4y5GAbnitr65U0uOWBreuEewo mihkLZ80R09OCes07dQVcg== X-Google-Smtp-Source: AA6agR5RhOvnr+n8C+QckGvAPfLQPD+H4Z9Kyq6FS5FDBt09E1rsRMXpjGgfl8V7Hzvo18Hl1aKTcg== X-Received: by 2002:a63:ce06:0:b0:41d:dcc3:aa6e with SMTP id y6-20020a63ce06000000b0041ddcc3aa6emr15448270pgf.251.1661134548425; Sun, 21 Aug 2022 19:15:48 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:15:47 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Russell King , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , "Eric W. Biederman" , Mark Rutland , Marco Elver , Masami Hiramatsu , Dan Li , Song Liu , Sami Tolvanen , Arnd Bergmann , Linus Walleij , Ard Biesheuvel , Tony Lindgren , Nick Hawkins , John Crispin , Geert Uytterhoeven , Andrew Morton , Bjorn Andersson , Anshuman Khandual , Thomas Gleixner , Steven Price Subject: [RFC 02/10] cpu/hotplug: Compile smp_shutdown_nonboot_cpus() conditioned on CONFIG_SHUTDOWN_NONBOOT_CPUS Date: Mon, 22 Aug 2022 10:15:12 +0800 Message-Id: <20220822021520.6996-3-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" Only arm/arm64/ia64/riscv share the smp_shutdown_nonboot_cpus(). So compiling this code conditioned on the macro CONFIG_SHUTDOWN_NONBOOT_CPUS. Later this macro will brace the quick kexec reboot code. Signed-off-by: Pingfan Liu Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Peter Zijlstra Cc: "Eric W. Biederman" Cc: Mark Rutland Cc: Marco Elver Cc: Masami Hiramatsu Cc: Dan Li Cc: Song Liu Cc: Sami Tolvanen Cc: Arnd Bergmann Cc: Linus Walleij Cc: Ard Biesheuvel Cc: Tony Lindgren Cc: Nick Hawkins Cc: John Crispin Cc: Geert Uytterhoeven Cc: Andrew Morton Cc: Bjorn Andersson Cc: Anshuman Khandual Cc: Thomas Gleixner Cc: Steven Price To: linux-arm-kernel@lists.infradead.org To: linux-ia64@vger.kernel.org To: linux-riscv@lists.infradead.org To: linux-kernel@vger.kernel.org --- arch/Kconfig | 4 ++++ arch/arm/Kconfig | 1 + arch/arm64/Kconfig | 1 + arch/ia64/Kconfig | 1 + arch/riscv/Kconfig | 1 + kernel/cpu.c | 3 +++ 6 files changed, 11 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index f330410da63a..be447537d0f6 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -14,6 +14,10 @@ menu "General architecture-dependent options" config CRASH_CORE bool =20 +config SHUTDOWN_NONBOOT_CPUS + select KEXEC_CORE + bool + config KEXEC_CORE select CRASH_CORE bool diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 87badeae3181..711cfdb4f9f4 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -129,6 +129,7 @@ config ARM select PCI_SYSCALL if PCI select PERF_USE_VMALLOC select RTC_LIB + select SHUTDOWN_NONBOOT_CPUS select SYS_SUPPORTS_APM_EMULATION select THREAD_INFO_IN_TASK select HAVE_ARCH_VMAP_STACK if MMU && ARM_HAS_GROUP_RELOCS diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 571cc234d0b3..8c481a0b1829 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -223,6 +223,7 @@ config ARM64 select PCI_SYSCALL if PCI select POWER_RESET select POWER_SUPPLY + select SHUTDOWN_NONBOOT_CPUS select SPARSE_IRQ select SWIOTLB select SYSCTL_EXCEPTION_TRACE diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index 26ac8ea15a9e..8a3ddea97d1b 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -52,6 +52,7 @@ config IA64 select ARCH_CLOCKSOURCE_DATA select GENERIC_TIME_VSYSCALL select LEGACY_TIMER_TICK + select SHUTDOWN_NONBOOT_CPUS select SWIOTLB select SYSCTL_ARCH_UNALIGN_NO_WARN select HAVE_MOD_ARCH_SPECIFIC diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index ed66c31e4655..02606a48c5ea 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -120,6 +120,7 @@ config RISCV select PCI_MSI if PCI select RISCV_INTC select RISCV_TIMER if RISCV_SBI + select SHUTDOWN_NONBOOT_CPUS select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK diff --git a/kernel/cpu.c b/kernel/cpu.c index 338e1d426c7e..2be6ba811a01 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1258,6 +1258,8 @@ int remove_cpu(unsigned int cpu) } EXPORT_SYMBOL_GPL(remove_cpu); =20 +#ifdef CONFIG_SHUTDOWN_NONBOOT_CPUS + void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) { unsigned int cpu; @@ -1299,6 +1301,7 @@ void smp_shutdown_nonboot_cpus(unsigned int primary_c= pu) =20 cpu_maps_update_done(); } +#endif =20 #else #define takedown_cpu NULL --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 2FDD1C00140 for ; Mon, 22 Aug 2022 02:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232381AbiHVCQS (ORCPT ); Sun, 21 Aug 2022 22:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232251AbiHVCQD (ORCPT ); Sun, 21 Aug 2022 22:16:03 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B66D522288; Sun, 21 Aug 2022 19:15:56 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id r69so8185530pgr.2; Sun, 21 Aug 2022 19:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=WLszNFH6rAx833ludRXMY401Pm+H+RTV6I0FYUgHTg0=; b=SqqVBMOnC7CzBii1m0ocTxbCUywgAQHCwLfgqx83GK4H1dtDbCF9O6MIHnUWaRicTM 26QmKxmEBTyB+zRhgsS02GmtOBoSUG3n9vNLTx/oVFe/iLv2YXG5DBfeJVvp3N98Nqw3 QrOZY8/GZMChwXBy246ZcaxGqyefNTj4lrsFOg7n9KSwMyGWA/PJun+O3rN7k6IKejoS W0WGG2sDMSITPd9l5SFj5FDjiB8VxiEy3h01jTkhf4lwHS2n4jaEtlm95zcq47ioODO/ +xzMNd/XLGxseTgLin18K/K9szEkCq6SJSsPsuypa2ZcYXvVOjiUTEtup+0S+TuAjbog PD6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=WLszNFH6rAx833ludRXMY401Pm+H+RTV6I0FYUgHTg0=; b=WCRFC+8jMAoTgo7cxei6/FmCEAm8LbBWhUWgMI2YNrYUkNbmXuanKvivQ0P14TKIpc NI5YghcAt6UhgadbR/pXtEb46256fW6BvpX/v60OOB2UUtfmpKgGbcrFer49N3nxpLVN zMb6k2gDvcSwFz09REzve0Xj8nTEA/ChGUN2NO/AuMQZSLsaBvyFh3cIfFCb4tgr6qn/ DdfsvmXI4kAfx0RoWsSo8kfOhZ6LKS8hDxwtp/1XQiC0h7DUXtKJCqE4wPookdxvdd9e A1mnJlEm2al8viQey7FF0tI4BC3Z9dJLtlHSS8ldecAhemzb8LKo5daCyDVEHycS6bS4 uEEQ== X-Gm-Message-State: ACgBeo3UUHiuelYgqYyr0C0n2cj1LfOYL03cmJI4PANcIYaK6yrUJjlq 1vvOxfis3IngBgKJSka6VA== X-Google-Smtp-Source: AA6agR6OqW8j4jhaYEyPSXqhTTqweo/eD8PzrvQ6+13CJ2uOIZ0noYxOQmPKYGKHiep+6to1lt7J9Q== X-Received: by 2002:a05:6a00:23c1:b0:536:463e:e53b with SMTP id g1-20020a056a0023c100b00536463ee53bmr9714834pfc.43.1661134556164; Sun, 21 Aug 2022 19:15:56 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:15:55 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Thomas Gleixner , Steven Price , Kuppuswamy Sathyanarayanan , "Jason A. Donenfeld" , Frederic Weisbecker , Russell King , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , "Eric W. Biederman" Subject: [RFC 03/10] cpu/hotplug: Introduce fast kexec reboot Date: Mon, 22 Aug 2022 10:15:13 +0800 Message-Id: <20220822021520.6996-4-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" *** Current situation 'slow kexec reboot' *** At present, some architectures rely on smp_shutdown_nonboot_cpus() to implement "kexec -e". Since smp_shutdown_nonboot_cpus() tears down the cpus serially, it is very slow. Take a close look, a cpu_down() processing on a single cpu can approximatel= y be divided into two stages: -1. from CPUHP_ONLINE to CPUHP_TEARDOWN_CPU -2. from CPUHP_TEARDOWN_CPU to CPUHP_AP_IDLE_DEAD which is by stop_machine_cpuslocked(take_cpu_down, NULL, cpumask_of(cpu= )); and runs on the teardown cpu. If these processes can run in parallel, then, the reboot can be speeded up. That is the aim of this patch. *** Contrast to other implements *** X86 and PowerPC have their own machine_shutdown(), which does not reply on the cpu hot-removing mechanism. They just discriminate some critical component and tears them down in per cpu NMI handler during the kexec reboot. But for some architectures, let's say arm64, it is not easy to defi= ne these critical component due to various chipmakers' implements. As a result, sticking to the cpu hot-removing mechanism is the simplest way to re-implement the parallel. It also renders an opportunity to implement the cpu_down() in parallel in future (not done by this series). *** Things worthy of consideration *** 1. The definition of a clean boundary between the first kernel and the new = kernel -1.1 firmware The firmware's internal state should enter into a proper state. And this is achieved by the firmware's cpuhp_step's teardown interface if any. -1.2 CPU internal Whether the cache or PMU needs a clean shutdown before rebooting. 2. The dependency of each cpuhp_step The boundary of a clean cut involves only few cpuhp_step, but they may propagate to other cpuhp_step by the way of the dependency. This series does not bother to judge the dependency, instead, just iterate downside each cpuhp_step. And this stragegy demands that each cpuhp_step's teardown interface supports parallel. *** Solution *** Ideally, if the interface _cpu_down() can be enhanced to enable parallel, then the fast reboot can be achieved. But revisiting the two parts of the current cpu_down() process, the second part 'stop_machine_cpuslocked()' is a blockade. Packed inside the _cpu_down(), stop_machine_cpuslocked() only allow one cpu to execute the teardown. So this patch breaks down the process of _cpu_down(), and divides the teardown into three steps. And the exposed stop_machine_cpuslocked() can be used to support parallel. 1. Bring each AP from CPUHP_ONLINE to CPUHP_TEARDOWN_CPU in parallel. 2. Sync on BP to wait all APs to enter CPUHP_TEARDOWN_CPU state 3. Bring each AP from CPUHP_TEARDOWN_CPU to CPUHP_AP_IDLE_DEAD by the interface of stop_machine_cpuslocked() in parallel. Apparently, the step 2 is introduced in order to satisfy the condition on which stop_machine_cpuslocked() can start on each cpu. Then the rest issue is about how to support parallel in step 1&3. Furtunately, each subsystem has its own carefully designed lock mechanism. In each cpuhp_step teardown interface, adopting to the subsystem's lock rule will make things work. *** No rollback if failure *** During kexec reboot, the devices have already been shutdown, there is no way for system to roll back to a workable state. So this series also does not consider the rollback issue. Signed-off-by: Pingfan Liu Cc: Thomas Gleixner Cc: Steven Price Cc: Kuppuswamy Sathyanarayanan Cc: "Jason A. Donenfeld" Cc: Frederic Weisbecker Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Peter Zijlstra Cc: "Eric W. Biederman" To: linux-arm-kernel@lists.infradead.org To: linux-ia64@vger.kernel.org To: linux-riscv@lists.infradead.org To: linux-kernel@vger.kernel.org --- kernel/cpu.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 10 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 2be6ba811a01..94ab2727d6bb 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1260,10 +1260,125 @@ EXPORT_SYMBOL_GPL(remove_cpu); =20 #ifdef CONFIG_SHUTDOWN_NONBOOT_CPUS =20 -void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) +/* + * Push all of cpus to the state CPUHP_AP_ONLINE_IDLE. + * Since kexec-reboot has already shut down all devices, there is no way to + * roll back, the cpus' teardown also requires no rollback, instead, just = throw + * warning. + */ +static void cpus_down_no_rollback(struct cpumask *cpus) { + struct cpuhp_cpu_state *st; unsigned int cpu; + + /* launch ap work one by one, but not wait for completion */ + for_each_cpu(cpu, cpus) { + st =3D per_cpu_ptr(&cpuhp_state, cpu); + /* + * If the current CPU state is in the range of the AP hotplug thread, + * then we need to kick the thread. + */ + if (st->state > CPUHP_TEARDOWN_CPU) { + cpuhp_set_state(cpu, st, CPUHP_TEARDOWN_CPU); + /* In order to parallel, async. And there is no way to rollback */ + cpuhp_kick_ap_work_async(cpu); + } + } + + /* wait for all ap work completion */ + for_each_cpu(cpu, cpus) { + st =3D per_cpu_ptr(&cpuhp_state, cpu); + wait_for_ap_thread(st, st->bringup); + if (st->result) + pr_warn("cpu %u refuses to offline due to %d\n", cpu, st->result); + else if (st->state > CPUHP_TEARDOWN_CPU) + pr_warn("cpu %u refuses to offline, state: %d\n", cpu, st->state); + } +} + +static int __takedown_cpu_cleanup(unsigned int cpu) +{ + struct cpuhp_cpu_state *st =3D per_cpu_ptr(&cpuhp_state, cpu); + + /* + * The teardown callback for CPUHP_AP_SCHED_STARTING will have removed + * all runnable tasks from the CPU, there's only the idle task left now + * that the migration thread is done doing the stop_machine thing. + * + * Wait for the stop thread to go away. + */ + wait_for_ap_thread(st, false); + BUG_ON(st->state !=3D CPUHP_AP_IDLE_DEAD); + + hotplug_cpu__broadcast_tick_pull(cpu); + /* This actually kills the CPU. */ + __cpu_die(cpu); + + tick_cleanup_dead_cpu(cpu); + rcutree_migrate_callbacks(cpu); + return 0; +} + +/* + * There is a sync that all ap threads are done before calling this func. + */ +static void takedown_cpus_no_rollback(struct cpumask *cpus) +{ + struct cpuhp_cpu_state *st; + unsigned int cpu; + + for_each_cpu(cpu, cpus) { + st =3D per_cpu_ptr(&cpuhp_state, cpu); + WARN_ON(st->state !=3D CPUHP_TEARDOWN_CPU); + /* No invoke to takedown_cpu(), so set the state by manual */ + st->state =3D CPUHP_AP_ONLINE; + cpuhp_set_state(cpu, st, CPUHP_AP_OFFLINE); + } + + irq_lock_sparse(); + /* ask stopper kthreads to execute take_cpu_down() in parallel */ + stop_machine_cpuslocked(take_cpu_down, NULL, cpus); + + /* Finally wait for completion and clean up */ + for_each_cpu(cpu, cpus) + __takedown_cpu_cleanup(cpu); + irq_unlock_sparse(); +} + +static bool check_quick_reboot(void) +{ + return false; +} + +static struct cpumask kexec_ap_map; + +void smp_shutdown_nonboot_cpus_quick_path(unsigned int primary_cpu) +{ + struct cpumask *cpus =3D &kexec_ap_map; + /* + * To prevent other subsystem from access to __cpu_online_mask, but inter= nally, + * __cpu_disable() accesses the bitmap in parral and needs its own local = lock. + */ + cpus_write_lock(); + + cpumask_copy(cpus, cpu_online_mask); + cpumask_clear_cpu(primary_cpu, cpus); + cpus_down_no_rollback(cpus); + takedown_cpus_no_rollback(cpus); + /* + * For some subsystems, there are still remains for offline cpus from + * CPUHP_BRINGUP_CPU to CPUHP_OFFLINE. But since none of them interact + * with hardwares or firmware, they have no effect on the new kernel. + * So skipping the cpuhp callbacks in that range + */ + + cpus_write_unlock(); +} + +void smp_shutdown_nonboot_cpus(unsigned int primary_cpu) +{ int error; + unsigned int cpu; =20 cpu_maps_update_begin(); =20 @@ -1275,15 +1390,19 @@ void smp_shutdown_nonboot_cpus(unsigned int primary= _cpu) if (!cpu_online(primary_cpu)) primary_cpu =3D cpumask_first(cpu_online_mask); =20 - for_each_online_cpu(cpu) { - if (cpu =3D=3D primary_cpu) - continue; - - error =3D cpu_down_maps_locked(cpu, CPUHP_OFFLINE); - if (error) { - pr_err("Failed to offline CPU%d - error=3D%d", - cpu, error); - break; + if (check_quick_reboot()) { + smp_shutdown_nonboot_cpus_quick_path(primary_cpu); + } else { + for_each_online_cpu(cpu) { + if (cpu =3D=3D primary_cpu) + continue; + + error =3D cpu_down_maps_locked(cpu, CPUHP_OFFLINE); + if (error) { + pr_err("Failed to offline CPU%d - error=3D%d", + cpu, error); + break; + } } } =20 --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 39E3CC00140 for ; Mon, 22 Aug 2022 02:16:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232285AbiHVCQa (ORCPT ); Sun, 21 Aug 2022 22:16:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbiHVCQO (ORCPT ); Sun, 21 Aug 2022 22:16:14 -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 92FC222510; Sun, 21 Aug 2022 19:16:06 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id y141so9022140pfb.7; Sun, 21 Aug 2022 19:16:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=xSWHQT0Gh+ASwqDbuftZ9hOwt+7ZpIdbcTfHZLJUjew=; b=drdEGnn6bSG1bQXrr6SCO9vL8sEJJnSyNh0s4SAbgA50zj3osmvGAr+RilNPSGW7tp KAfFuc5fnb/IN3BmLw8Lx1KUVaemwzWMqg+7fGeE+qpb2RuR+Kib91bE6zeP6pdAU+Iv rHPp+ANtA230uW3x89/bKkqo7TORCuWAHvqz4rYuwfwa0RHsGIPHziXZEfrA5sbdna54 tQSSr4N/VaS9RF7zANbJqRDu+IaNTN4xu3gRYTJ/+K+ZA/pY1IFky9Y0+JvCObZ18NYD vzacLfpll9SGbrBMx+pDubr0qCbwovinLpHj7a49H5uO4QvUDuMrSrN+nvwfBoxvGTK5 Cm8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=xSWHQT0Gh+ASwqDbuftZ9hOwt+7ZpIdbcTfHZLJUjew=; b=lXmwxlw58DzQIZPoXb/N0fB2vn79WR8mkpVy4vIIQxK3gz/Op8huAfKDW42IHVZ+ZN n2Z10hSlQkwHdb/qNZoGOGnc0l3EV+336k/+f8N5ihTcWcahltvpYIl9rMgBlBKZSBt1 XWBK8cKIa4duqU+QnAVOIaIcJ8pyD6D4bxDUwbexMEwrI7pudc1+cwPFW8iVYUdXhT2g e68tuyiONI5GAw8NE+XBr9zdblp+qzhV8Dhi+Mz3Rk3Pk9JcCo82xkAcWhotDXocDAHB tqzCsq7dIVrC3x7sP5mU3ztixcMXmwB05yxKl273Aili9xJ+CK8isMNDU1Uv/mNgVilt Uvfw== X-Gm-Message-State: ACgBeo1sDVDiNV/3IhdKztANZxWIGk3VU4A+Qwt8Qx5xIhBe3SbeGltr V0LXA3u8olitfczvP+tDAA== X-Google-Smtp-Source: AA6agR7KljxZ9kbPwullzRTYyS9R74MZRULUzSQZWPtq0VQwcgMNVf0XgsbzpqwnU5ffstdl5YcXvw== X-Received: by 2002:a63:c1f:0:b0:41a:9b73:a89e with SMTP id b31-20020a630c1f000000b0041a9b73a89emr14967609pgl.342.1661134566121; Sun, 21 Aug 2022 19:16:06 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:05 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Thomas Gleixner , Steven Price , Kuppuswamy Sathyanarayanan , "Jason A. Donenfeld" , Frederic Weisbecker , Russell King , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Peter Zijlstra , "Eric W. Biederman" Subject: [RFC 04/10] cpu/hotplug: Check the capability of kexec quick reboot Date: Mon, 22 Aug 2022 10:15:14 +0800 Message-Id: <20220822021520.6996-5-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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 kexec quick reboot needs each involved cpuhp_step to run in parallel. There are lots of teardown cpuhp_step, but not all of them belong to arm/arm64/riscv kexec reboot path. So introducing a member 'support_kexec_parallel' in the struct cpuhp_step to signal whether the teardown supports parallel or not. If a cpuhp_step is used in kexec reboot, then it needs to support parallel to enable the quick reboot. The function check_quick_reboot() checks all teardown cpuhp_steps and report those unsupported if any. Signed-off-by: Pingfan Liu Cc: Thomas Gleixner Cc: Steven Price Cc: Kuppuswamy Sathyanarayanan Cc: "Jason A. Donenfeld" Cc: Frederic Weisbecker Cc: Russell King Cc: Catalin Marinas Cc: Will Deacon Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Peter Zijlstra Cc: "Eric W. Biederman" To: linux-arm-kernel@lists.infradead.org To: linux-ia64@vger.kernel.org To: linux-riscv@lists.infradead.org To: linux-kernel@vger.kernel.org --- include/linux/cpuhotplug.h | 2 ++ kernel/cpu.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index f61447913db9..73093fc15aec 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -374,6 +374,8 @@ static inline int cpuhp_setup_state_multi(enum cpuhp_st= ate state, (void *) teardown, true); } =20 +void cpuhp_set_step_parallel(enum cpuhp_state state); + int __cpuhp_state_add_instance(enum cpuhp_state state, struct hlist_node *= node, bool invoke); int __cpuhp_state_add_instance_cpuslocked(enum cpuhp_state state, diff --git a/kernel/cpu.c b/kernel/cpu.c index 94ab2727d6bb..1261c3f3be51 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -137,6 +137,9 @@ struct cpuhp_step { /* public: */ bool cant_stop; bool multi_instance; +#ifdef CONFIG_SHUTDOWN_NONBOOT_CPUS + bool support_kexec_parallel; +#endif }; =20 static DEFINE_MUTEX(cpuhp_state_mutex); @@ -147,6 +150,14 @@ static struct cpuhp_step *cpuhp_get_step(enum cpuhp_st= ate state) return cpuhp_hp_states + state; } =20 +#ifdef CONFIG_SHUTDOWN_NONBOOT_CPUS +void cpuhp_set_step_parallel(enum cpuhp_state state) +{ + cpuhp_hp_states[state].support_kexec_parallel =3D true; +} +EXPORT_SYMBOL(cpuhp_set_step_parallel); +#endif + static bool cpuhp_step_empty(bool bringup, struct cpuhp_step *step) { return bringup ? !step->startup.single : !step->teardown.single; @@ -1347,7 +1358,22 @@ static void takedown_cpus_no_rollback(struct cpumask= *cpus) =20 static bool check_quick_reboot(void) { - return false; + struct cpuhp_step *step; + enum cpuhp_state state; + bool ret =3D true; + + for (state =3D CPUHP_ONLINE; state >=3D CPUHP_AP_OFFLINE; state--) { + step =3D cpuhp_get_step(state); + if (step->teardown.single =3D=3D NULL) + continue; + if (step->support_kexec_parallel =3D=3D false) { + pr_info("cpuhp state:%d, %s, does not support cpudown in parallel\n", + state, step->name); + ret =3D false; + } + } + + return ret; } =20 static struct cpumask kexec_ap_map; --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 16D18C00140 for ; Mon, 22 Aug 2022 02:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232449AbiHVCQf (ORCPT ); Sun, 21 Aug 2022 22:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiHVCQQ (ORCPT ); Sun, 21 Aug 2022 22:16:16 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6E8522B00 for ; Sun, 21 Aug 2022 19:16:09 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id y15so5045101pfr.9 for ; Sun, 21 Aug 2022 19:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=gsR63uXiD4J4dRjeMZsAaLt2fDvFcRZsnDNlGseIAjE=; b=Pk0rIhqwd8AcUkq5KmJe9mjrUF6uNVfJWfjWUkbfwuQIGmV+U3/UFgPVoh1gYGq+bd lbCSRPMb+1x0M86+ymqwzFqN8nb+l68wSITrsmEixSWhlHgDZLB/R0svIyy5MO54R6Ym PwVfSVkrB8SoRCQ7vzL1LQZzM9iHBwApzh6vrmeiZsltT6ynaL3sdrb1ZhJGPhmFyOD3 4s2db1YqPkPeaWJ6qcSkXxuYfgRl3Eokk297cD1GGHz/Q5l5MVSGxbVpp3c4meit/hP+ bSsrrIKUfzH3yc9hotWq9Z7duppQSn0jH3GGkXZbsN3yxozQbvoh5tqw/X+vXNhleLsl cX7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=gsR63uXiD4J4dRjeMZsAaLt2fDvFcRZsnDNlGseIAjE=; b=HOHcPCk4ASOtghHeID7Onllfy2UXYmYiS7ExjKij6GSBU+H4cK3DYzht9dKrOUrREy +gmiF8xqJQIia3KZLyCfElryBVBVPGbX+par2yJJZE5iGZefgcPryLUKgStxQQWYky3Q TAOzkD57sbXwHk1fl5Oeg+XQ87RMIEfrzojp7gA84yS3CJqcFW2BGFcoemn9nJBwqX+H FXu9ZHIgBhQ1+8T9CC0e+WoispqEyPTfIIo+6GOZNhMA9mAP6ntmDw2Qh4b0x1ZTCD36 p1fLPBHVN3g9x0huuYa0wp5l97BR+oJ/zkLMvhs/bbz9VcmJPwgXHq6TC0uY0sP14kTp Q54w== X-Gm-Message-State: ACgBeo2idlwXL+UOwDH/hQ6U1tyHhEhqbjhNRe84mU6LpMF2AN+vZxoN Vv7satEu20mADWevzrtpTl8G39mY1Q== X-Google-Smtp-Source: AA6agR796+xdB/mm2oEQUhLS61HVQaOmFzmcD/yNrFj1veXL2aZ9RxDMlPamwMMKooh9so1wCzMtIA== X-Received: by 2002:a63:4b62:0:b0:421:8c8b:163c with SMTP id k34-20020a634b62000000b004218c8b163cmr14624442pgl.182.1661134569229; Sun, 21 Aug 2022 19:16:09 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:08 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Will Deacon , Mark Rutland Subject: [RFC 05/10] perf/arm-dsu: Make dsu_pmu_cpu_teardown() parallel Date: Mon, 22 Aug 2022 10:15:15 +0800 Message-Id: <20220822021520.6996-6-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" In the case of kexec quick reboot, dsu_pmu_cpu_teardown() confronts parallel and lock are needed to protect the contest on a dsu_pmu. Signed-off-by: Pingfan Liu Cc: Will Deacon Cc: Mark Rutland To: linux-arm-kernel@lists.infradead.org To: linux-kernel@vger.kernel.org --- drivers/perf/arm_dsu_pmu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index a36698a90d2f..aa9f4393ff0c 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -833,16 +833,23 @@ static int dsu_pmu_cpu_teardown(unsigned int cpu, str= uct hlist_node *node) struct dsu_pmu *dsu_pmu =3D hlist_entry_safe(node, struct dsu_pmu, cpuhp_node); =20 - if (!cpumask_test_and_clear_cpu(cpu, &dsu_pmu->active_cpu)) + raw_spin_lock(&dsu_pmu->pmu_lock); + if (!cpumask_test_and_clear_cpu(cpu, &dsu_pmu->active_cpu)) { + raw_spin_unlock(&dsu_pmu->pmu_lock); return 0; + } =20 dst =3D dsu_pmu_get_online_cpu_any_but(dsu_pmu, cpu); /* If there are no active CPUs in the DSU, leave IRQ disabled */ - if (dst >=3D nr_cpu_ids) + if (dst >=3D nr_cpu_ids) { + raw_spin_unlock(&dsu_pmu->pmu_lock); return 0; + } =20 - perf_pmu_migrate_context(&dsu_pmu->pmu, cpu, dst); + /* dst should not be in dying mask. So after setting, blocking parallel */ dsu_pmu_set_active_cpu(dst, dsu_pmu); + raw_spin_unlock(&dsu_pmu->pmu_lock); + perf_pmu_migrate_context(&dsu_pmu->pmu, cpu, dst); =20 return 0; } @@ -858,6 +865,7 @@ static int __init dsu_pmu_init(void) if (ret < 0) return ret; dsu_pmu_cpuhp_state =3D ret; + cpuhp_set_step_parallel(ret); return platform_driver_register(&dsu_pmu_driver); } =20 --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 D3D85C32774 for ; Mon, 22 Aug 2022 02:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbiHVCQq (ORCPT ); Sun, 21 Aug 2022 22:16:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232410AbiHVCQ2 (ORCPT ); Sun, 21 Aug 2022 22:16:28 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A37EA222B4; Sun, 21 Aug 2022 19:16:18 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id l64so8204056pge.0; Sun, 21 Aug 2022 19:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=1Aq+TVGo9jWjEOz30MnnCagkM1BEYPOn6zoekJQrcT8=; b=Lz0gNtnR0Gx/blm6zrBVhXfF2MRVTbwlEL1W81C3w2unXlO+5HrmDF2WUIx+7vPA/p 5h26+kDRmt6agXESmcH7W1XPsWzhNtF+Hhc5epkLkEqsC6lV5h80hUb5rumqD8Aat9+8 az50QeOE3YFOGu168p8qC9UcWS0LT45eCLOdSKt7l0Ubh8sOX3hneZpi80j2XnHP0zkN BFD8wiPD/Pf37aSGTzr7XBIzsXaHRMSIMMmDbIpQSwhWQointOliw4mnNomAJGF3An4a dpxHHJ9T6yCioZ2u38tL9HbxZRzbu4NXg585fk/7At6WOx3mLm9cWD3MEGNwq2sEgGM/ KbaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=1Aq+TVGo9jWjEOz30MnnCagkM1BEYPOn6zoekJQrcT8=; b=gyZ+UsOboqXBFDc8qrQ6sXRBBJsx1qb1vCrrik2qH0k3YvkUr/OFgjSr0DTLxv2wnP TSiD8XVyg7QEBeXMAkd5MFARcbUB3XzK69GGm++pBdKLZnF6/X8v9HTvRuMEIrvPNpB+ vtLuunQL5Zq5sTgWQHAL/COMZeKY9h5eGS9th2jmlbr6CDulG9zv3F6gqMC0fOajAi1G nlAKgZmI1yHKEmLSJnKgYeCudbfI+zlxHyLso2SE31TvFmQLOHVsX3MpTn8ic3h+NZ9a XchLc4aK/toRv78FV//J8JAnqnBGJcnUsxhWOTUm2MJROIj1Mn5K2IOJqZqJCRQyPFiq eK1w== X-Gm-Message-State: ACgBeo10LfgMRJkTBsW19d96crsV7ulNS8xsdULrD5HbN5MUFP32V8wn suIxV2sqUstGjjWpP3rDoCVPNUDITA== X-Google-Smtp-Source: AA6agR4D50rPJbn2tq2GNSeHmdvNBpKQlkNzme4yJlxq0DguP1NGJn/0sSXGbSX983tnXc0H9IKnEg== X-Received: by 2002:a63:df13:0:b0:42a:b008:3d56 with SMTP id u19-20020a63df13000000b0042ab0083d56mr2751744pgg.425.1661134577330; Sun, 21 Aug 2022 19:16:17 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:16 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Cc: Pingfan Liu , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Thomas Gleixner , Steven Price , Mark Rutland , Kuppuswamy Sathyanarayanan , "Jason A. Donenfeld" Subject: [RFC 06/10] rcu/hotplug: Make rcutree_dead_cpu() parallel Date: Mon, 22 Aug 2022 10:15:16 +0800 Message-Id: <20220822021520.6996-7-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" In order to support parallel, rcu_state.n_online_cpus should be atomic_dec() Signed-off-by: Pingfan Liu Cc: "Paul E. McKenney" Cc: Frederic Weisbecker Cc: Neeraj Upadhyay Cc: Josh Triplett Cc: Steven Rostedt Cc: Mathieu Desnoyers Cc: Lai Jiangshan Cc: Joel Fernandes Cc: Thomas Gleixner Cc: Steven Price Cc: "Peter Zijlstra Cc: Mark Rutland Cc: Kuppuswamy Sathyanarayanan Cc: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org To: rcu@vger.kernel.org --- kernel/cpu.c | 1 + kernel/rcu/tree.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 1261c3f3be51..90debbe28e85 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1872,6 +1872,7 @@ static struct cpuhp_step cpuhp_hp_states[] =3D { .name =3D "RCU/tree:prepare", .startup.single =3D rcutree_prepare_cpu, .teardown.single =3D rcutree_dead_cpu, + .support_kexec_parallel =3D true, }, /* * On the tear-down path, timers_dead_cpu() must be invoked diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 79aea7df4345..07d31e16c65e 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2168,7 +2168,8 @@ int rcutree_dead_cpu(unsigned int cpu) if (!IS_ENABLED(CONFIG_HOTPLUG_CPU)) return 0; =20 - WRITE_ONCE(rcu_state.n_online_cpus, rcu_state.n_online_cpus - 1); + /* Hot remove path allows parallel, while Hot add races against remove on= lock */ + atomic_dec((atomic_t *)&rcu_state.n_online_cpus); /* Adjust any no-longer-needed kthreads. */ rcu_boost_kthread_setaffinity(rnp, -1); // Stop-machine done, so allow nohz_full to disable tick. --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 8A796C00140 for ; Mon, 22 Aug 2022 02:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbiHVCQu (ORCPT ); Sun, 21 Aug 2022 22:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232344AbiHVCQd (ORCPT ); Sun, 21 Aug 2022 22:16:33 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C5B722BD9 for ; Sun, 21 Aug 2022 19:16:22 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id x19so6244337pfq.1 for ; Sun, 21 Aug 2022 19:16:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=a1gA9IAalPkJ/r41Sbu0lXlyv4sE6FWwFkcXTLlSUhQ=; b=f1Rj4AszKhqTPEhdKzS4a7bGXzhl4OYAwmwBWFAzl1fstspH3uQgHSN3GkYGHFJyI4 eplR605POer+GLNLpquluEFzZK3qJekzAI4t/LFPL1g5jk+IDfuJFdN1AoEKZEOQcZ8i CUmbpoB/lWov7uW7y/3M54xBU5z5viFwBbJXcN7fIePWUXlkJaJAz+Elp0hqFJq5hp8w AHFq4TwrICRurHqhldjCSmPd7RtXt8EHYfs9MjYOjs5IpLmj2S76x6Lscenv1VkNE5Rb NBqYq+ANAa+5G6zUh2d6O99ZQSg8F09O0dd27mwJE7fKbLHHjjbuz4CNqbnXKP4eHrWI J6Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=a1gA9IAalPkJ/r41Sbu0lXlyv4sE6FWwFkcXTLlSUhQ=; b=jiwVSAktM9zay2260nHU8nPXsBWtoTBoZYs7LVdkI8JdH4fpZOvl8FHcPuipVwvxdF kqq9FVFp39i00K/NW/MB0yWBv69dEPQZGUNDup/TxkUysBGmBKST/k4qKAYdxTC1caq8 BUzOCDXmMyyV1e9hsIQscEqx243TgXv/B/BoqBvHUzGTCxQXiCRqgjkSUBDkPk0u7Ors FQdpnv+rGR7nFHFTulydZgdaZeVINDIqKt9Un+QUP5Yf45Ago592zjofTkLNOvOxDuM7 J1td9S5wTqDbR4yX8/GqJ9iISGu4DqC9+v2j7Z8azNvjUbSpe88XgrsjxSCogMndI+Wn cLrg== X-Gm-Message-State: ACgBeo2S1MQ+jo/3L2H29rz3Qcxt4yEvCkf5NvGREz1y2eOFF43mzDG6 UuEcRFqD+YxS3NW8S5ErnO+9+volUg== X-Google-Smtp-Source: AA6agR7ZwA26k/5afRUdoN/q/wA2eMJhK0L8eSeeuTTyKuF0SCN0KPGRNvuKCEpeW87yk+qbLb9bfQ== X-Received: by 2002:a63:147:0:b0:42a:5157:c083 with SMTP id 68-20020a630147000000b0042a5157c083mr9835298pgb.269.1661134581473; Sun, 21 Aug 2022 19:16:21 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:20 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Yury Norov , Andy Shevchenko , Rasmus Villemoes , Thomas Gleixner , Steven Price , Mark Rutland , "Jason A. Donenfeld" , Kuppuswamy Sathyanarayanan Subject: [RFC 07/10] lib/cpumask: Introduce cpumask_not_dying_but() Date: Mon, 22 Aug 2022 10:15:17 +0800 Message-Id: <20220822021520.6996-8-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" During cpu hot-removing, the dying cpus are still in cpu_online_mask. On the other hand, A subsystem will migrate its broker from the dying cpu to a online cpu in its teardown cpuhp_step. After enabling the teardown of cpus in parallel, cpu_online_mask can not tell those dying from the real online. Introducing a function cpumask_not_dying_but() to pick a real online cpu. Signed-off-by: Pingfan Liu Cc: Yury Norov Cc: Andy Shevchenko Cc: Rasmus Villemoes Cc: Thomas Gleixner Cc: Steven Price Cc: Mark Rutland Cc: "Jason A. Donenfeld" Cc: Kuppuswamy Sathyanarayanan To: linux-kernel@vger.kernel.org --- include/linux/cpumask.h | 3 +++ kernel/cpu.c | 3 +++ lib/cpumask.c | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 0d435d0edbcb..d2033a239a07 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -317,6 +317,9 @@ unsigned int cpumask_any_but(const struct cpumask *mask= , unsigned int cpu) return i; } =20 +/* for parallel kexec reboot */ +int cpumask_not_dying_but(const struct cpumask *mask, unsigned int cpu); + #define CPU_BITS_NONE \ { \ [0 ... BITS_TO_LONGS(NR_CPUS)-1] =3D 0UL \ diff --git a/kernel/cpu.c b/kernel/cpu.c index 90debbe28e85..771e344f8ff9 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -1282,6 +1282,9 @@ static void cpus_down_no_rollback(struct cpumask *cpu= s) struct cpuhp_cpu_state *st; unsigned int cpu; =20 + for_each_cpu(cpu, cpus) + set_cpu_dying(cpu, true); + /* launch ap work one by one, but not wait for completion */ for_each_cpu(cpu, cpus) { st =3D per_cpu_ptr(&cpuhp_state, cpu); diff --git a/lib/cpumask.c b/lib/cpumask.c index 8baeb37e23d3..6474f07ed87a 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -7,6 +7,24 @@ #include #include =20 +/* Used in parallel kexec-reboot cpuhp callbacks */ +int cpumask_not_dying_but(const struct cpumask *mask, + unsigned int cpu) +{ + unsigned int i; + + if (CONFIG_SHUTDOWN_NONBOOT_CPUS) { + cpumask_check(cpu); + for_each_cpu(i, mask) + if (i !=3D cpu && !cpumask_test_cpu(i, cpu_dying_mask)) + break; + return i; + } else { + return cpumask_any_but(mask, cpu); + } +} +EXPORT_SYMBOL(cpumask_not_dying_but); + /** * cpumask_next_wrap - helper to implement for_each_cpu_wrap * @n: the cpu prior to the place to search --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 B7F62C00140 for ; Mon, 22 Aug 2022 02:17:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232424AbiHVCRI (ORCPT ); Sun, 21 Aug 2022 22:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232470AbiHVCQn (ORCPT ); Sun, 21 Aug 2022 22:16:43 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AA6C22BE5; Sun, 21 Aug 2022 19:16:35 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id c2so8679027plo.3; Sun, 21 Aug 2022 19:16:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=xB76u9yqtIZ+mSa30ADibl4N4bymJ9Dh7UlLFPT7o98=; b=HRSBxEVCt3rvrI/7lmMMzAo0rRbfGOgqEC67o825HvHiARvDrjB8+tDVoRpWMePXYp 9oQI+id67tHzlJ/A1v+NZiooV2Ufdbed57m4RPzeWT4HTWQ3q2I+/Pe+oeuuLSkGr3sH OFGxMUhrOnPgyl+8PJjFb2VlRGBH65CMs+CTIcK33IedsTj91WJy8qIYPkCyA3YhPpbN xDCCgOZKQ5Y1aN3JjfMjYvKZvr6vDO7+ZcRdt9uyjXkR87MKlV9+WnblT5SVy92eqfSx w3yN/jWsdSyvHft8Zf3G5N2NxPQml5tWr62cry/lKZIDETPbgI06U3OybrR+Eaet25zB MNXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=xB76u9yqtIZ+mSa30ADibl4N4bymJ9Dh7UlLFPT7o98=; b=8HTec5PKe3qNIodA8+yUymOr1kqtqer4mcRv6RSpygHXfAWmuHpvMJzKtn4TcI1uwg zlfaCE/GOg1M3Tff9mf1JFEI8o1qpxFJ84zY8twMkOnTEWR16ZDC3FSowSSBCs8NXmA+ Pa9D6z/iMCZUpG4ryP4xajmsjBysnj9bzzq7aaGGgJl5+pkdxy6dJtWmyxkTOR8an//T 1yZU0tmzbJyZMpJO4g2mtlcUfaABTeq+n26BJSIbUwwdj0lyaonOGPnlURM+vxOl6CHO nj1blI06Un713sWZAof80W7zmttoEUs4z/+8kXWD3oriB7GnKdH1rGSO8PxxJD1NAhw/ 24Lg== X-Gm-Message-State: ACgBeo1cK40iG/0rQfPTbxfNf6jDO9GVXQ3jxODlOOt+RNbGdX4D3zM4 ldaUrG0OFGwuCIV9bT3fJg== X-Google-Smtp-Source: AA6agR522vRbRjKGj/9trWnx6g9g6lhC9pFTs134FCjBnfDght6iTV00F7UnaCUQri0jee4v1rjxPQ== X-Received: by 2002:a17:90b:33ce:b0:1fb:1aec:ffac with SMTP id lk14-20020a17090b33ce00b001fb1aecffacmr5850314pjb.137.1661134594615; Sun, 21 Aug 2022 19:16:34 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:34 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-fpga@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Russell King , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Fenghua Yu , Dave Jiang , Vinod Koul , Wu Hao , Tom Rix , Moritz Fischer , Xu Yilun , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Will Deacon , Mark Rutland , Frank Li , Shaokun Zhang , Qi Liu , Andy Gross , Bjorn Andersson , Konrad Dybcio , Khuong Dinh , Li Yang , Yury Norov Subject: [RFC 08/10] cpuhp: Replace cpumask_any_but(cpu_online_mask, cpu) Date: Mon, 22 Aug 2022 10:15:18 +0800 Message-Id: <20220822021520.6996-9-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" In a kexec quick reboot path, the dying cpus are still on cpu_online_mask. During the teardown of cpu, a subsystem needs to migrate its broker to a real online cpu. This patch replaces cpumask_any_but(cpu_online_mask, cpu) in a teardown procedure with cpumask_not_dying_but(cpu_online_mask, cpu). Signed-off-by: Pingfan Liu Cc: Russell King Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: NXP Linux Team Cc: Fenghua Yu Cc: Dave Jiang Cc: Vinod Koul Cc: Wu Hao Cc: Tom Rix Cc: Moritz Fischer Cc: Xu Yilun Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Rodrigo Vivi Cc: Tvrtko Ursulin Cc: David Airlie Cc: Daniel Vetter Cc: Will Deacon Cc: Mark Rutland Cc: Frank Li Cc: Shaokun Zhang Cc: Qi Liu Cc: Andy Gross Cc: Bjorn Andersson Cc: Konrad Dybcio Cc: Khuong Dinh Cc: Li Yang Cc: Yury Norov To: linux-arm-kernel@lists.infradead.org To: dmaengine@vger.kernel.org To: linux-fpga@vger.kernel.org To: intel-gfx@lists.freedesktop.org To: dri-devel@lists.freedesktop.org To: linux-arm-msm@vger.kernel.org To: linuxppc-dev@lists.ozlabs.org To: linux-kernel@vger.kernel.org --- arch/arm/mach-imx/mmdc.c | 2 +- arch/arm/mm/cache-l2x0-pmu.c | 2 +- drivers/dma/idxd/perfmon.c | 2 +- drivers/fpga/dfl-fme-perf.c | 2 +- drivers/gpu/drm/i915/i915_pmu.c | 2 +- drivers/perf/arm-cci.c | 2 +- drivers/perf/arm-ccn.c | 2 +- drivers/perf/arm-cmn.c | 4 ++-- drivers/perf/arm_dmc620_pmu.c | 2 +- drivers/perf/arm_dsu_pmu.c | 2 +- drivers/perf/arm_smmuv3_pmu.c | 2 +- drivers/perf/fsl_imx8_ddr_perf.c | 2 +- drivers/perf/hisilicon/hisi_uncore_pmu.c | 2 +- drivers/perf/marvell_cn10k_tad_pmu.c | 2 +- drivers/perf/qcom_l2_pmu.c | 2 +- drivers/perf/qcom_l3_pmu.c | 2 +- drivers/perf/xgene_pmu.c | 2 +- drivers/soc/fsl/qbman/bman_portal.c | 2 +- drivers/soc/fsl/qbman/qman_portal.c | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/arch/arm/mach-imx/mmdc.c b/arch/arm/mach-imx/mmdc.c index af12668d0bf5..a109a7ea8613 100644 --- a/arch/arm/mach-imx/mmdc.c +++ b/arch/arm/mach-imx/mmdc.c @@ -220,7 +220,7 @@ static int mmdc_pmu_offline_cpu(unsigned int cpu, struc= t hlist_node *node) if (!cpumask_test_and_clear_cpu(cpu, &pmu_mmdc->cpu)) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/arch/arm/mm/cache-l2x0-pmu.c b/arch/arm/mm/cache-l2x0-pmu.c index 993fefdc167a..1b0037ef7fa5 100644 --- a/arch/arm/mm/cache-l2x0-pmu.c +++ b/arch/arm/mm/cache-l2x0-pmu.c @@ -428,7 +428,7 @@ static int l2x0_pmu_offline_cpu(unsigned int cpu) if (!cpumask_test_and_clear_cpu(cpu, &pmu_cpu)) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/dma/idxd/perfmon.c b/drivers/dma/idxd/perfmon.c index d73004f47cf4..f3f1ccb55f73 100644 --- a/drivers/dma/idxd/perfmon.c +++ b/drivers/dma/idxd/perfmon.c @@ -528,7 +528,7 @@ static int perf_event_cpu_offline(unsigned int cpu, str= uct hlist_node *node) if (!cpumask_test_and_clear_cpu(cpu, &perfmon_dsa_cpu_mask)) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); =20 /* migrate events if there is a valid target */ if (target < nr_cpu_ids) diff --git a/drivers/fpga/dfl-fme-perf.c b/drivers/fpga/dfl-fme-perf.c index 587c82be12f7..57804f28357e 100644 --- a/drivers/fpga/dfl-fme-perf.c +++ b/drivers/fpga/dfl-fme-perf.c @@ -948,7 +948,7 @@ static int fme_perf_offline_cpu(unsigned int cpu, struc= t hlist_node *node) if (cpu !=3D priv->cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pm= u.c index 958b37123bf1..f866f9223492 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -1068,7 +1068,7 @@ static int i915_pmu_cpu_offline(unsigned int cpu, str= uct hlist_node *node) return 0; =20 if (cpumask_test_and_clear_cpu(cpu, &i915_pmu_cpumask)) { - target =3D cpumask_any_but(topology_sibling_cpumask(cpu), cpu); + target =3D cpumask_not_dying_but(topology_sibling_cpumask(cpu), cpu); =20 /* Migrate events if there is a valid target */ if (target < nr_cpu_ids) { diff --git a/drivers/perf/arm-cci.c b/drivers/perf/arm-cci.c index 03b1309875ae..481da937fb9d 100644 --- a/drivers/perf/arm-cci.c +++ b/drivers/perf/arm-cci.c @@ -1447,7 +1447,7 @@ static int cci_pmu_offline_cpu(unsigned int cpu) if (!g_cci_pmu || cpu !=3D g_cci_pmu->cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/arm-ccn.c b/drivers/perf/arm-ccn.c index 728d13d8e98a..573d6906ec9b 100644 --- a/drivers/perf/arm-ccn.c +++ b/drivers/perf/arm-ccn.c @@ -1205,7 +1205,7 @@ static int arm_ccn_pmu_offline_cpu(unsigned int cpu, = struct hlist_node *node) =20 if (cpu !=3D dt->cpu) return 0; - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; perf_pmu_migrate_context(&dt->pmu, cpu, target); diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index 80d8309652a4..1847182a1ed3 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -1787,9 +1787,9 @@ static int arm_cmn_pmu_offline_cpu(unsigned int cpu, = struct hlist_node *cpuhp_no node =3D dev_to_node(cmn->dev); if (cpumask_and(&mask, cpumask_of_node(node), cpu_online_mask) && cpumask_andnot(&mask, &mask, cpumask_of(cpu))) - target =3D cpumask_any(&mask); + target =3D cpumask_not_dying_but(&mask, cpu); else - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target < nr_cpu_ids) arm_cmn_migrate(cmn, target); return 0; diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c index 280a6ae3e27c..3a0a2bb92e12 100644 --- a/drivers/perf/arm_dmc620_pmu.c +++ b/drivers/perf/arm_dmc620_pmu.c @@ -611,7 +611,7 @@ static int dmc620_pmu_cpu_teardown(unsigned int cpu, if (cpu !=3D irq->cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index aa9f4393ff0c..e19ce0406b02 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -236,7 +236,7 @@ static int dsu_pmu_get_online_cpu_any_but(struct dsu_pm= u *dsu_pmu, int cpu) =20 cpumask_and(&online_supported, &dsu_pmu->associated_cpus, cpu_online_mask); - return cpumask_any_but(&online_supported, cpu); + return cpumask_not_dying_but(&online_supported, cpu); } =20 static inline bool dsu_pmu_counter_valid(struct dsu_pmu *dsu_pmu, u32 idx) diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c index 00d4c45a8017..827315d31056 100644 --- a/drivers/perf/arm_smmuv3_pmu.c +++ b/drivers/perf/arm_smmuv3_pmu.c @@ -640,7 +640,7 @@ static int smmu_pmu_offline_cpu(unsigned int cpu, struc= t hlist_node *node) if (cpu !=3D smmu_pmu->on_cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_p= erf.c index 8e058e08fe81..4e0276fc1548 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -664,7 +664,7 @@ static int ddr_perf_offline_cpu(unsigned int cpu, struc= t hlist_node *node) if (cpu !=3D pmu->cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/hisilicon/hisi_uncore_pmu.c b/drivers/perf/hisili= con/hisi_uncore_pmu.c index fbc8a93d5eac..8c39da8f4b3c 100644 --- a/drivers/perf/hisilicon/hisi_uncore_pmu.c +++ b/drivers/perf/hisilicon/hisi_uncore_pmu.c @@ -518,7 +518,7 @@ int hisi_uncore_pmu_offline_cpu(unsigned int cpu, struc= t hlist_node *node) /* Choose a new CPU to migrate ownership of the PMU to */ cpumask_and(&pmu_online_cpus, &hisi_pmu->associated_cpus, cpu_online_mask); - target =3D cpumask_any_but(&pmu_online_cpus, cpu); + target =3D cpumask_not_dying_but(&pmu_online_cpus, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/marvell_cn10k_tad_pmu.c b/drivers/perf/marvell_cn= 10k_tad_pmu.c index 69c3050a4348..268e3288893d 100644 --- a/drivers/perf/marvell_cn10k_tad_pmu.c +++ b/drivers/perf/marvell_cn10k_tad_pmu.c @@ -387,7 +387,7 @@ static int tad_pmu_offline_cpu(unsigned int cpu, struct= hlist_node *node) if (cpu !=3D pmu->cpu) return 0; =20 - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/perf/qcom_l2_pmu.c b/drivers/perf/qcom_l2_pmu.c index 30234c261b05..8823d0bb6476 100644 --- a/drivers/perf/qcom_l2_pmu.c +++ b/drivers/perf/qcom_l2_pmu.c @@ -822,7 +822,7 @@ static int l2cache_pmu_offline_cpu(unsigned int cpu, st= ruct hlist_node *node) /* Any other CPU for this cluster which is still online */ cpumask_and(&cluster_online_cpus, &cluster->cluster_cpus, cpu_online_mask); - target =3D cpumask_any_but(&cluster_online_cpus, cpu); + target =3D cpumask_not_dying_but(&cluster_online_cpus, cpu); if (target >=3D nr_cpu_ids) { disable_irq(cluster->irq); return 0; diff --git a/drivers/perf/qcom_l3_pmu.c b/drivers/perf/qcom_l3_pmu.c index 1ff2ff6582bf..ba26b2fa0736 100644 --- a/drivers/perf/qcom_l3_pmu.c +++ b/drivers/perf/qcom_l3_pmu.c @@ -718,7 +718,7 @@ static int qcom_l3_cache_pmu_offline_cpu(unsigned int c= pu, struct hlist_node *no =20 if (!cpumask_test_and_clear_cpu(cpu, &l3pmu->cpumask)) return 0; - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; perf_pmu_migrate_context(&l3pmu->pmu, cpu, target); diff --git a/drivers/perf/xgene_pmu.c b/drivers/perf/xgene_pmu.c index 0c32dffc7ede..069eb0a0d3ba 100644 --- a/drivers/perf/xgene_pmu.c +++ b/drivers/perf/xgene_pmu.c @@ -1804,7 +1804,7 @@ static int xgene_pmu_offline_cpu(unsigned int cpu, st= ruct hlist_node *node) =20 if (!cpumask_test_and_clear_cpu(cpu, &xgene_pmu->cpu)) return 0; - target =3D cpumask_any_but(cpu_online_mask, cpu); + target =3D cpumask_not_dying_but(cpu_online_mask, cpu); if (target >=3D nr_cpu_ids) return 0; =20 diff --git a/drivers/soc/fsl/qbman/bman_portal.c b/drivers/soc/fsl/qbman/bm= an_portal.c index 4d7b9caee1c4..8ebcf87e7d06 100644 --- a/drivers/soc/fsl/qbman/bman_portal.c +++ b/drivers/soc/fsl/qbman/bman_portal.c @@ -67,7 +67,7 @@ static int bman_offline_cpu(unsigned int cpu) return 0; =20 /* use any other online CPU */ - cpu =3D cpumask_any_but(cpu_online_mask, cpu); + cpu =3D cpumask_not_dying_but(cpu_online_mask, cpu); irq_set_affinity(pcfg->irq, cpumask_of(cpu)); return 0; } diff --git a/drivers/soc/fsl/qbman/qman_portal.c b/drivers/soc/fsl/qbman/qm= an_portal.c index e23b60618c1a..3807a8285ced 100644 --- a/drivers/soc/fsl/qbman/qman_portal.c +++ b/drivers/soc/fsl/qbman/qman_portal.c @@ -148,7 +148,7 @@ static int qman_offline_cpu(unsigned int cpu) pcfg =3D qman_get_qm_portal_config(p); if (pcfg) { /* select any other online CPU */ - cpu =3D cpumask_any_but(cpu_online_mask, cpu); + cpu =3D cpumask_not_dying_but(cpu_online_mask, cpu); irq_set_affinity(pcfg->irq, cpumask_of(cpu)); qman_portal_update_sdest(pcfg, cpu); } --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 91451C28D13 for ; Mon, 22 Aug 2022 02:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232408AbiHVCRF (ORCPT ); Sun, 21 Aug 2022 22:17:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232397AbiHVCQn (ORCPT ); Sun, 21 Aug 2022 22:16:43 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D9223142 for ; Sun, 21 Aug 2022 19:16:38 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id x63-20020a17090a6c4500b001fabbf8debfso9858483pjj.4 for ; Sun, 21 Aug 2022 19:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=+0W7rWPWhLmI9QuHXdXsDD8LiCq/u7awU886T4LTBws=; b=Npc2Tz77mETNRwOyyPYKRPVZNQgGuakYpf5WKXaRUm6l7/hpc+nr6Rf44tM+jZIhxe elkqBJhS4gcgZWfly532U5KKp+x3q1RO51AaFDFke+JTzkOam5lw44eRT4a2sDRcM9KL PxUFE2eB1nsNKjEdszC+GxePBLzNsYiu/jepd/IULwWwgr9tMQSfBJ+pg/2ZRrQEOv1Q k1Vs11xybyIoMv7fIFI8+IckthGyeme2p3v84OID5T4hayU/HE9WAk/08seX2HOQc6nc L9pKYSdD/Hw+T6OlPqTOnWSp0bonCgmFwX+98AaJCvFOZa30kBXhe2BBaTIxdDtNdCOM u01w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=+0W7rWPWhLmI9QuHXdXsDD8LiCq/u7awU886T4LTBws=; b=IpHKZPUes1vYjj561x6S7kvBljdEHrjRbgomeoWcAEy88+g00Ire7ulJoYDfA2pXW3 NL1/nDL6aFr4pnAOi9lFWISZQwAGahdYhUHbHlwFpxm4moeAAv6L3DKiyQ5pKUcn9vNc TKfwKe3dccgn8EKgNhquApDCikFA8dDOUJ5u8szTAxKJFDIvg882P5Sd6wnzIw83k7r1 SaGRq8nnRApRbUeK2dVmTyO0E4BYUY/QTg+0Ho/vJ639rpccbJGNnTqEbujb2sNRr2CE oPFwbGHEWSTgJVpUls5W+i7Xk0eC41Z4YN1iIro+HQSEEpmFimbs5kpgMUdqtyu/VIrp 5+Sg== X-Gm-Message-State: ACgBeo2CUYJgwqXj7IaFq7Ly7ebyGHfOh+3cMA8tV06hQZMDonZtrCrh 3CdW3h1Bw8rO/Kab0OOCoq3CEYYHKg== X-Google-Smtp-Source: AA6agR7sI9w4tDb1cOlX9FSkP2tbSrmD7yqoY0aTCVdZqY2NheG24QO3KWL1XwhHXLDZaKxsym+Tqg== X-Received: by 2002:a17:903:1106:b0:172:9801:cb96 with SMTP id n6-20020a170903110600b001729801cb96mr18140713plh.91.1661134597390; Sun, 21 Aug 2022 19:16:37 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:36 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Thomas Gleixner Subject: [RFC 09/10] genirq/cpuhotplug: Ask migrate_one_irq() to migrate to a real online cpu Date: Mon, 22 Aug 2022 10:15:19 +0800 Message-Id: <20220822021520.6996-10-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" In kexec quick reboot path, the dying cpus are still on the cpu_online_mask, but the interrupt should be migrated onto a real online cpu instead of a dying one. Otherwise, the interrupt has no opportunity to move onto a live cpu. Signed-off-by: Pingfan Liu Cc: Thomas Gleixner To: linux-kernel@vger.kernel.org --- kernel/irq/cpuhotplug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/irq/cpuhotplug.c b/kernel/irq/cpuhotplug.c index 1ed2b1739363..e85d6456f310 100644 --- a/kernel/irq/cpuhotplug.c +++ b/kernel/irq/cpuhotplug.c @@ -110,6 +110,7 @@ static bool migrate_one_irq(struct irq_desc *desc) if (maskchip && chip->irq_mask) chip->irq_mask(d); =20 + cpumask_andnot(affinity, affinity, cpu_dying_mask); if (cpumask_any_and(affinity, cpu_online_mask) >=3D nr_cpu_ids) { /* * If the interrupt is managed, then shut it down and leave @@ -120,7 +121,7 @@ static bool migrate_one_irq(struct irq_desc *desc) irq_shutdown_and_deactivate(desc); return false; } - affinity =3D cpu_online_mask; + cpumask_andnot(affinity, cpu_online_mask, cpu_dying_mask); brokeaff =3D true; } /* --=20 2.31.1 From nobody Fri Apr 10 17:13:29 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 82651C00140 for ; Mon, 22 Aug 2022 02:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232508AbiHVCRM (ORCPT ); Sun, 21 Aug 2022 22:17:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232413AbiHVCQo (ORCPT ); Sun, 21 Aug 2022 22:16:44 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 937F122B34 for ; Sun, 21 Aug 2022 19:16:43 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id u22so8652404plq.12 for ; Sun, 21 Aug 2022 19:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=PHnhWNxyM6E9IxuW9zPMNCsqVfB66utEZnswI2QVnUY=; b=moyaT8LSzbsNueFItnBmXfweqqJW9rd5NwnfMitdVq1qYPLzlWYAklL72LaXB9oDvS JpCgS1YpoIHyPnh0KSuubJSnDsEtvOt1uncB6yxmaK8MQOhSUye5ULeoyFZ8gLHcgLtm CZha7A0JSZxdrdNhCQIMcHj8tXNLhk7KWvT6y/0bqmWktx98ivUpz7ndxNdcnYsvd4Gv djm4Wghi5lRR/MwRT4vwVy70tUYaHEdli5D2yg/fRmtSZ4BS+A33PfPf0bFw2aQWfAY8 ieb8o1pFrhi9TXDdC7A1CU5ozlkzki6nUWCPZilyRhE0maI0dWIklZ1jVX0QH4g3WCqd nXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=PHnhWNxyM6E9IxuW9zPMNCsqVfB66utEZnswI2QVnUY=; b=jhl2tQ5whCyjlssfauajxzmwSbQ94GcGetZL4l2ZnSstahovw6SdiOVDkwtGTO4hIx Z7eacy927u0EpsfDQCo7y7+kli/I//p+p+XTL4pKeDtSO15rHdc1QlvcxqjlL4Uj8qKo MVybAMa2jPDTnJuFmcTt/lEOcJN3qYoCEHzFGCDtQRQpVOGlsxNoPzvphZ9D0hFbaYFb lN2/+0Qa5eK3JaoJaeOzjB0snwN1NtHPiJDEC+6NyIWM0xLEQrQcHT2G8c7DQfYZM9TN 9tlO8/WL9JSwJ6+ucR3AEYNvALBo86Llvl4YlJvz/4iol3vD4wCdzY5YBpUZNV8cvHxS Ck4Q== X-Gm-Message-State: ACgBeo0oiZyXEti1ELq6yGcm54dbTtZSY/R1IPxHJKvwWrgavnedHbEm kYzhwrG0+RKA3sttJ33XNA== X-Google-Smtp-Source: AA6agR57jl9X7wl2LO5S9m+7exo7QRftfzMvBzue936dsrZ1sTIFM7iDKbI/NpJ/4k6h+XhaKlz7WA== X-Received: by 2002:a17:90a:c402:b0:1f8:c335:d4d7 with SMTP id i2-20020a17090ac40200b001f8c335d4d7mr26607609pjt.242.1661134602655; Sun, 21 Aug 2022 19:16:42 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k3-20020aa79723000000b005321340753fsm7312139pfg.103.2022.08.21.19.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 19:16:42 -0700 (PDT) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Viresh Kumar , Sudeep Holla , Phil Auld , Rob Herring , Ben Dooks Subject: [RFC 10/10] arm64: smp: Make __cpu_disable() parallel Date: Mon, 22 Aug 2022 10:15:20 +0800 Message-Id: <20220822021520.6996-11-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com> References: <20220822021520.6996-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" On a dying cpu, take_cpu_down()->__cpu_disable(), which means if the teardown path supports parallel, __cpu_disable() confront the parallel, which may ruin cpu_online_mask etc if no extra lock provides the protection. At present, the cpumask is protected by cpu_add_remove_lock, that lock is quite above __cpu_disable(). In order to protect __cpu_disable() from parrallel in kexec quick reboot path, introducing a local lock cpumap_lock. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Viresh Kumar Cc: Sudeep Holla Cc: Phil Auld Cc: Rob Herring Cc: Ben Dooks To: linux-arm-kernel@lists.infradead.org To: linux-kernel@vger.kernel.org --- arch/arm64/kernel/smp.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index ffc5d76cf695..fee8879048b0 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -287,6 +287,28 @@ static int op_cpu_disable(unsigned int cpu) return 0; } =20 +static DEFINE_SPINLOCK(cpumap_lock); + +static void __cpu_clear_maps(unsigned int cpu) +{ + /* + * In the case of kexec rebooting, the cpu_add_remove_lock mutex can not = protect + */ + if (kexec_in_progress) + spin_lock(&cpumap_lock); + remove_cpu_topology(cpu); + numa_remove_cpu(cpu); + + /* + * Take this CPU offline. Once we clear this, we can't return, + * and we must not schedule until we're ready to give up the cpu. + */ + set_cpu_online(cpu, false); + if (kexec_in_progress) + spin_unlock(&cpumap_lock); + +} + /* * __cpu_disable runs on the processor to be shutdown. */ @@ -299,14 +321,7 @@ int __cpu_disable(void) if (ret) return ret; =20 - remove_cpu_topology(cpu); - numa_remove_cpu(cpu); - - /* - * Take this CPU offline. Once we clear this, we can't return, - * and we must not schedule until we're ready to give up the cpu. - */ - set_cpu_online(cpu, false); + __cpu_clear_maps(cpu); ipi_teardown(cpu); =20 /* --=20 2.31.1