]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ublk: don't take ublk_queue in ublk_unregister_io_buf()
authorCaleb Sander Mateos <csander@purestorage.com>
Fri, 20 Jun 2025 15:10:02 +0000 (09:10 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 1 Jul 2025 02:13:42 +0000 (20:13 -0600)
UBLK_IO_UNREGISTER_IO_BUF currently requires a valid q_id and tag to be
passed in the ublksrv_io_cmd. However, only the addr (registered buffer
index) is actually used to unregister the buffer. There is no check that
the q_id and tag are for the ublk request whose buffer is registered at
the given index. To prepare to allow userspace to omit the q_id and tag,
check the UBLK_F_SUPPORT_ZERO_COPY flag on the ublk_device instead of
the ublk_queue.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250620151008.3976463-9-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c

index 9ea7cd698d20f5a1da02bfa5b0de4112bf8d1756..0c244fe76d277d7f30581dcc38d365d049ec74a1 100644 (file)
@@ -2041,10 +2041,10 @@ static int ublk_register_io_buf(struct io_uring_cmd *cmd,
 }
 
 static int ublk_unregister_io_buf(struct io_uring_cmd *cmd,
-                                 const struct ublk_queue *ubq,
+                                 const struct ublk_device *ub,
                                  unsigned int index, unsigned int issue_flags)
 {
-       if (!ublk_support_zero_copy(ubq))
+       if (!(ub->dev_info.flags & UBLK_F_SUPPORT_ZERO_COPY))
                return -EINVAL;
 
        return io_buffer_unregister_bvec(cmd, index, issue_flags);
@@ -2245,7 +2245,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
        case UBLK_IO_REGISTER_IO_BUF:
                return ublk_register_io_buf(cmd, ubq, io, ub_cmd->addr, issue_flags);
        case UBLK_IO_UNREGISTER_IO_BUF:
-               return ublk_unregister_io_buf(cmd, ubq, ub_cmd->addr, issue_flags);
+               return ublk_unregister_io_buf(cmd, ub, ub_cmd->addr, issue_flags);
        case UBLK_IO_COMMIT_AND_FETCH_REQ:
                ret = ublk_commit_and_fetch(ubq, io, cmd, ub_cmd, issue_flags);
                if (ret)