Re: [PATCH 2/6] workqueue: Protect wq_unbound_cpumask with wq_pool_attach_mutex in init_rescuer()

From: Tejun Heo
Date: Wed Jul 03 2024 - 14:28:21 EST


Hello, Lai.

On Wed, Jul 03, 2024 at 11:38:51AM +0800, Lai Jiangshan wrote:
> @@ -5533,6 +5533,9 @@ static int init_rescuer(struct workqueue_struct *wq)
> return ret;
> }
>
> + /* lock wq_pool_attach_mutex for wq_unbound_cpumask */
> + mutex_lock(&wq_pool_attach_mutex);
> +
> wq->rescuer = rescuer;
> if (wq->flags & WQ_UNBOUND)
> kthread_bind_mask(rescuer->task, wq_unbound_cpumask);
> @@ -5540,6 +5543,8 @@ static int init_rescuer(struct workqueue_struct *wq)
> kthread_bind_mask(rescuer->task, cpu_possible_mask);
> wake_up_process(rescuer->task);
>
> + mutex_unlock(&wq_pool_attach_mutex);
> +

Isn't that just protecting the reads on wq_unbound_cpumask? I don't
understand what this protects against. Shouldn't the interlocking be
something like "either new rescuer reads the updated cpumask or the
workqueue is already on the workqueue list"?

Thanks.

--
tejun