All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Josef Bacik <josef@toxicpanda.com>,
	Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 7.2 59/88] io_uring: look up the file before queueing to io-wq
Date: Wed, 28 Oct 2026 18:00:07 +0100	[thread overview]
Message-ID: <20261028165943.501273043@linuxfoundation.org> (raw)
In-Reply-To: <20261028165942.107695352@linuxfoundation.org>

7.2-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Josef Bacik <josef@toxicpanda.com>

Commit 98bc044d5a5374f8d3605fe55a8e2df6d6fc3f82 upstream.

io_prep_async_work() decides by the file of a request what kind of work
it is for io-wq. I/O on regular files and block devices is bounded work,
limited to min(SQ entries, 4 * CPUs) workers, for anything else that may
block indefinitely the limit is RLIMIT_NPROC. Writes to a regular file
are hashed by the inode, so that they are run one after the other instead
of having a bunch of workers fight for the inode lock.

Since the file is only assigned when a request is issued, a request that
is queued without an attempt to issue it, REQ_F_FORCE_ASYNC, doesn't have
one at that point. io_prep_async_work() takes that for "not a regular
file or block device":

- Reads and writes end up as unbound work. 32 reads with IOSQE_ASYNC from
  a slow block device on a ring with 4 SQ entries get 32 workers, not 4.
- Writes aren't hashed. Four buffered writes to one file get four
  workers, three of which do nothing but wait for the lock.

The late assignment is for the benefit of links, where a request may use
a fixed file that one of its predecessors installs. By the time a request
gets to io_queue_iowq() these are done, it is as good as issued. Assign
the file there.

io_assign_file() moves up and is forced inline. With a third caller the
compiler may stop inlining it, and every request that is issued would
pay for a call.

IORING_OP_SPLICE is left as it is, unbound and not hashed. The file of
the request is where it writes to, which says nothing about how long it
takes: a splice from an empty pipe or a socket into a regular file waits
for its input. As bounded work, four of these on a ring with 4 SQ entries
keep all other bounded work of the task from running, and as hashed work
one of them blocks all writes to that file.

REQ_F_FORCE_ASYNC is not only set for IOSQE_ASYNC. What changes, and
brings back what was the case before the file assignment was deferred:

- Requests with IOSQE_ASYNC or IOSQE_IO_DRAIN, and all requests that are
  submitted while a drain is active: reads and writes on regular files
  and block devices count against the limit for bounded workers, including
  the one set with IORING_REGISTER_IOWQ_MAX_WORKERS, so fewer of them run
  at the same time.
- Of these, writes to one regular file are run one at a time, unless they
  are O_DIRECT and the filesystem has FOP_DIO_PARALLEL_WRITE.
- IORING_OP_FALLOCATE and IORING_OP_FTRUNCATE, which always go to io-wq,
  are run one at a time per file, and in turn with these writes.
- The descriptor or the fixed file slot is looked up when the request is
  queued, not when a worker gets around to it, so closing or replacing it
  in between no longer has an effect on the request.

Fixes: 6bf9c47a3989 ("io_uring: defer file assignment")
Assisted-by: LLM
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Link: https://patch.msgid.link/20261015-b4-io-uring-fixes-v1-43-c1556f5d7bf5@toxicpanda.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 io_uring/io_uring.c |   43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -405,17 +405,46 @@ static void io_prep_async_link(struct io
 	}
 }
 
+/* Called for every request that is issued: keep it inline */
+static __always_inline bool io_assign_file(struct io_kiocb *req,
+					   const struct io_issue_def *def,
+					   unsigned int issue_flags)
+{
+	if (req->file || !def->needs_file)
+		return true;
+
+	if (req->flags & REQ_F_FIXED_FILE)
+		req->file = io_file_get_fixed(req, req->cqe.fd, issue_flags);
+	else
+		req->file = io_file_get_normal(req, req->cqe.fd);
+
+	return !!req->file;
+}
+
 static void io_queue_iowq(struct io_kiocb *req)
 {
 	struct io_uring_task *tctx = req->tctx;
 
 	BUG_ON(!tctx);
+	lockdep_assert_held(&req->ctx->uring_lock);
 
 	if ((current->flags & PF_KTHREAD) || !tctx->io_wq) {
 		io_req_task_queue_fail(req, -ECANCELED);
 		return;
 	}
 
+	/*
+	 * The file is looked up as late as possible, as it may be the result
+	 * of an earlier request of the link. This one is up now, and what kind
+	 * of work it is depends on the file. If that fails, leave the error
+	 * handling to the worker.
+	 *
+	 * Not for a splice: whatever it writes to, it may wait for its input
+	 * for ever. It has to remain unbound work that isn't hashed.
+	 */
+	if (req->opcode != IORING_OP_SPLICE)
+		io_assign_file(req, &io_issue_defs[req->opcode], 0);
+
 	/* init ->work of the whole link before punting */
 	io_prep_async_link(req);
 
@@ -1365,20 +1394,6 @@ static __cold void io_drain_req(struct i
 		ctx->int_flags &= ~IO_RING_F_DRAIN_ACTIVE;
 }
 
-static bool io_assign_file(struct io_kiocb *req, const struct io_issue_def *def,
-			   unsigned int issue_flags)
-{
-	if (req->file || !def->needs_file)
-		return true;
-
-	if (req->flags & REQ_F_FIXED_FILE)
-		req->file = io_file_get_fixed(req, req->cqe.fd, issue_flags);
-	else
-		req->file = io_file_get_normal(req, req->cqe.fd);
-
-	return !!req->file;
-}
-
 #define REQ_ISSUE_SLOW_FLAGS	(REQ_F_CREDS | REQ_F_ARM_LTIMEOUT)
 
 static inline int __io_issue_sqe(struct io_kiocb *req,



  parent reply	other threads:[~2026-10-28 17:08 UTC|newest]

Thread overview: 99+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 16:59 [PATCH 7.2 00/88] 7.2.14-rc1 review Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 01/88] sched_ext: Wait for SCX_OPSS_DISPATCHING before moving tasks off DSQs Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 02/88] ntfs: fix race between fallocate and mmap reads Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 03/88] ntfs: take invalidate_lock in ntfs_filemap_page_mkwrite() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 04/88] mm/damon/core: error damos_commit_quota_goal() for zero target_value Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 05/88] sched/fair: Avoid overflow in place_entity() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 06/88] Bluetooth: L2CAP: refuse __l2cap_chan_add if chan already has conn Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 07/88] tools/dma: fix building with O= Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 08/88] tracing: Hold trace_types_lock when updating modules in persistent instances Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 09/88] tracing: Hold trace_types_lock when resetting last boot data from readers Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 10/88] tracing: Reject incomplete event filter expressions Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 11/88] tracing: Save the event file instead of the compatible histogram Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 12/88] tracing: Unregister field variable histograms when the command fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 13/88] tracing: Fix 64-bit and signed histogram fields on 32-bit kernels Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 14/88] tracing/histograms: Verify event_call identity when updating synth_event refcount Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 15/88] tracing/syscalls: Use copy_from_user for the faultable syscall buffer Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 16/88] io-wq: order the exit bit against worker creation task work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 17/88] io_uring/waitid: own the request before clearing ->head Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 18/88] io_uring/cmd: dont leave list poison in ->hash_node Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 19/88] io_uring/wait: dont spin on a stuck overflow list Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 20/88] io_uring/io-wq: dont lose the signal that ends work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 21/88] io_uring/io-wq: dont hide a link from cancellations Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 22/88] io_uring: dont flood a cancelling task with task_work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 23/88] io_uring: dont lose the DEFER_TASKRUN wake up Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 24/88] io_uring/cancel: rearm local work wake up before sleep Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 25/88] io_uring/mpscq: disable preemption while pushing Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 26/88] io_uring/io-wq: dont go to sleep on pending work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 27/88] io_uring/io-wq: dont strand work when a worker exits Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 28/88] io_uring/io-wq: dont exit with a creation pending Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 29/88] io_uring/io-wq: let cancel find picked up hashed work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 30/88] io_uring/poll: dont lose a cancel as io-wq arms poll Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 31/88] io_uring: dont lose a cancel as io-wq parks a request Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 32/88] io_uring/cancel: dont forget that the work was running Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 33/88] io_uring/cancel: recognize "no timeout" on 32-bit Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 34/88] io_uring/cancel: let CANCEL_ALL find parked requests Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 35/88] io_uring: wake ring pollers for local task_work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 36/88] io_uring/wait: look at all CQ waiters on wake up Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 37/88] io_uring/poll: drop stale double poll entry on rearm Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 38/88] io_uring/futex: allocate private hash before waiting Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 39/88] io_uring: drop the CQE cache if a refill fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 40/88] io_uring: dont split 128b SQEs at the SQPOLL cap Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 41/88] io_uring/register: dont wrap 32b CQEs when resizing Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 42/88] io_uring/register: handle index wrap " Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 43/88] io_uring/register: keep 128b SQEs intact on resize Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 44/88] io_uring/fdinfo: fix CQE dump of CQE32 rings Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 45/88] io_uring/timeout: dont skip over reached sequences Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 46/88] io_uring/timeout: keep repeat count on multishot update Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 47/88] io_uring/timeout: use the right clock for ABS updates Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 48/88] io_uring/wait: no early -ETIME if min_wait finds work Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 49/88] io_uring/napi: make stale entries time out after 60s Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 50/88] io_uring/napi: dont busy poll past an expired timeout Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.2 51/88] io_uring/zcrx: fix buffer offsets in areas above 4GB Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 52/88] io_uring/kbuf: handle index wrap in last buffer check Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 53/88] io_uring/sqpoll: let the thread sleep on disabled rings Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 54/88] io_uring/openclose: keep the lock in io_pipe_fixed() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 55/88] io_uring: dont pass restart error codes to userspace Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 56/88] io_uring/net: dont retry recv on uncommitted buffers Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 57/88] io_uring/timeout: no ABS update of multishot timeouts Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 58/88] io_uring/timeout: dont end a linked timeout with 1 Greg Kroah-Hartman
2026-10-28 17:00 ` Greg Kroah-Hartman [this message]
2026-10-28 17:00 ` [PATCH 7.2 60/88] io_uring/poll: avoid retry wakeup loss when dropping ownership Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 61/88] io_uring/timeout: dont put a sequence target behind the last flush Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 62/88] io_uring/timeout: dont flush with the sequence " Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 63/88] io_uring/timeout: dont lose a cancel as io-wq arms a timeout Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 64/88] io_uring/poll: dont loop on HUP with multiple references Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 65/88] io_uring/net: keep recv buffer select length within MAX_RW_COUNT Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 66/88] io_uring/wait: wake real-time waiters from hard interrupt context Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 67/88] io_uring/waitid: prevent cancel reference wrap Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 68/88] io_uring: end the drain when the drain request completes Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 69/88] io_uring: keep the drain active when a deferred drain request is started Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 70/88] keys: Avoid the owner account dereference in named keyring lookup Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 71/88] keys: Check the authorization payload in process keyring searches Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 72/88] keys: Protect the type name while describing a key Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 73/88] keys: make keyring indexes independent of kernel addresses Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 74/88] keys: Protect the read method check against type removal Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 75/88] KEYS: Fix key_reject_and_link() race with keyring restriction Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 76/88] KEYS: trusted: Fix blob allocation size in tpm2_key_decode() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 77/88] keys/trusted_keys: return immediately after TPM unseal failure Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 78/88] asymmetric_keys: reject trust keys without IDs Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 79/88] ftrace: Initialize modname and offset in print_rec() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 80/88] coredump: hold RCU while releasing parked threads Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 81/88] signal: only SIGKILL and the freezers interrupt a coredumping task Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 82/88] signal: dont retarget shared signals in a dying thread group Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 83/88] ptrace: refuse to change the signal mask of a user worker Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 84/88] fork: release the files of a failed fork after sched_cancel_fork() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 85/88] exit: hang up the tty before closing the files Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 86/88] coredump: prevent TIF_NOTIFY_SIGNAL from interrupting coredumps Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 87/88] pid_namespace: prevent TIF_NOTIFY_SIGNAL from interrupting the reaper Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.2 88/88] signal: allow taks to temporarily block TIF_NOTIFY_SIGNAL Greg Kroah-Hartman
2026-10-28 19:39 ` [PATCH 7.2 00/88] 7.2.14-rc1 review Brett A C Sheffield
2026-10-29  4:09 ` Peter Schneider
2026-10-29 10:08 ` Pavel Machek
2026-10-29 13:49 ` Miguel Ojeda
2026-10-29 14:17 ` Ron Economos
2026-10-29 14:43 ` SJ Park
2026-10-29 15:19 ` Shuah Khan
2026-10-29 15:57 ` Barry K. Nathan
2026-10-29 16:56 ` Florian Fainelli
2026-10-29 22:27 ` Sean Lyon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028165943.501273043@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=axboe@kernel.dk \
    --cc=josef@toxicpanda.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.