diff mbox series

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

Message ID 20241216163125.438156-1-arbab@linux.ibm.com (mailing list archive)
State New
Headers show
Series virtio-balloon-pci: Allow setting nvectors, so we can use MSI-X | expand

Commit Message

Reza Arbab Dec. 16, 2024, 4:31 p.m. UTC
Most virtio-pci devices allow MSI-X. Add it to virtio-balloon-pci, but
only enable it in new machine types, so we don't break migration of
existing machine types between different qemu versions.

This copies what was done for virtio-rng-pci in:
9ea02e8f1306 ("virtio-rng-pci: Allow setting nvectors, so we can use MSI-X")
bad9c5a5166f ("virtio-rng-pci: fix migration compat for vectors")
62bdb8871512 ("virtio-rng-pci: fix transitional migration compat for vectors")

Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
---
 hw/core/machine.c              |  6 +++++-
 hw/virtio/virtio-balloon-pci.c | 13 +++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)


base-commit: ca80a5d026a280762e0772615f1988db542b3ade

Comments

David Hildenbrand Dec. 18, 2024, 10:37 a.m. UTC | #1
On 16.12.24 17:31, Reza Arbab wrote:
> Most virtio-pci devices allow MSI-X. Add it to virtio-balloon-pci, but
> only enable it in new machine types, so we don't break migration of
> existing machine types between different qemu versions.
> 
> This copies what was done for virtio-rng-pci in:
> 9ea02e8f1306 ("virtio-rng-pci: Allow setting nvectors, so we can use MSI-X")
> bad9c5a5166f ("virtio-rng-pci: fix migration compat for vectors")
> 62bdb8871512 ("virtio-rng-pci: fix transitional migration compat for vectors")
> 
> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
> ---
>   hw/core/machine.c              |  6 +++++-
>   hw/virtio/virtio-balloon-pci.c | 13 +++++++++++++
>   2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index e6900b43efa2..db59c7771ec4 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -36,7 +36,11 @@
>   #include "hw/virtio/virtio-iommu.h"
>   #include "audio/audio.h"
>   
> -GlobalProperty hw_compat_9_2[] = {};
> +GlobalProperty hw_compat_9_2[] = {
> +    { "virtio-balloon-pci", "vectors", "0" },
> +    { "virtio-balloon-pci-transitional", "vectors", "0" },
> +    { "virtio-balloon-pci-non-transitional", "vectors", "0" },
> +};
>   const size_t hw_compat_9_2_len = G_N_ELEMENTS(hw_compat_9_2);
>   
>   GlobalProperty hw_compat_9_1[] = {
> diff --git a/hw/virtio/virtio-balloon-pci.c b/hw/virtio/virtio-balloon-pci.c
> index ce2645ba7187..1c2b071eff0c 100644
> --- a/hw/virtio/virtio-balloon-pci.c
> +++ b/hw/virtio/virtio-balloon-pci.c
> @@ -35,11 +35,23 @@ struct VirtIOBalloonPCI {
>       VirtIOBalloon vdev;
>   };
>   
> +static Property virtio_balloon_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_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
>   {
>       VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
>       DeviceState *vdev = DEVICE(&dev->vdev);
>   
> +    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
> +        vpci_dev->nvectors = 2;
> +    }
> +
>       vpci_dev->class_code = PCI_CLASS_OTHERS;
>       qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
>   }
> @@ -55,6 +67,7 @@ static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
>       pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
>       pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
>       pcidev_k->class_id = PCI_CLASS_OTHERS;
> +    device_class_set_props(dc, virtio_balloon_properties);
>   }
>   
>   static void virtio_balloon_pci_instance_init(Object *obj)
> 
> base-commit: ca80a5d026a280762e0772615f1988db542b3ade

No expert on any of that MSi-X / PCI magic, but LGTM

Acked-by: David Hildenbrand <david@redhat.com>
Reza Arbab Jan. 8, 2025, 3:14 p.m. UTC | #2
On Wed, Dec 18, 2024 at 11:37:05AM +0100, David Hildenbrand wrote:
>No expert on any of that MSi-X / PCI magic, but LGTM
>
>Acked-by: David Hildenbrand <david@redhat.com>

Thanks David!

Did anyone else have any comments? Just want to make sure I have things 
in order to get this into the next release.
diff mbox series

Patch

diff --git a/hw/core/machine.c b/hw/core/machine.c
index e6900b43efa2..db59c7771ec4 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -36,7 +36,11 @@ 
 #include "hw/virtio/virtio-iommu.h"
 #include "audio/audio.h"
 
-GlobalProperty hw_compat_9_2[] = {};
+GlobalProperty hw_compat_9_2[] = {
+    { "virtio-balloon-pci", "vectors", "0" },
+    { "virtio-balloon-pci-transitional", "vectors", "0" },
+    { "virtio-balloon-pci-non-transitional", "vectors", "0" },
+};
 const size_t hw_compat_9_2_len = G_N_ELEMENTS(hw_compat_9_2);
 
 GlobalProperty hw_compat_9_1[] = {
diff --git a/hw/virtio/virtio-balloon-pci.c b/hw/virtio/virtio-balloon-pci.c
index ce2645ba7187..1c2b071eff0c 100644
--- a/hw/virtio/virtio-balloon-pci.c
+++ b/hw/virtio/virtio-balloon-pci.c
@@ -35,11 +35,23 @@  struct VirtIOBalloonPCI {
     VirtIOBalloon vdev;
 };
 
+static Property virtio_balloon_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_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
 {
     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
 
+    if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+        vpci_dev->nvectors = 2;
+    }
+
     vpci_dev->class_code = PCI_CLASS_OTHERS;
     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
 }
@@ -55,6 +67,7 @@  static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
     pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
     pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
     pcidev_k->class_id = PCI_CLASS_OTHERS;
+    device_class_set_props(dc, virtio_balloon_properties);
 }
 
 static void virtio_balloon_pci_instance_init(Object *obj)