Skip to content

Commit 58465d8

Browse files
Dongli Zhangmstsirkin
authored andcommitted
vhost-scsi: Fix vhost_scsi_send_status()
Although the support of VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 was signaled by the commit 664ed90 ("vhost/scsi: Set VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 feature bits"), vhost_scsi_send_bad_target() still assumes the response in a single descriptor. Similar issue in vhost_scsi_send_bad_target() has been fixed in previous commit. In addition, similar issue for vhost_scsi_complete_cmd_work() has been fixed by the commit 6dd88fd ("vhost-scsi: unbreak any layout for response"). Fixes: 3ca5166 ("vhost-scsi: Add better resource allocation failure handling") Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> Acked-by: Jason Wang <jasowang@redhat.com> Reviewed-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20250403063028.16045-4-dongli.zhang@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent b182687 commit 58465d8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/vhost/scsi.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,18 +999,22 @@ static void vhost_scsi_target_queue_cmd(struct vhost_scsi_nexus *nexus,
999999

10001000
static void
10011001
vhost_scsi_send_status(struct vhost_scsi *vs, struct vhost_virtqueue *vq,
1002-
int head, unsigned int out, u8 status)
1002+
struct vhost_scsi_ctx *vc, u8 status)
10031003
{
1004-
struct virtio_scsi_cmd_resp __user *resp;
10051004
struct virtio_scsi_cmd_resp rsp;
1005+
struct iov_iter iov_iter;
10061006
int ret;
10071007

10081008
memset(&rsp, 0, sizeof(rsp));
10091009
rsp.status = status;
1010-
resp = vq->iov[out].iov_base;
1011-
ret = __copy_to_user(resp, &rsp, sizeof(rsp));
1012-
if (!ret)
1013-
vhost_add_used_and_signal(&vs->dev, vq, head, 0);
1010+
1011+
iov_iter_init(&iov_iter, ITER_DEST, &vq->iov[vc->out], vc->in,
1012+
sizeof(rsp));
1013+
1014+
ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter);
1015+
1016+
if (likely(ret == sizeof(rsp)))
1017+
vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0);
10141018
else
10151019
pr_err("Faulted on virtio_scsi_cmd_resp\n");
10161020
}
@@ -1420,7 +1424,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
14201424
else if (ret == -EIO)
14211425
vhost_scsi_send_bad_target(vs, vq, &vc, TYPE_IO_CMD);
14221426
else if (ret == -ENOMEM)
1423-
vhost_scsi_send_status(vs, vq, vc.head, vc.out,
1427+
vhost_scsi_send_status(vs, vq, &vc,
14241428
SAM_STAT_TASK_SET_FULL);
14251429
} while (likely(!vhost_exceeds_weight(vq, ++c, 0)));
14261430
out:

0 commit comments

Comments
 (0)