From nobody Mon May 11 05:35:27 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 5D1CCC433F5 for ; Wed, 13 Apr 2022 19:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238375AbiDMTfI (ORCPT ); Wed, 13 Apr 2022 15:35:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235045AbiDMTe7 (ORCPT ); Wed, 13 Apr 2022 15:34:59 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AEAF765A3; Wed, 13 Apr 2022 12:32:37 -0700 (PDT) Date: Wed, 13 Apr 2022 19:32:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649878356; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i6lyY7gYuA3rQrqgOJCKcG1pvgSi2gRjRaKKzPU+WDk=; b=IGeIC6Oarbu7Qh2cXS6/G0oHWodiTdhhOt7kZEtjAJA65CiLhQLWgo13um51VHz4El7BXL mP8oiLuCKNoG0/jEvwJfhmUbmPxBacmNfJE+NvvGNexTdafvlT60PWu6dFTEthxiYgOPIO CfgoHNjLmnxkUl14J7vvgRqUQDIkdg9zzlQ0eLbbou5E7gpR23s2L3Gp8Pp5entrJntN9+ B7sWs081XsmgpumCCabYKgQ3N7JyAE5MOC6o4zNftp1RzSV56Ip5pfNdB1fozoXnq76WAk PhlbPiZXbDmy9FEaJydtH5VzVYsifGGtyMQXdI2g2gxkKdPTzOBsEhn0VPeEOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649878356; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i6lyY7gYuA3rQrqgOJCKcG1pvgSi2gRjRaKKzPU+WDk=; b=6UJQEOHtIWlgxiKw8lZHXo08QPScoIk3lrKd+XTPfaZx/wKkp/oubvkp564n16qU+0yuE+ WnuT9g8ctmzoleBg== From: "tip-bot2 for Steven Price" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: smp/core] cpu/hotplug: Remove the 'cpu' member of cpuhp_cpu_state Cc: Steven Price , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220411152233.474129-2-steven.price@arm.com> References: <20220411152233.474129-2-steven.price@arm.com> MIME-Version: 1.0 Message-ID: <164987835485.4207.7844394206761192724.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the smp/core branch of tip: Commit-ID: b7ba6d8dc3569e49800ef0136799f26f43e237e8 Gitweb: https://git.kernel.org/tip/b7ba6d8dc3569e49800ef0136799f26f4= 3e237e8 Author: Steven Price AuthorDate: Mon, 11 Apr 2022 16:22:32 +01:00 Committer: Thomas Gleixner CommitterDate: Wed, 13 Apr 2022 21:25:40 +02:00 cpu/hotplug: Remove the 'cpu' member of cpuhp_cpu_state Currently the setting of the 'cpu' member of struct cpuhp_cpu_state in cpuhp_create() is too late as it is used earlier in _cpu_up(). If kzalloc_node() in __smpboot_create_thread() fails then the rollback will be done with st->cpu=3D=3D0 causing CPU0 to be erroneously set to be dying, causing the scheduler to get mightily confused and throw its toys out of the pram. However the cpu number is actually available directly, so simply remove the 'cpu' member and avoid the problem in the first place. Fixes: 2ea46c6fc945 ("cpumask/hotplug: Fix cpu_dying() state tracking") Signed-off-by: Steven Price Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20220411152233.474129-2-steven.price@arm.com --- kernel/cpu.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 5797c2a..d0a9aa0 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -71,7 +71,6 @@ struct cpuhp_cpu_state { bool rollback; bool single; bool bringup; - int cpu; struct hlist_node *node; struct hlist_node *last; enum cpuhp_state cb_state; @@ -475,7 +474,7 @@ static inline bool cpu_smt_allowed(unsigned int cpu) { = return true; } #endif =20 static inline enum cpuhp_state -cpuhp_set_state(struct cpuhp_cpu_state *st, enum cpuhp_state target) +cpuhp_set_state(int cpu, struct cpuhp_cpu_state *st, enum cpuhp_state targ= et) { enum cpuhp_state prev_state =3D st->state; bool bringup =3D st->state < target; @@ -486,14 +485,15 @@ cpuhp_set_state(struct cpuhp_cpu_state *st, enum cpuh= p_state target) st->target =3D target; st->single =3D false; st->bringup =3D bringup; - if (cpu_dying(st->cpu) !=3D !bringup) - set_cpu_dying(st->cpu, !bringup); + if (cpu_dying(cpu) !=3D !bringup) + set_cpu_dying(cpu, !bringup); =20 return prev_state; } =20 static inline void -cpuhp_reset_state(struct cpuhp_cpu_state *st, enum cpuhp_state prev_state) +cpuhp_reset_state(int cpu, struct cpuhp_cpu_state *st, + enum cpuhp_state prev_state) { bool bringup =3D !st->bringup; =20 @@ -520,8 +520,8 @@ cpuhp_reset_state(struct cpuhp_cpu_state *st, enum cpuh= p_state prev_state) } =20 st->bringup =3D bringup; - if (cpu_dying(st->cpu) !=3D !bringup) - set_cpu_dying(st->cpu, !bringup); + if (cpu_dying(cpu) !=3D !bringup) + set_cpu_dying(cpu, !bringup); } =20 /* Regular hotplug invocation of the AP hotplug thread */ @@ -541,15 +541,16 @@ static void __cpuhp_kick_ap(struct cpuhp_cpu_state *s= t) wait_for_ap_thread(st, st->bringup); } =20 -static int cpuhp_kick_ap(struct cpuhp_cpu_state *st, enum cpuhp_state targ= et) +static int cpuhp_kick_ap(int cpu, struct cpuhp_cpu_state *st, + enum cpuhp_state target) { enum cpuhp_state prev_state; int ret; =20 - prev_state =3D cpuhp_set_state(st, target); + prev_state =3D cpuhp_set_state(cpu, st, target); __cpuhp_kick_ap(st); if ((ret =3D st->result)) { - cpuhp_reset_state(st, prev_state); + cpuhp_reset_state(cpu, st, prev_state); __cpuhp_kick_ap(st); } =20 @@ -581,7 +582,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(st, st->target); + return cpuhp_kick_ap(cpu, st, st->target); } =20 static int bringup_cpu(unsigned int cpu) @@ -704,7 +705,7 @@ static int cpuhp_up_callbacks(unsigned int cpu, struct = cpuhp_cpu_state *st, ret, cpu, cpuhp_get_step(st->state)->name, st->state); =20 - cpuhp_reset_state(st, prev_state); + cpuhp_reset_state(cpu, st, prev_state); if (can_rollback_cpu(st)) WARN_ON(cpuhp_invoke_callback_range(false, cpu, st, prev_state)); @@ -721,7 +722,6 @@ static void cpuhp_create(unsigned int cpu) =20 init_completion(&st->done_up); init_completion(&st->done_down); - st->cpu =3D cpu; } =20 static int cpuhp_should_run(unsigned int cpu) @@ -875,7 +875,7 @@ 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(st, st->target); + ret =3D cpuhp_kick_ap(cpu, st, st->target); trace_cpuhp_exit(cpu, st->state, prev_state, ret); =20 return ret; @@ -1107,7 +1107,7 @@ static int cpuhp_down_callbacks(unsigned int cpu, str= uct cpuhp_cpu_state *st, ret, cpu, cpuhp_get_step(st->state)->name, st->state); =20 - cpuhp_reset_state(st, prev_state); + cpuhp_reset_state(cpu, st, prev_state); =20 if (st->state < prev_state) WARN_ON(cpuhp_invoke_callback_range(true, cpu, st, @@ -1134,7 +1134,7 @@ static int __ref _cpu_down(unsigned int cpu, int task= s_frozen, =20 cpuhp_tasks_frozen =3D tasks_frozen; =20 - prev_state =3D cpuhp_set_state(st, target); + prev_state =3D cpuhp_set_state(cpu, st, target); /* * If the current CPU state is in the range of the AP hotplug thread, * then we need to kick the thread. @@ -1165,7 +1165,7 @@ static int __ref _cpu_down(unsigned int cpu, int task= s_frozen, ret =3D cpuhp_down_callbacks(cpu, st, target); if (ret && st->state < prev_state) { if (st->state =3D=3D CPUHP_TEARDOWN_CPU) { - cpuhp_reset_state(st, prev_state); + cpuhp_reset_state(cpu, st, prev_state); __cpuhp_kick_ap(st); } else { WARN(1, "DEAD callback error for CPU%d", cpu); @@ -1352,7 +1352,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen= , enum cpuhp_state target) =20 cpuhp_tasks_frozen =3D tasks_frozen; =20 - cpuhp_set_state(st, target); + cpuhp_set_state(cpu, st, target); /* * If the current CPU state is in the range of the AP hotplug thread, * then we need to kick the thread once more.