return !!req->file;
}
+static void io_queue_iowq(struct io_kiocb *req);
+
+static void io_queue_iowq_foreign_tw(struct io_tw_req tw_req, io_tw_token_t tw)
+{
+ struct io_kiocb *req = tw_req.req;
+
+ io_tw_lock(req->ctx, tw);
+ if (unlikely(tw.cancel))
+ io_req_defer_failed(req, -ECANCELED);
+ else
+ io_queue_iowq(req);
+}
+
static void io_queue_iowq(struct io_kiocb *req)
{
struct io_uring_task *tctx = req->tctx;
BUG_ON(!tctx);
lockdep_assert_held(&req->ctx->uring_lock);
- if ((current->flags & PF_KTHREAD) || !tctx->io_wq) {
- io_req_task_queue_fail(req, -ECANCELED);
+ if (current->flags & PF_KTHREAD)
+ goto cancel;
+
+ /* Only the submitter can safely access its io-wq during task exit. */
+ if (unlikely(current != tctx->task)) {
+ req->io_task_work.func = io_queue_iowq_foreign_tw;
+ io_req_task_work_add(req);
return;
}
+ if (!tctx->io_wq)
+ goto cancel;
/*
* The file is looked up as late as possible, as it may be the result
trace_io_uring_queue_async_work(req, io_wq_is_hashed(&req->work));
io_wq_enqueue(tctx->io_wq, &req->work);
+ return;
+cancel:
+ io_req_task_queue_fail(req, -ECANCELED);
}
static void io_req_queue_iowq_tw(struct io_tw_req tw_req, io_tw_token_t tw)