block: only read from sqe on initial invocation of blkdev_uring_cmd()
Jens Axboe
maintainerPATCH 1/1 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.
---
block/ioctl.c +15 -9
@@ -857,6 +857,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)#endif struct blk_iou_cmd { +u64 start; +u64 len;int res;bool nowait; };
@@ -946,23 +948,27 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) {struct block_device *bdev =I_BDEV (cmd->file->f_mapping->host); struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); -const struct io_uring_sqe *sqe = cmd->sqe;u32 cmd_op = cmd->cmd_op; -uint64_t start, len; -if (unlikely (sqe->ioprio || sqe->__pad1 || sqe->len || - sqe->rw_flags || sqe->file_index)) -return -EINVAL ; +/* Read what we need from the SQE on the first issue */ +if (issue_flags &IO_URING_F_INLINE ) { +const struct io_uring_sqe *sqe = cmd->sqe; + +if (unlikely (sqe->ioprio || sqe->__pad1 || sqe->len || + sqe->rw_flags || sqe->file_index)) +return -EINVAL ; + + bic->start =READ_ONCE (sqe->addr); + bic->len =READ_ONCE (sqe->addr3); + } bic->res =0 ; bic->nowait = issue_flags &IO_URING_F_NONBLOCK ; - start =READ_ONCE (sqe->addr); - len =READ_ONCE (sqe->addr3); -switch (cmd_op) {case BLOCK_URING_CMD_DISCARD : -return blkdev_cmd_discard (cmd, bdev, start, len, bic->nowait); +return blkdev_cmd_discard (cmd, bdev, bic->start, bic->len, + bic->nowait); }return -EINVAL ; }
Signature · 1 line
Jens Axboe
Quoted 29 lines · Jens Axboe
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 [email protected] # 6.17+Signed-off-by Jens Axboe <[email protected]>---
block/ioctl.c +2
-0@@ -857,6 +857,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)#endif struct blk_iou_cmd { +u64 start; +u64 len;int res;bool nowait; };@@ -946,23 +948,27 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) {struct block_device *bdev =I_BDEV (cmd->file->f_mapping->host);
block/ioctl.c int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) · line 954
Quoted 10 lines
block/ioctl.c +2
-5struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); -const struct io_uring_sqe *sqe = cmd->sqe;u32 cmd_op = cmd->cmd_op; -uint64_t start, len; -if (unlikely (sqe->ioprio || sqe->__pad1 || sqe->len || - sqe->rw_flags || sqe->file_index)) -return -EINVAL ; +/* Read what we need from the SQE on the first issue */ +if (issue_flags &IO_URING_F_INLINE ) {
I don't think IO_URING_F_INLINE is guaranteed to be set on the first issue? For example, a subsequent command in a linked chain, or one that sets REQ_F_FORCE_ASYNC or REQ_F_IO_DRAIN will be issued asynchronously originally. Could you check !(issue_flags & IORING_URING_CMD_REISSUE) instead?
Best,
Caleb
Quoted 29 lines
block/ioctl.c +11
-5+const struct io_uring_sqe *sqe = cmd->sqe; + +if (unlikely (sqe->ioprio || sqe->__pad1 || sqe->len || + sqe->rw_flags || sqe->file_index)) +return -EINVAL ; + + bic->start =READ_ONCE (sqe->addr); + bic->len =READ_ONCE (sqe->addr3); + } bic->res =0 ; bic->nowait = issue_flags &IO_URING_F_NONBLOCK ; - start =READ_ONCE (sqe->addr); - len =READ_ONCE (sqe->addr3); -switch (cmd_op) {case BLOCK_URING_CMD_DISCARD : -return blkdev_cmd_discard (cmd, bdev, start, len, bic->nowait); +return blkdev_cmd_discard (cmd, bdev, bic->start, bic->len, + bic->nowait); }return -EINVAL ; } --Jens Axboe
Jens Axboe
maintainerQuoted 35 lines · Caleb Sander Mateos
Quoted 34 lines · Jens Axboe
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 [email protected] # 6.17+Signed-off-by Jens Axboe <[email protected]>---
block/ioctl.c +2
-2@@ -857,6 +857,8 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)#endif struct blk_iou_cmd { +u64 start; +u64 len;int res;bool nowait; };@@ -946,23 +948,27 @@ int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) {struct block_device *bdev =I_BDEV (cmd->file->f_mapping->host); struct blk_iou_cmd *bic = io_uring_cmd_to_pdu(cmd, struct blk_iou_cmd); -const struct io_uring_sqe *sqe = cmd->sqe;u32 cmd_op = cmd->cmd_op; -uint64_t start, len;
Quoted 11 lines
block/ioctl.c int blkdev_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) · line 954
Quoted 5 lines
block/ioctl.c +2
-3-if (unlikely (sqe->ioprio || sqe->__pad1 || sqe->len || - sqe->rw_flags || sqe->file_index)) -return -EINVAL ; +/* Read what we need from the SQE on the first issue */ +if (issue_flags &IO_URING_F_INLINE ) {I don't think
IO_URING_F_INLINEis guaranteed to be set on the first issue? For example, a subsequent command in a linked chain, or one that setsREQ_F_FORCE_ASYNCorREQ_F_IO_DRAINwill be issued asynchronously originally. Could you check !(issue_flags &IORING_URING_CMD_REISSUE) instead?
Good point, that is more self-explanatory too (and correct). I'll make the change.
Signature · 1 line
Jens Axboe