io_uring: Pass whole sqe to commands

JIRA: https://issues.redhat.com/browse/RHEL-12076
Conflicts: RHEL does not yet support ublk, so this backport removes
  those changes from the patch.

commit fd9b8547bc5c34186dc42ea05fb4380d21695374
Author: Breno Leitao <leitao@debian.org>
Date:   Thu May 4 05:18:55 2023 -0700

    io_uring: Pass whole sqe to commands
    
    Currently uring CMD operation relies on having large SQEs, but future
    operations might want to use normal SQE.
    
    The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
    but, for commands that use normal SQE size, it might be necessary to
    access the initial SQE fields outside of the payload/cmd block.  So,
    saves the whole SQE other than just the pdu.
    
    This changes slightly how the io_uring_cmd works, since the cmd
    structures and callbacks are not opaque to io_uring anymore. I.e, the
    callbacks can look at the SQE entries, not only, in the cmd structure.
    
    The main advantage is that we don't need to create custom structures for
    simple commands.
    
    Creates io_uring_sqe_cmd() that returns the cmd private data as a null
    pointer and avoids casting in the callee side.
    Also, make most of ublk_drv's sqe->cmd priv structure into const, and use
    io_uring_sqe_cmd() to get the private structure, removing the unwanted
    cast. (There is one case where the cast is still needed since the
    header->{len,addr} is updated in the private structure)
    
    Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
    Signed-off-by: Breno Leitao <leitao@debian.org>
    Reviewed-by: Keith Busch <kbusch@kernel.org>
    Reviewed-by: Christoph Hellwig <hch@lst.de>
    Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/20230504121856.904491-3-leitao@debian.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
This commit is contained in:
Jeff Moyer 2023-05-04 05:18:55 -07:00
parent 28532e38e4
commit 0454a9fd14
4 changed files with 11 additions and 9 deletions

View File

@ -551,7 +551,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
struct io_uring_cmd *ioucmd, unsigned int issue_flags, bool vec)
{
struct nvme_uring_cmd_pdu *pdu = nvme_uring_cmd_pdu(ioucmd);
const struct nvme_uring_cmd *cmd = ioucmd->cmd;
const struct nvme_uring_cmd *cmd = io_uring_sqe_cmd(ioucmd->sqe);
struct request_queue *q = ns ? ns->queue : ctrl->admin_q;
struct nvme_uring_data d;
struct nvme_command c;

View File

@ -24,7 +24,7 @@ enum io_uring_cmd_flags {
struct io_uring_cmd {
struct file *file;
const void *cmd;
const struct io_uring_sqe *sqe;
union {
/* callback to defer completions to task context */
void (*task_work_cb)(struct io_uring_cmd *cmd, unsigned);
@ -66,6 +66,11 @@ static inline void io_uring_free(struct task_struct *tsk)
if (tsk->io_uring)
__io_uring_free(tsk);
}
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
{
return sqe->cmd;
}
#else
static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
struct iov_iter *iter, void *ioucmd)

View File

@ -627,7 +627,7 @@ const struct io_cold_def io_cold_defs[] = {
},
[IORING_OP_URING_CMD] = {
.name = "URING_CMD",
.async_size = uring_cmd_pdu_size(1),
.async_size = 2 * sizeof(struct io_uring_sqe),
.prep_async = io_uring_cmd_prep_async,
},
[IORING_OP_SEND_ZC] = {

View File

@ -69,15 +69,12 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
int io_uring_cmd_prep_async(struct io_kiocb *req)
{
struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
size_t cmd_size;
BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
memcpy(req->async_data, ioucmd->cmd, cmd_size);
ioucmd->cmd = req->async_data;
memcpy(req->async_data, ioucmd->sqe, uring_sqe_size(req->ctx));
ioucmd->sqe = req->async_data;
return 0;
}
@ -103,7 +100,7 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
req->imu = ctx->user_bufs[index];
io_req_set_rsrc_node(req, ctx, 0);
}
ioucmd->cmd = sqe->cmd;
ioucmd->sqe = sqe;
ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);
return 0;
}