* [PATCH] io_uring: pass struct io_tw_state by value
@ 2025-02-11 21:45 Caleb Sander Mateos
2025-02-12 13:31 ` Pavel Begunkov
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Caleb Sander Mateos @ 2025-02-11 21:45 UTC (permalink / raw)
To: Jens Axboe, Pavel Begunkov; +Cc: Caleb Sander Mateos, io-uring, linux-kernel
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.
Also add a comment to struct io_tw_state to explain its purpose.
Signed-off-by: Caleb Sander Mateos <[email protected]>
---
include/linux/io_uring_types.h | 3 ++-
io_uring/futex.c | 6 +++---
io_uring/io_uring.c | 30 +++++++++++++++---------------
io_uring/io_uring.h | 8 ++++----
io_uring/msg_ring.c | 2 +-
io_uring/notif.c | 2 +-
io_uring/poll.c | 4 ++--
io_uring/poll.h | 2 +-
io_uring/rw.c | 2 +-
io_uring/rw.h | 2 +-
io_uring/timeout.c | 6 +++---
io_uring/uring_cmd.c | 2 +-
io_uring/waitid.c | 6 +++---
13 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index e2fef264ff8b..4abd0299fdfb 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -434,10 +434,11 @@ struct io_ring_ctx {
struct io_mapped_region ring_region;
/* used for optimised request parameter and wait argument passing */
struct io_mapped_region param_region;
};
+/* Token passed to task work callbacks to indicate ctx->uring_lock is held */
struct io_tw_state {
};
enum {
REQ_F_FIXED_FILE_BIT = IOSQE_FIXED_FILE_BIT,
@@ -561,11 +562,11 @@ enum {
REQ_F_BUF_NODE = IO_REQ_FLAG(REQ_F_BUF_NODE_BIT),
/* request has read/write metadata assigned */
REQ_F_HAS_METADATA = IO_REQ_FLAG(REQ_F_HAS_METADATA_BIT),
};
-typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts);
+typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state ts);
struct io_task_work {
struct llist_node node;
io_req_tw_func_t func;
};
diff --git a/io_uring/futex.c b/io_uring/futex.c
index 54b9760f2aa6..d4f9591c821f 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -42,29 +42,29 @@ bool io_futex_cache_init(struct io_ring_ctx *ctx)
void io_futex_cache_free(struct io_ring_ctx *ctx)
{
io_alloc_cache_free(&ctx->futex_cache, kfree);
}
-static void __io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts)
+static void __io_futex_complete(struct io_kiocb *req, struct io_tw_state ts)
{
req->async_data = NULL;
hlist_del_init(&req->hash_node);
io_req_task_complete(req, ts);
}
-static void io_futex_complete(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_futex_complete(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_futex_data *ifd = req->async_data;
struct io_ring_ctx *ctx = req->ctx;
io_tw_lock(ctx, ts);
if (!io_alloc_cache_put(&ctx->futex_cache, ifd))
kfree(ifd);
__io_futex_complete(req, ts);
}
-static void io_futexv_complete(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_futexv_complete(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_futex *iof = io_kiocb_to_cmd(req, struct io_futex);
struct futex_vector *futexv = req->async_data;
io_tw_lock(req->ctx, ts);
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index ec98a0ec6f34..578f894a3bdb 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -252,11 +252,11 @@ static __cold void io_fallback_req_func(struct work_struct *work)
struct io_tw_state ts = {};
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);
}
@@ -540,11 +540,11 @@ static void io_queue_iowq(struct io_kiocb *req)
io_wq_enqueue(tctx->io_wq, &req->work);
if (link)
io_queue_linked_timeout(link);
}
-static void io_req_queue_iowq_tw(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_req_queue_iowq_tw(struct io_kiocb *req, struct io_tw_state ts)
{
io_queue_iowq(req);
}
void io_req_queue_iowq(struct io_kiocb *req)
@@ -1019,11 +1019,11 @@ static inline struct io_kiocb *io_req_find_next(struct io_kiocb *req)
nxt = req->link;
req->link = NULL;
return nxt;
}
-static void ctx_flush_and_put(struct io_ring_ctx *ctx, struct io_tw_state *ts)
+static void ctx_flush_and_put(struct io_ring_ctx *ctx, struct io_tw_state ts)
{
if (!ctx)
return;
if (ctx->flags & IORING_SETUP_TASKRUN_FLAG)
atomic_andnot(IORING_SQ_TASKRUN, &ctx->rings->sq_flags);
@@ -1049,28 +1049,28 @@ struct llist_node *io_handle_tw_list(struct llist_node *node,
struct llist_node *next = node->next;
struct io_kiocb *req = container_of(node, struct io_kiocb,
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;
}
static __cold void __io_fallback_tw(struct llist_node *node, bool sync)
{
@@ -1274,11 +1274,11 @@ static bool io_run_local_work_continue(struct io_ring_ctx *ctx, int events,
atomic_or(IORING_SQ_TASKRUN, &ctx->rings->sq_flags);
return false;
}
static int __io_run_local_work_loop(struct llist_node **node,
- struct io_tw_state *ts,
+ struct io_tw_state ts,
int events)
{
int ret = 0;
while (*node) {
@@ -1294,11 +1294,11 @@ static int __io_run_local_work_loop(struct llist_node **node,
}
return ret;
}
-static int __io_run_local_work(struct io_ring_ctx *ctx, struct io_tw_state *ts,
+static int __io_run_local_work(struct io_ring_ctx *ctx, struct io_tw_state ts,
int min_events, int max_events)
{
struct llist_node *node;
unsigned int loops = 0;
int ret = 0;
@@ -1338,33 +1338,33 @@ static inline int io_run_local_work_locked(struct io_ring_ctx *ctx,
{
struct io_tw_state ts = {};
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));
}
static int io_run_local_work(struct io_ring_ctx *ctx, int min_events,
int max_events)
{
struct io_tw_state ts = {};
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;
}
-static void io_req_task_cancel(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_req_task_cancel(struct io_kiocb *req, struct io_tw_state ts)
{
io_tw_lock(req->ctx, ts);
io_req_defer_failed(req, req->cqe.res);
}
-void io_req_task_submit(struct io_kiocb *req, struct io_tw_state *ts)
+void io_req_task_submit(struct io_kiocb *req, struct io_tw_state ts)
{
io_tw_lock(req->ctx, ts);
if (unlikely(io_should_terminate_tw()))
io_req_defer_failed(req, -EFAULT);
else if (req->flags & REQ_F_FORCE_ASYNC)
@@ -1580,11 +1580,11 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min)
} while (nr_events < min);
return 0;
}
-void io_req_task_complete(struct io_kiocb *req, struct io_tw_state *ts)
+void io_req_task_complete(struct io_kiocb *req, struct io_tw_state ts)
{
io_req_complete_defer(req);
}
/*
@@ -1760,11 +1760,11 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
io_iopoll_req_issued(req, issue_flags);
}
return ret;
}
-int io_poll_issue(struct io_kiocb *req, struct io_tw_state *ts)
+int io_poll_issue(struct io_kiocb *req, struct io_tw_state ts)
{
io_tw_lock(req->ctx, ts);
return io_issue_sqe(req, IO_URING_F_NONBLOCK|IO_URING_F_MULTISHOT|
IO_URING_F_COMPLETE_DEFER);
}
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 85bc8f76ca19..230653b97d12 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -88,13 +88,13 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
void __io_req_task_work_add(struct io_kiocb *req, unsigned flags);
void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx,
unsigned flags);
bool io_alloc_async_data(struct io_kiocb *req);
void io_req_task_queue(struct io_kiocb *req);
-void io_req_task_complete(struct io_kiocb *req, struct io_tw_state *ts);
+void io_req_task_complete(struct io_kiocb *req, struct io_tw_state ts);
void io_req_task_queue_fail(struct io_kiocb *req, int ret);
-void io_req_task_submit(struct io_kiocb *req, struct io_tw_state *ts);
+void io_req_task_submit(struct io_kiocb *req, struct io_tw_state ts);
struct llist_node *io_handle_tw_list(struct llist_node *node, unsigned int *count, unsigned int max_entries);
struct llist_node *tctx_task_work_run(struct io_uring_task *tctx, unsigned int max_entries, unsigned int *count);
void tctx_task_work(struct callback_head *cb);
__cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd);
int io_uring_alloc_task_context(struct task_struct *task,
@@ -102,11 +102,11 @@ int io_uring_alloc_task_context(struct task_struct *task,
int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file,
int start, int end);
void io_req_queue_iowq(struct io_kiocb *req);
-int io_poll_issue(struct io_kiocb *req, struct io_tw_state *ts);
+int io_poll_issue(struct io_kiocb *req, struct io_tw_state ts);
int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr);
int io_do_iopoll(struct io_ring_ctx *ctx, bool force_nonspin);
void __io_submit_flush_completions(struct io_ring_ctx *ctx);
struct io_wq_work *io_wq_free_work(struct io_wq_work *work);
@@ -374,11 +374,11 @@ static inline bool io_local_work_pending(struct io_ring_ctx *ctx)
static inline bool io_task_work_pending(struct io_ring_ctx *ctx)
{
return task_work_pending(current) || io_local_work_pending(ctx);
}
-static inline void io_tw_lock(struct io_ring_ctx *ctx, struct io_tw_state *ts)
+static inline void io_tw_lock(struct io_ring_ctx *ctx, struct io_tw_state ts)
{
lockdep_assert_held(&ctx->uring_lock);
}
/*
diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
index 7e6f68e911f1..aae1e7f84615 100644
--- a/io_uring/msg_ring.c
+++ b/io_uring/msg_ring.c
@@ -69,11 +69,11 @@ void io_msg_ring_cleanup(struct io_kiocb *req)
static inline bool io_msg_need_remote(struct io_ring_ctx *target_ctx)
{
return target_ctx->task_complete;
}
-static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_ring_ctx *ctx = req->ctx;
io_add_aux_cqe(ctx, req->cqe.user_data, req->cqe.res, req->cqe.flags);
if (spin_trylock(&ctx->msg_lock)) {
diff --git a/io_uring/notif.c b/io_uring/notif.c
index ee3a33510b3c..c3460b295dcc 100644
--- a/io_uring/notif.c
+++ b/io_uring/notif.c
@@ -9,11 +9,11 @@
#include "notif.h"
#include "rsrc.h"
static const struct ubuf_info_ops io_ubuf_ops;
-static void io_notif_tw_complete(struct io_kiocb *notif, struct io_tw_state *ts)
+static void io_notif_tw_complete(struct io_kiocb *notif, struct io_tw_state ts)
{
struct io_notif_data *nd = io_notif_to_data(notif);
do {
notif = cmd_to_io_kiocb(nd);
diff --git a/io_uring/poll.c b/io_uring/poll.c
index bb1c0cd4f809..bc5e0125db3f 100644
--- a/io_uring/poll.c
+++ b/io_uring/poll.c
@@ -218,11 +218,11 @@ static inline void io_poll_execute(struct io_kiocb *req, int res)
* require, which is either spurious wakeup or multishot CQE is served.
* IOU_POLL_DONE when it's done with the request, then the mask is stored in
* req->cqe.res. IOU_POLL_REMOVE_POLL_USE_RES indicates to remove multishot
* poll and that the result is stored in req->cqe.
*/
-static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state *ts)
+static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state ts)
{
int v;
if (unlikely(io_should_terminate_tw()))
return -ECANCELED;
@@ -309,11 +309,11 @@ static int io_poll_check_events(struct io_kiocb *req, struct io_tw_state *ts)
io_napi_add(req);
return IOU_POLL_NO_ACTION;
}
-void io_poll_task_func(struct io_kiocb *req, struct io_tw_state *ts)
+void io_poll_task_func(struct io_kiocb *req, struct io_tw_state ts)
{
int ret;
ret = io_poll_check_events(req, ts);
if (ret == IOU_POLL_NO_ACTION) {
diff --git a/io_uring/poll.h b/io_uring/poll.h
index 04ede93113dc..7825688aab3d 100644
--- a/io_uring/poll.h
+++ b/io_uring/poll.h
@@ -41,6 +41,6 @@ int io_poll_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd,
unsigned issue_flags);
int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags);
bool io_poll_remove_all(struct io_ring_ctx *ctx, struct io_uring_task *tctx,
bool cancel_all);
-void io_poll_task_func(struct io_kiocb *req, struct io_tw_state *ts);
+void io_poll_task_func(struct io_kiocb *req, struct io_tw_state ts);
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 7aa1e4c9f64a..17f08b3b754f 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -509,11 +509,11 @@ static inline int io_fixup_rw_res(struct io_kiocb *req, long res)
res += io->bytes_done;
}
return res;
}
-void io_req_rw_complete(struct io_kiocb *req, struct io_tw_state *ts)
+void io_req_rw_complete(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
struct kiocb *kiocb = &rw->kiocb;
if ((kiocb->ki_flags & IOCB_DIO_CALLER_COMP) && kiocb->dio_complete) {
diff --git a/io_uring/rw.h b/io_uring/rw.h
index eaa59bd64870..e0c1d760cbc2 100644
--- a/io_uring/rw.h
+++ b/io_uring/rw.h
@@ -37,9 +37,9 @@ int io_prep_read(struct io_kiocb *req, const struct io_uring_sqe *sqe);
int io_prep_write(struct io_kiocb *req, const struct io_uring_sqe *sqe);
int io_read(struct io_kiocb *req, unsigned int issue_flags);
int io_write(struct io_kiocb *req, unsigned int issue_flags);
void io_readv_writev_cleanup(struct io_kiocb *req);
void io_rw_fail(struct io_kiocb *req);
-void io_req_rw_complete(struct io_kiocb *req, struct io_tw_state *ts);
+void io_req_rw_complete(struct io_kiocb *req, struct io_tw_state ts);
int io_read_mshot_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
int io_read_mshot(struct io_kiocb *req, unsigned int issue_flags);
void io_rw_cache_free(const void *entry);
diff --git a/io_uring/timeout.c b/io_uring/timeout.c
index 48fc8cf70784..31fadd3342a5 100644
--- a/io_uring/timeout.c
+++ b/io_uring/timeout.c
@@ -63,11 +63,11 @@ static inline bool io_timeout_finish(struct io_timeout *timeout,
return true;
}
static enum hrtimer_restart io_timeout_fn(struct hrtimer *timer);
-static void io_timeout_complete(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_timeout_complete(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout);
struct io_timeout_data *data = req->async_data;
struct io_ring_ctx *ctx = req->ctx;
@@ -152,11 +152,11 @@ __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
ctx->cq_last_tm_flush = seq;
raw_spin_unlock_irq(&ctx->timeout_lock);
io_flush_killed_timeouts(&list, 0);
}
-static void io_req_tw_fail_links(struct io_kiocb *link, struct io_tw_state *ts)
+static void io_req_tw_fail_links(struct io_kiocb *link, struct io_tw_state ts)
{
io_tw_lock(link->ctx, ts);
while (link) {
struct io_kiocb *nxt = link->link;
long res = -ECANCELED;
@@ -310,11 +310,11 @@ int io_timeout_cancel(struct io_ring_ctx *ctx, struct io_cancel_data *cd)
return PTR_ERR(req);
io_req_task_queue_fail(req, -ECANCELED);
return 0;
}
-static void io_req_task_link_timeout(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_req_task_link_timeout(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_timeout *timeout = io_kiocb_to_cmd(req, struct io_timeout);
struct io_kiocb *prev = timeout->prev;
int ret;
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index 1f6a82128b47..0a6688b72041 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -103,11 +103,11 @@ void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
io_ring_submit_unlock(ctx, issue_flags);
}
}
EXPORT_SYMBOL_GPL(io_uring_cmd_mark_cancelable);
-static void io_uring_cmd_work(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_uring_cmd_work(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
unsigned int flags = IO_URING_F_COMPLETE_DEFER;
if (io_should_terminate_tw())
diff --git a/io_uring/waitid.c b/io_uring/waitid.c
index 4fb465b48560..8b2f606b047b 100644
--- a/io_uring/waitid.c
+++ b/io_uring/waitid.c
@@ -14,11 +14,11 @@
#include "io_uring.h"
#include "cancel.h"
#include "waitid.h"
#include "../kernel/exit.h"
-static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state *ts);
+static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state ts);
#define IO_WAITID_CANCEL_FLAG BIT(31)
#define IO_WAITID_REF_MASK GENMASK(30, 0)
struct io_waitid {
@@ -129,11 +129,11 @@ static void io_waitid_complete(struct io_kiocb *req, int ret)
ret = io_waitid_finish(req, ret);
if (ret < 0)
req_set_fail(req);
io_req_set_res(req, ret, 0);
- io_req_task_complete(req, &ts);
+ io_req_task_complete(req, ts);
}
static bool __io_waitid_cancel(struct io_kiocb *req)
{
struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
@@ -184,11 +184,11 @@ static inline bool io_waitid_drop_issue_ref(struct io_kiocb *req)
io_req_task_work_add(req);
remove_wait_queue(iw->head, &iwa->wo.child_wait);
return true;
}
-static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state *ts)
+static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state ts)
{
struct io_waitid_async *iwa = req->async_data;
struct io_ring_ctx *ctx = req->ctx;
int ret;
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] io_uring: pass struct io_tw_state by value
2025-02-11 21:45 [PATCH] io_uring: pass struct io_tw_state by value Caleb Sander Mateos
@ 2025-02-12 13:31 ` Pavel Begunkov
2025-02-12 14:33 ` Jens Axboe
2025-02-13 16:54 ` Pavel Begunkov
2 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-02-12 13:31 UTC (permalink / raw)
To: Caleb Sander Mateos, Jens Axboe; +Cc: io-uring, linux-kernel
On 2/11/25 21:45, Caleb Sander Mateos wrote:
...
> --- a/io_uring/waitid.c
> +++ b/io_uring/waitid.c
> @@ -14,11 +14,11 @@
> #include "io_uring.h"
> #include "cancel.h"
> #include "waitid.h"
> #include "../kernel/exit.h"
>
> -static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state *ts);
> +static void io_waitid_cb(struct io_kiocb *req, struct io_tw_state ts);
>
> #define IO_WAITID_CANCEL_FLAG BIT(31)
> #define IO_WAITID_REF_MASK GENMASK(30, 0)
>
> struct io_waitid {
> @@ -129,11 +129,11 @@ static void io_waitid_complete(struct io_kiocb *req, int ret)
>
> ret = io_waitid_finish(req, ret);
> if (ret < 0)
> req_set_fail(req);
> io_req_set_res(req, ret, 0);
> - io_req_task_complete(req, &ts);
This thing will need to be fixed first
> + io_req_task_complete(req, ts);
> }
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] io_uring: pass struct io_tw_state by value
2025-02-11 21:45 [PATCH] io_uring: pass struct io_tw_state by value Caleb Sander Mateos
2025-02-12 13:31 ` Pavel Begunkov
@ 2025-02-12 14:33 ` Jens Axboe
2025-02-12 14:49 ` Pavel Begunkov
2025-02-13 16:54 ` Pavel Begunkov
2 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2025-02-12 14:33 UTC (permalink / raw)
To: Caleb Sander Mateos, Pavel Begunkov; +Cc: io-uring, linux-kernel
On 2/11/25 2:45 PM, Caleb Sander Mateos wrote:
> 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.
>
> Also add a comment to struct io_tw_state to explain its purpose.
This is nice, reduces the code generated. It'll conflict with the
fix that Pavel posted, but I can just mangle this one once I get
the 6.15 branch rebased on top of -rc3. No need to send a v2.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] io_uring: pass struct io_tw_state by value
2025-02-12 14:33 ` Jens Axboe
@ 2025-02-12 14:49 ` Pavel Begunkov
2025-02-12 14:50 ` Jens Axboe
0 siblings, 1 reply; 6+ messages in thread
From: Pavel Begunkov @ 2025-02-12 14:49 UTC (permalink / raw)
To: Jens Axboe, Caleb Sander Mateos; +Cc: io-uring, linux-kernel
On 2/12/25 14:33, Jens Axboe wrote:
> On 2/11/25 2:45 PM, Caleb Sander Mateos wrote:
>> 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.
>>
>> Also add a comment to struct io_tw_state to explain its purpose.
>
> This is nice, reduces the code generated. It'll conflict with the
> fix that Pavel posted, but I can just mangle this one once I get
> the 6.15 branch rebased on top of -rc3. No need to send a v2.
Hold on this one, we're better to adjust the patch, I'll
follow up later today.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] io_uring: pass struct io_tw_state by value
2025-02-12 14:49 ` Pavel Begunkov
@ 2025-02-12 14:50 ` Jens Axboe
0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2025-02-12 14:50 UTC (permalink / raw)
To: Pavel Begunkov, Caleb Sander Mateos; +Cc: io-uring, linux-kernel
On 2/12/25 7:49 AM, Pavel Begunkov wrote:
> On 2/12/25 14:33, Jens Axboe wrote:
>> On 2/11/25 2:45 PM, Caleb Sander Mateos wrote:
>>> 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.
>>>
>>> Also add a comment to struct io_tw_state to explain its purpose.
>>
>> This is nice, reduces the code generated. It'll conflict with the
>> fix that Pavel posted, but I can just mangle this one once I get
>> the 6.15 branch rebased on top of -rc3. No need to send a v2.
>
> Hold on this one, we're better to adjust the patch, I'll
> follow up later today.
Sure no problem, it'll be early next week on the 6.15 front anyway,
nothing is being committed right now.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] io_uring: pass struct io_tw_state by value
2025-02-11 21:45 [PATCH] io_uring: pass struct io_tw_state by value Caleb Sander Mateos
2025-02-12 13:31 ` Pavel Begunkov
2025-02-12 14:33 ` Jens Axboe
@ 2025-02-13 16:54 ` Pavel Begunkov
2 siblings, 0 replies; 6+ messages in thread
From: Pavel Begunkov @ 2025-02-13 16:54 UTC (permalink / raw)
To: Caleb Sander Mateos, Jens Axboe; +Cc: io-uring, linux-kernel
On 2/11/25 21:45, Caleb Sander Mateos wrote:
> 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".
The other unnamed reason was to limit the mess from io_uring wide
changes while it might still be used later on. It's always a pain
for backporting, so if we're doing that we might as well make it
easily convertible for future plans. Let's do
typedef struct io_tw_state iou_state_t;
Might be useful for leaking it to cmds as well.
> 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.
>
> Also add a comment to struct io_tw_state to explain its purpose.
>
> Signed-off-by: Caleb Sander Mateos <[email protected]>
> ---
> include/linux/io_uring_types.h | 3 ++-
> io_uring/futex.c | 6 +++---
> io_uring/io_uring.c | 30 +++++++++++++++---------------
> io_uring/io_uring.h | 8 ++++----
> io_uring/msg_ring.c | 2 +-
> io_uring/notif.c | 2 +-
> io_uring/poll.c | 4 ++--
> io_uring/poll.h | 2 +-
> io_uring/rw.c | 2 +-
> io_uring/rw.h | 2 +-
> io_uring/timeout.c | 6 +++---
> io_uring/uring_cmd.c | 2 +-
> io_uring/waitid.c | 6 +++---
> 13 files changed, 38 insertions(+), 37 deletions(-)
>
> diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
> index e2fef264ff8b..4abd0299fdfb 100644
> --- a/include/linux/io_uring_types.h
> +++ b/include/linux/io_uring_types.h
> @@ -434,10 +434,11 @@ struct io_ring_ctx {
> struct io_mapped_region ring_region;
> /* used for optimised request parameter and wait argument passing */
> struct io_mapped_region param_region;
> };
>
> +/* Token passed to task work callbacks to indicate ctx->uring_lock is held */
It indicates the current context not locking specifically, which is
why the chunk from waitid as below is not correct:
mutex_lock(uring_lock);
struct io_tw_state dummy;
io_uring_core_helper(&dummy);
mutex_unlock(uring_lock);
Probably something like "Token passed around to indicate the current
io_uring execution context". And it doesn't need to be more specific
as long as type system works for us. It might be a good idea to add
a note in bold that nobody outside of core io_uring is allowed
creating it, though it'll be ignored anyway.
> struct io_tw_state {
> };
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-02-13 16:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-11 21:45 [PATCH] io_uring: pass struct io_tw_state by value Caleb Sander Mateos
2025-02-12 13:31 ` Pavel Begunkov
2025-02-12 14:33 ` Jens Axboe
2025-02-12 14:49 ` Pavel Begunkov
2025-02-12 14:50 ` Jens Axboe
2025-02-13 16:54 ` Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox