Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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()

+42 -17
-1
Documentation/driver-api/virtio/writing_virtio_drivers.rst
··· 97 97 98 98 static struct virtio_driver virtio_dummy_driver = { 99 99 .driver.name = KBUILD_MODNAME, 100 - .driver.owner = THIS_MODULE, 101 100 .id_table = id_table, 102 101 .probe = virtio_dummy_probe, 103 102 .remove = virtio_dummy_remove,
+25 -5
drivers/vhost/vhost.c
··· 2515 2515 vq->avail_idx = vhost16_to_cpu(vq, avail_idx); 2516 2516 2517 2517 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", 2519 2519 last_avail_idx, vq->avail_idx); 2520 2520 return -EFAULT; 2521 2521 } ··· 2799 2799 r = vhost_get_avail_idx(vq, &avail_idx); 2800 2800 if (unlikely(r)) 2801 2801 return false; 2802 - vq->avail_idx = vhost16_to_cpu(vq, avail_idx); 2803 2802 2804 - return vq->avail_idx == vq->last_avail_idx; 2803 + 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 + } 2813 + 2814 + return true; 2805 2815 } 2806 2816 EXPORT_SYMBOL_GPL(vhost_vq_avail_empty); 2807 2817 ··· 2848 2838 &vq->avail->idx, r); 2849 2839 return false; 2850 2840 } 2851 - vq->avail_idx = vhost16_to_cpu(vq, avail_idx); 2852 2841 2853 - return vq->avail_idx != vq->last_avail_idx; 2842 + vq->avail_idx = vhost16_to_cpu(vq, avail_idx); 2843 + if (vq->avail_idx != vq->last_avail_idx) { 2844 + /* Since we have updated avail_idx, the following 2845 + * call to vhost_get_vq_desc() will read available 2846 + * ring entries. Make sure that read happens after 2847 + * the avail_idx read. 2848 + */ 2849 + smp_rmb(); 2850 + return true; 2851 + } 2852 + 2853 + return false; 2854 2854 } 2855 2855 EXPORT_SYMBOL_GPL(vhost_enable_notify); 2856 2856
+4 -2
drivers/virtio/virtio.c
··· 362 362 .remove = virtio_dev_remove, 363 363 }; 364 364 365 - int register_virtio_driver(struct virtio_driver *driver) 365 + int __register_virtio_driver(struct virtio_driver *driver, struct module *owner) 366 366 { 367 367 /* Catch this early. */ 368 368 BUG_ON(driver->feature_table_size && !driver->feature_table); 369 369 driver->driver.bus = &virtio_bus; 370 + driver->driver.owner = owner; 371 + 370 372 return driver_register(&driver->driver); 371 373 } 372 - EXPORT_SYMBOL_GPL(register_virtio_driver); 374 + EXPORT_SYMBOL_GPL(__register_virtio_driver); 373 375 374 376 void unregister_virtio_driver(struct virtio_driver *driver) 375 377 {
+5 -2
include/linux/virtio.h
··· 170 170 171 171 /** 172 172 * 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). 174 174 * @id_table: the ids serviced by this driver. 175 175 * @feature_table: an array of feature numbers supported by this driver. 176 176 * @feature_table_size: number of entries in the feature table array. ··· 208 208 return container_of(drv, struct virtio_driver, driver); 209 209 } 210 210 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); 212 215 void unregister_virtio_driver(struct virtio_driver *drv); 213 216 214 217 /* module_virtio_driver() - Helper macro for drivers that don't do
+8 -7
include/uapi/linux/vhost.h
··· 179 179 /* Get the config size */ 180 180 #define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32) 181 181 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 - 188 182 /* Get the number of address spaces. */ 189 183 #define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) 190 184 ··· 222 228 #define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ 223 229 struct vhost_vring_state) 224 230 231 + 232 + /* Get the count of all virtqueues */ 233 + #define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) 234 + 235 + /* Get the number of virtqueue groups. */ 236 + #define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32) 237 + 225 238 /* Get the queue size of a specific virtqueue. 226 239 * userspace set the vring index in vhost_vring_state.index 227 240 * kernel set the queue size in vhost_vring_state.num 228 241 */ 229 - #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x80, \ 242 + #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ 230 243 struct vhost_vring_state) 231 244 #endif