]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring: pass struct io_tw_state by value
authorCaleb Sander Mateos <csander@purestorage.com>
Mon, 17 Feb 2025 02:25:05 +0000 (19:25 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 17 Feb 2025 12:34:50 +0000 (05:34 -0700)
8e5b3b89ecaf ("io_uring: remove struct io_tw_state::locked") removed the
only field of io_tw_state but kept it as a task work callback argument
to "forc[e] users not to invoke them carelessly out of a wrong context".
Passing the struct io_tw_state * argument adds a few instructions to all
callers that can't inline the functions and see the argument is unused.

So pass struct io_tw_state by value instead. Since it's a 0-sized value,
it can be passed without any instructions needed to initialize it.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Link: https://lore.kernel.org/r/20250217022511.1150145-2-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
io_uring/io_uring.c

index ea4694ee9d199b669ac01e6da392929edf295100..123e693687305e07c69d4e6807840866faace46d 100644 (file)
@@ -444,7 +444,7 @@ struct io_ring_ctx {
 struct io_tw_state {
 };
 /* Alias to use in code that doesn't instantiate struct io_tw_state */
-typedef struct io_tw_state *io_tw_token_t;
+typedef struct io_tw_state io_tw_token_t;
 
 enum {
        REQ_F_FIXED_FILE_BIT    = IOSQE_FIXED_FILE_BIT,
index b44ff88717258faa55e8e81c7d69c501c76ae61d..b688953d1de8e52d3a44d6f63bd06034956ec0d1 100644 (file)
@@ -255,7 +255,7 @@ static __cold void io_fallback_req_func(struct work_struct *work)
        percpu_ref_get(&ctx->refs);
        mutex_lock(&ctx->uring_lock);
        llist_for_each_entry_safe(req, tmp, node, io_task_work.node)
-               req->io_task_work.func(req, &ts);
+               req->io_task_work.func(req, ts);
        io_submit_flush_completions(ctx);
        mutex_unlock(&ctx->uring_lock);
        percpu_ref_put(&ctx->refs);
@@ -1052,24 +1052,24 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
                                                    io_task_work.node);
 
                if (req->ctx != ctx) {
-                       ctx_flush_and_put(ctx, &ts);
+                       ctx_flush_and_put(ctx, ts);
                        ctx = req->ctx;
                        mutex_lock(&ctx->uring_lock);
                        percpu_ref_get(&ctx->refs);
                }
                INDIRECT_CALL_2(req->io_task_work.func,
                                io_poll_task_func, io_req_rw_complete,
-                               req, &ts);
+                               req, ts);
                node = next;
                (*count)++;
                if (unlikely(need_resched())) {
-                       ctx_flush_and_put(ctx, &ts);
+                       ctx_flush_and_put(ctx, ts);
                        ctx = NULL;
                        cond_resched();
                }
        } while (node && *count < max_entries);
 
-       ctx_flush_and_put(ctx, &ts);
+       ctx_flush_and_put(ctx, ts);
        return node;
 }
 
@@ -1341,7 +1341,7 @@ static inline int io_run_local_work_locked(struct io_ring_ctx *ctx,
 
        if (!io_local_work_pending(ctx))
                return 0;
-       return __io_run_local_work(ctx, &ts, min_events,
+       return __io_run_local_work(ctx, ts, min_events,
                                        max(IO_LOCAL_TW_DEFAULT_MAX, min_events));
 }
 
@@ -1352,7 +1352,7 @@ static int io_run_local_work(struct io_ring_ctx *ctx, int min_events,
        int ret;
 
        mutex_lock(&ctx->uring_lock);
-       ret = __io_run_local_work(ctx, &ts, min_events, max_events);
+       ret = __io_run_local_work(ctx, ts, min_events, max_events);
        mutex_unlock(&ctx->uring_lock);
        return ret;
 }