Re: [PATCH v7 4/4] workqueue: Unbind kworkers before sending them to exit()

From: Tejun Heo
Date: Tue Jan 10 2023 - 15:31:35 EST


Hello,

The series generally looks good to me. Just one thing.

On Mon, Jan 09, 2023 at 01:33:16PM +0000, Valentin Schneider wrote:
> @@ -3658,13 +3702,24 @@ static void put_unbound_pool(struct worker_pool *pool)
> TASK_UNINTERRUPTIBLE);
> pool->flags |= POOL_MANAGER_ACTIVE;
>
> + /*
> + * We need to hold wq_pool_attach_mutex() while destroying the workers,
> + * but we can't grab it in rcuwait_wait_event() as it can clobber
> + * current's task state. We can drop pool->lock here as we've set
> + * POOL_MANAGER_ACTIVE, no one else can steal our manager position.
> + */
> + raw_spin_unlock_irq(&pool->lock);
> + mutex_lock(&wq_pool_attach_mutex);
> + raw_spin_lock_irq(&pool->lock);

The original pattern was a bit weird to begin with and this makes it quite
worse. Let's do something more straight forward like:

while (true) {
rcuwait_wait_event(&manager_wait,
!(pool->flags & POOL_MANAGER_ACTIVE),
TASK_UNINTERRUPTIBLE);
mutex_lock(&wq_pool_attach_mutex);
raw_spin_lock_irq(&pool->lock);
if (!(pool->flags & POOL_MANAGER_ACTIVE)) {
pool->flags |= POOL_MANAGER_ACTIVE;
break;
}
raw_spin_unlock_irq(&pool->lock);
mutex_unlock(&wq_pool_attach_mutex);
}

Thanks.

--
tejun