diff mbox series

ublk_drv: update iod->addr for UBLK_IO_NEED_GET_DATA

Message ID 20220810055212.66417-1-ZiyangZhang@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series ublk_drv: update iod->addr for UBLK_IO_NEED_GET_DATA | expand

Commit Message

Ziyang Zhang Aug. 10, 2022, 5:52 a.m. UTC
If ublksrv sends UBLK_IO_NEED_GET_DATA with new allocated io buffer, we
have to update iod->addr in task_work before calling io_uring_cmd_done().
Then usersapce target can handle (write)io request with the new io
buffer reading from updated iod.

Without this change, userspace target may touch a wrong io buffer!

Signed-off-by: ZiyangZhang <ZiyangZhang@linux.alibaba.com>
---
 drivers/block/ublk_drv.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Ming Lei Aug. 13, 2022, 10:34 a.m. UTC | #1
On Wed, Aug 10, 2022 at 1:53 PM ZiyangZhang
<ZiyangZhang@linux.alibaba.com> wrote:
>
> If ublksrv sends UBLK_IO_NEED_GET_DATA with new allocated io buffer, we
> have to update iod->addr in task_work before calling io_uring_cmd_done().
> Then usersapce target can handle (write)io request with the new io
> buffer reading from updated iod.
>
> Without this change, userspace target may touch a wrong io buffer!
>
> Signed-off-by: ZiyangZhang <ZiyangZhang@linux.alibaba.com>
> ---
>  drivers/block/ublk_drv.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 0b9bd9e02b53..98c345df6896 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -677,6 +677,11 @@ static inline void __ublk_rq_task_work(struct request *req)
>                  * do the copy work.
>                  */
>                 io->flags &= ~UBLK_IO_FLAG_NEED_GET_DATA;
> +               /* update iod->addr because ublksrv may have passed a new io buffer */
> +               ublk_get_iod(ubq, req->tag)->addr = io->addr;
> +               pr_devel("%s: update iod->addr: op %d, qid %d tag %d io_flags %x addr %llx\n",
> +                               __func__, io->cmd->cmd_op, ubq->q_id, req->tag, io->flags,
> +                               ublk_get_iod(ubq, req->tag)->addr);

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Jens Axboe Aug. 13, 2022, 2:35 p.m. UTC | #2
On Wed, 10 Aug 2022 13:52:12 +0800, ZiyangZhang wrote:
> If ublksrv sends UBLK_IO_NEED_GET_DATA with new allocated io buffer, we
> have to update iod->addr in task_work before calling io_uring_cmd_done().
> Then usersapce target can handle (write)io request with the new io
> buffer reading from updated iod.
> 
> Without this change, userspace target may touch a wrong io buffer!
> 
> [...]

Applied, thanks!

[1/1] ublk_drv: update iod->addr for UBLK_IO_NEED_GET_DATA
      commit: 92cb6e2e5dbaea02c2fa317f3543c8918db25e89

Best regards,
diff mbox series

Patch

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 0b9bd9e02b53..98c345df6896 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -677,6 +677,11 @@  static inline void __ublk_rq_task_work(struct request *req)
 		 * do the copy work.
 		 */
 		io->flags &= ~UBLK_IO_FLAG_NEED_GET_DATA;
+		/* update iod->addr because ublksrv may have passed a new io buffer */
+		ublk_get_iod(ubq, req->tag)->addr = io->addr;
+		pr_devel("%s: update iod->addr: op %d, qid %d tag %d io_flags %x addr %llx\n",
+				__func__, io->cmd->cmd_op, ubq->q_id, req->tag, io->flags,
+				ublk_get_iod(ubq, req->tag)->addr);
 	}
 
 	mapped_bytes = ublk_map_io(ubq, req, io);