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

Valentin Schneider
2022-10-05T16:14:29Z

On 05/10/22 22:50, Hillf Danton wrote:
> On 05 Oct 2022 12:13:17 +0100 Valentin Schneider <vschneid@redhat.com>
>
> Bound kworkers can be destroyed by the idle timer on a housekeeping CPU.
>
> Diff is only for thoughts.
>
> +++ b/kernel/workqueue.c
> @@ -1985,6 +1985,7 @@ fail:
> static void destroy_worker(struct worker *worker)
> {
> struct worker_pool *pool = worker->pool;
> + int cpu = smp_processor_id();
>
> lockdep_assert_held(&pool->lock);
>
> @@ -1999,6 +2000,12 @@ static void destroy_worker(struct worker
>
> list_del_init(&worker->entry);
> worker->flags |= WORKER_DIE;
> +
> + if (!(pool->flags & POOL_DISASSOCIATED) && pool->cpu != cpu) {
> + /* send worker to die on a housekeeping cpu */
> + cpumask_clear(&worker->task->cpus_mask);
> + cpumask_set_cpu(cpu, &worker->task->cpus_mask);
> + }
> wake_up_process(worker->task);
> }
>

The proper interface to play with that cpumask is set_cpus_allowed_ptr(),
which requires a sleepable context, hence the whole series.