Skip to content

Commit 212ec34

Browse files
committed
block: only read from sqe on initial invocation of blkdev_uring_cmd()
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>
1 parent 845db02 commit 212ec34

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
@@ -857,6 +857,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
857857
#endif
858858

859859
struct blk_iou_cmd {
860+
u64 start;
861+
u64 len;
860862
int res;
861863
bool nowait;
862864
};
@@ -946,23 +948,27 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
946948
{
947949
struct block_device *bdev = I_BDEV(cmd->file->f_mapping->host);
948950
struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd);
949-
const struct io_uring_sqe *sqe = cmd->sqe;
950951
u32 cmd_op = cmd->cmd_op;
951-
uint64_t start, len;
952952

953-
if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
954-
sqe->rw_flags || sqe->file_index))
955-
return -EINVAL;
953+
/* Read what we need from the SQE on the first issue */
954+
if (!(issue_flags & IORING_URING_CMD_REISSUE)) {
955+
const struct io_uring_sqe *sqe = cmd->sqe;
956+
957+
if (unlikely(sqe->ioprio || sqe->__pad1 || sqe->len ||
958+
sqe->rw_flags || sqe->file_index))
959+
return -EINVAL;
960+
961+
bic->start = READ_ONCE(sqe->addr);
962+
bic->len = READ_ONCE(sqe->addr3);
963+
}
956964

957965
bic->res = 0;
958966
bic->nowait = issue_flags & IO_URING_F_NONBLOCK;
959967

960-
start = READ_ONCE(sqe->addr);
961-
len = READ_ONCE(sqe->addr3);
962-
963968
switch (cmd_op) {
964969
case BLOCK_URING_CMD_DISCARD:
965-
return blkdev_cmd_discard(cmd, bdev, start, len, bic->nowait);
970+
return blkdev_cmd_discard(cmd, bdev, bic->start, bic->len,
971+
bic->nowait);
966972
}
967973
return -EINVAL;
968974
}

0 commit comments

Comments
 (0)