Skip to content

Commit a68ed2d

Browse files
committed
io_uring/poll: fix multishot recv missing EOF on wakeup race
When a socket send and shutdown() happen back-to-back, both fire wake-ups before the receiver's task_work has a chance to run. The first wake gets poll ownership (poll_refs=1), and the second bumps it to 2. When io_poll_check_events() runs, it calls io_poll_issue() which does a recv that reads the data and returns IOU_RETRY. The loop then drains all accumulated refs (atomic_sub_return(2) -> 0) and exits, even though only the first event was consumed. Since the shutdown is a persistent state change, no further wakeups will happen, and the multishot recv can hang forever. Check specifically for HUP in the poll loop, and ensure that another loop is done to check for status if more than a single poll activation is pending. This ensures we don't lose the shutdown event. Cc: stable@vger.kernel.org Fixes: dbc2564 ("io_uring: let fast poll support multishot") Reported-by: Francis Brosseau <francis@malagauche.com> Link: axboe/liburing#1549 Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c2c185b commit a68ed2d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

io_uring/poll.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
272272
atomic_andnot(IO_POLL_RETRY_FLAG, &req->poll_refs);
273273
v &= ~IO_POLL_RETRY_FLAG;
274274
}
275+
v &= IO_POLL_REF_MASK;
275276
}
276277

277278
/* the mask was stashed in __io_poll_execute */
@@ -304,8 +305,13 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
304305
return IOU_POLL_REMOVE_POLL_USE_RES;
305306
}
306307
} else {
307-
int ret = io_poll_issue(req, tw);
308+
int ret;
308309

310+
/* multiple refs and HUP, ensure we loop once more */
311+
if ((req->cqe.res & (POLLHUP | POLLRDHUP)) && v != 1)
312+
v--;
313+
314+
ret = io_poll_issue(req, tw);
309315
if (ret == IOU_COMPLETE)
310316
return IOU_POLL_REMOVE_POLL_USE_RES;
311317
else if (ret == IOU_REQUEUE)
@@ -321,7 +327,6 @@ static int io_poll_check_events(struct io_kiocb *req, io_tw_token_t tw)
321327
* Release all references, retry if someone tried to restart
322328
* task_work while we were executing it.
323329
*/
324-
v &= IO_POLL_REF_MASK;
325330
} while (atomic_sub_return(v, &req->poll_refs) & IO_POLL_REF_MASK);
326331

327332
io_napi_add(req);

0 commit comments

Comments
 (0)