From nobody Fri Oct 3 14:34:21 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE8BD2264A3 for ; Thu, 28 Aug 2025 22:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756420819; cv=none; b=q4p88E3fmcSZ/Rr2zWZJ+1s3FGyidRN9vqGts7/+gNluuKQdiAjTwJka58UhDu++dlR6JxCqD+AMIhLY5Cuq6dfaVebpoiIaBcVsqq9xaX9ejqWLmFocA1qj2AERQmlz6lo55uHqdeZnELzYOsBXbb5BBWRRC1B2s8V6FzBcW5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756420819; c=relaxed/simple; bh=3GiqgHj2UCdSsbG5WJ6XWydJWCGenb/LnjW5cFj29m0=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=YOPUStrbIPZaaaz9ZC4o/5v7y9MatZ0jyKJKjzB39A1XDHd1CBCNgdQx97qKbCHatjTLTM5owJZEx1zd4LWW25jnjEjeEzvT/MdW7gN3Ulk0g4KpNhAyH4Pt02pJ2A5oSs/DzpgFaI0PxUAAJOQlU7B8cQfezoqO0KUTv8q60YA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCFF11655; Thu, 28 Aug 2025 15:40:07 -0700 (PDT) Received: from [192.168.0.16] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 371A73F63F; Thu, 28 Aug 2025 15:40:15 -0700 (PDT) Message-ID: Date: Thu, 28 Aug 2025 23:40:13 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Thomas Gleixner , "linux-kernel@vger.kernel.org" , yury.norov@gmail.com Cc: Rik van Riel From: Christian Loehle Subject: [PATCH] smp: Fix smp_call_function_any() if no CPU online Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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, =20 /* Try for same CPU (cheapest) */ cpu =3D get_cpu(); - if (!cpumask_test_cpu(cpu, mask)) + if (!cpumask_intersects(mask, cpu_online_mask)) + cpu =3D nr_cpu_ids; + else if (!cpumask_test_cpu(cpu, mask)) cpu =3D sched_numa_find_nth_cpu(mask, 0, cpu_to_node(cpu)); =20 ret =3D smp_call_function_single(cpu, func, info, wait); --=20 2.34.1