mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpu: Fix online housekeeping CPU check in _cpu_down()
@ 2026-11-08 18:08 Waiman Long
  2026-11-08 18:19 ` Waiman Long
  0 siblings, 1 reply; 2+ messages in thread
From: Waiman Long @ 2026-11-08 18:08 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra, Frederic Weisbecker
  Cc: linux-kernel, Waiman Long

There is currently a check in _cpu_down() to make sure that there is
at least one online housekeeping (HK) CPU left after the shutdown of
the given @cpu parameter. However the cpu_online_mask used for the
check may include the current @cpu to be shut down. So the fact that
there is at least one online housekeeping CPU at the moment does not
guarantee that there will be any online housekeeping CPU left for the
sched domain after the shutdown.

Fix that by making sure that there are at least 2 online housekeeping
CPUs available if @cpu is currently a housekeeping CPU.

Fixes: de715325cc47 ("cpu: Revert "cpu/hotplug: Prevent self deadlock on CPU hot-unplug"")
Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/cpu.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index b3c8553d7bd6..ed641ee6b37c 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1415,11 +1415,14 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
 	cpus_write_lock();
 
 	/*
-	 * Keep at least one housekeeping cpu onlined to avoid generating
-	 * an empty sched_domain span.
+	 * Keep at least one housekeeping cpu online to avoid generating an
+	 * empty sched_domain span. As cpu_online_mask includes the @cpu to be
+	 * shut down, there should be at least 2 online HK CPUs at the moment
+	 * if @cpu is currently a HK CPU.
 	 */
-	if (cpumask_any_and(cpu_online_mask,
-			    housekeeping_cpumask(HK_TYPE_DOMAIN)) >= nr_cpu_ids) {
+	if (cpumask_test_cpu(cpu, housekeeping_cpumask(HK_TYPE_DOMAIN)) &&
+	   (cpumask_weight_and(cpu_online_mask,
+			       housekeeping_cpumask(HK_TYPE_DOMAIN)) < 2)) {
 		ret = -EBUSY;
 		goto out;
 	}
-- 
2.56.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cpu: Fix online housekeeping CPU check in _cpu_down()
  2026-11-08 18:08 [PATCH] cpu: Fix online housekeeping CPU check in _cpu_down() Waiman Long
@ 2026-11-08 18:19 ` Waiman Long
  0 siblings, 0 replies; 2+ messages in thread
From: Waiman Long @ 2026-11-08 18:19 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: linux-kernel, Thomas Gleixner, Frederic Weisbecker, Peter Zijlstra

Mathieu,

Sorry, I forgot to cc you on this patch.

Cheers,
Longman

On 11/8/26 1:08 PM, Waiman Long wrote:
> There is currently a check in _cpu_down() to make sure that there is
> at least one online housekeeping (HK) CPU left after the shutdown of
> the given @cpu parameter. However the cpu_online_mask used for the
> check may include the current @cpu to be shut down. So the fact that
> there is at least one online housekeeping CPU at the moment does not
> guarantee that there will be any online housekeeping CPU left for the
> sched domain after the shutdown.
>
> Fix that by making sure that there are at least 2 online housekeeping
> CPUs available if @cpu is currently a housekeeping CPU.
>
> Fixes: de715325cc47 ("cpu: Revert "cpu/hotplug: Prevent self deadlock on CPU hot-unplug"")
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>   kernel/cpu.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index b3c8553d7bd6..ed641ee6b37c 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -1415,11 +1415,14 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
>   	cpus_write_lock();
>   
>   	/*
> -	 * Keep at least one housekeeping cpu onlined to avoid generating
> -	 * an empty sched_domain span.
> +	 * Keep at least one housekeeping cpu online to avoid generating an
> +	 * empty sched_domain span. As cpu_online_mask includes the @cpu to be
> +	 * shut down, there should be at least 2 online HK CPUs at the moment
> +	 * if @cpu is currently a HK CPU.
>   	 */
> -	if (cpumask_any_and(cpu_online_mask,
> -			    housekeeping_cpumask(HK_TYPE_DOMAIN)) >= nr_cpu_ids) {
> +	if (cpumask_test_cpu(cpu, housekeeping_cpumask(HK_TYPE_DOMAIN)) &&
> +	   (cpumask_weight_and(cpu_online_mask,
> +			       housekeeping_cpumask(HK_TYPE_DOMAIN)) < 2)) {
>   		ret = -EBUSY;
>   		goto out;
>   	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-08 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 18:08 [PATCH] cpu: Fix online housekeeping CPU check in _cpu_down() Waiman Long
2026-11-08 18:19 ` Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®