Re: [Bug] premature worker thread wakeup
From: Valentin Schneider
Date: Fri Sep 20 2024 - 06:18:25 EST
On 20/09/24 15:25, Yan, Zheng wrote:
>
> Looks like the newly created kthread got woke up prematurely. Checking
> the source code, path "workqueue: Unbind kworkers before sending them
> to exit()" looks suspicious. The patch wakes up dying worker's task up
> without holding pool->lock. Is it possible that another worker thread
> recently died, the newly create worker thread reused the dead thread's
> task_struct and wrongly got woke up.
>
Per the comment in idle_cull_fn():
* Grabbing wq_pool_attach_mutex here ensures an already-running worker
* cannot proceed beyong set_pf_worker() in its self-destruct path.
* This is required as a previously-preempted worker could run after
* set_worker_dying() has happened but before detach_dying_workers() did.
the task shouldn't be able to exit() even if we don't hold &pool->lock.
Also, things have changed a little in this area, for instance see
f4b7b53c94af ("workqueue: Detach workers directly in idle_cull_fn()")
Could you try to reproduce this using a more recent upstream kernel?
> Regards
> Yan, Zheng