Skip to content

Commit 0251ddb

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael Tsirkin: "A small number of fixes: - virtgpu is exempt from reset shutdown fow now - a more complete fix is in the works - spec compliance fixes in: - virtio-pci cap commands - vhost_scsi_send_bad_target - virtio console resize - missing locking fix in vhost-scsi - virtio ring - a KCSAN false positive fix - VHOST_*_OWNER documentation fix" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost-scsi: Fix vhost_scsi_send_status() vhost-scsi: Fix vhost_scsi_send_bad_target() vhost-scsi: protect vq->log_used with vq->mutex vhost_task: fix vhost_task_create() documentation virtio_console: fix order of fields cols and rows virtio_console: fix missing byte order handling for cols and rows virtgpu: don't reset on shutdown virtio_ring: Fix data race by tagging event_triggered as racy for KCSAN vhost: fix VHOST_*_OWNER documentation virtio_pci: Use self group type for cap commands
2 parents bc33723 + 58465d8 commit 0251ddb

File tree

10 files changed

+85
-27
lines changed

10 files changed

+85
-27
lines changed

drivers/char/virtio_console.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1576,16 +1576,17 @@ static void handle_control_message(struct virtio_device *vdev,
15761576
break;
15771577
case VIRTIO_CONSOLE_RESIZE: {
15781578
struct {
1579-
__u16 rows;
1580-
__u16 cols;
1579+
__virtio16 cols;
1580+
__virtio16 rows;
15811581
} size;
15821582

15831583
if (!is_console_port(port))
15841584
break;
15851585

15861586
memcpy(&size, buf->buf + buf->offset + sizeof(*cpkt),
15871587
sizeof(size));
1588-
set_console_size(port, size.rows, size.cols);
1588+
set_console_size(port, virtio16_to_cpu(vdev, size.rows),
1589+
virtio16_to_cpu(vdev, size.cols));
15891590

15901591
port->cons.hvc->irq_requested = 1;
15911592
resize_console(port);

drivers/gpu/drm/virtio/virtgpu_drv.c

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ static void virtio_gpu_remove(struct virtio_device *vdev)
128128
drm_dev_put(dev);
129129
}
130130

131+
static void virtio_gpu_shutdown(struct virtio_device *vdev)
132+
{
133+
/*
134+
* drm does its own synchronization on shutdown.
135+
* Do nothing here, opt out of device reset.
136+
*/
137+
}
138+
131139
static void virtio_gpu_config_changed(struct virtio_device *vdev)
132140
{
133141
struct drm_device *dev = vdev->priv;
@@ -162,6 +170,7 @@ static struct virtio_driver virtio_gpu_driver = {
162170
.id_table = id_table,
163171
.probe = virtio_gpu_probe,
164172
.remove = virtio_gpu_remove,
173+
.shutdown = virtio_gpu_shutdown,
165174
.config_changed = virtio_gpu_config_changed
166175
};
167176

drivers/vhost/scsi.c

+56-18
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
627627
int ret;
628628

629629
llnode = llist_del_all(&svq->completion_list);
630+
631+
mutex_lock(&svq->vq.mutex);
632+
630633
llist_for_each_entry_safe(cmd, t, llnode, tvc_completion_list) {
631634
se_cmd = &cmd->tvc_se_cmd;
632635

@@ -660,6 +663,8 @@ static void vhost_scsi_complete_cmd_work(struct vhost_work *work)
660663
vhost_scsi_release_cmd_res(se_cmd);
661664
}
662665

666+
mutex_unlock(&svq->vq.mutex);
667+
663668
if (signal)
664669
vhost_signal(&svq->vs->dev, &svq->vq);
665670
}
@@ -994,39 +999,66 @@ static void vhost_scsi_target_queue_cmd(struct vhost_scsi_nexus *nexus,
994999

9951000
static void
9961001
vhost_scsi_send_status(struct vhost_scsi *vs, struct vhost_virtqueue *vq,
997-
int head, unsigned int out, u8 status)
1002+
struct vhost_scsi_ctx *vc, u8 status)
9981003
{
999-
struct virtio_scsi_cmd_resp __user *resp;
10001004
struct virtio_scsi_cmd_resp rsp;
1005+
struct iov_iter iov_iter;
10011006
int ret;
10021007

10031008
memset(&rsp, 0, sizeof(rsp));
10041009
rsp.status = status;
1005-
resp = vq->iov[out].iov_base;
1006-
ret = __copy_to_user(resp, &rsp, sizeof(rsp));
1007-
if (!ret)
1008-
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);
10091018
else
10101019
pr_err("Faulted on virtio_scsi_cmd_resp\n");
10111020
}
10121021

1022+
#define TYPE_IO_CMD 0
1023+
#define TYPE_CTRL_TMF 1
1024+
#define TYPE_CTRL_AN 2
1025+
10131026
static void
10141027
vhost_scsi_send_bad_target(struct vhost_scsi *vs,
10151028
struct vhost_virtqueue *vq,
1016-
int head, unsigned out)
1029+
struct vhost_scsi_ctx *vc, int type)
10171030
{
1018-
struct virtio_scsi_cmd_resp __user *resp;
1019-
struct virtio_scsi_cmd_resp rsp;
1031+
union {
1032+
struct virtio_scsi_cmd_resp cmd;
1033+
struct virtio_scsi_ctrl_tmf_resp tmf;
1034+
struct virtio_scsi_ctrl_an_resp an;
1035+
} rsp;
1036+
struct iov_iter iov_iter;
1037+
size_t rsp_size;
10201038
int ret;
10211039

10221040
memset(&rsp, 0, sizeof(rsp));
1023-
rsp.response = VIRTIO_SCSI_S_BAD_TARGET;
1024-
resp = vq->iov[out].iov_base;
1025-
ret = __copy_to_user(resp, &rsp, sizeof(rsp));
1026-
if (!ret)
1027-
vhost_add_used_and_signal(&vs->dev, vq, head, 0);
1041+
1042+
if (type == TYPE_IO_CMD) {
1043+
rsp_size = sizeof(struct virtio_scsi_cmd_resp);
1044+
rsp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET;
1045+
} else if (type == TYPE_CTRL_TMF) {
1046+
rsp_size = sizeof(struct virtio_scsi_ctrl_tmf_resp);
1047+
rsp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET;
1048+
} else {
1049+
rsp_size = sizeof(struct virtio_scsi_ctrl_an_resp);
1050+
rsp.an.response = VIRTIO_SCSI_S_BAD_TARGET;
1051+
}
1052+
1053+
iov_iter_init(&iov_iter, ITER_DEST, &vq->iov[vc->out], vc->in,
1054+
rsp_size);
1055+
1056+
ret = copy_to_iter(&rsp, rsp_size, &iov_iter);
1057+
1058+
if (likely(ret == rsp_size))
1059+
vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0);
10281060
else
1029-
pr_err("Faulted on virtio_scsi_cmd_resp\n");
1061+
pr_err("Faulted on virtio scsi type=%d\n", type);
10301062
}
10311063

10321064
static int
@@ -1390,9 +1422,9 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
13901422
if (ret == -ENXIO)
13911423
break;
13921424
else if (ret == -EIO)
1393-
vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out);
1425+
vhost_scsi_send_bad_target(vs, vq, &vc, TYPE_IO_CMD);
13941426
else if (ret == -ENOMEM)
1395-
vhost_scsi_send_status(vs, vq, vc.head, vc.out,
1427+
vhost_scsi_send_status(vs, vq, &vc,
13961428
SAM_STAT_TASK_SET_FULL);
13971429
} while (likely(!vhost_exceeds_weight(vq, ++c, 0)));
13981430
out:
@@ -1432,8 +1464,11 @@ static void vhost_scsi_tmf_resp_work(struct vhost_work *work)
14321464
else
14331465
resp_code = VIRTIO_SCSI_S_FUNCTION_REJECTED;
14341466

1467+
mutex_lock(&tmf->svq->vq.mutex);
14351468
vhost_scsi_send_tmf_resp(tmf->vhost, &tmf->svq->vq, tmf->in_iovs,
14361469
tmf->vq_desc, &tmf->resp_iov, resp_code);
1470+
mutex_unlock(&tmf->svq->vq.mutex);
1471+
14371472
vhost_scsi_release_tmf_res(tmf);
14381473
}
14391474

@@ -1623,7 +1658,10 @@ vhost_scsi_ctl_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
16231658
if (ret == -ENXIO)
16241659
break;
16251660
else if (ret == -EIO)
1626-
vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out);
1661+
vhost_scsi_send_bad_target(vs, vq, &vc,
1662+
v_req.type == VIRTIO_SCSI_T_TMF ?
1663+
TYPE_CTRL_TMF :
1664+
TYPE_CTRL_AN);
16271665
} while (likely(!vhost_exceeds_weight(vq, ++c, 0)));
16281666
out:
16291667
mutex_unlock(&vq->mutex);

drivers/virtio/virtio.c

+6
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ static void virtio_dev_shutdown(struct device *_d)
407407
if (!drv)
408408
return;
409409

410+
/* If the driver has its own shutdown method, use that. */
411+
if (drv->shutdown) {
412+
drv->shutdown(dev);
413+
return;
414+
}
415+
410416
/*
411417
* Some devices get wedged if you kick them after they are
412418
* reset. Mark all vqs as broken to make sure we don't.

drivers/virtio/virtio_pci_modern.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ virtio_pci_admin_cmd_dev_parts_objects_enable(struct virtio_device *virtio_dev)
247247
sg_init_one(&data_sg, get_data, sizeof(*get_data));
248248
sg_init_one(&result_sg, result, sizeof(*result));
249249
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET);
250-
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
250+
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
251251
cmd.data_sg = &data_sg;
252252
cmd.result_sg = &result_sg;
253253
ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);
@@ -305,7 +305,7 @@ static void virtio_pci_admin_cmd_cap_init(struct virtio_device *virtio_dev)
305305

306306
sg_init_one(&result_sg, data, sizeof(*data));
307307
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY);
308-
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
308+
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
309309
cmd.result_sg = &result_sg;
310310

311311
ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);

drivers/virtio/virtio_ring.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
26502650
struct vring_virtqueue *vq = to_vvq(_vq);
26512651

26522652
if (vq->event_triggered)
2653-
vq->event_triggered = false;
2653+
data_race(vq->event_triggered = false);
26542654

26552655
return vq->packed_ring ? virtqueue_enable_cb_delayed_packed(_vq) :
26562656
virtqueue_enable_cb_delayed_split(_vq);

include/linux/virtio.h

+3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ size_t virtio_max_dma_size(const struct virtio_device *vdev);
220220
* occurs.
221221
* @reset_done: optional function to call after transport specific reset
222222
* operation has finished.
223+
* @shutdown: synchronize with the device on shutdown. If provided, replaces
224+
* the virtio core implementation.
223225
*/
224226
struct virtio_driver {
225227
struct device_driver driver;
@@ -237,6 +239,7 @@ struct virtio_driver {
237239
int (*restore)(struct virtio_device *dev);
238240
int (*reset_prepare)(struct virtio_device *dev);
239241
int (*reset_done)(struct virtio_device *dev);
242+
void (*shutdown)(struct virtio_device *dev);
240243
};
241244

242245
#define drv_to_virtio(__drv) container_of_const(__drv, struct virtio_driver, driver)

include/uapi/linux/vhost.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828

2929
/* Set current process as the (exclusive) owner of this file descriptor. This
3030
* must be called before any other vhost command. Further calls to
31-
* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
31+
* VHOST_SET_OWNER fail until VHOST_RESET_OWNER is called. */
3232
#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
3333
/* Give up ownership, and reset the device to default values.
34-
* Allows subsequent call to VHOST_OWNER_SET to succeed. */
34+
* Allows subsequent call to VHOST_SET_OWNER to succeed. */
3535
#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
3636

3737
/* Set up/modify memory layout */

include/uapi/linux/virtio_pci.h

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ struct virtio_pci_cfg_cap {
246246
#define VIRTIO_ADMIN_CMD_LIST_USE 0x1
247247

248248
/* Admin command group type. */
249+
#define VIRTIO_ADMIN_GROUP_TYPE_SELF 0x0
249250
#define VIRTIO_ADMIN_GROUP_TYPE_SRIOV 0x1
250251

251252
/* Transitional device admin command. */

kernel/vhost_task.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(vhost_task_stop);
111111
* @arg: data to be passed to fn and handled_kill
112112
* @name: the thread's name
113113
*
114-
* This returns a specialized task for use by the vhost layer or NULL on
114+
* This returns a specialized task for use by the vhost layer or ERR_PTR() on
115115
* failure. The returned task is inactive, and the caller must fire it up
116116
* through vhost_task_start().
117117
*/

0 commit comments

Comments
 (0)