Re: [PATCH v8 05/14] smp: Alloc percpu csd data in smpcfd_prepare_cpu() only once
From: Thomas Gleixner
Date: Fri Jun 26 2026 - 10:34:05 EST
On Tue, Jun 16 2026 at 19:11, Chuyi Zhou wrote:
> Later patch would enable preemption during csd_lock_wait() in
> smp_call_function_many_cond(), which may cause access cfd->csd data that
> has already been freed in smpcfd_dead_cpu().
>
> One way to fix the above issue is to use the RCU mechanism to protect the
> csd data and wait for all read critical sections to exit before freeing
> the memory in smpcfd_dead_cpu(), but this could delay CPU shutdown. This
> patch chooses a simpler approach: allocate the percpu csd on the UP side
> only once and skip freeing the csd memory in smpcfd_dead_cpu().
See earlier comments about change logs.
> - cfd->csd = alloc_percpu(call_single_data_t);
> +
> + /*
> + * The percpu csd is allocated only once and never freed.
> + * This ensures that smp_call_function_many_cond() can safely
> + * access the csd of an offlined CPU if it gets preempted
> + * during csd_lock_wait().
I know what you are trying to say, but that sentence does not parse.
Allocate the per CPU csd at the first time a CPU comes up. It's
not freed when the CPU is offlined. That ensures that the per CPU
CSD can be accessed from csd_lock_wait() even when the CPU was
offlined after preemption was reenabled before invoking it.
Or something like that.