Re: [PATCH v2 05/12] smp: Free call_function_data via RCU in smpcfd_dead_cpu
From: Chuyi Zhou
Date: Tue Mar 10 2026 - 03:27:36 EST
Hi Muchun,
在 2026/3/10 15:05, Muchun Song 写道:
>
>
>> On Mar 2, 2026, at 15:52, Chuyi Zhou <zhouchuyi@xxxxxxxxxxxxx> wrote:
>>
>> Use rcu_read_lock to protect the hole scope of smp_call_function_many_cond
> ^
> whole
>
> BTW, The protection we often refer to actually pertains to data, not code.
> Therefore, the rcu_read_lock() here is actually preventing smp_call_function_many_cond()
> from accessing percpu csd data that has already been freed (which is
> what smpcfd_dead_cpu() does).
>
OK.
>> and wait for all read critical sections to exit before releasing percpu csd
>> data. This is a preparation for enabling preemption during csd_lock_wait().
>>
>> Signed-off-by: Chuyi Zhou <zhouchuyi@xxxxxxxxxxxxx>
>> ---
>> kernel/smp.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/kernel/smp.c b/kernel/smp.c
>> index 9728ba55944d..ad6073b71bbd 100644
>> --- a/kernel/smp.c
>> +++ b/kernel/smp.c
>> @@ -77,6 +77,7 @@ int smpcfd_dead_cpu(unsigned int cpu)
>> {
>> struct call_function_data *cfd = &per_cpu(cfd_data, cpu);
>>
>> + synchronize_rcu();
>> free_cpumask_var(cfd->cpumask);
>> free_cpumask_var(cfd->cpumask_ipi);
>> free_percpu(cfd->csd);
>> @@ -810,6 +811,7 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>>
>> lockdep_assert_preemption_disabled();
>>
>> + rcu_read_lock();
>> cfd = this_cpu_ptr(&cfd_data);
>> cpumask = cfd->cpumask;
>>
>> @@ -907,6 +909,7 @@ static void smp_call_function_many_cond(const struct cpumask *mask,
>>
>> if (preemptible_wait)
>> free_cpumask_var(cpumask_stack);
>> + rcu_read_unlock();
>
> We could call rcu_read_unlock() before free_cpumask_var() above.
I will update in the next version.
Thanks.
>
>> }
>>
>> /**
>> --
>> 2.20.1
>