Skip to contentSkip to conversation

virtio-rng-pci: Allow setting nvectors, so we can use MSI-X

PATCH In review Philippe Mathieu-Daudé 2 participants 2 messages Oct 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-rng-pci: Allow setting nvectors, so we can use MSI-X

From: David Daney <[email protected]>

Most other virtio-pci devices allow MSI-X, let's have it for rng too.

---
 hw/virtio/virtio-rng-pci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
hw/virtio/virtio-rng-pci.c +14 -0
index 151ece6f94..6e76f8b57b 100644
@@ -13,6 +13,7 @@
 
 #include "hw/virtio/virtio-pci.h"
 #include "hw/virtio/virtio-rng.h"
+#include "hw/qdev-properties.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qom/object.h"
@@ -31,11 +32,23 @@ struct VirtIORngPCI {
     VirtIORNG vdev;
 };
 
+static Property virtio_rng_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 {
     VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&vrng->vdev);
 
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2;
+    }
+
     if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
         return;
     }
@@ -54,6 +67,7 @@ static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
+    device_class_set_props(dc, virtio_rng_properties);
 }
 
 static void virtio_rng_initfn(Object *obj)
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Philippe Mathieu-Daudé

From: David Daney <[email protected]>

Most other virtio-pci devices allow MSI-X, let's have it for rng too.

---
 hw/virtio/virtio-rng-pci.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
hw/virtio/virtio-rng-pci.c +1 -0
index 151ece6f94..6e76f8b57b 100644
@@ -13,6 +13,7 @@
 
 #include "hw/virtio/virtio-pci.h"
 #include "hw/virtio/virtio-rng.h"
+#include "hw/qdev-properties.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "qom/object.h"

hw/virtio/virtio-rng-pci.c struct VirtIORngPCI { · line 37

Quoted 6 lines
hw/virtio/virtio-rng-pci.c +3 -0
@@ -31,11 +32,23 @@ struct VirtIORngPCI {
     VirtIORNG vdev;
 };
 
+static Property virtio_rng_properties[] = {
+    DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),

ioeventfd is unrelated to MSI-X. It controls whether the virtqueue kick is handled in the vCPU thread (ioctl(KVM_RUN) exit) or the main loop thread (KVM ioeventfd).

I took a quick look at virtio-rng.c to see if there is anything that doesn't work in the main loop. It looks okay to me but consider dropping this line to minimize the risk of breaking something.

hw/virtio/virtio-rng-pci.c struct VirtIORngPCI { · line 49

Quoted 12 lines
hw/virtio/virtio-rng-pci.c +7 -0
+    DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+                       DEV_NVECTORS_UNSPECIFIED),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 {
     VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&vrng->vdev);
 
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2;

Checked against the spec: 1 configuration change notification and 1 virtqueue used buffer notification = 2 MSI-X vectors.

Quoted 17 lines
hw/virtio/virtio-rng-pci.c +3 -1
+     }
+
     if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
         return;
     }
@@ -54,6 +67,7 @@ static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
+    device_class_set_props(dc, virtio_rng_properties);
 }
 
 static void virtio_rng_initfn(Object *obj)
--

2.37.3