linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Loehle <christian.loehle@arm.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	yury.norov@gmail.com
Cc: Rik van Riel <riel@surriel.com>
Subject: [PATCH] smp: Fix smp_call_function_any() if no CPU online
Date: Thu, 28 Aug 2025 23:40:13 +0100	[thread overview]
Message-ID: <e381fd4b-fb90-41ae-a480-0dad1ce2aa9f@arm.com> (raw)

smp_call_function_any() used to handle a mask without any online
CPUs just fine, but when switching to use sched_numa_find_nth_cpu()
a previous check for online CPUs was removed.
smp_call_function_single() handles invalid CPUs just fine, so
just add the check back before calling sched_numa_find_nth_cpu().

An observed issue was when initializing PMUs on HMP if all CPUs
were offline (e.g. by booting with maxcpus):

[    1.192642] Call trace:
[    1.192868]  sched_numa_find_nth_cpu+0xc0/0x170 (P)
[    1.193323]  smp_call_function_any+0xc8/0xd0
[    1.193724]  armv8_pmu_init+0x58/0x27c
[    1.194079]  armv8_cortex_a72_pmu_init+0x20/0x2c
[    1.194507]  arm_pmu_device_probe+0x1e4/0x5e8
[    1.194911]  armv8_pmu_device_probe+0x1c/0x28
[    1.195316]  platform_probe+0x5c/0xac
[    1.195658]  really_probe+0xbc/0x298
[    1.195995]  __driver_probe_device+0x78/0x12c
[    1.196399]  driver_probe_device+0xdc/0x160
[    1.196787]  __driver_attach+0x94/0x19c
[    1.197146]  bus_for_each_dev+0x74/0xd4
[    1.197503]  driver_attach+0x24/0x30
[    1.197838]  bus_add_driver+0xe4/0x208
[    1.198187]  driver_register+0x60/0x128
[    1.198546]  __platform_driver_register+0x24/0x30
[    1.198974]  armv8_pmu_driver_init+0x28/0x4c
[    1.199372]  do_one_initcall+0x44/0x25c
[    1.199729]  kernel_init_freeable+0x1dc/0x3bc
[    1.200134]  kernel_init+0x20/0x1d8
[    1.200466]  ret_from_fork+0x10/0x20
[    1.200809] Code: 4b020264 eb04007f 54000129 51000402 (f860d825)
[    1.201355] ---[ end trace 0000000000000000 ]---

Fixes: 5f295519b42f ("smp: Improve locality in smp_call_function_any()")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Loehle <christian.loehle@arm.com>
---
 kernel/smp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index 56f83aa58ec8..cbce9699ced6 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -759,7 +759,9 @@ int smp_call_function_any(const struct cpumask *mask,
 
 	/* Try for same CPU (cheapest) */
 	cpu = get_cpu();
-	if (!cpumask_test_cpu(cpu, mask))
+	if (!cpumask_intersects(mask, cpu_online_mask))
+		cpu = nr_cpu_ids;
+	else if (!cpumask_test_cpu(cpu, mask))
 		cpu = sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu));
 
 	ret = smp_call_function_single(cpu, func, info, wait);
-- 
2.34.1

             reply	other threads:[~2025-08-28 22:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28 22:40 Christian Loehle [this message]
2025-09-03 15:53 ` [PATCH] smp: Fix smp_call_function_any() if no CPU online Christian Loehle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e381fd4b-fb90-41ae-a480-0dad1ce2aa9f@arm.com \
    --to=christian.loehle@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=riel@surriel.com \
    --cc=tglx@linutronix.de \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).