Skip to content

Commit 2f3f056

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "virtio, vhost: features, fixes - PCI virtual function support for virtio - DMA barriers for virtio strong barriers - bugfixes" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio: update the comments for transport features virtio_pci: support enabling VFs vhost: fix info leak due to uninitialized memory virtio_ring: switch to dma_XX barriers for rpmsg
2 parents 4c5e8fc + 2eb9810 commit 2f3f056

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

drivers/vhost/vhost.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,9 @@ struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type)
23492349
struct vhost_msg_node *node = kmalloc(sizeof *node, GFP_KERNEL);
23502350
if (!node)
23512351
return NULL;
2352+
2353+
/* Make sure all padding within the structure is initialized. */
2354+
memset(&node->msg, 0, sizeof node->msg);
23522355
node->vq = vq;
23532356
node->msg.type = type;
23542357
return node;

drivers/virtio/virtio_pci_common.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
578578
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
579579
struct device *dev = get_device(&vp_dev->vdev.dev);
580580

581+
pci_disable_sriov(pci_dev);
582+
581583
unregister_virtio_device(&vp_dev->vdev);
582584

583585
if (vp_dev->ioaddr)
@@ -589,6 +591,33 @@ static void virtio_pci_remove(struct pci_dev *pci_dev)
589591
put_device(dev);
590592
}
591593

594+
static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs)
595+
{
596+
struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
597+
struct virtio_device *vdev = &vp_dev->vdev;
598+
int ret;
599+
600+
if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK))
601+
return -EBUSY;
602+
603+
if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV))
604+
return -EINVAL;
605+
606+
if (pci_vfs_assigned(pci_dev))
607+
return -EPERM;
608+
609+
if (num_vfs == 0) {
610+
pci_disable_sriov(pci_dev);
611+
return 0;
612+
}
613+
614+
ret = pci_enable_sriov(pci_dev, num_vfs);
615+
if (ret < 0)
616+
return ret;
617+
618+
return num_vfs;
619+
}
620+
592621
static struct pci_driver virtio_pci_driver = {
593622
.name = "virtio-pci",
594623
.id_table = virtio_pci_id_table,
@@ -597,6 +626,7 @@ static struct pci_driver virtio_pci_driver = {
597626
#ifdef CONFIG_PM_SLEEP
598627
.driver.pm = &virtio_pci_pm_ops,
599628
#endif
629+
.sriov_configure = virtio_pci_sriov_configure,
600630
};
601631

602632
module_pci_driver(virtio_pci_driver);

drivers/virtio/virtio_pci_modern.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,28 @@ static u64 vp_get_features(struct virtio_device *vdev)
153153
return features;
154154
}
155155

156+
static void vp_transport_features(struct virtio_device *vdev, u64 features)
157+
{
158+
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
159+
struct pci_dev *pci_dev = vp_dev->pci_dev;
160+
161+
if ((features & BIT_ULL(VIRTIO_F_SR_IOV)) &&
162+
pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV))
163+
__virtio_set_bit(vdev, VIRTIO_F_SR_IOV);
164+
}
165+
156166
/* virtio config->finalize_features() implementation */
157167
static int vp_finalize_features(struct virtio_device *vdev)
158168
{
159169
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
170+
u64 features = vdev->features;
160171

161172
/* Give virtio_ring a chance to accept features. */
162173
vring_transport_features(vdev);
163174

175+
/* Give virtio_pci a chance to accept features. */
176+
vp_transport_features(vdev, features);
177+
164178
if (!__virtio_test_bit(vdev, VIRTIO_F_VERSION_1)) {
165179
dev_err(&vdev->dev, "virtio: device uses modern interface "
166180
"but does not have VIRTIO_F_VERSION_1\n");

include/linux/virtio_ring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ static inline void virtio_rmb(bool weak_barriers)
3535
if (weak_barriers)
3636
virt_rmb();
3737
else
38-
rmb();
38+
dma_rmb();
3939
}
4040

4141
static inline void virtio_wmb(bool weak_barriers)
4242
{
4343
if (weak_barriers)
4444
virt_wmb();
4545
else
46-
wmb();
46+
dma_wmb();
4747
}
4848

4949
static inline void virtio_store_mb(bool weak_barriers,

include/uapi/linux/virtio_config.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@
4545
/* We've given up on this device. */
4646
#define VIRTIO_CONFIG_S_FAILED 0x80
4747

48-
/* Some virtio feature bits (currently bits 28 through 32) are reserved for the
49-
* transport being used (eg. virtio_ring), the rest are per-device feature
50-
* bits. */
48+
/*
49+
* Virtio feature bits VIRTIO_TRANSPORT_F_START through
50+
* VIRTIO_TRANSPORT_F_END are reserved for the transport
51+
* being used (e.g. virtio_ring, virtio_pci etc.), the
52+
* rest are per-device feature bits.
53+
*/
5154
#define VIRTIO_TRANSPORT_F_START 28
52-
#define VIRTIO_TRANSPORT_F_END 34
55+
#define VIRTIO_TRANSPORT_F_END 38
5356

5457
#ifndef VIRTIO_CONFIG_NO_LEGACY
5558
/* Do we get callbacks when the ring is completely used, even if we've
@@ -71,4 +74,9 @@
7174
* this is for compatibility with legacy systems.
7275
*/
7376
#define VIRTIO_F_IOMMU_PLATFORM 33
77+
78+
/*
79+
* Does the device support Single Root I/O Virtualization?
80+
*/
81+
#define VIRTIO_F_SR_IOV 37
7482
#endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */

0 commit comments

Comments
 (0)