Skip to contentSkip to conversation

net/virtio_user: fix issue with converting cq descriptor IOVA address to VA

PATCH In review Srujana Challa 2 participants 8 messages Jul 11, 2024 – Jul 12, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/virtio_user: fix issue with converting cq descriptor IOVA address to VA

This patch modifies the code to convert descriptor buffer IOVA addresses to virtual addresses only when use_va flag is false.

This patch resolves a segmentation fault with the vhost-user backend that occurs during the processing of the shadow control queue.

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

---
v2:
- Added Reported-by tag.

 .../net/virtio/virtio_user/virtio_user_dev.c  | 28 +++++++++++--------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +16 -12
index fed66d2ae9..94e0ddcb94 100644
@@ -905,12 +905,12 @@ 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(rte_iova_t iova, bool use_va)
 {
-	if (rte_eal_iova_mode() == RTE_IOVA_VA)
-		return (void *)(uintptr_t)iova;
-	else
+	if (rte_eal_iova_mode() == RTE_IOVA_PA && !use_va)
 		return rte_mem_iova2virt(iova);
+	else
+		return (void *)(uintptr_t)iova;
 }
 
 static uint32_t
@@ -922,6 +922,7 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri
 	uint16_t i, idx_data, idx_status;
 	uint32_t n_descs = 0;
 	int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+	bool use_va = dev->hw.use_va;
 
 	/* locate desc for header, data, and status */
 	idx_data = vring->desc[idx_hdr].next;
@@ -938,18 +939,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(vring->desc[idx_hdr].addr, use_va);
 	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(vring->desc[idx_data].addr, use_va);
 		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(vring->desc[idx_data].addr, use_va);
 		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 +963,8 @@ 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(vring->desc[idx_status].addr, use_va) = status;
 
 	return n_descs;
 }
@@ -987,6 +989,7 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
 	/* initialize to one, header is first */
 	uint32_t n_descs = 1;
 	int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+	bool use_va = dev->hw.use_va;
 
 	/* locate desc for header, data, and status */
 	idx_data = idx_hdr + 1;
@@ -1004,18 +1007,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(vring->desc[idx_hdr].addr, use_va);
 	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(vring->desc[idx_data].addr, use_va);
 		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(vring->desc[idx_data].addr, use_va);
 		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 +1031,8 @@ 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(vring->desc[idx_status].addr, use_va) = status;
 
 	/* Update used descriptor */
 	vring->desc[idx_hdr].id = vring->desc[idx_status].id;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Srujana Challa

This patch modifies the code to convert descriptor buffer IOVA addresses to virtual addresses only when use_va flag is false.

This patch resolves a segmentation fault with the vhost-user backend that occurs during the processing of the shadow control queue.

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

No single quote around the Fixes: tag, and on a single line please.

As for the title, how about: "net/virtio_user: fix cq descriptor conversion with non vDPA backend" ?

Quoted 15 lines

---
v2:
- Added Reported-by tag.

 .../net/virtio/virtio_user/virtio_user_dev.c  | 28 +++++++++++--------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
index fed66d2ae9..94e0ddcb94 100644

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) · line 908

Quoted 5 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
@@ -905,12 +905,12 @@ 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(rte_iova_t iova, bool use_va)

All the code in this file passes the virtio_user_dev object, please keep this convention.

IOW:
-virtio_user_iova2virt(rte_iova_t iova) +virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova)

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) · line 913

Quoted 8 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -3
 {
-       if (rte_eal_iova_mode() == RTE_IOVA_VA)
-               return (void *)(uintptr_t)iova;
-       else
+       if (rte_eal_iova_mode() == RTE_IOVA_PA && !use_va)
                return rte_mem_iova2virt(iova);
+       else
+               return (void *)(uintptr_t)iova;

Why do we need to invert this test?

I would make the change as simple as:
- if (rte_eal_iova_mode() == RTE_IOVA_VA)
+ if (rte_eal_iova_mode() == RTE_IOVA_VA || dev->hw.use_va)

Quoted 34 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +4 -3
 }
 
 static uint32_t
@@ -922,6 +922,7 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri
        uint16_t i, idx_data, idx_status;
        uint32_t n_descs = 0;
        int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+       bool use_va = dev->hw.use_va;
 
        /* locate desc for header, data, and status */
        idx_data = vring->desc[idx_hdr].next;
@@ -938,18 +939,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(vring->desc[idx_hdr].addr, use_va);
        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(vring->desc[idx_data].addr, use_va);
                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(vring->desc[idx_data].addr, use_va);
                status = virtio_user_handle_mq(dev, rss->max_tx_vq);
        } else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
                   hdr->class == VIRTIO_NET_CTRL_MAC ||

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri · line 967

Quoted 6 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
@@ -962,7 +963,8 @@ 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(vring->desc[idx_status].addr, use_va) = status;

Afaics, no need for reindenting.

Quoted 34 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +4 -3
        return n_descs;
 }
@@ -987,6 +989,7 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
        /* initialize to one, header is first */
        uint32_t n_descs = 1;
        int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+       bool use_va = dev->hw.use_va;
 
        /* locate desc for header, data, and status */
        idx_data = idx_hdr + 1;
@@ -1004,18 +1007,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(vring->desc[idx_hdr].addr, use_va);
        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(vring->desc[idx_data].addr, use_va);
                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(vring->desc[idx_data].addr, use_va);
                status = virtio_user_handle_mq(dev, rss->max_tx_vq);
        } else if (hdr->class == VIRTIO_NET_CTRL_RX  ||
                   hdr->class == VIRTIO_NET_CTRL_MAC ||

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev, · line 1035

Quoted 6 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
@@ -1028,7 +1031,8 @@ 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(vring->desc[idx_status].addr, use_va) = status;

Idem, no reindenting.

Quoted 6 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -1
        /* Update used descriptor */
        vring->desc[idx_hdr].id = vring->desc[idx_status].id;
--

2.25.1

Signature · 1 line
David Marchand
#2 lore raw
Quoted 5 lines · Srujana Challa
Quoted 4 lines

This patch modifies the code to convert descriptor buffer IOVA addresses to virtual addresses only when use_va flag is false.

Quoted 7 lines
Quoted 5 lines

This patch resolves a segmentation fault with the vhost-user backend that occurs during the processing of the shadow control queue.

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

No single quote around the Fixes: tag, and on a single line please.

Ack

Quoted 3 lines

As for the title, how about: "net/virtio_user: fix cq descriptor conversion with non vDPA backend" ?

Ack

Quoted 20 lines
Quoted 20 lines

---
v2:
- Added Reported-by tag.

 .../net/virtio/virtio_user/virtio_user_dev.c  | 28
+++++++++++--------
 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
index fed66d2ae9..94e0ddcb94 100644
@@ -905,12 +905,12 @@ virtio_user_handle_mq(struct virtio_user_dev
 *dev, uint16_t q_pairs)  #define CVQ_MAX_DATA_DESCS 32
 
Quoted 6 lines

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) · line 908

Quoted 3 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
 static inline void *
-virtio_user_iova2virt(rte_iova_t iova)
+virtio_user_iova2virt(rte_iova_t iova, bool use_va)

All the code in this file passes the virtio_user_dev object, please keep this convention.

Ack

Quoted 14 lines

IOW:

(quoted diff) +1 -1
-virtio_user_iova2virt(rte_iova_t iova)
+virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova)

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs) · line 913

Quoted 9 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -3
 {
-       if (rte_eal_iova_mode() == RTE_IOVA_VA)
-               return (void *)(uintptr_t)iova;
-       else
+       if (rte_eal_iova_mode() == RTE_IOVA_PA && !use_va)
                return rte_mem_iova2virt(iova);
+       else
+               return (void *)(uintptr_t)iova;
Quoted 1 line

Why do we need to invert this test?

Made this change to ensure that rte_mem_iova2virt() is not called when the IOVA mode is RTE_IOVA_DC by any chance.

Quoted 50 lines

I would make the change as simple as:

(quoted diff) +1 -1
-       if (rte_eal_iova_mode() == RTE_IOVA_VA)
+       if (rte_eal_iova_mode() == RTE_IOVA_VA || dev->hw.use_va)

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_split(struct

Quoted 6 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
 }
 
 static uint32_t
@@ -922,6 +922,7 @@ virtio_user_handle_ctrl_msg_split(struct

virtio_user_dev *dev, struct vring *vri

Quoted 8 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -0
        uint16_t i, idx_data, idx_status;
        uint32_t n_descs = 0;
        int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+       bool use_va = dev->hw.use_va;
 
        /* locate desc for header, data, and status */
        idx_data = vring->desc[idx_hdr].next; @@ -938,18 +939,18 @@

virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring

*vri

Quoted 6 lines
        idx_status = i;
        n_descs++;
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
-       hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr);
+       hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr,
+ use_va);

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri

Quoted 10 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
        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(vring->desc[idx_data].addr, use_va);
                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) {

drivers/net/virtio/virtio_user/virtio_user_dev.c

Quoted 9 lines
                struct virtio_net_ctrl_rss *rss;
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -1
-               rss = virtio_user_iova2virt(vring->desc[idx_data].addr);
+               rss =
+ virtio_user_iova2virt(vring->desc[idx_data].addr, use_va);
                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
+963,8 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev,

struct vring *vri

Quoted 3 lines

(struct virtio_pmd_ctrl *)hdr, dlen,
nb_dlen);

Quoted 8 lines

drivers/net/virtio/virtio_user/virtio_user_dev.c

Quoted 6 lines
        /* Update status */

- *(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring-
desc[idx_status].addr) = status;

drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -0
+       *(virtio_net_ctrl_ack *)
+               virtio_user_iova2virt(vring->desc[idx_status].addr,
+ use_va) = status;

Afaics, no need for reindenting.

It crossed 100 line boundary actually.

Quoted 64 lines

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_packed(struct

Quoted 5 lines

        return n_descs;

}

drivers/net/virtio/virtio_user/virtio_user_dev.c +0 -0
@@ -987,6 +989,7 @@ virtio_user_handle_ctrl_msg_packed(struct

virtio_user_dev *dev,

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_packed(struct

Quoted 8 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -0
        /* initialize to one, header is first */
        uint32_t n_descs = 1;
        int dlen[CVQ_MAX_DATA_DESCS], nb_dlen = 0;
+       bool use_va = dev->hw.use_va;
 
        /* locate desc for header, data, and status */
        idx_data = idx_hdr + 1;
@@ -1004,18 +1007,18 @@ virtio_user_handle_ctrl_msg_packed(struct

virtio_user_dev *dev,

Quoted 6 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
                n_descs++;
        }
 
-       hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr);
+       hdr = virtio_user_iova2virt(vring->desc[idx_hdr].addr,
+ use_va);

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,

Quoted 10 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -1
        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(vring->desc[idx_data].addr, use_va);
                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) {

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev, struct vring *vri

Quoted 9 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -1
                struct virtio_net_ctrl_rss *rss;
 
-               rss = virtio_user_iova2virt(vring->desc[idx_data].addr);
+               rss =
+ virtio_user_iova2virt(vring->desc[idx_data].addr, use_va);
                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
+1031,8 @@ virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev

*dev,

drivers/net/virtio/virtio_user/virtio_user_dev.c

Quoted 9 lines

(struct virtio_pmd_ctrl *)hdr, dlen,
nb_dlen);

        /* Update status */

- *(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring-
desc[idx_status].addr) = status;

drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -0
+       *(virtio_net_ctrl_ack *)
+               virtio_user_iova2virt(vring->desc[idx_status].addr,
+ use_va) = status;

Idem, no reindenting.

Quoted 6 lines
        /* Update used descriptor */
        vring->desc[idx_hdr].id = vring->desc[idx_status].id;

--
2.25.1

--
David Marchand

#3 lore raw
Quoted 12 lines · Srujana Challa
Quoted 12 lines
Quoted 1 line

+963,8 @@ virtio_user_handle_ctrl_msg_split(struct virtio_user_dev *dev,

struct vring *vri

Quoted 9 lines

(struct virtio_pmd_ctrl *)hdr, dlen,
nb_dlen);

        /* Update status */

- *(virtio_net_ctrl_ack *)virtio_user_iova2virt(vring-
desc[idx_status].addr) = status;

(quoted diff) +3 -0
+       *(virtio_net_ctrl_ack *)
+               virtio_user_iova2virt(vring->desc[idx_status].addr,
+ use_va) = status;
Quoted 2 lines
Quoted 1 line

Afaics, no need for reindenting.

It crossed 100 line boundary actually.

Ah indeed, it is crossed with "use_va".
But it won't be the case when passing dev.
So please don't touch original indent after applying my suggestion.

Signature · 1 line
David Marchand
#4 lore raw
In reply to Srujana Challa
Quoted 12 lines · Srujana Challa
Quoted 12 lines
(quoted diff) +1 -1
-virtio_user_iova2virt(rte_iova_t iova)
+virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova)
Quoted 9 lines

{

drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -3
-       if (rte_eal_iova_mode() == RTE_IOVA_VA)
-               return (void *)(uintptr_t)iova;
-       else
+       if (rte_eal_iova_mode() == RTE_IOVA_PA && !use_va)
                return rte_mem_iova2virt(iova);
+       else
+               return (void *)(uintptr_t)iova;
Quoted 3 lines
Quoted 1 line

Why do we need to invert this test?

Made this change to ensure that rte_mem_iova2virt() is not called when the IOVA mode is RTE_IOVA_DC by any chance.

Just repeating what I replied in the other thread as I see it was suggested by Jerin.
It is not possible iova mode == RTE_IOVA_DC.

Signature · 1 line
David Marchand
#5 lore raw
Quoted 13 lines · Srujana Challa
Quoted 12 lines
Quoted 12 lines
(quoted diff) +1 -1
-virtio_user_iova2virt(rte_iova_t iova)
+virtio_user_iova2virt(struct virtio_user_dev *dev, rte_iova_t iova)
Quoted 9 lines

{

drivers/net/virtio/virtio_user/virtio_user_dev.c +3 -3
-       if (rte_eal_iova_mode() == RTE_IOVA_VA)
-               return (void *)(uintptr_t)iova;
-       else
+       if (rte_eal_iova_mode() == RTE_IOVA_PA && !use_va)
                return rte_mem_iova2virt(iova);
+       else
+               return (void *)(uintptr_t)iova;
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Why do we need to invert this test?

Made this change to ensure that rte_mem_iova2virt() is not called when the IOVA mode is RTE_IOVA_DC by any chance.

Just repeating what I replied in the other thread as I see it was suggested by Jerin.
It is not possible iova mode == RTE_IOVA_DC.

Thank you for the clarification. I’ll incorporate the suggested changes in the next version.

Quoted 4 lines

--
David Marchand

#6 lore raw

PATCH v3 1/1 net/virtio_user: fix cq descriptor conversion with non vDPA backend

In reply to Srujana Challa

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

---
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(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +10 -10
index fed66d2ae9..48b872524a 100644
@@ -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;
Signature · 1 line
2.25.1
#7 lore raw

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

Quoted 7 lines · Srujana Challa

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.

Quoted 3 lines

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

Signature · 1 line
David Marchand