DPDK patches and discussions
 help / color / mirror / Atom feed
From: Srujana Challa <schalla@marvell.com>
To: <dev@dpdk.org>, <maxime.coquelin@redhat.com>, <chenbox@nvidia.com>
Cc: <jerinj@marvell.com>, <ndabilpuram@marvell.com>,
	<vattunuru@marvell.com>,  <schalla@marvell.com>
Subject: [PATCH v2 3/3] net/virtio_user: support sharing vq descriptor IOVA to the backend
Date: Thu, 29 Feb 2024 18:59:19 +0530	[thread overview]
Message-ID: <20240229132919.2186118-4-schalla@marvell.com> (raw)
In-Reply-To: <20240229132919.2186118-1-schalla@marvell.com>

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(-)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index bf3da4340f..8ad10e6354 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -62,6 +62,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,
@@ -81,16 +82,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;
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index bf9de36d8f..ae6593ba0b 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -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) {
-- 
2.25.1


      parent reply	other threads:[~2024-02-29 13:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 13:29 [PATCH v2 0/3] net/virtio: support IOVA as PA mode for vDPA backend Srujana Challa
2024-02-29 13:29 ` [PATCH v2 1/3] net/virtio_user: avoid cq descriptor buffer address accessing Srujana Challa
2024-02-29 13:29 ` [PATCH v2 2/3] net/virtio: store desc IOVA address in vring data structure Srujana Challa
2024-02-29 13:29 ` Srujana Challa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240229132919.2186118-4-schalla@marvell.com \
    --to=schalla@marvell.com \
    --cc=chenbox@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=ndabilpuram@marvell.com \
    --cc=vattunuru@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).