Re: [PATCH v3 04/12] smp: Use on-stack cpumask in smp_call_function_many_cond

From: Steven Rostedt

Date: Wed Mar 18 2026 - 10:46:39 EST


On Wed, 18 Mar 2026 12:56:30 +0800
"Chuyi Zhou" <zhouchuyi@xxxxxxxxxxxxx> wrote:

> diff --git a/kernel/smp.c b/kernel/smp.c
> index 80daf9dd4a25..9728ba55944d 100644
> --- a/kernel/smp.c
> +++ b/kernel/smp.c
> @@ -799,14 +799,25 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
> unsigned int scf_flags,
> smp_cond_func_t cond_func)
> {
> + bool preemptible_wait = !IS_ENABLED(CONFIG_CPUMASK_OFFSTACK);
> int cpu, last_cpu, this_cpu = smp_processor_id();
> struct call_function_data *cfd;
> bool wait = scf_flags & SCF_WAIT;
> + cpumask_var_t cpumask_stack;
> + struct cpumask *cpumask;
> int nr_cpus = 0;
> bool run_remote = false;

> @@ -887,13 +897,16 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
> }
>
> if (run_remote && wait) {
> - for_each_cpu(cpu, cfd->cpumask) {
> + for_each_cpu(cpu, cpumask) {
> call_single_data_t *csd;
>
> csd = per_cpu_ptr(cfd->csd, cpu);
> csd_lock_wait(csd);
> }
> }
> +
> + if (preemptible_wait)
> + free_cpumask_var(cpumask_stack);

Ironic, that preemptible_wait is only true if !CONFIG_CPUMASK_OFFSTACK, and
free_cpumask_var() is defined as:

// #ifndef CONFIG_CPUMASK_OFFSTACK
static __always_inline void free_cpumask_var(cpumask_var_t mask)
{
}

So basically the above is just a compiler exercise to insert a nop :-/

-- Steve


> }