Commit 81ec803b authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: refactor io_disarm_next() locking

Split timeout handling into removal + failing, so we can reduce
spinlocking time and remove another instance of triple nested locking.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/0f00d115f9d4c5749028f19623708ad3695512d6.1650458197.git.asml.silence@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3645c200
...@@ -2372,7 +2372,7 @@ static inline void io_remove_next_linked(struct io_kiocb *req) ...@@ -2372,7 +2372,7 @@ static inline void io_remove_next_linked(struct io_kiocb *req)
nxt->link = NULL; nxt->link = NULL;
} }
static bool io_kill_linked_timeout(struct io_kiocb *req) static struct io_kiocb *io_disarm_linked_timeout(struct io_kiocb *req)
__must_hold(&req->ctx->completion_lock) __must_hold(&req->ctx->completion_lock)
__must_hold(&req->ctx->timeout_lock) __must_hold(&req->ctx->timeout_lock)
{ {
...@@ -2385,11 +2385,10 @@ static bool io_kill_linked_timeout(struct io_kiocb *req) ...@@ -2385,11 +2385,10 @@ static bool io_kill_linked_timeout(struct io_kiocb *req)
link->timeout.head = NULL; link->timeout.head = NULL;
if (hrtimer_try_to_cancel(&io->timer) != -1) { if (hrtimer_try_to_cancel(&io->timer) != -1) {
list_del(&link->timeout.list); list_del(&link->timeout.list);
io_req_tw_post_queue(link, -ECANCELED, 0); return link;
return true;
} }
} }
return false; return NULL;
} }
static void io_fail_links(struct io_kiocb *req) static void io_fail_links(struct io_kiocb *req)
...@@ -2423,11 +2422,11 @@ static void io_fail_links(struct io_kiocb *req) ...@@ -2423,11 +2422,11 @@ static void io_fail_links(struct io_kiocb *req)
static bool io_disarm_next(struct io_kiocb *req) static bool io_disarm_next(struct io_kiocb *req)
__must_hold(&req->ctx->completion_lock) __must_hold(&req->ctx->completion_lock)
{ {
struct io_kiocb *link = NULL;
bool posted = false; bool posted = false;
if (req->flags & REQ_F_ARM_LTIMEOUT) { if (req->flags & REQ_F_ARM_LTIMEOUT) {
struct io_kiocb *link = req->link; link = req->link;
req->flags &= ~REQ_F_ARM_LTIMEOUT; req->flags &= ~REQ_F_ARM_LTIMEOUT;
if (link && link->opcode == IORING_OP_LINK_TIMEOUT) { if (link && link->opcode == IORING_OP_LINK_TIMEOUT) {
io_remove_next_linked(req); io_remove_next_linked(req);
...@@ -2438,8 +2437,12 @@ static bool io_disarm_next(struct io_kiocb *req) ...@@ -2438,8 +2437,12 @@ static bool io_disarm_next(struct io_kiocb *req)
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
spin_lock_irq(&ctx->timeout_lock); spin_lock_irq(&ctx->timeout_lock);
posted = io_kill_linked_timeout(req); link = io_disarm_linked_timeout(req);
spin_unlock_irq(&ctx->timeout_lock); spin_unlock_irq(&ctx->timeout_lock);
if (link) {
posted = true;
io_req_tw_post_queue(link, -ECANCELED, 0);
}
} }
if (unlikely((req->flags & REQ_F_FAIL) && if (unlikely((req->flags & REQ_F_FAIL) &&
!(req->flags & REQ_F_HARDLINK))) { !(req->flags & REQ_F_HARDLINK))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment