Skip to content

Commit 27a5d52

Browse files
Dongli ZhangBrian Maly
authored andcommitted
vhost-scsi: Fix vhost_scsi_send_bad_target()
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. In addition, although vhost_scsi_send_bad_target() is used by both I/O queue and control queue, the response header is always virtio_scsi_cmd_resp. It is required to use virtio_scsi_ctrl_tmf_resp or virtio_scsi_ctrl_an_resp for control queue. Fixes: 664ed90 ("vhost/scsi: Set VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 feature bits") Signed-off-by: Dongli Zhang <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Mike Christie <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> (cherry picked from commit b182687135474d7ed905a07cc6cb2734b359e13e) Orabug: 37980690 Conflicts: - commit de4eda9 ("use less confusing names for iov_iter direction initializers") is not merged in UEK7 so we are still using READ instead of ITER_DEST. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Dongli Zhang <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 3eaa952 commit 27a5d52

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

drivers/vhost/scsi.c

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,23 +1033,46 @@ vhost_scsi_send_status(struct vhost_scsi *vs, struct vhost_virtqueue *vq,
10331033
pr_err("Faulted on virtio_scsi_cmd_resp\n");
10341034
}
10351035

1036+
#define TYPE_IO_CMD 0
1037+
#define TYPE_CTRL_TMF 1
1038+
#define TYPE_CTRL_AN 2
1039+
10361040
static void
10371041
vhost_scsi_send_bad_target(struct vhost_scsi *vs,
10381042
struct vhost_virtqueue *vq,
1039-
int head, unsigned out)
1043+
struct vhost_scsi_ctx *vc, int type)
10401044
{
1041-
struct virtio_scsi_cmd_resp __user *resp;
1042-
struct virtio_scsi_cmd_resp rsp;
1045+
union {
1046+
struct virtio_scsi_cmd_resp cmd;
1047+
struct virtio_scsi_ctrl_tmf_resp tmf;
1048+
struct virtio_scsi_ctrl_an_resp an;
1049+
} rsp;
1050+
struct iov_iter iov_iter;
1051+
size_t rsp_size;
10431052
int ret;
10441053

10451054
memset(&rsp, 0, sizeof(rsp));
1046-
rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
1047-
resp = vq->iov[out].iov_base;
1048-
ret = __copy_to_user(resp, &rsp, sizeof(rsp));
1049-
if (!ret)
1050-
vhost_add_used_and_signal(&vs->dev, vq, head, 0);
1055+
1056+
if (type == TYPE_IO_CMD) {
1057+
rsp_size = sizeof(struct virtio_scsi_cmd_resp);
1058+
rsp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET;
1059+
} else if (type == TYPE_CTRL_TMF) {
1060+
rsp_size = sizeof(struct virtio_scsi_ctrl_tmf_resp);
1061+
rsp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET;
1062+
} else {
1063+
rsp_size = sizeof(struct virtio_scsi_ctrl_an_resp);
1064+
rsp.an.response = VIRTIO_SCSI_S_BAD_TARGET;
1065+
}
1066+
1067+
iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in,
1068+
rsp_size);
1069+
1070+
ret = copy_to_iter(&rsp, rsp_size, &iov_iter);
1071+
1072+
if (likely(ret == rsp_size))
1073+
vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0);
10511074
else
1052-
pr_err("Faulted on virtio_scsi_cmd_resp\n");
1075+
pr_err("Faulted on virtio scsi type=%d\n", type);
10531076
}
10541077

10551078
static int
@@ -1413,7 +1436,7 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
14131436
if (ret == -ENXIO)
14141437
break;
14151438
else if (ret == -EIO)
1416-
vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out);
1439+
vhost_scsi_send_bad_target(vs, vq, &vc, TYPE_IO_CMD);
14171440
else if (ret == -ENOMEM)
14181441
vhost_scsi_send_status(vs, vq, vc.head, vc.out,
14191442
SAM_STAT_TASK_SET_FULL);
@@ -1642,7 +1665,10 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
16421665
if (ret == -ENXIO)
16431666
break;
16441667
else if (ret == -EIO)
1645-
vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out);
1668+
vhost_scsi_send_bad_target(vs, vq, &vc,
1669+
v_req.type == VIRTIO_SCSI_T_TMF ?
1670+
TYPE_CTRL_TMF :
1671+
TYPE_CTRL_AN);
16461672
} while (likely(!vhost_exceeds_weight(vq, ++c, 0)));
16471673
out:
16481674
mutex_unlock(&vq->mutex);

0 commit comments

Comments
 (0)