Skip to content

Commit 39f90c1

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio/vhost fixes from Michael Tsirkin: "More small fixes. Most notably this fixes a messed up ioctl number, and a regression in shmem affecting drm users" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio_net: adjust the execution order of function `virtnet_close` during freeze virtio_input: Improve freeze handling vhost: Fix ioctl # for VHOST_[GS]ET_FORK_FROM_OWNER Revert "virtio: reject shm region if length is zero" vhost/net: Protect ubufs with rcu read lock in vhost_net_ubuf_put() virtio_pci: Fix misleading comment for queue vector
2 parents 518b21b + 45d8ef6 commit 39f90c1

File tree

7 files changed

+21
-13
lines changed

7 files changed

+21
-13
lines changed

drivers/net/virtio_net.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5758,14 +5758,15 @@ static void virtnet_freeze_down(struct virtio_device *vdev)
57585758
disable_rx_mode_work(vi);
57595759
flush_work(&vi->rx_mode_work);
57605760

5761-
netif_tx_lock_bh(vi->dev);
5762-
netif_device_detach(vi->dev);
5763-
netif_tx_unlock_bh(vi->dev);
57645761
if (netif_running(vi->dev)) {
57655762
rtnl_lock();
57665763
virtnet_close(vi->dev);
57675764
rtnl_unlock();
57685765
}
5766+
5767+
netif_tx_lock_bh(vi->dev);
5768+
netif_device_detach(vi->dev);
5769+
netif_tx_unlock_bh(vi->dev);
57695770
}
57705771

57715772
static int init_vqs(struct virtnet_info *vi);

drivers/vhost/net.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct vhost_net_ubuf_ref {
9999
atomic_t refcount;
100100
wait_queue_head_t wait;
101101
struct vhost_virtqueue *vq;
102+
struct rcu_head rcu;
102103
};
103104

104105
#define VHOST_NET_BATCH 64
@@ -250,9 +251,13 @@ vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy)
250251

251252
static int vhost_net_ubuf_put(struct vhost_net_ubuf_ref *ubufs)
252253
{
253-
int r = atomic_sub_return(1, &ubufs->refcount);
254+
int r;
255+
256+
rcu_read_lock();
257+
r = atomic_sub_return(1, &ubufs->refcount);
254258
if (unlikely(!r))
255259
wake_up(&ubufs->wait);
260+
rcu_read_unlock();
256261
return r;
257262
}
258263

@@ -265,7 +270,7 @@ static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
265270
static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
266271
{
267272
vhost_net_ubuf_put_and_wait(ubufs);
268-
kfree(ubufs);
273+
kfree_rcu(ubufs, rcu);
269274
}
270275

271276
static void vhost_net_clear_ubuf_info(struct vhost_net *n)

drivers/virtio/virtio_input.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,15 @@ static int virtinput_freeze(struct virtio_device *vdev)
360360
{
361361
struct virtio_input *vi = vdev->priv;
362362
unsigned long flags;
363+
void *buf;
363364

364365
spin_lock_irqsave(&vi->lock, flags);
365366
vi->ready = false;
366367
spin_unlock_irqrestore(&vi->lock, flags);
367368

369+
virtio_reset_device(vdev);
370+
while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
371+
kfree(buf);
368372
vdev->config->del_vqs(vdev);
369373
return 0;
370374
}

drivers/virtio/virtio_pci_legacy_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ EXPORT_SYMBOL_GPL(vp_legacy_set_status);
140140
* vp_legacy_queue_vector - set the MSIX vector for a specific virtqueue
141141
* @ldev: the legacy virtio-pci device
142142
* @index: queue index
143-
* @vector: the config vector
143+
* @vector: the queue vector
144144
*
145-
* Returns the config vector read from the device
145+
* Returns the queue vector read from the device
146146
*/
147147
u16 vp_legacy_queue_vector(struct virtio_pci_legacy_device *ldev,
148148
u16 index, u16 vector)

drivers/virtio/virtio_pci_modern_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ EXPORT_SYMBOL_GPL(vp_modern_set_queue_reset);
546546
* vp_modern_queue_vector - set the MSIX vector for a specific virtqueue
547547
* @mdev: the modern virtio-pci device
548548
* @index: queue index
549-
* @vector: the config vector
549+
* @vector: the queue vector
550550
*
551-
* Returns the config vector read from the device
551+
* Returns the queue vector read from the device
552552
*/
553553
u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
554554
u16 index, u16 vector)

include/linux/virtio_config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,6 @@ static inline
328328
bool virtio_get_shm_region(struct virtio_device *vdev,
329329
struct virtio_shm_region *region, u8 id)
330330
{
331-
if (!region->len)
332-
return false;
333331
if (!vdev->config->get_shm_region)
334332
return false;
335333
return vdev->config->get_shm_region(vdev, region, id);

include/uapi/linux/vhost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@
260260
* When fork_owner is set to VHOST_FORK_OWNER_KTHREAD:
261261
* - Vhost will create vhost workers as kernel threads.
262262
*/
263-
#define VHOST_SET_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x83, __u8)
263+
#define VHOST_SET_FORK_FROM_OWNER _IOW(VHOST_VIRTIO, 0x84, __u8)
264264

265265
/**
266266
* VHOST_GET_FORK_OWNER - Get the current fork_owner flag for the vhost device.
267267
* Only available when CONFIG_VHOST_ENABLE_FORK_OWNER_CONTROL=y
268268
*
269269
* @return: An 8-bit value indicating the current thread mode.
270270
*/
271-
#define VHOST_GET_FORK_FROM_OWNER _IOR(VHOST_VIRTIO, 0x84, __u8)
271+
#define VHOST_GET_FORK_FROM_OWNER _IOR(VHOST_VIRTIO, 0x85, __u8)
272272

273273
#endif

0 commit comments

Comments
 (0)