diff mbox series

[v4] virtio-pci: correctly set virtio pci queue mem multiplier

Message ID 20240229064302.2183241-1-schalla@marvell.com
State New
Headers show
Series [v4] virtio-pci: correctly set virtio pci queue mem multiplier | expand

Commit Message

Srujana Challa Feb. 29, 2024, 6:43 a.m. UTC
Currently, virtio_pci_queue_mem_mult function always returns 4K
when VIRTIO_PCI_FLAG_PAGE_PER_VQ is set. But this won't
work for vhost vdpa when host has page size other than 4K.
This patch introduces a new property(page-per-vdpa-vq) for vdpa
use case to fix the same.

Signed-off-by: Srujana Challa <schalla@marvell.com>
---
v3->v4:
- Return failure if both page_per_vq and host_page_per_vq are set.

v2->v3:
- Modified property name, page-per-vdpa-vq to host-page-per-vq.

v1->v2:
- Introduced a new property to get virtqueue mem multiplier for
  vdpa use case.

 hw/virtio/virtio-pci.c         | 18 ++++++++++++++++--
 include/hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 21 insertions(+), 2 deletions(-)

Comments

Srujana Challa March 8, 2024, 1:08 p.m. UTC | #1
Ping.

> -----Original Message-----
> From: Srujana Challa <schalla@marvell.com>
> Sent: Thursday, February 29, 2024 12:13 PM
> To: qemu-devel@nongnu.org
> Cc: mst@redhat.com; jasowang@redhat.com; Vamsi Krishna Attunuru
> <vattunuru@marvell.com>; Jerin Jacob <jerinj@marvell.com>; Srujana Challa
> <schalla@marvell.com>
> Subject: [PATCH v4] virtio-pci: correctly set virtio pci queue mem multiplier
> 
> Currently, virtio_pci_queue_mem_mult function always returns 4K when
> VIRTIO_PCI_FLAG_PAGE_PER_VQ is set. But this won't work for vhost vdpa
> when host has page size other than 4K.
> This patch introduces a new property(page-per-vdpa-vq) for vdpa use case to
> fix the same.
> 
> Signed-off-by: Srujana Challa <schalla@marvell.com>
> ---
> v3->v4:
> - Return failure if both page_per_vq and host_page_per_vq are set.
> 
> v2->v3:
> - Modified property name, page-per-vdpa-vq to host-page-per-vq.
> 
> v1->v2:
> - Introduced a new property to get virtqueue mem multiplier for
>   vdpa use case.
> 
>  hw/virtio/virtio-pci.c         | 18 ++++++++++++++++--
>  include/hw/virtio/virtio-pci.h |  5 +++++
>  2 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index
> 1a7039fb0c..4e31169c6f 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -320,8 +320,12 @@ static bool virtio_pci_ioeventfd_enabled(DeviceState
> *d)
> 
>  static inline int virtio_pci_queue_mem_mult(struct VirtIOPCIProxy *proxy)  {
> -    return (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) ?
> -        QEMU_VIRTIO_PCI_QUEUE_MEM_MULT : 4;
> +    if (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)
> +        return QEMU_VIRTIO_PCI_QUEUE_MEM_MULT;
> +    else if (proxy->flags & VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ)
> +        return qemu_real_host_page_size();
> +    else
> +        return 4;
>  }
> 
>  static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
> @@ -2108,6 +2112,14 @@ static void virtio_pci_realize(PCIDevice *pci_dev,
> Error **errp)
>          proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
>      }
> 
> +    if ((proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) &&
> +        (proxy->flags & VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ)) {
> +        error_setg(errp, "device cannot work with both page-per-vq and"
> +                   " host-page-per-vq at the same time");
> +        error_append_hint(errp, "Set either page-per-vq or host-page-per-
> vq\n");
> +        return;
> +    }
> +
>      /*
>       * virtio pci bar layout used by default.
>       * subclasses can re-arrange things if needed.
> @@ -2301,6 +2313,8 @@ static Property virtio_pci_properties[] = {
>                      VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
>      DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags,
>                      VIRTIO_PCI_FLAG_AER_BIT, false),
> +    DEFINE_PROP_BIT("host-page-per-vq", VirtIOPCIProxy, flags,
> +                    VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT, false),
>      DEFINE_PROP_END_OF_LIST(),
>  };
> 
> diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index
> 59d88018c1..81b6de4291 100644
> --- a/include/hw/virtio/virtio-pci.h
> +++ b/include/hw/virtio/virtio-pci.h
> @@ -43,6 +43,7 @@ enum {
>      VIRTIO_PCI_FLAG_INIT_FLR_BIT,
>      VIRTIO_PCI_FLAG_AER_BIT,
>      VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT,
> +    VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT,
>  };
> 
>  /* Need to activate work-arounds for buggy guests at vmstate load. */ @@ -
> 89,6 +90,10 @@ enum {  #define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
>    (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
> 
> +/* page per vdpa vq flag to be used for vhost vdpa backends */ #define
> +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ \
> +    (1 << VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT)
> +
>  typedef struct {
>      MSIMessage msg;
>      int virq;
> --
> 2.25.1
diff mbox series

Patch

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1a7039fb0c..4e31169c6f 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -320,8 +320,12 @@  static bool virtio_pci_ioeventfd_enabled(DeviceState *d)
 
 static inline int virtio_pci_queue_mem_mult(struct VirtIOPCIProxy *proxy)
 {
-    return (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) ?
-        QEMU_VIRTIO_PCI_QUEUE_MEM_MULT : 4;
+    if (proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)
+        return QEMU_VIRTIO_PCI_QUEUE_MEM_MULT;
+    else if (proxy->flags & VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ)
+        return qemu_real_host_page_size();
+    else
+        return 4;
 }
 
 static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
@@ -2108,6 +2112,14 @@  static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)
         proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
     }
 
+    if ((proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ) &&
+        (proxy->flags & VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ)) {
+        error_setg(errp, "device cannot work with both page-per-vq and"
+                   " host-page-per-vq at the same time");
+        error_append_hint(errp, "Set either page-per-vq or host-page-per-vq\n");
+        return;
+    }
+
     /*
      * virtio pci bar layout used by default.
      * subclasses can re-arrange things if needed.
@@ -2301,6 +2313,8 @@  static Property virtio_pci_properties[] = {
                     VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
     DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags,
                     VIRTIO_PCI_FLAG_AER_BIT, false),
+    DEFINE_PROP_BIT("host-page-per-vq", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h
index 59d88018c1..81b6de4291 100644
--- a/include/hw/virtio/virtio-pci.h
+++ b/include/hw/virtio/virtio-pci.h
@@ -43,6 +43,7 @@  enum {
     VIRTIO_PCI_FLAG_INIT_FLR_BIT,
     VIRTIO_PCI_FLAG_AER_BIT,
     VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT,
+    VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT,
 };
 
 /* Need to activate work-arounds for buggy guests at vmstate load. */
@@ -89,6 +90,10 @@  enum {
 #define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \
   (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)
 
+/* page per vdpa vq flag to be used for vhost vdpa backends */
+#define VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ \
+    (1 << VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT)
+
 typedef struct {
     MSIMessage msg;
     int virq;