Skip to content

Commit 81f48e4

Browse files
isilencemehmetb0
authored andcommitted
io_uring/waitid: don't abuse io_tw_state
BugLink: https://bugs.launchpad.net/bugs/2104873 [ Upstream commit 06521ac ] struct io_tw_state is managed by core io_uring, and opcode handling code must never try to cheat and create their own instances, it's plain incorrect. io_waitid_complete() attempts exactly that outside of the task work context, and even though the ring is locked, there would be no one to reap the requests from the defer completion list. It only works now because luckily it's called before io_uring_try_cancel_uring_cmd(), which flushes completions. Fixes: f31ecf6 ("io_uring: add IORING_OP_WAITID support") Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Noah Wager <noah.wager@canonical.com>
1 parent c80b4c3 commit 81f48e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

io_uring/waitid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ static int io_waitid_finish(struct io_kiocb *req, int ret)
118118
static void io_waitid_complete(struct io_kiocb *req, int ret)
119119
{
120120
struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
121-
struct io_tw_state ts = {};
122121

123122
/* anyone completing better be holding a reference */
124123
WARN_ON_ONCE(!(atomic_read(&iw->refs) & IO_WAITID_REF_MASK));
@@ -131,7 +130,6 @@ static void io_waitid_complete(struct io_kiocb *req, int ret)
131130
if (ret < 0)
132131
req_set_fail(req);
133132
io_req_set_res(req, ret, 0);
134-
io_req_task_complete(req, &ts);
135133
}
136134

137135
static bool __io_waitid_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
@@ -153,6 +151,7 @@ static bool __io_waitid_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req)
153151
list_del_init(&iwa->wo.child_wait.entry);
154152
spin_unlock_irq(&iw->head->lock);
155153
io_waitid_complete(req, -ECANCELED);
154+
io_req_queue_tw_complete(req, -ECANCELED);
156155
return true;
157156
}
158157

@@ -258,6 +257,7 @@ static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state *ts)
258257
}
259258

260259
io_waitid_complete(req, ret);
260+
io_req_task_complete(req, ts);
261261
}
262262

263263
static int io_waitid_wait(struct wait_queue_entry *wait, unsigned mode,

0 commit comments

Comments
 (0)