smp: Fix smp_call_function_any() if no CPU online
PATCH 1/1 smp: Fix smp_call_function_any() if no CPU online
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 ]---
--- kernel/smp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/smp.c +3 -1
@@ -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);
Signature · 1 line
2.34.1
Quoted 46 lines · Christian Loehle
smp_call_function_any()used to handle a mask without any online CPUs just fine, but when switching to usesched_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 callingsched_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()")Signed-off-by Christian Loehle <[email protected]>--- kernel/smp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/smp.c +0
-0
kernel/smp.c int smp_call_function_any(const struct cpumask *mask, · line 767
Quoted 10 lines
kernel/smp.c +3
-1@@ -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);
Please disregard in favor of
https://lore.kernel.org/lkml/[email protected]/
as sched_numa_find_nth_cpu() should've handled this case.