Skip to content

Commit c3ac76f

Browse files
committed
io_uring: add remote task_work execution helper
All our task_work handling is targeted at the state in the io_kiocb itself, which is what it is being used for. However, MSG_RING rolls its own task_work handling, ignoring how that is usually done. In preparation for switching MSG_RING to be able to use the normal task_work handling, add io_req_task_work_add_remote() which allows the caller to pass in the target io_ring_ctx. Signed-off-by: Jens Axboe <[email protected]>
1 parent d57afd8 commit c3ac76f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

io_uring/io_uring.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,10 @@ void tctx_task_work(struct callback_head *cb)
10981098
WARN_ON_ONCE(ret);
10991099
}
11001100

1101-
static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
1101+
static inline void io_req_local_work_add(struct io_kiocb *req,
1102+
struct io_ring_ctx *ctx,
1103+
unsigned flags)
11021104
{
1103-
struct io_ring_ctx *ctx = req->ctx;
11041105
unsigned nr_wait, nr_tw, nr_tw_prev;
11051106
struct llist_node *head;
11061107

@@ -1114,6 +1115,8 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags)
11141115
if (req->flags & (REQ_F_LINK | REQ_F_HARDLINK))
11151116
flags &= ~IOU_F_TWQ_LAZY_WAKE;
11161117

1118+
guard(rcu)();
1119+
11171120
head = READ_ONCE(ctx->work_llist.first);
11181121
do {
11191122
nr_tw_prev = 0;
@@ -1195,13 +1198,18 @@ static void io_req_normal_work_add(struct io_kiocb *req)
11951198

11961199
void __io_req_task_work_add(struct io_kiocb *req, unsigned flags)
11971200
{
1198-
if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN) {
1199-
rcu_read_lock();
1200-
io_req_local_work_add(req, flags);
1201-
rcu_read_unlock();
1202-
} else {
1201+
if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN)
1202+
io_req_local_work_add(req, req->ctx, flags);
1203+
else
12031204
io_req_normal_work_add(req);
1204-
}
1205+
}
1206+
1207+
void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx,
1208+
unsigned flags)
1209+
{
1210+
if (WARN_ON_ONCE(!(ctx->flags & IORING_SETUP_DEFER_TASKRUN)))
1211+
return;
1212+
io_req_local_work_add(req, ctx, flags);
12051213
}
12061214

12071215
static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx)

io_uring/io_uring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd,
7373
unsigned issue_flags);
7474

7575
void __io_req_task_work_add(struct io_kiocb *req, unsigned flags);
76+
void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx,
77+
unsigned flags);
7678
bool io_alloc_async_data(struct io_kiocb *req);
7779
void io_req_task_queue(struct io_kiocb *req);
7880
void io_req_task_complete(struct io_kiocb *req, struct io_tw_state *ts);

0 commit comments

Comments
 (0)