Move ASID test to vhost-vdpa net initialization
v2 cover Move ASID test to vhost-vdpa net initialization
QEMU v8.0.0-rc0 is able to switch dynamically between vhost-vdpa passthrough and SVQ mode as long as the net device does not have CVQ. The net device state followed (and migrated) by CVQ requires special care.
A pre-requisite to add CVQ to that framework is to determine if devices with CVQ are migratable or not at initialization time. The solution to it is to always shadow only CVQ, and vq groups and ASID are used for that.
However, current qemu version only checks ASID at device start (as "driver set DRIVER_OK status bit"), not at device initialization. A check at initialization time is required. Otherwise, the guest would be able to set and remove migration blockers at will [1].
This series is a requisite for migration of vhost-vdpa net devices with CVQ. However it already makes sense by its own, as it reduces the number of ioctls at migration time, decreasing the error paths there.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
---
v2:
* Take out the reset of the device from vhost_vdpa_cvq_is_isolated (reported by Lei Yang).
* Expand patch messages by Stefano G. questions.
Eugenio Pérez (6):
vdpa: Remove status in reset tracing
vdpa: add vhost_vdpa_reset_status_fd
vdpa: add vhost_vdpa_set_dev_features_fd
vdpa: return errno in vhost_vdpa_get_vring_group error
vdpa: move CVQ isolation check to net_init_vhost_vdpa
vdpa: Cache cvq group in VhostVDPAState
include/hw/virtio/vhost-vdpa.h | 2 + hw/virtio/vhost-vdpa.c | 78 ++++++++----- net/vhost-vdpa.c | 199 +++++++++++++++++++++++++++------ hw/virtio/trace-events | 2 +- 4 files changed, 221 insertions(+), 60 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/6 vdpa: Remove status in reset tracing
It is always 0 and it is not useful to route call through file descriptor.
--- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +1 -1
@@ -716,7 +716,7 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev)uint8_t status =0 ; ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev, status); +trace_vhost_vdpa_reset_device (dev); v->suspended = false;return ret; }
hw/virtio/trace-events +1 -1
@@ -44,7 +44,7 @@ vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "dev: % vhost_vdpa_dump_regions(void *dev, int i, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, uint64_t flags_padding) "dev: %p %d: guest_phys_addr: 0x%"PRIx64" memory_size: 0x%"PRIx64" userspace_addr: 0x%"PRIx64" flags_padding: 0x%"PRIx64 vhost_vdpa_set_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64 vhost_vdpa_get_device_id(void *dev, uint32_t device_id) "dev: %p device_id %"PRIu32 -vhost_vdpa_reset_device(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 +vhost_vdpa_reset_device(void *dev) "dev: %p" vhost_vdpa_get_vq_index(void *dev, int idx, int vq_idx) "dev: %p idx: %d vq idx: %d" vhost_vdpa_set_vring_ready(void *dev) "dev: %p" vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s"
Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 1/6] vdpa: Remove status in reset tracing
Quoted 8 lines · Eugenio Pérez
It is always 0 and it is not useful to route call through file descriptor.
Signed-off-by Eugenio Pérez <[email protected]>---
hw/virtio/vhost-vdpa.c| 2 +-
hw/virtio/trace-events | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 30 lines
hw/virtio/vhost-vdpa.c +1
-1@@ -716,7 +716,7 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev)uint8_t status =0 ; ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev, status); +trace_vhost_vdpa_reset_device (dev); v->suspended = false;return ret; }hw/virtio/trace-events +0
-0@@ -44,7 +44,7 @@ vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "dev: %vhost_vdpa_dump_regions(void *dev, int i,
uint64_tguest_phys_addr,uint64_tmemory_size,uint64_tuserspace_addr,uint64_tflags_padding) "dev: %p %d:guest_phys_addr: 0x%"PRIx64"memory_size: 0x%"PRIx64"userspace_addr: 0x%"PRIx64"flags_padding: 0x%"PRIx64vhost_vdpa_set_features(void *dev, uint64_t features)"dev: %p features: 0x%"PRIx64vhost_vdpa_get_device_id(void *dev, uint32_t device_id)"dev: %pdevice_id%"PRIu32hw/virtio/trace-events +1
-1-vhost_vdpa_reset_device(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 +vhost_vdpa_reset_device(void *dev) "dev: %p"
vhost_vdpa_get_vq_index(void *dev, int idx, int vq_idx)"dev: %p idx: %d vq idx: %d"vhost_vdpa_set_vring_ready(void *dev)"dev: %p"vhost_vdpa_dump_config(void *dev, const char *line)"dev: %p %s"Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 1/6] vdpa: Remove status in reset tracing
In reply to Eugenio PérezQuoted 5 lines · Eugenio Pérez
It is always 0 and it is not useful to route call through file descriptor.
Signed-off-by Eugenio Pérez <[email protected]>
Thanks
Quoted 34 lines
--- hw/virtio/vhost-vdpa.c | 2 +- hw/virtio/trace-events | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)hw/virtio/vhost-vdpa.c +1
-1@@ -716,7 +716,7 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev)uint8_t status =0 ; ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev, status); +trace_vhost_vdpa_reset_device (dev); v->suspended = false;return ret; }hw/virtio/trace-events +1
-2@@ -44,7 +44,7 @@ vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "dev: % vhost_vdpa_dump_regions(void *dev, int i, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, uint64_t flags_padding) "dev: %p %d: guest_phys_addr: 0x%"PRIx64" memory_size: 0x%"PRIx64" userspace_addr: 0x%"PRIx64" flags_padding: 0x%"PRIx64 vhost_vdpa_set_features(void *dev, uint64_t features) "dev: %p features: 0x%"PRIx64 vhost_vdpa_get_device_id(void *dev, uint32_t device_id) "dev: %p device_id %"PRIu32 -vhost_vdpa_reset_device(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 +vhost_vdpa_reset_device(void *dev) "dev: %p" vhost_vdpa_get_vq_index(void *dev, int idx, int vq_idx) "dev: %p idx: %d vq idx: %d" vhost_vdpa_set_vring_ready(void *dev) "dev: %p" vhost_vdpa_dump_config(void *dev, const char *line) "dev: %p %s" --2.31.1
PATCH v2 2/6 vdpa: add vhost_vdpa_reset_status_fd
In reply to Eugenio PérezThis allows to reset a vhost-vdpa device from external subsystems like vhost-net, since it does not have any struct vhost_dev by the time we need to use it.
It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 58 +++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 18 deletions(-)
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -54,6 +54,7 @@ typedef struct vhost_vdpa {VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ]; } VhostVDPA; +void vhost_vdpa_reset_status_fd (int fd);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
hw/virtio/vhost-vdpa.c +40 -18
115 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 2/6] vdpa: add vhost_vdpa_reset_status_fd
Quoted 4 lines · Eugenio Pérez
This allows to reset a vhost-vdpa device from external subsystems like vhost-net, since it does not have any struct
vhost_devby the time we need to use it.
Quoted 8 lines
It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
Signed-off-by Eugenio Pérez <[email protected]>---
include/hw/virtio/vhost-vdpa.h| 1 +hw/virtio/vhost-vdpa.c| 58 +++++++++++++++++++++++-----------2 files changed, 41 insertions(+), 18 deletions(-)
Quoted 140 lines
include/hw/virtio/vhost-vdpa.h +1
-0@@ -54,6 +54,7 @@ typedef struct vhost_vdpa {VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ]; } VhostVDPA; +void vhost_vdpa_reset_status_fd (int fd);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,hw/virtio/vhost-vdpa.c +40
-18@@ -335,38 +335,45 @@ static const MemoryListener vhost_vdpa_memory_listener = { .region_del = vhost_vdpa_listener_region_del, }; -static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, -void *arg) +static int vhost_vdpa_dev_fd (const struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int fd = v->device_fd; -int ret;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA ); +return v->device_fd; +} + +static int vhost_vdpa_call_fd (int fd,unsigned long int request,void *arg) +{ +int ret =ioctl (fd, request, arg); - ret =ioctl (fd, request, arg);return ret <0 ? -errno : ret; } -static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, +void *arg) +{ +return vhost_vdpa_call_fd (vhost_vdpa_dev_fd (dev), request, arg); +} + +static int vhost_vdpa_add_status_fd (int fd,uint8_t status) {uint8_t s;int ret; -trace_vhost_vdpa_add_status (dev, status); - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; } s |= status; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &s);if (ret <0 ) {return ret; } - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; }@@ -378,6 +385,12 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; } +static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +{ +trace_vhost_vdpa_add_status (dev, status); +return vhost_vdpa_add_status_fd (vhost_vdpa_dev_fd (dev), status); +} +int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range) {int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range);@@ -709,16 +722,20 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,return ret; } +static int vhost_vdpa_reset_device_fd (int fd) +{ +uint8_t status =0 ; + +return vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &status); +} +static int vhost_vdpa_reset_device (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int ret; -uint8_t status =0 ; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev); v->suspended = false; -return ret; +trace_vhost_vdpa_reset_device (dev); +return vhost_vdpa_reset_device_fd (vhost_vdpa_dev_fd (dev)); }static int vhost_vdpa_get_vq_index (struct vhost_dev *dev,int idx)@@ -1170,6 +1187,13 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)return 0 ; } +void vhost_vdpa_reset_status_fd (int fd) +{ +vhost_vdpa_reset_device_fd (fd); +vhost_vdpa_add_status_fd (fd,VIRTIO_CONFIG_S_ACKNOWLEDGE | +VIRTIO_CONFIG_S_DRIVER ); +} +static void vhost_vdpa_reset_status (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;@@ -1178,9 +1202,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev)return ; } -vhost_vdpa_reset_device (dev); -vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE | -VIRTIO_CONFIG_S_DRIVER ); +vhost_vdpa_reset_status_fd (vhost_vdpa_dev_fd (dev));memory_listener_unregister (&v->listener); }Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 2/6] vdpa: add vhost_vdpa_reset_status_fd
In reply to Eugenio PérezQuoted 1 line · Eugenio Pérez
The title needs some tweak, I think the more appropriate one is "introduce vhost_vdpa_call_fd()"
Quoted 3 lines
This allows to reset a vhost-vdpa device from external subsystems like vhost-net, since it does not have any struct
vhost_devby the time we need to use it.
This part needs some clarification, vhost-net should be initialized after vhost_dev, so it can access its parent vhost_dev structure?
Quoted 54 lines
It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 58 +++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 18 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -54,6 +54,7 @@ typedef struct vhost_vdpa {VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ]; } VhostVDPA; +void vhost_vdpa_reset_status_fd (int fd);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,hw/virtio/vhost-vdpa.c +10
-6@@ -335,38 +335,45 @@ static const MemoryListener vhost_vdpa_memory_listener = { .region_del = vhost_vdpa_listener_region_del, }; -static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, -void *arg) +static int vhost_vdpa_dev_fd (const struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int fd = v->device_fd; -int ret;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA ); +return v->device_fd; +} + +static int vhost_vdpa_call_fd (int fd,unsigned long int request,void *arg) +{ +int ret =ioctl (fd, request, arg); - ret =ioctl (fd, request, arg);return ret <0 ? -errno : ret; } -static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, +void *arg) +{
hw/virtio/vhost-vdpa.c static const MemoryListener vhost_vdpa_memory_listener = { · line 357
Quoted 10 lines
hw/virtio/vhost-vdpa.c +4
-2+return vhost_vdpa_call_fd (vhost_vdpa_dev_fd (dev), request, arg); +} + +static int vhost_vdpa_add_status_fd (int fd,uint8_t status) {uint8_t s;int ret; -trace_vhost_vdpa_add_status (dev, status); - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s);
We can stick a vhost_vdpa_call() function that calls vhost_vdpa_call_fd() then we can avoid a lot of changes?
Thanks
Quoted 85 lines
hw/virtio/vhost-vdpa.c +26
-11+ ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; } s |= status; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &s);if (ret <0 ) {return ret; } - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; }@@ -378,6 +385,12 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; } +static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +{ +trace_vhost_vdpa_add_status (dev, status); +return vhost_vdpa_add_status_fd (vhost_vdpa_dev_fd (dev), status); +} +int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range) {int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range);@@ -709,16 +722,20 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,return ret; } +static int vhost_vdpa_reset_device_fd (int fd) +{ +uint8_t status =0 ; + +return vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &status); +} +static int vhost_vdpa_reset_device (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int ret; -uint8_t status =0 ; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev); v->suspended = false; -return ret; +trace_vhost_vdpa_reset_device (dev); +return vhost_vdpa_reset_device_fd (vhost_vdpa_dev_fd (dev)); }static int vhost_vdpa_get_vq_index (struct vhost_dev *dev,int idx)@@ -1170,6 +1187,13 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)return 0 ; } +void vhost_vdpa_reset_status_fd (int fd) +{ +vhost_vdpa_reset_device_fd (fd); +vhost_vdpa_add_status_fd (fd,VIRTIO_CONFIG_S_ACKNOWLEDGE | +VIRTIO_CONFIG_S_DRIVER ); +} +static void vhost_vdpa_reset_status (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;@@ -1178,9 +1202,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev)return ; } -vhost_vdpa_reset_device (dev); -vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE | -VIRTIO_CONFIG_S_DRIVER ); +vhost_vdpa_reset_status_fd (vhost_vdpa_dev_fd (dev));memory_listener_unregister (&v->listener); } --2.31.1
Re: [PATCH for 8.1 v2 2/6] vdpa: add vhost_vdpa_reset_status_fd
Quoted 7 lines · Jason Wang
Quoted 1 line · Eugenio Pérez
The title needs some tweak, I think the more appropriate one is "introduce
vhost_vdpa_call_fd()"
We can do it otherwise, but the function exported in the include/hw/virtio/vhost-vdpa.h file is vhost_vdpa_reset_status_fd. I'd consider vhost_vdpa_call_fd an implementation detail, only in hw/virtio/vhost-vdpa.c file.
Quoted 7 lines
Quoted 3 lines
This allows to reset a vhost-vdpa device from external subsystems like vhost-net, since it does not have any struct
vhost_devby the time we need to use it.This part needs some clarification, vhost-net should be initialized after
vhost_dev, so it can access its parentvhost_devstructure?
Next patches probes CVQ vring groups at initialization net-vdpa initialization time (net_init_vhost_vdpa). It already fetches things like device features using raw ioctl() calls because vhost_dev is still not available.
Quoted 62 lines
Quoted 62 lines
It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
Signed-off-by Eugenio Pérez <[email protected]>--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 58 +++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 18 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -54,6 +54,7 @@ typedef struct vhost_vdpa {VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ]; } VhostVDPA; +void vhost_vdpa_reset_status_fd (int fd);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,hw/virtio/vhost-vdpa.c +14
-6@@ -335,38 +335,45 @@ static const MemoryListener vhost_vdpa_memory_listener = { .region_del = vhost_vdpa_listener_region_del, }; -static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, -void *arg) +static int vhost_vdpa_dev_fd (const struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int fd = v->device_fd; -int ret;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA ); +return v->device_fd; +} + +static int vhost_vdpa_call_fd (int fd,unsigned long int request,void *arg) +{ +int ret =ioctl (fd, request, arg); - ret =ioctl (fd, request, arg);return ret <0 ? -errno : ret; } -static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, +void *arg) +{ +return vhost_vdpa_call_fd (vhost_vdpa_dev_fd (dev), request, arg); +} + +static int vhost_vdpa_add_status_fd (int fd,uint8_t status) {uint8_t s;int ret;
Quoted 6 lines
hw/virtio/vhost-vdpa.c static const MemoryListener vhost_vdpa_memory_listener = { · line 357
Quoted 2 lines
hw/virtio/vhost-vdpa.c +0
-2-trace_vhost_vdpa_add_status (dev, status); - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s);We can stick a
vhost_vdpa_call()function that callsvhost_vdpa_call_fd()then we can avoid a lot of changes?
I don't follow this. vhost_vdpa_call already calls vhost_vdpa_call_fd.
Thanks!
Quoted 88 lines
Thanks
Quoted 85 lines
hw/virtio/vhost-vdpa.c +26
-11+ ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; } s |= status; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &s);if (ret <0 ) {return ret; } - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s); + ret =vhost_vdpa_call_fd (fd,VHOST_VDPA_GET_STATUS , &s);if (ret <0 ) {return ret; }@@ -378,6 +385,12 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; } +static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +{ +trace_vhost_vdpa_add_status (dev, status); +return vhost_vdpa_add_status_fd (vhost_vdpa_dev_fd (dev), status); +} +int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range) {int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range);@@ -709,16 +722,20 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,return ret; } +static int vhost_vdpa_reset_device_fd (int fd) +{ +uint8_t status =0 ; + +return vhost_vdpa_call_fd (fd,VHOST_VDPA_SET_STATUS , &status); +} +static int vhost_vdpa_reset_device (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int ret; -uint8_t status =0 ; - ret =vhost_vdpa_call (dev,VHOST_VDPA_SET_STATUS , &status); -trace_vhost_vdpa_reset_device (dev); v->suspended = false; -return ret; +trace_vhost_vdpa_reset_device (dev); +return vhost_vdpa_reset_device_fd (vhost_vdpa_dev_fd (dev)); }static int vhost_vdpa_get_vq_index (struct vhost_dev *dev,int idx)@@ -1170,6 +1187,13 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)return 0 ; } +void vhost_vdpa_reset_status_fd (int fd) +{ +vhost_vdpa_reset_device_fd (fd); +vhost_vdpa_add_status_fd (fd,VIRTIO_CONFIG_S_ACKNOWLEDGE | +VIRTIO_CONFIG_S_DRIVER ); +} +static void vhost_vdpa_reset_status (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;@@ -1178,9 +1202,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev *dev)return ; } -vhost_vdpa_reset_device (dev); -vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_ACKNOWLEDGE | -VIRTIO_CONFIG_S_DRIVER ); +vhost_vdpa_reset_status_fd (vhost_vdpa_dev_fd (dev));memory_listener_unregister (&v->listener); } --2.31.1
Re: [PATCH for 8.1 v2 2/6] vdpa: add vhost_vdpa_reset_status_fd
Quoted 47 lines · Eugenio Perez Martin
Quoted 40 lines
Quoted 40 lines
hw/virtio/vhost-vdpa.c +14
-6@@ -335,38 +335,45 @@ static const MemoryListener vhost_vdpa_memory_listener = { .region_del = vhost_vdpa_listener_region_del, }; -static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, -void *arg) +static int vhost_vdpa_dev_fd (const struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -int fd = v->device_fd; -int ret;assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA ); +return v->device_fd; +} + +static int vhost_vdpa_call_fd (int fd,unsigned long int request,void *arg) +{ +int ret =ioctl (fd, request, arg); - ret =ioctl (fd, request, arg);return ret <0 ? -errno : ret; } -static int vhost_vdpa_add_status (struct vhost_dev *dev,uint8_t status) +static int vhost_vdpa_call (struct vhost_dev *dev,unsigned long int request, +void *arg) +{ +return vhost_vdpa_call_fd (vhost_vdpa_dev_fd (dev), request, arg); +} + +static int vhost_vdpa_add_status_fd (int fd,uint8_t status) {uint8_t s;int ret;Quoted 6 lines
hw/virtio/vhost-vdpa.c static const MemoryListener vhost_vdpa_memory_listener = { · line 357
Quoted 2 lines
hw/virtio/vhost-vdpa.c +0
-2-trace_vhost_vdpa_add_status (dev, status); - ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &s);We can stick a
vhost_vdpa_call()function that callsvhost_vdpa_call_fd()then we can avoid a lot of changes?
Quoted 3 lines
I don't follow this.
vhost_vdpa_callalready callsvhost_vdpa_call_fd.Thanks!
Jason were you going to reply?
PATCH v2 3/6 vdpa: add vhost_vdpa_set_dev_features_fd
In reply to Eugenio PérezThis allows to set the features of a vhost-vdpa device from external subsystems like vhost-net. It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-)
include/hw/virtio/vhost-vdpa.h +1 -0
@@ -55,6 +55,7 @@ typedef struct vhost_vdpa { } VhostVDPA;void vhost_vdpa_reset_status_fd (int fd); +int vhost_vdpa_set_dev_features_fd (int fd,uint64_t features);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
hw/virtio/vhost-vdpa.c +13 -7
@@ -651,11 +651,22 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev,return 0 ; } +int vhost_vdpa_set_dev_features_fd (int fd,uint64_t features) +{ +int ret; + + ret =vhost_vdpa_call_fd (fd,VHOST_SET_FEATURES , &features); +if (ret) { +return ret; + } + +return vhost_vdpa_add_status_fd (fd,VIRTIO_CONFIG_S_FEATURES_OK ); +} +static int vhost_vdpa_set_features (struct vhost_dev *dev,uint64_t features) {struct vhost_vdpa *v = dev->opaque; -int ret;if (!vhost_vdpa_first_dev (dev)) {return 0 ;
@@ -678,12 +689,7 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev, }trace_vhost_vdpa_set_features (dev, features); - ret =vhost_vdpa_call (dev,VHOST_SET_FEATURES , &features); -if (ret) { -return ret; - } - -return vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_FEATURES_OK ); +return vhost_vdpa_set_dev_features_fd (vhost_vdpa_dev_fd (dev), features); }static int vhost_vdpa_set_backend_cap (struct vhost_dev *dev)
Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 3/6] vdpa: add vhost_vdpa_set_dev_features_fd
Quoted 7 lines · Eugenio Pérez
This allows to set the features of a vhost-vdpa device from external subsystems like vhost-net. It is used in subsequent patches to negotiate features and probe for CVQ ASID isolation.
Reviewed-by Stefano Garzarella <[email protected]>Signed-off-by Eugenio Pérez <[email protected]>
Thanks
Quoted 62 lines
--- include/hw/virtio/vhost-vdpa.h | 1 + hw/virtio/vhost-vdpa.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-)include/hw/virtio/vhost-vdpa.h +1
-0@@ -55,6 +55,7 @@ typedef struct vhost_vdpa { } VhostVDPA;void vhost_vdpa_reset_status_fd (int fd); +int vhost_vdpa_set_dev_features_fd (int fd,uint64_t features);int vhost_vdpa_get_iova_range (int fd,struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,hw/virtio/vhost-vdpa.c +13
-8@@ -651,11 +651,22 @@ static int vhost_vdpa_set_mem_table(struct vhost_dev *dev,return 0 ; } +int vhost_vdpa_set_dev_features_fd (int fd,uint64_t features) +{ +int ret; + + ret =vhost_vdpa_call_fd (fd,VHOST_SET_FEATURES , &features); +if (ret) { +return ret; + } + +return vhost_vdpa_add_status_fd (fd,VIRTIO_CONFIG_S_FEATURES_OK ); +} +static int vhost_vdpa_set_features (struct vhost_dev *dev,uint64_t features) {struct vhost_vdpa *v = dev->opaque; -int ret;if (!vhost_vdpa_first_dev (dev)) {return 0 ;@@ -678,12 +689,7 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev, }trace_vhost_vdpa_set_features (dev, features); - ret =vhost_vdpa_call (dev,VHOST_SET_FEATURES , &features); -if (ret) { -return ret; - } - -return vhost_vdpa_add_status (dev,VIRTIO_CONFIG_S_FEATURES_OK ); +return vhost_vdpa_set_dev_features_fd (vhost_vdpa_dev_fd (dev), features); }static int vhost_vdpa_set_backend_cap (struct vhost_dev *dev) --2.31.1
PATCH v2 4/6 vdpa: return errno in vhost_vdpa_get_vring_group error
In reply to Eugenio PérezWe need to tell in the caller, as some errors are expected in a normal workflow. In particular, parent drivers in recent kernels with VHOST_BACKEND_F_IOTLB_ASID may not support vring groups. In that case, -ENOTSUP is returned.
This is the case of vp_vdpa in Linux 6.2.
Next patches in this series will use that information to know if it must abort or not. Also, next patches return properly an errp instead of printing with error_report.
--- net/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+)
net/vhost-vdpa.c +9 -0
@@ -361,6 +361,14 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +/** +* Get vring virtqueue group +* +* @device_fd vdpa device fd +* @vq_index Virtqueue index +* +* Return -errno in case of error, or vq group if success. +*/ static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) {struct vhost_vring_state state = {
@@ -369,6 +377,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_GROUP , &state);if (unlikely (r <0 )) { + r = -errno;error_report ("Cannot get VQ %u group: %s" , vq_index,g_strerror (errno));return r;
Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 4/6] vdpa: return errno in vhost_vdpa_get_vring_group error
Quoted 7 lines · Eugenio Pérez
We need to tell in the caller, as some errors are expected in a normal workflow. In particular, parent drivers in recent kernels with
VHOST_BACKEND_F_IOTLB_ASIDmay not support vring groups. In that case,-ENOTSUPis returned.This is the case of
vp_vdpain Linux 6.2.
Quoted 8 lines
Next patches in this series will use that information to know if it must abort or not. Also, next patches return properly an errp instead of printing with
error_report.Signed-off-by Eugenio Pérez <[email protected]>---
net/vhost-vdpa.c| 9 +++++++++1 file changed, 9 insertions(+)
Quoted 31 lines
net/vhost-vdpa.c +9
-0@@ -361,6 +361,14 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +/** +* Get vring virtqueue group +* +* @device_fd vdpa device fd +* @vq_index Virtqueue index +* +* Return -errno in case of error, or vq group if success. +*/ static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) {struct vhost_vring_state state = {@@ -369,6 +377,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_GROUP , &state);if (unlikely (r <0 )) { + r = -errno;error_report ("Cannot get VQ %u group: %s" , vq_index,g_strerror (errno));return r;Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 4/6] vdpa: return errno in vhost_vdpa_get_vring_group error
In reply to Eugenio PérezQuoted 6 lines · Eugenio Pérez
We need to tell in the caller, as some errors are expected in a normal workflow. In particular, parent drivers in recent kernels with
VHOST_BACKEND_F_IOTLB_ASIDmay not support vring groups. In that case,-ENOTSUPis returned.
Quoted 7 lines
This is the case of
vp_vdpain Linux 6.2.Next patches in this series will use that information to know if it must abort or not. Also, next patches return properly an errp instead of printing with
error_report.Signed-off-by Eugenio Pérez <[email protected]>
Thanks
Quoted 34 lines
--- net/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+)net/vhost-vdpa.c +9
-1@@ -361,6 +361,14 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +/** +* Get vring virtqueue group +* +* @device_fd vdpa device fd +* @vq_index Virtqueue index +* +* Return -errno in case of error, or vq group if success. +*/ static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) {struct vhost_vring_state state = {@@ -369,6 +377,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_GROUP , &state);if (unlikely (r <0 )) { + r = -errno;error_report ("Cannot get VQ %u group: %s" , vq_index,g_strerror (errno));return r; --2.31.1
PATCH v2 5/6 vdpa: move CVQ isolation check to net_init_vhost_vdpa
In reply to Eugenio PérezEvaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
---
v2: Take out the reset of the device from vhost_vdpa_cvq_is_isolated
--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)
net/vhost-vdpa.c +151 -43
@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated; +bool started; } VhostVDPAState;
@@ -361,15 +368,8 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; -/** -* Get vring virtqueue group -* -* @device_fd vdpa device fd -* @vq_index Virtqueue index -* -* Return -errno in case of error, or vq group if success. -*/ -static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) +static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index, +Error **errp) {struct vhost_vring_state state = { .index = vq_index,
@@ -378,8 +378,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)if (unlikely (r <0 )) { r = -errno; -error_report ("Cannot get VQ %u group: %s" , vq_index, -g_strerror (errno)); +error_setg_errno (errp, errno,"Cannot get VQ %u group" , vq_index);return r; }
@@ -479,9 +478,9 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) {VhostVDPAState *s, *s0;struct vhost_vdpa *v; -uint64_t backend_features;int64_t cvq_group; -int cvq_index, r; +int r; +Error *err =NULL ;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );
@@ -501,42 +500,29 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)/* * If we early return in these cases SVQ will not be enabled. The migration * will be blocked as long as vhost-vdpa backends will not offer _F_LOG. -* -* Calling VHOST_GET_BACKEND_FEATURES as they are not available in v->dev -* yet. */ - r =ioctl (v->device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); -if (unlikely (r <0 )) { -error_report ("Cannot get vdpa backend_features: %s(%d)" , -g_strerror (errno), errno); -return -1 ; - } -if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID )) || - !vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) { +if (!vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) {return 0 ; } -/* -* Check if all the virtqueues of the virtio device are in a different vq -* than the last vq. VQ group of last group passed in cvq_group. -*/ - cvq_index = v->dev->vq_index_end -1 ; - cvq_group =vhost_vdpa_get_vring_group (v->device_fd, cvq_index); -if (unlikely (cvq_group <0 )) { -return cvq_group; - } -for (int i =0 ; i < cvq_index; ++i) { -int64_t group =vhost_vdpa_get_vring_group (v->device_fd, i); - -if (unlikely (group <0 )) { -return group; +if (v->dev->features &BIT_ULL (VIRTIO_NET_F_MQ )) { +if (!s->cvq_isolated_mq) { +return 0 ; } - -if (group == cvq_group) { + }else { +if (!s->cvq_isolated) {return 0 ; } } + cvq_group =vhost_vdpa_get_vring_group (v->device_fd, + v->dev->vq_index_end -1 , + &err); +if (unlikely (cvq_group <0 )) { +error_report_err (err); +return cvq_group; + } + r =vhost_vdpa_set_address_space_id (v, cvq_group,VHOST_VDPA_NET_CVQ_ASID );if (unlikely (r <0 )) {return r;
@@ -798,6 +784,116 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +/** +* Probe the device to check control virtqueue is isolated. +* +* @device_fd vhost-vdpa file descriptor +* @features features to negotiate +* @cvq_index Control vq index +* +* Returns -1 in case of error, 0 if false and 1 if true +*/ +static int vhost_vdpa_cvq_is_isolated (int device_fd,uint64_t features, +unsigned cvq_index,Error **errp) +{ +int64_t cvq_group; +int r; + + r =vhost_vdpa_set_dev_features_fd (device_fd, features); +if (unlikely (r <0 )) { +error_setg_errno (errp, -r,"Cannot set device features" ); +return r; + } + + cvq_group =vhost_vdpa_get_vring_group (device_fd, cvq_index, errp); +if (unlikely (cvq_group <0 )) { +return cvq_group; + } + +for (int i =0 ; i < cvq_index; ++i) { +int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp); + +if (unlikely (group <0 )) { +return group; + } + +if (group == (int64_t )cvq_group) { +return 0 ; + } + } + +return 1 ; +} + +/** +* Probe if CVQ is isolated when the device is MQ and when it is not MQ +* +* @device_fd The vdpa device fd +* @features Features offered by the device. +* @cvq_index The control vq index if mq is negotiated. Ignored +* otherwise. +* @cvq_isolated It'll be set to true if cvq is isolated if mq is not +* negotiated. +* @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is +* negotiated. +* +* Returns -1 in case of failure +*/ +static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features, +int cvq_index,bool *cvq_isolated, +bool *cvq_isolated_mq,Error **errp) +{ +uint64_t backend_features; +int r; + +ERRP_GUARD (); + + *cvq_isolated = false; + *cvq_isolated_mq = false; + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, + features & ~BIT_ULL (VIRTIO_NET_F_MQ ),2 , + errp); +if (unlikely (r <0 )) { +if (r == -ENOTSUP ) { +/* +* The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa +* frontend support ASID but the parent driver does not. The CVQ +* cannot be isolated in this case. +*/ +error_free (*errp); + *errp =NULL ; +return 0 ; + } + +return r; + } + + *cvq_isolated = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +if (!(features &BIT_ULL (VIRTIO_NET_F_MQ ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, features, cvq_index *2 , errp); +if (unlikely (r <0 )) { +return r; + } + + *cvq_isolated_mq = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +return 0 ; +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name,
@@ -807,16 +903,26 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,bool is_datapath, bool svq, struct vhost_vdpa_iova_range iova_range, - uint64_t features) + uint64_t features, + Error **errp) { NetClientState *nc = NULL;VhostVDPAState *s;int ret =0 ;assert (name); +bool cvq_isolated, cvq_isolated_mq; +if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { + ret =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, + queue_pair_index, &cvq_isolated, + &cvq_isolated_mq, errp); +if (unlikely (ret)) { +return NULL ; + } + nc =qemu_new_net_control_client (&net_vhost_vdpa_cvq_info, peer, device, name); }
@@ -843,6 +949,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; + s->cvq_isolated = cvq_isolated; + s->cvq_isolated_mq = cvq_isolated_mq;/* * TODO: We cannot migrate devices with CVQ as there is no way to set
@@ -971,7 +1079,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,2 , true, opts->x_svq, - iova_range, features); + iova_range, features, errp);if (!ncs[i]) goto err; }
@@ -979,7 +1087,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,1 , false, - opts->x_svq, iova_range, features); + opts->x_svq, iova_range, features, errp);if (!nc) goto err; }
Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 10 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
I don't know this code sufficiently to do a review, but now I understand the motivation behind it ;-)
Thanks,
Stefano
Quoted 298 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated
---net/vhost-vdpa.c| 194 ++++++++++++++++++++++++++++++++++++-----------1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +151
-43@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated; +bool started; } VhostVDPAState;@@ -361,15 +368,8 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; -/** -* Get vring virtqueue group -* -* @device_fd vdpa device fd -* @vq_index Virtqueue index -* -* Return -errno in case of error, or vq group if success. -*/ -static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) +static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index, +Error **errp) {struct vhost_vring_state state = { .index = vq_index,@@ -378,8 +378,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)if (unlikely (r <0 )) { r = -errno; -error_report ("Cannot get VQ %u group: %s" , vq_index, -g_strerror (errno)); +error_setg_errno (errp, errno,"Cannot get VQ %u group" , vq_index);return r; }@@ -479,9 +478,9 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) {VhostVDPAState *s, *s0;struct vhost_vdpa *v; -uint64_t backend_features;int64_t cvq_group; -int cvq_index, r; +int r; +Error *err =NULL ;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -501,42 +500,29 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)/* * If we early return in these cases SVQ will not be enabled. The migration * will be blocked as long as vhost-vdpa backends will not offer _F_LOG. -* -* Calling VHOST_GET_BACKEND_FEATURES as they are not available in v->dev -* yet. */ - r =ioctl (v->device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); -if (unlikely (r <0 )) { -error_report ("Cannot get vdpa backend_features: %s(%d)" , -g_strerror (errno), errno); -return -1 ; - } -if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID )) || - !vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) { +if (!vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) {return 0 ; } -/* -* Check if all the virtqueues of the virtio device are in a different vq -* than the last vq. VQ group of last group passed in cvq_group. -*/ - cvq_index = v->dev->vq_index_end -1 ; - cvq_group =vhost_vdpa_get_vring_group (v->device_fd, cvq_index); -if (unlikely (cvq_group <0 )) { -return cvq_group; - } -for (int i =0 ; i < cvq_index; ++i) { -int64_t group =vhost_vdpa_get_vring_group (v->device_fd, i); - -if (unlikely (group <0 )) { -return group; +if (v->dev->features &BIT_ULL (VIRTIO_NET_F_MQ )) { +if (!s->cvq_isolated_mq) { +return 0 ; } - -if (group == cvq_group) { + }else { +if (!s->cvq_isolated) {return 0 ; } } + cvq_group =vhost_vdpa_get_vring_group (v->device_fd, + v->dev->vq_index_end -1 , + &err); +if (unlikely (cvq_group <0 )) { +error_report_err (err); +return cvq_group; + } + r =vhost_vdpa_set_address_space_id (v, cvq_group,VHOST_VDPA_NET_CVQ_ASID );if (unlikely (r <0 )) {return r;@@ -798,6 +784,116 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +/** +* Probe the device to check control virtqueue is isolated. +* +* @device_fd vhost-vdpa file descriptor +* @features features to negotiate +* @cvq_index Control vq index +* +* Returns -1 in case of error, 0 if false and 1 if true +*/ +static int vhost_vdpa_cvq_is_isolated (int device_fd,uint64_t features, +unsigned cvq_index,Error **errp) +{ +int64_t cvq_group; +int r; + + r =vhost_vdpa_set_dev_features_fd (device_fd, features); +if (unlikely (r <0 )) { +error_setg_errno (errp, -r,"Cannot set device features" ); +return r; + } + + cvq_group =vhost_vdpa_get_vring_group (device_fd, cvq_index, errp); +if (unlikely (cvq_group <0 )) { +return cvq_group; + } + +for (int i =0 ; i < cvq_index; ++i) { +int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp); + +if (unlikely (group <0 )) { +return group; + } + +if (group == (int64_t )cvq_group) { +return 0 ; + } + } + +return 1 ; +} + +/** +* Probe if CVQ is isolated when the device is MQ and when it is not MQ +* +* @device_fd The vdpa device fd +* @features Features offered by the device. +* @cvq_index The control vq index if mq is negotiated. Ignored +* otherwise. +* @cvq_isolated It'll be set to true if cvq is isolated if mq is not +* negotiated. +* @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is +* negotiated. +* +* Returns -1 in case of failure +*/ +static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features, +int cvq_index,bool *cvq_isolated, +bool *cvq_isolated_mq,Error **errp) +{ +uint64_t backend_features; +int r; + +ERRP_GUARD (); + + *cvq_isolated = false; + *cvq_isolated_mq = false; + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, + features & ~BIT_ULL (VIRTIO_NET_F_MQ ),2 , + errp); +if (unlikely (r <0 )) { +if (r == -ENOTSUP ) { +/* +* The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa +* frontend support ASID but the parent driver does not. The CVQ +* cannot be isolated in this case. +*/ +error_free (*errp); + *errp =NULL ; +return 0 ; + } + +return r; + } + + *cvq_isolated = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +if (!(features &BIT_ULL (VIRTIO_NET_F_MQ ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, features, cvq_index *2 , errp); +if (unlikely (r <0 )) { +return r; + } + + *cvq_isolated_mq = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +return 0 ; +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name,@@ -807,16 +903,26 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,bool is_datapath, bool svq, struct vhost_vdpa_iova_range iova_range, - uint64_t features) + uint64_t features, + Error **errp) { NetClientState *nc = NULL;VhostVDPAState *s;int ret =0 ;assert (name); +bool cvq_isolated, cvq_isolated_mq; +if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { + ret =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, + queue_pair_index, &cvq_isolated, + &cvq_isolated_mq, errp); +if (unlikely (ret)) { +return NULL ; + } + nc =qemu_new_net_control_client (&net_vhost_vdpa_cvq_info, peer, device, name); }@@ -843,6 +949,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; + s->cvq_isolated = cvq_isolated; + s->cvq_isolated_mq = cvq_isolated_mq;/* * TODO: We cannot migrate devices with CVQ as there is no way to set @@ -971,7 +1079,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,2 , true, opts->x_svq, - iova_range, features); + iova_range, features, errp);if (!ncs[i]) goto err; }@@ -979,7 +1087,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,1 , false, - opts->x_svq, iova_range, features); + opts->x_svq, iova_range, features, errp);if (!nc) goto err; }Signature · 1 line
2.31.1
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
In reply to Eugenio PérezQuoted 11 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 13 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0
net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;
As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Thanks
Quoted 276 lines
net/vhost-vdpa.c +145
-44+bool started; } VhostVDPAState;@@ -361,15 +368,8 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; -/** -* Get vring virtqueue group -* -* @device_fd vdpa device fd -* @vq_index Virtqueue index -* -* Return -errno in case of error, or vq group if success. -*/ -static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index) +static int64_t vhost_vdpa_get_vring_group (int device_fd,unsigned vq_index, +Error **errp) {struct vhost_vring_state state = { .index = vq_index,@@ -378,8 +378,7 @@ static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index)if (unlikely (r <0 )) { r = -errno; -error_report ("Cannot get VQ %u group: %s" , vq_index, -g_strerror (errno)); +error_setg_errno (errp, errno,"Cannot get VQ %u group" , vq_index);return r; }@@ -479,9 +478,9 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) {VhostVDPAState *s, *s0;struct vhost_vdpa *v; -uint64_t backend_features;int64_t cvq_group; -int cvq_index, r; +int r; +Error *err =NULL ;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -501,42 +500,29 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)/* * If we early return in these cases SVQ will not be enabled. The migration * will be blocked as long as vhost-vdpa backends will not offer _F_LOG. -* -* Calling VHOST_GET_BACKEND_FEATURES as they are not available in v->dev -* yet. */ - r =ioctl (v->device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); -if (unlikely (r <0 )) { -error_report ("Cannot get vdpa backend_features: %s(%d)" , -g_strerror (errno), errno); -return -1 ; - } -if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID )) || - !vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) { +if (!vhost_vdpa_net_valid_svq_features (v->dev->features,NULL )) {return 0 ; } -/* -* Check if all the virtqueues of the virtio device are in a different vq -* than the last vq. VQ group of last group passed in cvq_group. -*/ - cvq_index = v->dev->vq_index_end -1 ; - cvq_group =vhost_vdpa_get_vring_group (v->device_fd, cvq_index); -if (unlikely (cvq_group <0 )) { -return cvq_group; - } -for (int i =0 ; i < cvq_index; ++i) { -int64_t group =vhost_vdpa_get_vring_group (v->device_fd, i); - -if (unlikely (group <0 )) { -return group; +if (v->dev->features &BIT_ULL (VIRTIO_NET_F_MQ )) { +if (!s->cvq_isolated_mq) { +return 0 ; } - -if (group == cvq_group) { + }else { +if (!s->cvq_isolated) {return 0 ; } } + cvq_group =vhost_vdpa_get_vring_group (v->device_fd, + v->dev->vq_index_end -1 , + &err); +if (unlikely (cvq_group <0 )) { +error_report_err (err); +return cvq_group; + } + r =vhost_vdpa_set_address_space_id (v, cvq_group,VHOST_VDPA_NET_CVQ_ASID );if (unlikely (r <0 )) {return r;@@ -798,6 +784,116 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +/** +* Probe the device to check control virtqueue is isolated. +* +* @device_fd vhost-vdpa file descriptor +* @features features to negotiate +* @cvq_index Control vq index +* +* Returns -1 in case of error, 0 if false and 1 if true +*/ +static int vhost_vdpa_cvq_is_isolated (int device_fd,uint64_t features, +unsigned cvq_index,Error **errp) +{ +int64_t cvq_group; +int r; + + r =vhost_vdpa_set_dev_features_fd (device_fd, features); +if (unlikely (r <0 )) { +error_setg_errno (errp, -r,"Cannot set device features" ); +return r; + } + + cvq_group =vhost_vdpa_get_vring_group (device_fd, cvq_index, errp); +if (unlikely (cvq_group <0 )) { +return cvq_group; + } + +for (int i =0 ; i < cvq_index; ++i) { +int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp); + +if (unlikely (group <0 )) { +return group; + } + +if (group == (int64_t )cvq_group) { +return 0 ; + } + } + +return 1 ; +} + +/** +* Probe if CVQ is isolated when the device is MQ and when it is not MQ +* +* @device_fd The vdpa device fd +* @features Features offered by the device. +* @cvq_index The control vq index if mq is negotiated. Ignored +* otherwise. +* @cvq_isolated It'll be set to true if cvq is isolated if mq is not +* negotiated. +* @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is +* negotiated. +* +* Returns -1 in case of failure +*/ +static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features, +int cvq_index,bool *cvq_isolated, +bool *cvq_isolated_mq,Error **errp) +{ +uint64_t backend_features; +int r; + +ERRP_GUARD (); + + *cvq_isolated = false; + *cvq_isolated_mq = false; + r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features); +if (unlikely (r <0 )) { +error_setg_errno (errp, errno,"Cannot get vdpa backend_features" ); +return r; + } + +if (!(backend_features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, + features & ~BIT_ULL (VIRTIO_NET_F_MQ ),2 , + errp); +if (unlikely (r <0 )) { +if (r == -ENOTSUP ) { +/* +* The kernel report VHOST_BACKEND_F_IOTLB_ASID if the vdpa +* frontend support ASID but the parent driver does not. The CVQ +* cannot be isolated in this case. +*/ +error_free (*errp); + *errp =NULL ; +return 0 ; + } + +return r; + } + + *cvq_isolated = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +if (!(features &BIT_ULL (VIRTIO_NET_F_MQ ))) { +return 0 ; + } + + r =vhost_vdpa_cvq_is_isolated (device_fd, features, cvq_index *2 , errp); +if (unlikely (r <0 )) { +return r; + } + + *cvq_isolated_mq = r ==1 ; +vhost_vdpa_reset_status_fd (device_fd); +return 0 ; +} + static NetClientState *net_vhost_vdpa_init(NetClientState *peer, const char *device, const char *name,@@ -807,16 +903,26 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,bool is_datapath, bool svq, struct vhost_vdpa_iova_range iova_range, - uint64_t features) + uint64_t features, + Error **errp) { NetClientState *nc = NULL;VhostVDPAState *s;int ret =0 ;assert (name); +bool cvq_isolated, cvq_isolated_mq; +if (is_datapath) { nc =qemu_new_net_client (&net_vhost_vdpa_info, peer, device, name); }else { + ret =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, + queue_pair_index, &cvq_isolated, + &cvq_isolated_mq, errp); +if (unlikely (ret)) { +return NULL ; + } + nc =qemu_new_net_control_client (&net_vhost_vdpa_cvq_info, peer, device, name); }@@ -843,6 +949,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops = &vhost_vdpa_net_svq_ops; s->vhost_vdpa.shadow_vq_ops_opaque = s; + s->cvq_isolated = cvq_isolated; + s->cvq_isolated_mq = cvq_isolated_mq;/* * TODO: We cannot migrate devices with CVQ as there is no way to set @@ -971,7 +1079,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,2 , true, opts->x_svq, - iova_range, features); + iova_range, features, errp);if (!ncs[i]) goto err; }@@ -979,7 +1087,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, vdpa_device_fd, i,1 , false, - opts->x_svq, iova_range, features); + opts->x_svq, iova_range, features, errp);if (!nc) goto err; } --2.31.1
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 43 lines · Jason Wang
Quoted 11 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 13 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
Thanks
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 45 lines · Jason Wang
Quoted 43 lines · Jason Wang
Quoted 11 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 13 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 6 lines
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
I think it is a great idea and it simplifies this patch somehow. However, we need something like the queue mapping [1] to do so :).
To double confirm:
* If the device supports MQ, only probe MQ. If not, only probe !MQ.
* Only store cvq_isolated in VhostVDPAState.
Now, if the device does not negotiate MQ but the device supports MQ:
* All the requests to queue 3 must be redirected to the last queue in the device. That includes set_vq_address, notifiers regions, etc.
I'm totally ok to go this route but it's not immediate.
Thanks!
[1] https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg07157.html
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 45 lines · Eugenio Perez Martin
Quoted 39 lines · Jason Wang
Quoted 38 lines · Jason Wang
Quoted 10 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 12 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 5 lines
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
Quoted 8 lines
I think it is a great idea and it simplifies this patch somehow. However, we need something like the queue mapping [1] to do so :).
To double confirm:
* If the device supports MQ, only probe MQ. If not, only probe !MQ.
* Only storecvq_isolatedin VhostVDPAState.Now, if the device does not negotiate MQ but the device supports MQ:
I'm not sure I understand here, if device supports MQ it should accepts MQ or we can fail the initialization here.
Quoted 2 lines
* All the requests to queue 3 must be redirected to the last queue in the device. That includes
set_vq_address, notifiers regions, etc.
This also means we will only mediate the case:
1) Qemu emulated virtio-net has 1 queue but device support multiple queue
but not
2) Qemu emulated virtio-net has M queue but device support N queue (N>M)
Quoted 2 lines
I'm totally ok to go this route but it's not immediate.
Yes but I mean, we can start from failing the device if cvq_isolated_mq^cvq_isolated == true (or I wonder if we can meet this condition for any existing parents).
Thanks
Quoted 5 lines
Thanks!
[1] https://lists.gnu.org/archive/html/qemu-devel/2023-01/msg07157.html
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 55 lines · Jason Wang
Quoted 52 lines · Eugenio Perez Martin
Quoted 39 lines · Jason Wang
Quoted 38 lines · Jason Wang
Quoted 10 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 12 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 5 lines
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
I think it is a great idea and it simplifies this patch somehow. However, we need something like the queue mapping [1] to do so :).
To double confirm:
* If the device supports MQ, only probe MQ. If not, only probe !MQ.
* Only storecvq_isolatedin VhostVDPAState.
Quoted 6 lines
Quoted 1 line
Now, if the device does not negotiate MQ but the device supports MQ:
I'm not sure I understand here, if device supports MQ it should accepts MQ or we can fail the initialization here.
My fault, I wanted to say "if the device offers MQ but the driver does not acks it".
Quoted 5 lines
Quoted 3 lines
* All the requests to queue 3 must be redirected to the last queue in the device. That includes
set_vq_address, notifiers regions, etc.
Quoted 8 lines
This also means we will only mediate the case:
1) Qemu emulated virtio-net has 1 queue but device support multiple queue
but not
2) Qemu emulated virtio-net has M queue but device support N queue (N>M)
Right.
Quoted 8 lines
Quoted 3 lines
I'm totally ok to go this route but it's not immediate.
Yes but I mean, we can start from failing the device if cvq_isolated_mq^cvq_isolated == true
So probe the two cases but set VhostVDPAState->cvq_isolated = cvq_isolated && cvq_mq_isolated then? No map involved that way, and all parents should behave that way.
Quoted 1 line
(or I wonder if we can meet this condition for any existing parents).
I don't think so, but I think we need to probe the two anyway. Otherwise we may change the dataplane asid too.
Thanks!
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 92 lines · Eugenio Perez Martin
Quoted 55 lines · Jason Wang
Quoted 52 lines · Eugenio Perez Martin
Quoted 39 lines · Jason Wang
Quoted 38 lines · Jason Wang
Quoted 10 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 12 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 5 lines
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
I think it is a great idea and it simplifies this patch somehow. However, we need something like the queue mapping [1] to do so :).
To double confirm:
* If the device supports MQ, only probe MQ. If not, only probe !MQ.
* Only storecvq_isolatedin VhostVDPAState.Quoted 6 lines
Quoted 1 line
Now, if the device does not negotiate MQ but the device supports MQ:
I'm not sure I understand here, if device supports MQ it should accepts MQ or we can fail the initialization here.
My fault, I wanted to say "if the device offers MQ but the driver does not acks it".
Quoted 5 lines
Quoted 3 lines
* All the requests to queue 3 must be redirected to the last queue in the device. That includes
set_vq_address, notifiers regions, etc.Quoted 8 lines
This also means we will only mediate the case:
1) Qemu emulated virtio-net has 1 queue but device support multiple queue
but not
2) Qemu emulated virtio-net has M queue but device support N queue (N>M)
Right.
Quoted 8 lines
Quoted 3 lines
I'm totally ok to go this route but it's not immediate.
Yes but I mean, we can start from failing the device if cvq_isolated_mq^cvq_isolated == true
Quoted 8 lines
So probe the two cases but set
VhostVDPAState->cvq_isolated=cvq_isolated&&cvq_mq_isolatedthen? No map involved that way, and all parents should behave that way.Quoted 1 line
(or I wonder if we can meet this condition for any existing parents).
I don't think so, but I think we need to probe the two anyway. Otherwise we may change the dataplane asid too.
Just to make sure we are at the same page, I meant we could fail the initialization of vhost-vDPA is the device:
1) can isolate cvq in the case of singqueue but not multiqueue
or
2) can isolate cvq in the case of multiqueue but not single queue
Because I don't think there are any parents that have such a buggy implementation.
Thanks
Quoted 3 lines
Thanks!
Re: [PATCH for 8.1 v2 5/6] vdpa: move CVQ isolation check to net_init_vhost_vdpa
Quoted 107 lines · Jason Wang
Quoted 92 lines · Eugenio Perez Martin
Quoted 55 lines · Jason Wang
Quoted 52 lines · Eugenio Perez Martin
Quoted 39 lines · Jason Wang
Quoted 38 lines · Jason Wang
Quoted 10 lines · Eugenio Pérez
Evaluating it at start time instead of initialization time may make the guest capable of dynamically adding or removing migration blockers.
Also, moving to initialization reduces the number of ioctls in the migration, reducing failure possibilities.
As a drawback we need to check for CVQ isolation twice: one time with no MQ negotiated and another one acking it, as long as the device supports it. This is because Vring ASID / group management is based on vq indexes, but we don't know the index of CVQ before negotiating MQ.
We need to fail if we see a device that can isolate cvq without MQ but not with MQ.
Quoted 12 lines
Signed-off-by Eugenio Pérez <[email protected]>---
v2: Take out the reset of the device fromvhost_vdpa_cvq_is_isolated--- net/vhost-vdpa.c | 194 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 151 insertions(+), 43 deletions(-)net/vhost-vdpa.c +0
-0net/vhost-vdpa.c typedef struct VhostVDPAState { · line 51
Quoted 9 lines
net/vhost-vdpa.c +6
-0@@ -43,6 +43,13 @@ typedef struct VhostVDPAState {/* The device always have SVQ enabled */ bool always_svq; + +/* The device can isolate CVQ in its own ASID if MQ is negotiated */ +bool cvq_isolated_mq; + +/* The device can isolate CVQ in its own ASID if MQ is not negotiated */ +bool cvq_isolated;As stated above, if we need a device that cvq_isolated_mq^cvq_isolated == true, we need to fail. This may reduce the complexity of the code?
Quoted 5 lines
Quoted 1 line
Thanks
Since we are the mediation layer, Qemu can alway choose to negotiate MQ regardless whether or not it is supported by the guest. In this way, we can have a stable virtqueue index for cvq.
I think it is a great idea and it simplifies this patch somehow. However, we need something like the queue mapping [1] to do so :).
To double confirm:
* If the device supports MQ, only probe MQ. If not, only probe !MQ.
* Only storecvq_isolatedin VhostVDPAState.Quoted 6 lines
Quoted 1 line
Now, if the device does not negotiate MQ but the device supports MQ:
I'm not sure I understand here, if device supports MQ it should accepts MQ or we can fail the initialization here.
My fault, I wanted to say "if the device offers MQ but the driver does not acks it".
Quoted 5 lines
Quoted 3 lines
* All the requests to queue 3 must be redirected to the last queue in the device. That includes
set_vq_address, notifiers regions, etc.Quoted 8 lines
This also means we will only mediate the case:
1) Qemu emulated virtio-net has 1 queue but device support multiple queue
but not
2) Qemu emulated virtio-net has M queue but device support N queue (N>M)
Right.
Quoted 8 lines
Quoted 3 lines
I'm totally ok to go this route but it's not immediate.
Yes but I mean, we can start from failing the device if cvq_isolated_mq^cvq_isolated == true
Quoted 8 lines
So probe the two cases but set
VhostVDPAState->cvq_isolated=cvq_isolated&&cvq_mq_isolatedthen? No map involved that way, and all parents should behave that way.Quoted 1 line
(or I wonder if we can meet this condition for any existing parents).
I don't think so, but I think we need to probe the two anyway. Otherwise we may change the dataplane asid too.
Just to make sure we are at the same page, I meant we could fail the initialization of vhost-vDPA is the device:
Quoted 9 lines
1) can isolate cvq in the case of singqueue but not multiqueue
or
2) can isolate cvq in the case of multiqueue but not single queue
Because I don't think there are any parents that have such a buggy implementation.
Got it.
Leaving out the queue multiplex for the moment, as it adds complexity and we can add it on top.
Thanks!
PATCH v2 6/6 vdpa: Cache cvq group in VhostVDPAState
In reply to Eugenio PérezContinue the move of code that interacts with the device from control virtqueue start to control virtqueue init.
As with previous patches, it reduces the number of ioctls in the migration, reducing failure possibilities.
--- net/vhost-vdpa.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
net/vhost-vdpa.c +27 -13
@@ -41,6 +41,12 @@ typedef struct VhostVDPAState {void *cvq_cmd_out_buffer;virtio_net_ctrl_ack *status; +/* CVQ group if cvq_isolated_mq */ +uint32_t cvq_group_mq; + +/* CVQ group if cvq_isolated */ +uint32_t cvq_group; +/* The device always have SVQ enabled */ bool always_svq;
@@ -480,7 +486,6 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)struct vhost_vdpa *v;int64_t cvq_group;int r; -Error *err =NULL ;assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA );
@@ -509,18 +514,14 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc)if (!s->cvq_isolated_mq) {return 0 ; } + + cvq_group = s->cvq_group_mq; }else {if (!s->cvq_isolated) {return 0 ; } - } - cvq_group =vhost_vdpa_get_vring_group (v->device_fd, - v->dev->vq_index_end -1 , - &err); -if (unlikely (cvq_group <0 )) { -error_report_err (err); -return cvq_group; + cvq_group = s->cvq_group; } r =vhost_vdpa_set_address_space_id (v, cvq_group,VHOST_VDPA_NET_CVQ_ASID );
@@ -790,11 +791,13 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = {* @device_fd vhost-vdpa file descriptor * @features features to negotiate * @cvq_index Control vq index +* @pcvq_group: Returns CVQ group if cvq is isolated. * * Returns -1 in case of error, 0 if false and 1 if true */ static int vhost_vdpa_cvq_is_isolated (int device_fd,uint64_t features, -unsigned cvq_index,Error **errp) +unsigned cvq_index,uint32_t *pcvq_group, +Error **errp) {int64_t cvq_group;int r;
@@ -810,6 +813,7 @@ static int vhost_vdpa_cvq_is_isolated(int device_fd, uint64_t features,return cvq_group; } + *pcvq_group = (uint32_t )cvq_group;for (int i =0 ; i < cvq_index; ++i) {int64_t group =vhost_vdpa_get_vring_group (device_fd, i, errp);
@@ -836,12 +840,15 @@ static int vhost_vdpa_cvq_is_isolated(int device_fd, uint64_t features,* negotiated. * @cvq_isolated_mq It'll be set to true if cvq is isolated if mq is * negotiated. +* @cvq_group CVQ group if MQ is not negotiated. +* @cvq_group_mq CVQ group if MQ is negotiated. * * Returns -1 in case of failure */ static int vhost_vdpa_probe_cvq_isolation (int device_fd,uint64_t features,int cvq_index,bool *cvq_isolated, -bool *cvq_isolated_mq,Error **errp) +bool *cvq_isolated_mq,uint32_t *cvq_group, +uint32_t *cvq_group_mq,Error **errp) {uint64_t backend_features;int r;
@@ -850,6 +857,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, *cvq_isolated = false; *cvq_isolated_mq = false; + *cvq_group =0 ; + *cvq_group_mq =0 ; r =ioctl (device_fd,VHOST_GET_BACKEND_FEATURES , &backend_features);if (unlikely (r <0 )) {error_setg_errno (errp, errno,"Cannot get vdpa backend_features" );
@@ -862,7 +871,7 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features, r =vhost_vdpa_cvq_is_isolated (device_fd, features & ~BIT_ULL (VIRTIO_NET_F_MQ ),2 , - errp); + cvq_group, errp);if (unlikely (r <0 )) {if (r == -ENOTSUP ) {/*
@@ -884,7 +893,8 @@ static int vhost_vdpa_probe_cvq_isolation(int device_fd, uint64_t features,return 0 ; } - r =vhost_vdpa_cvq_is_isolated (device_fd, features, cvq_index *2 , errp); + r =vhost_vdpa_cvq_is_isolated (device_fd, features, cvq_index *2 , + cvq_group_mq, errp);if (unlikely (r <0 )) {return r; }
@@ -911,6 +921,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,int ret =0 ;assert (name);bool cvq_isolated, cvq_isolated_mq; +uint32_t cvq_group, cvq_group_mq;if (is_datapath) { nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device,
@@ -918,7 +929,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, }else { ret =vhost_vdpa_probe_cvq_isolation (vdpa_device_fd, features, queue_pair_index, &cvq_isolated, - &cvq_isolated_mq, errp); + &cvq_isolated_mq, &cvq_group, + &cvq_group_mq, errp);if (unlikely (ret)) {return NULL ; }
@@ -951,6 +963,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.shadow_vq_ops_opaque = s; s->cvq_isolated = cvq_isolated; s->cvq_isolated_mq = cvq_isolated_mq; + s->cvq_group = cvq_group; + s->cvq_group_mq = cvq_group_mq;/* * TODO: We cannot migrate devices with CVQ as there is no way to set
Signature · 1 line
2.31.1