Re: [RFC] exit: do exit_task_work() before shooting off mm

From: Oleg Nesterov
Date: Sun Dec 20 2020 - 09:13:47 EST


On 12/20, Pavel Begunkov wrote:
>
> On 08/12/2020 01:37, Al Viro wrote:
> > On Thu, Dec 03, 2020 at 02:30:46AM +0000, Pavel Begunkov wrote:
> >> Handle task works and lock it earlier before it starts killing off
> >> task's resources like mm. io_uring makes use of it a lot and it'd
> >> nicer to have all added task_work finding tasks in a consistent state.

I too do not understand this patch. task_work_add() will fail after
exit_task_work(). This means that, for example, exit_files() will use
schedule_delayed_work().

> One more moment, after we've set PF_EXITING any task_work_run() would be
> equivalent to exit_task_work()

Yes, currently task_work_run() can not be called after exit_signals().
And shouldn't be called imo ;)

> io_uring
> may want (currently doesn't) to run works for cancellation purposes.

Please see https://lore.kernel.org/io-uring/20200407163816.GB9655@xxxxxxxxxx/

> Shouldn't it be like below (not tested)? Also simplifies task_work_run().

I'd prefer the patch from the link above, but your version looks correct too.
However, I still think it would be better to not abuse task_work_run() too
much...

Oleg.