From edeac4546a71b6c1db4ba006a2dbf7c863f54e9a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 3 Nov 2026 08:46:59 -0700 Subject: [PATCH] io_uring/poll: don't poll a writer for urgent data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit io_arm_poll_handler() starts the mask of every async poll with EPOLLPRI, for a reader and a writer alike. A TCP socket reports EPOLLPRI for as long as urgent data sits unread, so once the peer has sent a byte with MSG_OOB, the async poll of a send that waits for buffer space is ready on every re-arm. The request spins through task_work and __io_arm_poll_handler() until APOLL_MAX_RETRY is used up and io-wq takes it, the same spin that EPOLLRDHUP caused for a half-closed peer. While it spins, the request is neither in the poll hash nor in io-wq. A cancel issued right after the send gets -ENOENT and the send stays pending, until a later cancel finds it in io-wq. Only add EPOLLPRI for polls that want to read. Urgent data is an event for a recv, not for a writer. Fixes: d7718a9d25a6 ("io_uring: use poll driven retry for files that support it") Reported-by: Lukáš Lalinský Signed-off-by: Jens Axboe --- io_uring/poll.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 9703a2fdfb44..fc1800c7097b 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -739,7 +739,7 @@ int io_arm_apoll(struct io_kiocb *req, unsigned issue_flags, __poll_t mask) int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) { const struct io_issue_def *def = &io_issue_defs[req->opcode]; - __poll_t mask = POLLPRI | POLLERR; + __poll_t mask = EPOLLERR; if (!def->pollin && !def->pollout) return IO_APOLL_ABORTED; @@ -747,7 +747,8 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) return IO_APOLL_ABORTED; if (def->pollin) { - mask |= EPOLLIN | EPOLLRDNORM; + /* urgent data is an event for a reader only */ + mask |= EPOLLIN | EPOLLRDNORM | EPOLLPRI; /* If reading from MSG_ERRQUEUE using recvmsg, ignore POLLIN */ if (req->flags & REQ_F_CLEAR_POLLIN)