Re: [PATCH/RFC] core/nfsd: allow kernel threads to use task_work.
From: Oleg Nesterov
Date: Tue Nov 28 2023 - 12:04:12 EST
On 11/28, Christian Brauner wrote:
>
> Yeah, I had played with that as well. Only reason I didn't do it was to
> avoid a PF_* flag. If that's preferable it might be worth to just add
> PF_TASK_WORK and decouple this from PF_KTHREAD.
OK, I won't insist.
But,
> + /*
> + * By default only non-kernel threads can use task work. Kernel
> + * threads that manage task work explicitly can add that flag in
> + * their kthread callback.
> + */
> + if (!args->kthread)
> + p->flags |= PF_TASK_WORK;
The comment and the name of the new flag look a bit misleading to me...
kthreads can use task_work's. You can create a kthread which does
task_work_run() from time to time and use task_work_add() on it,
nothing wrong with that.
Probably nobody does this right now (I didn't try to check), but please
note irq_thread()->task_work_add(on_exit_work).
Oleg.