virtio-pci: correctly set virtio pci queue mem multiplier
PATCH v3 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(host-page-per-vq) for vdpa use case to fix the same.
---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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)
hw/virtio/virtio-pci.c +8 -2
@@ -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,
@@ -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 ("host-page-per-vq" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT , false), DEFINE_PROP_END_OF_LIST(), };
include/hw/virtio/virtio-pci.h +5 -0
@@ -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;
Signature · 1 line
2.25.1
Hi Srujana,
Quoted 26 lines · Srujana Challa
Currently,
virtio_pci_queue_mem_multfunction always returns 4K whenVIRTIO_PCI_FLAG_PAGE_PER_VQis set. But this won't work for vhost vdpa when host has page size other than 4K. This patch introduces a new property(host-page-per-vq) for vdpa use case to fix the same.Signed-off-by Srujana Challa <[email protected]>---
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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c +0
-0@@ -320,8 +320,12 @@ static bool virtio_pci_ioeventfd_enabled(DeviceState *d)static inline int virtio_pci_queue_mem_mult (struct VirtIOPCIProxy *proxy)
hw/virtio/virtio-pci.c static bool virtio_pci_ioeventfd_enabled(DeviceState *d) · line 329
Quoted 10 lines
hw/virtio/virtio-pci.c +6
-2{ -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 ; }
Per our coding style, this code should use braces:
https://www.qemu.org/docs/master/devel/style.html#block-structure
Regards,
Phil.
Quoted 7 lines · Srujana Challa
Currently,
virtio_pci_queue_mem_multfunction always returns 4K whenVIRTIO_PCI_FLAG_PAGE_PER_VQis set. But this won't work for vhost vdpa when host has page size other than 4K. This patch introduces a new property(host-page-per-vq) for vdpa use case to fix the same.Signed-off-by Srujana Challa <[email protected]>
Looks good. I'd like to fail realize if both
(proxy->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)
and
(proxy->flags & VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ)
so users do not start depending on this combination.
Quoted 65 lines
---
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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c +8
-2@@ -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,@@ -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 ("host-page-per-vq" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT , false), DEFINE_PROP_END_OF_LIST(), };include/hw/virtio/virtio-pci.h +5
-0@@ -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;Signature · 1 line
2.25.1
Quoted 13 lines
Subject: [EXT] Re: [PATCH v3] virtio-pci: correctly set virtio pci queue mem multiplier
External Email
----------------------------------------------------------------------
Quoted 6 lines · Srujana Challa
Currently,
virtio_pci_queue_mem_multfunction always returns 4K whenVIRTIO_PCI_FLAG_PAGE_PER_VQis set. But this won't work for vhost vdpa when host has page size other than 4K.
This patch introduces a new property(host-page-per-vq) for vdpa use case to fix the same.
Quoted 6 lines
Quoted 1 line
Signed-off-by Srujana Challa <[email protected]>Looks good. I'd like to fail realize if both
(proxy->flags&VIRTIO_PCI_FLAG_PAGE_PER_VQ) and (proxy->flags&VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ) so users do not
start depending on this combination.
Could you confirm if we can add assertion for this case in virtio_pci_mem_mult() function?
Quoted 70 lines
Quoted 34 lines
---
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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c index renamed from hw/virtio/virtio-pci.c +0
-0
1a7039fb0c..f29e60830b100644hw/virtio/virtio-pci.c +6
-2@@ -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 ; }Quoted 2 lines
static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier
*notifier, @@ -2301,6 +2305,8 @@ static Property virtio_pci_properties[] ={
include/hw/virtio/virtio-pci.h enum { #define
Quoted 21 lines
VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_AER_BIT, false),hw/virtio/virtio-pci.c +2
-0+DEFINE_PROP_BIT ("host-page-per-vq" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT , false), DEFINE_PROP_END_OF_LIST(), };(quoted diff) +0
-0
b/include/hw/virtio/virtio-pci.hindex59d88018c1..81b6de4291100644include/hw/virtio/virtio-pci.h +1
-0@@ -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\Quoted 11 lines
include/hw/virtio/virtio-pci.h +4
-1(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
Quoted 13 lines · Srujana Challa
Quoted 13 lines
Subject: [EXT] Re: [PATCH v3] virtio-pci: correctly set virtio pci queue mem multiplier
External Email
----------------------------------------------------------------------
Quoted 6 lines · Srujana Challa
Currently,
virtio_pci_queue_mem_multfunction always returns 4K whenVIRTIO_PCI_FLAG_PAGE_PER_VQis set. But this won't work for vhost vdpa when host has page size other than 4K.
This patch introduces a new property(host-page-per-vq) for vdpa use case to fix the same.
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Srujana Challa <[email protected]>Looks good. I'd like to fail realize if both
(proxy->flags&VIRTIO_PCI_FLAG_PAGE_PER_VQ) and (proxy->flags&VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ) so users do not
start depending on this combination.Could you confirm if we can add assertion for this case in
virtio_pci_mem_mult()function?
No, reporting an error would be better since it's user-triggerable - it is not nice to report user errors through assertions, assertions are for conditions that can not be reached.
Quoted 70 lines
Quoted 70 lines
Quoted 34 lines
---
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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c index renamed from hw/virtio/virtio-pci.c +0
-0
1a7039fb0c..f29e60830b100644hw/virtio/virtio-pci.c +6
-2@@ -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 ; }Quoted 2 lines
static int virtio_pci_ioeventfd_assign(DeviceState *d, EventNotifier
*notifier, @@ -2301,6 +2305,8 @@ static Property virtio_pci_properties[] ={
include/hw/virtio/virtio-pci.h enum { #define
Quoted 21 lines
VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_AER_BIT, false),hw/virtio/virtio-pci.c +2
-0+DEFINE_PROP_BIT ("host-page-per-vq" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT , false), DEFINE_PROP_END_OF_LIST(), };(quoted diff) +0
-0
b/include/hw/virtio/virtio-pci.hindex59d88018c1..81b6de4291100644include/hw/virtio/virtio-pci.h +1
-0@@ -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\Quoted 11 lines
include/hw/virtio/virtio-pci.h +4
-1(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
Quoted 23 lines
Subject: Re: [EXT] Re: [PATCH v3] virtio-pci: correctly set virtio pci queue mem multiplier
Quoted 19 lines · Srujana Challa
Quoted 19 lines
Subject: [EXT] Re: [PATCH v3] virtio-pci: correctly set virtio pci queue mem multiplier
External Email
--------------------------------------------------------------------
Quoted 7 lines · Srujana Challa
Currently,
virtio_pci_queue_mem_multfunction always returns 4K whenVIRTIO_PCI_FLAG_PAGE_PER_VQis set. But this won't work for vhost vdpa when host has page size other than 4K.
This patch introduces a new property(host-page-per-vq) for vdpa use case to fix the same.Signed-off-by Srujana Challa <[email protected]>Looks good. I'd like to fail realize if both
(proxy->flags&VIRTIO_PCI_FLAG_PAGE_PER_VQ) and (proxy->flags&VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ) so users do not
start depending on this combination.
Quoted 6 lines
Quoted 1 line
Could you confirm if we can add assertion for this case in
virtio_pci_mem_mult()function?No, reporting an error would be better since it's user-triggerable - it is not nice to report user errors through assertions, assertions are for conditions that can not be reached.
Yes, but returning error from virtio_pci_queue_mem_mult() would need changes In multiple places right?
Quoted 74 lines
Quoted 74 lines
Quoted 74 lines
Quoted 36 lines
---
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 | 10 ++++++++-- include/hw/virtio/virtio-pci.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c index renamed from hw/virtio/virtio-pci.c +0
-0
1a7039fb0c..f29e60830b100644hw/virtio/virtio-pci.c +6
-2@@ -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 ; }Quoted 3 lines
static int virtio_pci_ioeventfd_assign(DeviceState *d,
EventNotifier *notifier, @@ -2301,6 +2305,8 @@ static Property virtio_pci_properties[] ={
Quoted 21 lines
VIRTIO_PCI_FLAG_INIT_FLR_BIT, true),
DEFINE_PROP_BIT("aer", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_AER_BIT, false),hw/virtio/virtio-pci.c +2
-0+DEFINE_PROP_BIT ("host-page-per-vq" , VirtIOPCIProxy, flags, +VIRTIO_PCI_FLAG_HOST_PAGE_PER_VQ_BIT , false), DEFINE_PROP_END_OF_LIST(), };(quoted diff) +0
-0
b/include/hw/virtio/virtio-pci.hindex59d88018c1..81b6de4291100644include/hw/virtio/virtio-pci.h +1
-0@@ -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 Quoted 1 line
load. */ @@ -89,6 +90,10 @@ enum { #define
VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED\Quoted 11 lines
(1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT)include/hw/virtio/virtio-pci.h +4
-1+/* 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