Skip to contentSkip to conversation

virtio-pci: correctly set virtio pci queue mem multiplier

PATCH Superseded Srujana Challa 3 participants 3 messages Feb 20, 2024 – Feb 26, 2024

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

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

 hw/virtio/virtio-pci.c         | 10 ++++++++--
 include/hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)
hw/virtio/virtio-pci.c +8 -2
index 1a7039fb0c..28dd6ab8b5 100644
@@ -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_PAGE_PER_VDPA_VQ)
+        return qemu_real_host_page_size();
+    else
+        return 4;
 }
 
 static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
@@ -2301,6 +2305,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("page-per-vdpa-vq", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/virtio/virtio-pci.h +5 -0
index 59d88018c1..10a30c26a2 100644
@@ -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_PAGE_PER_VDPA_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_PAGE_PER_VDPA_VQ \
+    (1 << VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT)
+
 typedef struct {
     MSIMessage msg;
     int virq;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Srujana Challa

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.

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

OK, I would maybe call it host-page-per-vq?

Jason?

Quoted 57 lines
 hw/virtio/virtio-pci.c         | 10 ++++++++--
 include/hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)
hw/virtio/virtio-pci.c +8 -2
index 1a7039fb0c..28dd6ab8b5 100644
@@ -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_PAGE_PER_VDPA_VQ)
+        return qemu_real_host_page_size();
+    else
+        return 4;
 }
 
 static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
@@ -2301,6 +2305,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("page-per-vdpa-vq", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/virtio/virtio-pci.h +5 -0
index 59d88018c1..10a30c26a2 100644
@@ -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_PAGE_PER_VDPA_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_PAGE_PER_VDPA_VQ \
+    (1 << VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT)
+
 typedef struct {
     MSIMessage msg;
     int virq;
Signature · 1 line
2.25.1
#2 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 11 lines · Srujana Challa

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.

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

Quoted 4 lines

OK, I would maybe call it host-page-per-vq?

Jason?

I agree.

Thanks

Quoted 58 lines
Quoted 57 lines
 hw/virtio/virtio-pci.c         | 10 ++++++++--
 include/hw/virtio/virtio-pci.h |  5 +++++
 2 files changed, 13 insertions(+), 2 deletions(-)
hw/virtio/virtio-pci.c +8 -2
index 1a7039fb0c..28dd6ab8b5 100644
@@ -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_PAGE_PER_VDPA_VQ)
+        return qemu_real_host_page_size();
+    else
+        return 4;
 }
 
 static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier *notifier,
@@ -2301,6 +2305,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("page-per-vdpa-vq", VirtIOPCIProxy, flags,
+                    VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
include/hw/virtio/virtio-pci.h +5 -1
index 59d88018c1..10a30c26a2 100644
@@ -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_PAGE_PER_VDPA_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_PAGE_PER_VDPA_VQ \
+    (1 << VIRTIO_PCI_FLAG_PAGE_PER_VDPA_VQ_BIT)
+
 typedef struct {
     MSIMessage msg;
     int virq;
--

2.25.1