Skip to content

Commit 6746ee4

Browse files
isilenceaxboe
authored andcommitted
io_uring/cmd: expose iowq to cmds
When an io_uring request needs blocking context we offload it to the io_uring's thread pool called io-wq. We can get there off ->uring_cmd by returning -EAGAIN, but there is no straightforward way of doing that from an asynchronous callback. Add a helper that would transfer a command to a blocking context. Note, we do an extra hop via task_work before io_queue_iowq(), that's a limitation of io_uring infra we have that can likely be lifted later if that would ever become a problem. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/f735f807d7c8ba50c9452c69dfe5d3e9e535037b.1726072086.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 6d0f8dc commit 6746ee4

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/linux/io_uring/cmd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
4848
void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
4949
unsigned int issue_flags);
5050

51+
/* Execute the request from a blocking context */
52+
void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd);
53+
5154
#else
5255
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
5356
struct iov_iter *iter, void *ioucmd)
@@ -67,6 +70,9 @@ static inline void io_uring_cmd_mark_cancelable(struct io_uring_cmd *cmd,
6770
unsigned int issue_flags)
6871
{
6972
}
73+
static inline void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd)
74+
{
75+
}
7076
#endif
7177

7278
/*

io_uring/io_uring.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,17 @@ static void io_queue_iowq(struct io_kiocb *req)
533533
io_queue_linked_timeout(link);
534534
}
535535

536+
static void io_req_queue_iowq_tw(struct io_kiocb *req, struct io_tw_state *ts)
537+
{
538+
io_queue_iowq(req);
539+
}
540+
541+
void io_req_queue_iowq(struct io_kiocb *req)
542+
{
543+
req->io_task_work.func = io_req_queue_iowq_tw;
544+
io_req_task_work_add(req);
545+
}
546+
536547
static __cold void io_queue_deferred(struct io_ring_ctx *ctx)
537548
{
538549
while (!list_empty(&ctx->defer_list)) {

io_uring/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int io_uring_alloc_task_context(struct task_struct *task,
9494

9595
int io_ring_add_registered_file(struct io_uring_task *tctx, struct file *file,
9696
int start, int end);
97+
void io_req_queue_iowq(struct io_kiocb *req);
9798

9899
int io_poll_issue(struct io_kiocb *req, struct io_tw_state *ts);
99100
int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr);

io_uring/uring_cmd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
277277
}
278278
EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed);
279279

280+
void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd)
281+
{
282+
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
283+
284+
io_req_queue_iowq(req);
285+
}
286+
280287
static inline int io_uring_cmd_getsockopt(struct socket *sock,
281288
struct io_uring_cmd *cmd,
282289
unsigned int issue_flags)

0 commit comments

Comments
 (0)