Re: [PATCH v3 06/12] smp: Enable preemption early in smp_call_function_many_cond

From: Chuyi Zhou

Date: Wed Mar 18 2026 - 23:47:14 EST


在 2026/3/19 00:55, Sebastian Andrzej Siewior 写道:
> On 2026-03-18 12:56:32 [+0800], Chuyi Zhou wrote:
>> --- a/kernel/smp.c
>> +++ b/kernel/smp.c
>> @@ -907,9 +920,11 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>> }
>> }
>
> So now I understand why we have this cpumask on stack.
> Could we, on a preemptible kernel, where we have a preemption counter,
> in the case of preemptible() allocate a cpumask and use it here? If the
> allocation fails or we are not on a preemptbile kernel then we don't do
> this optimized wait with enabled preemption.
>
> There is no benefit of doing all this if the caller has already
> preemption disabled.
>

IIUC, we can enable this feature only when
`IS_ENABLED(CONFIG_PREEMPTION) && preemptible()`.

This way, the optimization can also take effect for
CONFIG_CPUMASK_OFFSTACK=y without breaking the RT principle that forbids
memory allocation inside preemption-disabled critical sections.

Thanks.

>> - rcu_read_unlock();
>> - if (preemptible_wait)
>> + if (!preemptible_wait)
>> + put_cpu();
>> + else
>> free_cpumask_var(cpumask_stack);
>> + rcu_read_unlock();
>> }
>>
>> /**
>
> Sebastian