Skip to content

Commit 98f7743

Browse files
axboegregkh
authored andcommitted
block: only read from sqe on initial invocation of blkdev_uring_cmd()
commit 212ec34 upstream. This passthrough helper currently only supports discards. Part of that command is the start and length, which is read from the SQE. It does so on every invocation, where it really should just make it stable on the first invocation. This avoids needing to copy the SQE upfront, as we only really need those two 8b values stored in our per-req payload. Cc: stable@vger.kernel.org # 6.17+ Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 55fd8ad commit 98f7743

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

block/ioctl.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
864864
#endif
865865

866866
struct blk_iou_cmd {
867+
u64 start;
868+
u64 len;
867869
int res;
868870
bool nowait;
869871
};
@@ -953,23 +955,27 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
953955
{
954956
struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host);
955957
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
956-
const struct io_uring_sqe *sqe = cmd->sqe;
957958
u32 cmd_op = cmd->cmd_op;
958-
uint64_t start, len;
959959

960-
if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
961-
sqe->rw_flags || sqe->file_index))
962-
return -EINVAL;
960+
/* Read what we need from the SQE on the first issue */
961+
if (!(issue_flags & IORING_URING_CMD_REISSUE)) {
962+
const struct io_uring_sqe *sqe = cmd->sqe;
963+
964+
if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
965+
sqe->rw_flags || sqe->file_index))
966+
return -EINVAL;
967+
968+
bic->start = READ_ONCE(sqe->addr);
969+
bic->len = READ_ONCE(sqe->addr3);
970+
}
963971

964972
bic->res = 0;
965973
bic->nowait = issue_flags & IO_URING_F_NONBLOCK;
966974

967-
start = READ_ONCE(sqe->addr);
968-
len = READ_ONCE(sqe->addr3);
969-
970975
switch (cmd_op) {
971976
case BLOCK_URING_CMD_DISCARD:
972-
return blkdev_cmd_discard(cmd, bdev, start, len, bic->nowait);
977+
return blkdev_cmd_discard(cmd, bdev, bic->start, bic->len,
978+
bic->nowait);
973979
}
974980
return -EINVAL;
975981
}

0 commit comments

Comments
 (0)