[v3] net/virtio_user: fix cq descriptor conversion with non vDPA backend

Message ID 20240712123612.2389160-1-schalla@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v3] net/virtio_user: fix cq descriptor conversion with non vDPA backend |

Checks

Context Check Description
ci/loongarch-compilation success Compilation OK
ci/checkpatch success coding style OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing pending Testing pending
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS

Commit Message

Srujana Challa July 12, 2024, 12:36 p.m. UTC
This patch modifies the code to convert descriptor buffer IOVA
addresses to virtual addresses only when use_va flag is false.

This patch fixes segmentation fault with vhost-user backend.

Fixes: 67e9e504dae2 ("net/virtio_user: convert cq descriptor IOVA address to Virtual address")

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Srujana Challa <schalla@marvell.com>
---
v3:
- Addressed the review comments from David Marchand.
v2:
- Added Reported-by tag.

 .../net/virtio/virtio_user/virtio_user_dev.c  | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
  

Comments

David Marchand July 12, 2024, 2:24 p.m. UTC | #1
On Fri, Jul 12, 2024 at 2:36 PM Srujana Challa <schalla@marvell.com> wrote:
>
> This patch modifies the code to convert descriptor buffer IOVA
> addresses to virtual addresses only when use_va flag is false.
>
> This patch fixes segmentation fault with vhost-user backend.
>
> Fixes: 67e9e504dae2 ("net/virtio_user: convert cq descriptor IOVA address to Virtual address")

This is not the sha1 for the commit in the main repo, I updated it.

>
> Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Srujana Challa <schalla@marvell.com>

The reported issue is fixed in OVS unit tests.
Applied, thanks.
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index fed66d2ae9..48b872524a 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -905,9 +905,9 @@  virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
 #define CVQ_MAX_DATA_DESCS 32
 
 static inline void *
-virtio_user_iova2virt(rte_iova_t iova)
+virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova)
 {
-	if (rte_eal_iova_mode() == RTE_IOVA_VA)
+	if (rte_eal_iova_mode() == RTE_IOVA_VA || dev->hw.use_va)
 		return (void *)(uintptr_t)iova;
 	else
 		return rte_mem_iova2virt(iova);
@@ -938,18 +938,18 @@  virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri
 	idx_status = i;
 	n_descs++;
 
-	hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr);
+	hdr = virtio_user_iova2virt(dev, vring->desc[idx_hdr].addr);
 	if (hdr->class == VIRTIO_NET_CTRL_MQ &&
 	    hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
 		uint16_t queues, *addr;
 
-		addr = virtio_user_iova2virt(vring->desc[idx_data].addr);
+		addr = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
 		queues = *addr;
 		status = virtio_user_handle_mq(dev, queues);
 	} else if (hdr->class == VIRTIO_NET_CTRL_MQ && hdr->cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) {
 		struct virtio_net_ctrl_rss *rss;
 
-		rss = virtio_user_iova2virt(vring->desc[idx_data].addr);
+		rss = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
 		status = virtio_user_handle_mq(dev, rss->max_tx_vq);
 	} else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
 		   hdr->class == VIRTIO_NET_CTRL_MAC ||
@@ -962,7 +962,7 @@  virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri
 				(struct virtio_pmd_ctrl *)hdr, dlen, nb_dlen);
 
 	/* Update status */
-	*(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring->desc[idx_status].addr) = status;
+	*(virtio_net_ctrl_ack *)virtio_user_iova2virt(dev, vring->desc[idx_status].addr) = status;
 
 	return n_descs;
 }
@@ -1004,18 +1004,18 @@  virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
 		n_descs++;
 	}
 
-	hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr);
+	hdr = virtio_user_iova2virt(dev, vring->desc[idx_hdr].addr);
 	if (hdr->class == VIRTIO_NET_CTRL_MQ &&
 	    hdr->cmd == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {
 		uint16_t queues, *addr;
 
-		addr = virtio_user_iova2virt(vring->desc[idx_data].addr);
+		addr = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
 		queues = *addr;
 		status = virtio_user_handle_mq(dev, queues);
 	} else if (hdr->class == VIRTIO_NET_CTRL_MQ && hdr->cmd == VIRTIO_NET_CTRL_MQ_RSS_CONFIG) {
 		struct virtio_net_ctrl_rss *rss;
 
-		rss = virtio_user_iova2virt(vring->desc[idx_data].addr);
+		rss = virtio_user_iova2virt(dev, vring->desc[idx_data].addr);
 		status = virtio_user_handle_mq(dev, rss->max_tx_vq);
 	} else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
 		   hdr->class == VIRTIO_NET_CTRL_MAC ||
@@ -1028,7 +1028,7 @@  virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
 				(struct virtio_pmd_ctrl *)hdr, dlen, nb_dlen);
 
 	/* Update status */
-	*(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring->desc[idx_status].addr) = status;
+	*(virtio_net_ctrl_ack *)virtio_user_iova2virt(dev, vring->desc[idx_status].addr) = status;
 
 	/* Update used descriptor */
 	vring->desc[idx_hdr].id = vring->desc[idx_status].id;