[v3,3/3] net/virtio_user: support sharing vq descriptor IOVA to the backend
Checks
Commit Message
Adds support to share descriptor IOVA to the vhost backend.
This makes virtio_user driver works in IOVA as PA mode when
use_va flag is disabled.
This patch also disables use_va flag for VDPA backend.
Signed-off-by: Srujana Challa <schalla@marvell.com>
---
.../net/virtio/virtio_user/virtio_user_dev.c | 26 ++++++++++++-------
drivers/net/virtio/virtio_user_ethdev.c | 10 ++++++-
2 files changed, 26 insertions(+), 10 deletions(-)
Comments
On 7/3/24 12:03, Srujana Challa wrote:
> Adds support to share descriptor IOVA to the vhost backend.
> This makes virtio_user driver works in IOVA as PA mode when
> use_va flag is disabled.
> This patch also disables use_va flag for VDPA backend.
>
> Signed-off-by: Srujana Challa <schalla@marvell.com>
> ---
> .../net/virtio/virtio_user/virtio_user_dev.c | 26 ++++++++++++-------
> drivers/net/virtio/virtio_user_ethdev.c | 10 ++++++-
> 2 files changed, 26 insertions(+), 10 deletions(-)
>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Thanks,
Maxime
@@ -118,6 +118,7 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
struct vhost_vring_state state;
struct vring *vring = &dev->vrings.split[queue_sel];
struct vring_packed *pq_vring = &dev->vrings.packed[queue_sel];
+ uint64_t desc_addr, avail_addr, used_addr;
struct vhost_vring_addr addr = {
.index = queue_sel,
.log_guest_addr = 0,
@@ -137,16 +138,23 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
}
if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {
- addr.desc_user_addr =
- (uint64_t)(uintptr_t)pq_vring->desc;
- addr.avail_user_addr =
- (uint64_t)(uintptr_t)pq_vring->driver;
- addr.used_user_addr =
- (uint64_t)(uintptr_t)pq_vring->device;
+ desc_addr = pq_vring->desc_iova;
+ avail_addr = desc_addr + pq_vring->num * sizeof(struct vring_packed_desc);
+ used_addr = RTE_ALIGN_CEIL(avail_addr + sizeof(struct vring_packed_desc_event),
+ VIRTIO_VRING_ALIGN);
+
+ addr.desc_user_addr = desc_addr;
+ addr.avail_user_addr = avail_addr;
+ addr.used_user_addr = used_addr;
} else {
- addr.desc_user_addr = (uint64_t)(uintptr_t)vring->desc;
- addr.avail_user_addr = (uint64_t)(uintptr_t)vring->avail;
- addr.used_user_addr = (uint64_t)(uintptr_t)vring->used;
+ desc_addr = vring->desc_iova;
+ avail_addr = desc_addr + vring->num * sizeof(struct vring_desc);
+ used_addr = RTE_ALIGN_CEIL((uintptr_t)(&vring->avail->ring[vring->num]),
+ VIRTIO_VRING_ALIGN);
+
+ addr.desc_user_addr = desc_addr;
+ addr.avail_user_addr = avail_addr;
+ addr.used_user_addr = used_addr;
}
state.index = queue_sel;
@@ -198,6 +198,7 @@ virtio_user_setup_queue_packed(struct virtqueue *vq,
sizeof(struct vring_packed_desc_event),
VIRTIO_VRING_ALIGN);
vring->num = vq->vq_nentries;
+ vring->desc_iova = vq->vq_ring_mem;
vring->desc = (void *)(uintptr_t)desc_addr;
vring->driver = (void *)(uintptr_t)avail_addr;
vring->device = (void *)(uintptr_t)used_addr;
@@ -221,6 +222,7 @@ virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
VIRTIO_VRING_ALIGN);
dev->vrings.split[queue_idx].num = vq->vq_nentries;
+ dev->vrings.split[queue_idx].desc_iova = vq->vq_ring_mem;
dev->vrings.split[queue_idx].desc = (void *)(uintptr_t)desc_addr;
dev->vrings.split[queue_idx].avail = (void *)(uintptr_t)avail_addr;
dev->vrings.split[queue_idx].used = (void *)(uintptr_t)used_addr;
@@ -689,7 +691,13 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
* Virtio-user requires using virtual addresses for the descriptors
* buffers, whatever other devices require
*/
- hw->use_va = true;
+ if (backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA)
+ /* VDPA backend requires using iova for the buffers to make it
+ * work in IOVA as PA mode also.
+ */
+ hw->use_va = false;
+ else
+ hw->use_va = true;
/* previously called by pci probing for physical dev */
if (eth_virtio_dev_init(eth_dev) < 0) {