Skip to content

Commit febb985

Browse files
committed
io_uring/poll: add hash if ready poll request can't complete inline
If we don't, then we may lose access to it completely, leading to a request leak. This will eventually stall the ring exit process as well. Cc: [email protected] Fixes: 49f1c68 ("io_uring: optimise submission side poll_refs") Reported-and-tested-by: [email protected] Link: https://lore.kernel.org/io-uring/[email protected]/ Suggested-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e6db6f9 commit febb985

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

io_uring/poll.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ static bool io_poll_can_finish_inline(struct io_kiocb *req,
533533
return pt->owning || io_poll_get_ownership(req);
534534
}
535535

536+
static void io_poll_add_hash(struct io_kiocb *req)
537+
{
538+
if (req->flags & REQ_F_HASH_LOCKED)
539+
io_poll_req_insert_locked(req);
540+
else
541+
io_poll_req_insert(req);
542+
}
543+
536544
/*
537545
* Returns 0 when it's handed over for polling. The caller owns the requests if
538546
* it returns non-zero, but otherwise should not touch it. Negative values
@@ -591,18 +599,17 @@ static int __io_arm_poll_handler(struct io_kiocb *req,
591599

592600
if (mask &&
593601
((poll->events & (EPOLLET|EPOLLONESHOT)) == (EPOLLET|EPOLLONESHOT))) {
594-
if (!io_poll_can_finish_inline(req, ipt))
602+
if (!io_poll_can_finish_inline(req, ipt)) {
603+
io_poll_add_hash(req);
595604
return 0;
605+
}
596606
io_poll_remove_entries(req);
597607
ipt->result_mask = mask;
598608
/* no one else has access to the req, forget about the ref */
599609
return 1;
600610
}
601611

602-
if (req->flags & REQ_F_HASH_LOCKED)
603-
io_poll_req_insert_locked(req);
604-
else
605-
io_poll_req_insert(req);
612+
io_poll_add_hash(req);
606613

607614
if (mask && (poll->events & EPOLLET) &&
608615
io_poll_can_finish_inline(req, ipt)) {

0 commit comments

Comments
 (0)