Skip to content

Commit 399f4da

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio bugfixes from Michael Tsirkin: "Some small, obvious (in hindsight) bugfixes: - new ioctl in vhost-vdpa has a wrong # - not too late to fix - vhost has apparently been lacking an smp_rmb() - due to code duplication :( The duplication will be fixed in the next merge cycle, this is a minimal fix - an error message in vhost talks about guest moving used index - which of course never happens, guest only ever moves the available index - i2c-virtio didn't set the driver owner so it did not get refcounted correctly" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: correct misleading printing information vhost-vdpa: change ioctl # for VDPA_GET_VRING_SIZE virtio: store owner from modules with register_virtio_driver() vhost: Add smp_rmb() in vhost_enable_notify() vhost: Add smp_rmb() in vhost_vq_avail_empty()
2 parents ddd7ad5 + 76f4085 commit 399f4da

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

Documentation/driver-api/virtio/writing_virtio_drivers.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ like this::
9797

9898
static struct virtio_driver virtio_dummy_driver = {
9999
.driver.name = KBUILD_MODNAME,
100-
.driver.owner = THIS_MODULE,
101100
.id_table = id_table,
102101
.probe = virtio_dummy_probe,
103102
.remove = virtio_dummy_remove,

drivers/vhost/vhost.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,7 +2515,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,
25152515
vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
25162516

25172517
if (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) {
2518-
vq_err(vq, "Guest moved used index from %u to %u",
2518+
vq_err(vq, "Guest moved avail index from %u to %u",
25192519
last_avail_idx, vq->avail_idx);
25202520
return -EFAULT;
25212521
}
@@ -2799,9 +2799,19 @@ bool vhost_vq_avail_empty(struct vhost_dev *dev, struct vhost_virtqueue *vq)
27992799
r = vhost_get_avail_idx(vq, &avail_idx);
28002800
if (unlikely(r))
28012801
return false;
2802+
28022803
vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
2804+
if (vq->avail_idx != vq->last_avail_idx) {
2805+
/* Since we have updated avail_idx, the following
2806+
* call to vhost_get_vq_desc() will read available
2807+
* ring entries. Make sure that read happens after
2808+
* the avail_idx read.
2809+
*/
2810+
smp_rmb();
2811+
return false;
2812+
}
28032813

2804-
return vq->avail_idx == vq->last_avail_idx;
2814+
return true;
28052815
}
28062816
EXPORT_SYMBOL_GPL(vhost_vq_avail_empty);
28072817

@@ -2838,9 +2848,19 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
28382848
&vq->avail->idx, r);
28392849
return false;
28402850
}
2851+
28412852
vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
2853+
if (vq->avail_idx != vq->last_avail_idx) {
2854+
/* Since we have updated avail_idx, the following
2855+
* call to vhost_get_vq_desc() will read available
2856+
* ring entries. Make sure that read happens after
2857+
* the avail_idx read.
2858+
*/
2859+
smp_rmb();
2860+
return true;
2861+
}
28422862

2843-
return vq->avail_idx != vq->last_avail_idx;
2863+
return false;
28442864
}
28452865
EXPORT_SYMBOL_GPL(vhost_enable_notify);
28462866

drivers/virtio/virtio.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,16 @@ static const struct bus_type virtio_bus = {
362362
.remove = virtio_dev_remove,
363363
};
364364

365-
int register_virtio_driver(struct virtio_driver *driver)
365+
int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
366366
{
367367
/* Catch this early. */
368368
BUG_ON(driver->feature_table_size && !driver->feature_table);
369369
driver->driver.bus = &virtio_bus;
370+
driver->driver.owner = owner;
371+
370372
return driver_register(&driver->driver);
371373
}
372-
EXPORT_SYMBOL_GPL(register_virtio_driver);
374+
EXPORT_SYMBOL_GPL(__register_virtio_driver);
373375

374376
void unregister_virtio_driver(struct virtio_driver *driver)
375377
{

include/linux/virtio.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ size_t virtio_max_dma_size(const struct virtio_device *vdev);
170170

171171
/**
172172
* struct virtio_driver - operations for a virtio I/O driver
173-
* @driver: underlying device driver (populate name and owner).
173+
* @driver: underlying device driver (populate name).
174174
* @id_table: the ids serviced by this driver.
175175
* @feature_table: an array of feature numbers supported by this driver.
176176
* @feature_table_size: number of entries in the feature table array.
@@ -208,7 +208,10 @@ static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv)
208208
return container_of(drv, struct virtio_driver, driver);
209209
}
210210

211-
int register_virtio_driver(struct virtio_driver *drv);
211+
/* use a macro to avoid include chaining to get THIS_MODULE */
212+
#define register_virtio_driver(drv) \
213+
__register_virtio_driver(drv, THIS_MODULE)
214+
int __register_virtio_driver(struct virtio_driver *drv, struct module *owner);
212215
void unregister_virtio_driver(struct virtio_driver *drv);
213216

214217
/* module_virtio_driver() - Helper macro for drivers that don't do

include/uapi/linux/vhost.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@
179179
/* Get the config size */
180180
#define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32)
181181

182-
/* Get the count of all virtqueues */
183-
#define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32)
184-
185-
/* Get the number of virtqueue groups. */
186-
#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32)
187-
188182
/* Get the number of address spaces. */
189183
#define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int)
190184

@@ -228,10 +222,17 @@
228222
#define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \
229223
struct vhost_vring_state)
230224

225+
226+
/* Get the count of all virtqueues */
227+
#define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32)
228+
229+
/* Get the number of virtqueue groups. */
230+
#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32)
231+
231232
/* Get the queue size of a specific virtqueue.
232233
* userspace set the vring index in vhost_vring_state.index
233234
* kernel set the queue size in vhost_vring_state.num
234235
*/
235-
#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x80, \
236+
#define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \
236237
struct vhost_vring_state)
237238
#endif

0 commit comments

Comments
 (0)