On 19/09/2020 18:27, Pavel Begunkov wrote: > On 14/09/2020 19:25, Jens Axboe wrote: >> Always grab work environment for deferred links. The assumption that we >> will be running it always from the task in question is false, as exiting >> tasks may mean that we're deferring this one to a thread helper. And at >> that point it's too late to grab the work environment. > > That's a shame. Do you mean that's from lines like below? > > int io_async_buf_func() > { > ... > if (!io_req_task_work_add()) { > ... > tsk = io_wq_get_task(req->ctx->io_wq); > task_work_add(tsk, &req->task_work, 0); > } > } > > It looks like failing such requests would be a better option. > io_uring_flush() would want them killed for PF_EXITING processes anyway. Forgot that they will be cancelled there. So, how it could happen? Is that the initial thread will run task_work but loosing some resources like mm prior to that? e.g. in do_exit() > >> >> Fixes: debb85f496c9 ("io_uring: factor out grab_env() from defer_prep()") >> Signed-off-by: Jens Axboe <axboe@xxxxxxxxx> >> --- >> fs/io_uring.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/fs/io_uring.c b/fs/io_uring.c >> index 175fb647d099..be9d628e7854 100644 >> --- a/fs/io_uring.c >> +++ b/fs/io_uring.c >> @@ -5449,6 +5449,8 @@ static int io_req_defer_prep(struct io_kiocb *req, >> if (unlikely(ret)) >> return ret; >> >> + io_prep_async_work(req); >> + >> switch (req->opcode) { >> case IORING_OP_NOP: >> break; >> > -- Pavel Begunkov