From fca3ff9e2eee7d285585daf51942e0b5e2be354a Mon Sep 17 00:00:00 2001 From: Shuai Liu <847807867@qq.com> Date: Mon, 2 Nov 2026 16:05:42 +0800 Subject: [PATCH 01/11] io_uring/sqpoll: don't set IO_SQ_THREAD_SHOULD_STOP on thread exit io_sq_thread_stop() carries a WARN_ON_ONCE() asserting that IO_SQ_THREAD_SHOULD_STOP isn't set yet, i.e. that stopping the SQPOLL thread is never attempted twice. Since commit 22d9db9fd64a ("io_uring/sqpoll: don't attach to a thread that is canceling"), the SQPOLL thread itself sets that bit on its way out, so that io_sq_offload_create() won't attach a new ring to a thread that is canceling. When the thread exits on a fatal signal, the bit is thus set before the ring teardown gets to io_sq_thread_stop(), which now triggers the warning on every such exit: WARNING: io_uring/sqpoll.c:88 at io_sq_thread_stop Workqueue: iou_exit io_ring_exit_work Call Trace: io_put_sq_data io_sq_thread_finish io_ring_ctx_free io_ring_exit_work Introduce a separate IO_SQ_THREAD_EXITING bit for the thread marking itself as on its way out, and check it in io_sq_offload_create() along with IO_SQ_THREAD_SHOULD_STOP. IO_SQ_THREAD_SHOULD_STOP regains its original meaning, "a stop has been requested", and the WARN_ON_ONCE() holds again. Reproduced with an SQPOLL ring and an immediate fatal signal: the warning fires on v7.3.0+ (22d9db9fd64a present) and is gone with this change. Reported-by: syzbot+675af112519ca34f5502@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=675af112519ca34f5502 Fixes: 22d9db9fd64a ("io_uring/sqpoll: don't attach to a thread that is canceling") Signed-off-by: Shuai Liu <847807867@qq.com> Link: https://patch.msgid.link/tencent_BB08960D79E0261B5C1EB1E589787734E907@qq.com [axboe: trim excessive comment] Signed-off-by: Jens Axboe --- io_uring/sqpoll.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index c833e776320d..e86658ede44b 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -29,6 +29,7 @@ enum { IO_SQ_THREAD_SHOULD_STOP = 0, IO_SQ_THREAD_SHOULD_PARK, + IO_SQ_THREAD_EXITING, }; void io_sq_thread_unpark(struct io_sq_data *sqd) @@ -436,9 +437,10 @@ static int io_sq_thread(void *data) /* * Cancelation drops sqd->lock while it waits, and a ring could attach * to a thread that is on its way out. A fatal signal doesn't set the - * bit, so set it here for io_sq_offload_create() to see. + * stop bit, so mark the thread as exiting here for + * io_sq_offload_create() to see. */ - set_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state); + set_bit(IO_SQ_THREAD_EXITING, &sqd->state); io_uring_cancel_generic(true, sqd); rcu_assign_pointer(sqd->thread, NULL); put_task_struct(current); @@ -510,7 +512,8 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, /* don't attach to a dying SQPOLL thread, would be racy */ ret = 0; if (attached && (!sqd->thread || - test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state))) + test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state) || + test_bit(IO_SQ_THREAD_EXITING, &sqd->state))) ret = -ENXIO; io_sq_thread_unpark(sqd); From f013b695506491c5202a412a6568313549c81f50 Mon Sep 17 00:00:00 2001 From: Shakeel Butt Date: Sat, 31 Oct 2026 19:21:46 -0700 Subject: [PATCH 02/11] io_uring/sqpoll: do the return-to-userspace work in the SQPOLL thread The SQPOLL thread never returns to userspace. io_sq_tw() runs its task_work, but the rest of resume_user_mode_work(), like memory.high reclaim and block cgroup throttling, only runs when the thread exits. So memory.high reclaim only happens inside a charge, with sqd->lock and ctx->uring_lock held, and not at all if the charges can't block. This used to work. The loop called io_run_task_work(), which does this work since commit b5d3ae202fbf ("io_uring: handle TIF_NOTIFY_RESUME when checking for task_work"). Commit af5d68f8892f ("io_uring/sqpoll: manage task_work privately") replaced that call with io_sq_tw(). Call resume_user_mode_work() at the top of the loop when TIF_NOTIFY_RESUME is set, with sqd->lock dropped. It runs once per pass, so a pass that charges two or more batches still reclaims inside the charge, as before. Tested in a VM with memory.high=64M and swap on zram. An SQPOLL ring reads 256M from /dev/zero into untouched memory, 64K at a time. Before, the thread made 337 calls to __mem_cgroup_handle_over_high(), all from inside the charge. After, it makes 704, all from the top of the loop. memory.peak stays at 64M. With 1M reads, 296 of its 385 calls still come from inside the charge. Both runs take about 50% longer, and the extra time is in the handler, which now runs more often. Without memory.high pressure, the test never calls resume_user_mode_work() and the times do not change. Lockdep showed no warnings, also with io_uring_register() racing for sqd->lock. Fixes: af5d68f8892f ("io_uring/sqpoll: manage task_work privately") Cc: stable@vger.kernel.org Signed-off-by: Shakeel Butt Link: https://patch.msgid.link/20261101022146.309201-1-shakeel.butt@linux.dev Signed-off-by: Jens Axboe --- io_uring/sqpoll.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index e86658ede44b..d387488db2de 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -349,6 +349,18 @@ static int io_sq_thread(void *data) timeout = jiffies + sqd->sq_thread_idle; } + /* + * The SQPOLL thread never returns to userspace, so do the + * return-to-userspace work, like memory.high reclaim, here. + * It can sleep for a long time, so drop sqd->lock. + */ + if (test_thread_flag(TIF_NOTIFY_RESUME)) { + mutex_unlock(&sqd->lock); + resume_user_mode_work(NULL); + mutex_lock(&sqd->lock); + sqd->sq_cpu = raw_smp_processor_id(); + } + cap_entries = !list_is_singular(&sqd->ctx_list); list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { int ret; From 21ddbb14f7c3baab50a2a6c13ee375edc2bbe031 Mon Sep 17 00:00:00 2001 From: Shang En Sim Date: Fri, 30 Oct 2026 00:03:16 -0500 Subject: [PATCH 03/11] io_uring/cancel: count all requests that a CANCEL_ALL cancels With IORING_ASYNC_CANCEL_ALL, __io_async_cancel() counts one for each io_try_cancel() call that cancels something. io_futex_cancel() and io_waitid_cancel() cancel every match in one call and return how many, so four futex waits cancelled with CANCEL_ALL give a result of 1. Add the number that they return. Cc: stable@vger.kernel.org Fixes: 194bb58c6090 ("io_uring: add support for futex wake and wait") Fixes: f31ecf671ddc ("io_uring: add IORING_OP_WAITID support") Signed-off-by: Shang En Sim Link: https://patch.msgid.link/20261030050319.1448530-2-sim@shangen.org Signed-off-by: Jens Axboe --- io_uring/cancel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 79b5c133319b..50a65fbc6ff0 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -198,7 +198,8 @@ static int __io_async_cancel(struct io_cancel_data *cd, break; if (!all) return ret; - nr++; + /* futex and waitid return how many they cancelled */ + nr += max(ret, 1); } while (1); /* slow path, try all io-wq's */ From 9eff9c07e927dcd9c57150cd6fb3d4ec76f00480 Mon Sep 17 00:00:00 2001 From: Shang En Sim Date: Fri, 30 Oct 2026 00:03:17 -0500 Subject: [PATCH 04/11] io_uring/poll: cancel all matching requests in one pass With IORING_ASYNC_CANCEL_ALL, __io_async_cancel() calls io_try_cancel() until nothing is found, and io_poll_cancel() cancels one request per call, starting each lookup at the beginning of the hash. A cancelled request stays hashed until its task work runs, so every lookup walks past the ones already cancelled. Cancelling K of N pending polls visits about K*N/2 requests in one io_uring_enter(), with uring_lock held. A single CANCEL_FD|ALL on 80000 polls on one eventfd takes 17.06s, 0.02s with this change. With voluntary preemption the soft lockup watchdog fires: watchdog: BUG: soft lockup - CPU#1 stuck for 26s! [repro:100] RIP: 0010:io_cancel_req_match+0x19/0xa0 io_poll_cancel+0x73/0x170 io_try_cancel+0x7b/0xf0 __io_async_cancel+0x41/0x110 Walk the hash once and cancel every match, as io_cancel_remove() does for futex and waitid. Cancel by user_data only needs its own bucket. __io_async_cancel() still loops until nothing is found, so a request that io-wq parks in the poll hash meanwhile is still cancelled. A cancel that matches one request now walks the whole hash twice instead of stopping at the match. Cc: stable@vger.kernel.org Fixes: 8e29da69fead ("io_uring: add support for IORING_ASYNC_CANCEL_ALL") Signed-off-by: Shang En Sim Link: https://patch.msgid.link/20261030050319.1448530-3-sim@shangen.org Signed-off-by: Jens Axboe --- io_uring/cancel.c | 2 +- io_uring/poll.c | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/io_uring/cancel.c b/io_uring/cancel.c index 50a65fbc6ff0..e3d9fe8fc982 100644 --- a/io_uring/cancel.c +++ b/io_uring/cancel.c @@ -198,7 +198,7 @@ static int __io_async_cancel(struct io_cancel_data *cd, break; if (!all) return ret; - /* futex and waitid return how many they cancelled */ + /* poll, futex and waitid return how many they cancelled */ nr += max(ret, 1); } while (1); diff --git a/io_uring/poll.c b/io_uring/poll.c index 4f04bda42f7f..9b73b0d88a0e 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -827,12 +827,47 @@ static int io_poll_disarm(struct io_kiocb *req) return 0; } +/* + * Cancel every request matching @cd in one pass. Cancelled requests stay + * hashed until their task work runs, so finding them one at a time would + * walk past all the earlier ones on each lookup. + */ +static int io_poll_cancel_all(struct io_ring_ctx *ctx, struct io_cancel_data *cd) +{ + unsigned int nr_buckets = 1U << ctx->cancel_table.hash_bits; + unsigned int i = 0; + struct hlist_node *tmp; + struct io_kiocb *req; + int nr = 0; + + if (!(cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP | + IORING_ASYNC_CANCEL_ANY))) { + /* keyed by user_data, so only one bucket can match */ + i = hash_long(cd->data, ctx->cancel_table.hash_bits); + nr_buckets = i + 1; + } + + for (; i < nr_buckets; i++) { + struct io_hash_bucket *hb = &ctx->cancel_table.hbs[i]; + + hlist_for_each_entry_safe(req, tmp, &hb->list, hash_node) { + if (!io_cancel_req_match(req, cd)) + continue; + io_poll_cancel_req(req); + nr++; + } + } + return nr ?: -ENOENT; +} + static int __io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd) { struct io_kiocb *req; - if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP | - IORING_ASYNC_CANCEL_ANY)) + if (cd->flags & (IORING_ASYNC_CANCEL_ALL | IORING_ASYNC_CANCEL_ANY)) + return io_poll_cancel_all(ctx, cd); + + if (cd->flags & (IORING_ASYNC_CANCEL_FD | IORING_ASYNC_CANCEL_OP)) req = io_poll_file_find(ctx, cd); else req = io_poll_find(ctx, false, cd); From 74c1f1048e4401d6a953ab2299b14ace1ad6a899 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 29 Oct 2026 13:38:18 -0600 Subject: [PATCH 05/11] io_uring/poll: don't poll a writer for a read side hangup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit io_init_poll_iocb() adds EPOLLRDHUP to every poll, including the async poll of a send that waits for buffer space. Once the peer has shut down its sending side, the socket keeps reporting EPOLLRDHUP, so each re-arm in __io_arm_poll_handler() finds a ready mask and the request is issued again. The send still can't make progress, the request burns through APOLL_MAX_RETRY in a few milliseconds and ends up in io-wq. A send in io-wq blocks until the peer reads, but sendmsg and writev go through ____sys_sendmsg() and sock_write_iter(), which turn O_NONBLOCK into MSG_DONTWAIT, and the application gets -EAGAIN for a request that never asked for a non-blocking send. Only add EPOLLRDHUP for polls that want to read. A peer that stopped sending is no event for a writer, and a poll that asks for it explicitly still gets it. Fixes: 464dca612bc6 ("io_uring: mask in error/nval/hangup consistently for poll") Reported-by: Lukáš Lalinský Signed-off-by: Jens Axboe --- io_uring/poll.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 9b73b0d88a0e..9703a2fdfb44 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -128,12 +128,24 @@ static void io_poll_req_insert(struct io_kiocb *req) hlist_add_head(&req->hash_node, &table->hbs[index].list); } +#define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL) + +static __poll_t io_poll_unmask(__poll_t events) +{ + /* + * A peer that stopped sending is an event for a reader, but a write + * only poll must stay armed until the file is writable again. + */ + if (events & (EPOLLIN | EPOLLRDNORM | EPOLLRDBAND)) + return IO_POLL_UNMASK | EPOLLRDHUP; + return IO_POLL_UNMASK; +} + static void io_init_poll_iocb(struct io_poll *poll, __poll_t events) { poll->head = NULL; -#define IO_POLL_UNMASK (EPOLLERR|EPOLLHUP|EPOLLNVAL|EPOLLRDHUP) /* mask in events that we always want/need */ - poll->events = events | IO_POLL_UNMASK; + poll->events = events | io_poll_unmask(events); INIT_LIST_HEAD(&poll->wait.entry); init_waitqueue_func_entry(&poll->wait, io_poll_wake); } @@ -1006,7 +1018,7 @@ int io_poll_remove(struct io_kiocb *req, unsigned int issue_flags) poll->events &= ~0xffff; poll->events |= poll_update->events & 0xffff; - poll->events |= IO_POLL_UNMASK; + poll->events |= io_poll_unmask(poll->events); } if (poll_update->update_user_data) preq->cqe.user_data = poll_update->new_user_data; From edeac4546a71b6c1db4ba006a2dbf7c863f54e9a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 3 Nov 2026 08:46:59 -0700 Subject: [PATCH 06/11] 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) From 699e7ba5915c8b2c76e257e157464f2bfe7ab8bb Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 4 Nov 2026 09:46:23 -0500 Subject: [PATCH 07/11] selftests/io_uring: cast optval through uintptr_t in mini_liburing.h io_uring_prep_cmd() puts the optval pointer into the 64-bit optval field of the SQE with a plain cast, which warns on 32-bit architectures: mini_liburing.h:272:23: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] Cast through uintptr_t, and include for it. Reviewed-by: Breno Leitao Signed-off-by: Sasha Levin Link: https://patch.msgid.link/20261104144623.3803717-1-sashal@kernel.org Signed-off-by: Jens Axboe --- tools/include/io_uring/mini_liburing.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/include/io_uring/mini_liburing.h b/tools/include/io_uring/mini_liburing.h index 44be4446feda..6afe7efb4497 100644 --- a/tools/include/io_uring/mini_liburing.h +++ b/tools/include/io_uring/mini_liburing.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -269,7 +270,7 @@ static inline void io_uring_prep_cmd(struct io_uring_sqe *sqe, int op, sqe->level = level; sqe->optname = optname; - sqe->optval = (unsigned long long)optval; + sqe->optval = (unsigned long long)(uintptr_t)optval; sqe->optlen = optlen; } From d7c7037253f6935af243570635d71b4920b5a4ea Mon Sep 17 00:00:00 2001 From: Yuansheng Yang <0xbeac@gmail.com> Date: Wed, 4 Nov 2026 23:46:55 +0800 Subject: [PATCH 08/11] io_uring/rsrc: hold uring_lock across index-alloc put_user io_files_update_with_index_alloc() installs a fixed file via io_fixed_fd_install(), which drops ->uring_lock when the request runs on io-wq, then put_user()s the allocated slot back to userspace. If that faults, the error path calls __io_close_fixed() by slot index after re-taking the lock. The slot can be closed and reused between the install and that cleanup: another fixed CLOSE plus open/accept/pipe/socket, or a FILES_UPDATE, can put an unrelated file into the same slot. The error path then removes that file instead of the one this request installed, ending an unrelated file's fixed-table reference early. This is a correctness/DoS issue, not a use-after-free: fixed-file requests hold an io_rsrc_node reference, so the node and file stay alive until they are done. Hold ->uring_lock across __io_fixed_fd_install() and put_user(), and do the failure cleanup with io_fixed_fd_remove() under the same lock. This is the same class as the io_pipe_fixed() fix in a3d7ee11289f. Faulting while holding ->uring_lock is fine, the registration paths already do it. Fixes: a7c41b4687f5 ("io_uring: let IORING_OP_FILES_UPDATE support choosing fixed file slots") Signed-off-by: Yuansheng Yang <0xbeac@gmail.com> Link: https://patch.msgid.link/20261104154655.81876-1-0xbeac@gmail.com [axboe: various touch-ups] Signed-off-by: Jens Axboe --- io_uring/rsrc.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index e0345c3e764e..8de5737d223e 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -572,11 +572,12 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req, { struct io_rsrc_update *up = io_kiocb_to_cmd(req, struct io_rsrc_update); __s32 __user *fds = u64_to_user_ptr(up->arg); + struct io_ring_ctx *ctx = req->ctx; unsigned int done; struct file *file; int ret, fd; - if (!req->ctx->file_table.data.nr) + if (!ctx->file_table.data.nr) return -ENXIO; for (done = 0; done < up->nr_args; done++) { @@ -590,15 +591,25 @@ static int io_files_update_with_index_alloc(struct io_kiocb *req, ret = -EBADF; break; } - ret = io_fixed_fd_install(req, issue_flags, file, - IORING_FILE_INDEX_ALLOC); - if (ret < 0) + /* + * Hold the lock across the put_user(), if it's dropped the + * slot can be closed and reused before the error path runs. + */ + io_ring_submit_lock(ctx, issue_flags); + ret = __io_fixed_fd_install(ctx, file, + IORING_FILE_INDEX_ALLOC); + if (ret < 0) { + io_ring_submit_unlock(ctx, issue_flags); + fput(file); break; + } if (put_user(ret, &fds[done])) { - __io_close_fixed(req->ctx, issue_flags, ret); + io_fixed_fd_remove(ctx, ret); + io_ring_submit_unlock(ctx, issue_flags); ret = -EFAULT; break; } + io_ring_submit_unlock(ctx, issue_flags); } if (done) From 99b6efa810675d99c04216574a189aa4bf031cfd Mon Sep 17 00:00:00 2001 From: Ioannis Coward Date: Wed, 4 Nov 2026 10:47:07 +0000 Subject: [PATCH 09/11] io_uring/wait: don't sleep on an already expired timeout When io_cqring_wait() gets to the point of sleeping and the wait's timeout has already passed, io_cqring_schedule_timeout() still arms an hrtimer for it and calls schedule(). The timer fires right away, but only after the task has switched to idle, so getting -ETIME back costs a round trip through idle plus a timer interrupt. NAPI busy polling hits this on every wait that times out. __io_napi_busy_loop() caps the busy poll at the remaining timeout, so when the loop runs to its end without a completion, the timeout has expired by the time we get here. The task then stops polling for several usec, and packets that arrive meanwhile are left to the device interrupt. This affects one of our production workloads, which currently works around it by having another thread signal an eventfd on the ring before the timeout expires. A wait with a zero timeout, or one that runs out before the task gets to sleep, pays the same cost. io_uring_wait_cqe_timeout() with nothing to reap and a zero timeout takes ~11 usec and a voluntary context switch on a Zen 5 desktop. Return -ETIME without arming the timer once the timeout has passed, as ep_poll() already does with ep_schedule_timeout(). A passed timeout ends the wait with -ETIME whether or not a min_timeout is set, so the check covers both. It costs one io_get_time() per wait that is about to sleep with a timeout. Signed-off-by: Ioannis Coward Link: https://patch.msgid.link/20261104104707.2031280-1-ioanniscrd@gmail.com Signed-off-by: Jens Axboe --- io_uring/wait.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/io_uring/wait.c b/io_uring/wait.c index fb1c082993a7..367d49d631ec 100644 --- a/io_uring/wait.c +++ b/io_uring/wait.c @@ -165,6 +165,14 @@ static int __io_cqring_wait_schedule(struct io_ring_ctx *ctx, { int ret = 0; + /* + * Don't arm a timer for a timeout that has already passed, it would + * only fire to return -ETIME. NAPI busy polling gets here like that. + */ + if (iowq->timeout != KTIME_MAX && + ktime_compare(io_get_time(ctx), iowq->timeout) >= 0) + return -ETIME; + /* * Mark us as being in io_wait if we have pending requests, so cpufreq * can take into account that the task is waiting for IO - turns out From 21662435a5ee49c49a5ff05f2ddcde87acb7b293 Mon Sep 17 00:00:00 2001 From: Pavel Begunkov Date: Wed, 4 Nov 2026 00:10:49 +0000 Subject: [PATCH 10/11] io_uring: add feature flag for dma-buf support Add IORING_FEAT_REGBUF_TYPES, a feature flag that tells whether extended buffer registration and dma-buf buffers are available (see IO_REGBUF_TYPE_* and struct io_uring_regbuf_desc). Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers") Signed-off-by: Pavel Begunkov Link: https://patch.msgid.link/1b3ca4acc350aa5a397325d066533c4e5743a0f7.1793623347.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- include/uapi/linux/io_uring.h | 1 + io_uring/io_uring.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index b456f45fa8de..cf1afd11bb87 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -646,6 +646,7 @@ struct io_uring_params { #define IORING_FEAT_MIN_TIMEOUT (1U << 15) #define IORING_FEAT_RW_ATTR (1U << 16) #define IORING_FEAT_NO_IOWAIT (1U << 17) +#define IORING_FEAT_REGBUF_TYPES (1U << 18) /* * io_uring_register(2) opcodes and arguments diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 32247529076c..a0ed03fab123 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -50,7 +50,8 @@ struct io_ctx_config { IORING_FEAT_RECVSEND_BUNDLE |\ IORING_FEAT_MIN_TIMEOUT |\ IORING_FEAT_RW_ATTR |\ - IORING_FEAT_NO_IOWAIT) + IORING_FEAT_NO_IOWAIT |\ + IORING_FEAT_REGBUF_TYPES) #define IORING_SETUP_FLAGS (IORING_SETUP_IOPOLL |\ IORING_SETUP_SQPOLL |\ From cf6542493e35ab9e72ac07da10a178ac78db5a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orkun=20Emin=20Sar=C4=B1?= Date: Wed, 4 Nov 2026 19:51:42 +0300 Subject: [PATCH 11/11] io_uring: only wait for in-flight requests if the closing task uses the ring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit 13d3783a55b7 ("io_uring: wait for in-flight requests on ring release"), the task dropping the last reference to a ring waits for every request on it to complete. A process that only received the ring fd, e.g. over a UNIX socket, can then block in close(2) on requests owned by other tasks, such as a read from an unresponsive FUSE server. Skip the wait for tasks that never attached to the ring and leave those requests to io_ring_exit_work(), as before. Fixes: 13d3783a55b7 ("io_uring: wait for in-flight requests on ring release") Signed-off-by: Orkun Emin Sarı Link: https://patch.msgid.link/20261104-io-uring-wait-inflight-v2-1-f38f29fe8018@gmail.com Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 03724419c4e1..5db57bf675f0 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2547,7 +2547,10 @@ static __cold void io_ring_ctx_wait_inflight(struct io_ring_ctx *ctx) if (current->flags & (PF_KTHREAD | PF_EXITING)) return; - if (tctx && atomic_read(&tctx->in_cancel)) + /* Only wait if this task has attached to the ring */ + if (!tctx || !xa_load(&tctx->xa, (unsigned long)ctx)) + return; + if (atomic_read(&tctx->in_cancel)) return; while (io_ring_ctx_inflight(ctx) && !fatal_signal_pending(current)) {