Re: [PATCH v8 03/14] smp: Refactor remote CPU selection in smp_call_function_any()
From: Thomas Gleixner
Date: Fri Jun 26 2026 - 09:49:51 EST
On Tue, Jun 16 2026 at 19:11, Chuyi Zhou wrote:
> Currently, smp_call_function_any() disables preemption across the entire
> process of picking a target CPU, enqueueing the IPI, and synchronously
> waiting for the remote CPU. Since smp_call_function_single() has already
> been optimized to re-enable preemption before the synchronous
> csd_lock_wait(), callers of smp_call_function_any() should also benefit
> from this optimization to reduce the preemption-disabled critical section.
>
> A naive approach would be to simply remove get_cpu() and put_cpu() from
> smp_call_function_any(), leaving the preemption disablement entirely to
> smp_call_function_single(). However, doing so opens a dangerous
> preemption window between picking the remote CPU (e.g., via
> sched_numa_find_nth_cpu()) and dispatching the IPI inside
> smp_call_function_single(). If the selected remote CPU is fully offlined
> during this window, smp_call_function_single() will fail its
> cpu_online() check and return -ENXIO directly to the caller, violating
> the guarantee to execute on *any* online CPU in the mask.
>
> To safely enable this optimization, this patch refactors the logic of
s/this patch//
> smp_call_function_any() and smp_call_function_single(). By moving the
> random remote CPU selection into a common __smp_call_function_single(),
> and keep the entire selection and IPI dispatch process within a single
> preemption-disabled region.
This is actually a nice comprehensible change log.
> +static int __smp_call_function_single(int cpu, smp_call_func_t func,
> + void *info, const struct cpumask *mask, int wait)
Please align the second row argument with the first argument of the row
above. See Documentation. And while at it please make 'wait' bool
because it _is_ a boolean flag.
> +
> +/**
> + * smp_call_function_single - Run a function on a specific CPU
> + * @cpu: Specific target CPU for this function.
> + * @func: The function to run. This must be fast and non-blocking.
> + * @info: An arbitrary pointer to pass to the function.
> + * @wait: If true, wait until function has completed on other CPUs.
While at it please align the argument descriptors tabular. This zigzag
is harder too read. See documentation.
> + *
> + * Returns: %0 on success, else a negative status code.
> + */
> +int smp_call_function_single(int cpu, smp_call_func_t func, void *info,
> + int wait)
bool wait and no line break required.