Skip to contentSkip to conversation

vhost: fix index overflow issue in async vhost

PATCH Superseded Cheng Jiang 2 participants 6 messages Jul 8, 2021 – Jul 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fix index overflow issue in async vhost

We introduced some new indexes in async vhost. If we don't pay attention to the management of these indexes, they will eventually overflow and lead to errors. This patch is to check and keep these indexes within a reasonable range.

Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")
---
 lib/vhost/virtio_net.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
lib/vhost/virtio_net.c +15 -7
index f4a2c88d8b..61cb5a126c 100644
@@ -1614,6 +1614,7 @@ store_dma_desc_info_packed(struct vring_used_elem_packed *s_ring,
 
 	if (d_idx + count <= ring_size) {
 		rte_memcpy(d_ring + d_idx, s_ring + s_idx, count * elem_size);
+
 	} else {
 		uint16_t size = ring_size - d_idx;
 
@@ -2036,7 +2037,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 
 		slot_idx = (vq->async_pkts_idx + num_async_pkts) % vq->size;
 		if (it_pool[it_idx].count) {
-			uint16_t from, to;
+			uint16_t from;
 
 			async_descs_idx += num_descs;
 			async_fill_desc(&tdes[pkt_burst_idx++],
@@ -2055,11 +2056,13 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 			 * descriptors.
 			 */
 			from = vq->shadow_used_idx - num_buffers;
-			to = vq->async_buffer_idx_packed % vq->size;
 			store_dma_desc_info_packed(vq->shadow_used_packed,
-					vq->async_buffers_packed, vq->size, from, to, num_buffers);
+					vq->async_buffers_packed, vq->size, from,
+					vq->async_buffer_idx_packed, num_buffers);
 
 			vq->async_buffer_idx_packed += num_buffers;
+			if (vq->async_buffer_idx_packed >= vq->size)
+				vq->async_buffer_idx_packed -= vq->size;
 			vq->shadow_used_idx -= num_buffers;
 		} else {
 			comp_pkts[num_done_pkts++] = pkts[pkt_idx];
@@ -2112,6 +2115,8 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 		dma_error_handler_packed(vq, async_descs, async_descs_idx, slot_idx, pkt_err,
 					&pkt_idx, &num_async_pkts, &num_done_pkts);
 	vq->async_pkts_idx += num_async_pkts;
+	if (vq->async_pkts_idx >= vq->size)
+		vq->async_pkts_idx -= vq->size;
 	*comp_count = num_done_pkts;
 
 	if (likely(vq->shadow_used_idx)) {
@@ -2160,7 +2165,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue *vq,
 	uint16_t from, to;
 
 	do {
-		from = vq->last_async_buffer_idx_packed % vq->size;
+		from = vq->last_async_buffer_idx_packed;
 		to = (from + nr_left) % vq->size;
 		if (to > from) {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from, to - from);
@@ -2169,7 +2174,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue *vq,
 		} else {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from,
 				vq->size - from);
-			vq->last_async_buffer_idx_packed += vq->size - from;
+			vq->last_async_buffer_idx_packed = 0;
 			nr_left -= vq->size - from;
 		}
 	} while (nr_left > 0);
@@ -2252,10 +2257,13 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
-		if (vq_is_packed(dev))
+		if (vq_is_packed(dev)) {
 			vq->last_async_buffer_idx_packed += n_buffers;
-		else
+			if (vq->last_async_buffer_idx_packed >= vq->size)
+				vq->last_async_buffer_idx_packed -= vq->size;
+		} else {
 			vq->last_async_desc_idx_split += n_descs;
+		}
 	}
 
 done:
Signature · 1 line
2.29.2
#1 lore raw

Hi Cheng,

Quoted 8 lines

-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Thursday, July 8, 2021 6:45 PM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH] vhost: fix index overflow issue in async vhost

Since this fix is packed ring only, maybe 'fix index overflow for packed ring in async vhost' is better.

Quoted 5 lines

We introduced some new indexes in async vhost. If we don't pay attention to the management of these indexes, they will eventually overflow and lead to errors. This patch is to check and keep these indexes within a reasonable range.

Ditto. Should mention packed ring here.

Quoted 14 lines
Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")
---
 lib/vhost/virtio_net.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
lib/vhost/virtio_net.c +0 -0
index f4a2c88d8b..61cb5a126c 100644

lib/vhost/virtio_net.c store_dma_desc_info_packed(struct vring_used_elem_packed · line 1618

Quoted 5 lines
lib/vhost/virtio_net.c +1 -0
@@ -1614,6 +1614,7 @@ store_dma_desc_info_packed(struct vring_used_elem_packed
 *s_ring,
 
 	if (d_idx + count <= ring_size) {
 		rte_memcpy(d_ring + d_idx, s_ring + s_idx, count * elem_size);
+

Do we need a blank line here?

Thanks,
Chenbo

Quoted 80 lines
lib/vhost/virtio_net.c +5 -3
 	} else {
 		uint16_t size = ring_size - d_idx;
@@ -2036,7 +2037,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 
 		slot_idx = (vq->async_pkts_idx + num_async_pkts) % vq->size;
 		if (it_pool[it_idx].count) {
-			uint16_t from, to;
+			uint16_t from;
 
 			async_descs_idx += num_descs;
 			async_fill_desc(&tdes[pkt_burst_idx++],
@@ -2055,11 +2056,13 @@ virtio_dev_rx_async_submit_packed(struct virtio_net
 *dev,
 			 * descriptors.
 			 */
 			from = vq->shadow_used_idx - num_buffers;
-			to = vq->async_buffer_idx_packed % vq->size;
 			store_dma_desc_info_packed(vq->shadow_used_packed,
-					vq->async_buffers_packed, vq->size, from, to,
 num_buffers);
+					vq->async_buffers_packed, vq->size, from,
+					vq->async_buffer_idx_packed, num_buffers);
 
 			vq->async_buffer_idx_packed += num_buffers;
+			if (vq->async_buffer_idx_packed >= vq->size)
+				vq->async_buffer_idx_packed -= vq->size;
 			vq->shadow_used_idx -= num_buffers;
lib/vhost/virtio_net.c +2 -0
 		} else {
 			comp_pkts[num_done_pkts++] = pkts[pkt_idx];
@@ -2112,6 +2115,8 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 		dma_error_handler_packed(vq, async_descs, async_descs_idx,
 slot_idx, pkt_err,
 					&pkt_idx, &num_async_pkts, &num_done_pkts);
 	vq->async_pkts_idx += num_async_pkts;
+	if (vq->async_pkts_idx >= vq->size)
+		vq->async_pkts_idx -= vq->size;
 	*comp_count = num_done_pkts;
 
lib/vhost/virtio_net.c +1 -1
 	if (likely(vq->shadow_used_idx)) {
@@ -2160,7 +2165,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue
 *vq,
 	uint16_t from, to;
 
 	do {
-		from = vq->last_async_buffer_idx_packed % vq->size;
+		from = vq->last_async_buffer_idx_packed;
 		to = (from + nr_left) % vq->size;
 		if (to > from) {

vhost_update_used_packed(vq, vq->async_buffers_packed + from,
to - from);

lib/vhost/virtio_net.c +1 -1
@@ -2169,7 +2174,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue
 *vq,
 		} else {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from,
 				vq->size - from);
-			vq->last_async_buffer_idx_packed += vq->size - from;
+			vq->last_async_buffer_idx_packed = 0;
 			nr_left -= vq->size - from;
 		}
lib/vhost/virtio_net.c +5 -2
 	} while (nr_left > 0);
@@ -2252,10 +2257,13 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid,
 uint16_t queue_id,
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
-		if (vq_is_packed(dev))
+		if (vq_is_packed(dev)) {
 			vq->last_async_buffer_idx_packed += n_buffers;
-		else
+			if (vq->last_async_buffer_idx_packed >= vq->size)
+				vq->last_async_buffer_idx_packed -= vq->size;
+		} else {
 			vq->last_async_desc_idx_split += n_descs;
+		}
 	}
 

done:
--
2.29.2

#2 lore raw

Hi Chenbo,

Quoted 19 lines

-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Thursday, July 15, 2021 4:37 PM
To: Jiang, Cheng1 <[email protected]>; [email protected]
Cc: [email protected]; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; [email protected]
Subject: RE: [PATCH] vhost: fix index overflow issue in async vhost

Hi Cheng,

Quoted 8 lines

-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Thursday, July 8, 2021 6:45 PM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH] vhost: fix index overflow issue in async vhost

Quoted 3 lines

Since this fix is packed ring only, maybe 'fix index overflow for packed ring in async vhost' is better.

Sure, that make sense.
I'll fix it in the next version.

Quoted 7 lines
Quoted 5 lines

We introduced some new indexes in async vhost. If we don't pay attention to the management of these indexes, they will eventually overflow and lead to errors. This patch is to check and keep these indexes within a reasonable range.

Ditto. Should mention packed ring here.

Sure.

Quoted 17 lines
Quoted 17 lines
Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")
---
 lib/vhost/virtio_net.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
lib/vhost/virtio_net.c index renamed from lib/vhost/virtio_net.c +0 -0

f4a2c88d8b..61cb5a126c 100644

lib/vhost/virtio_net.c +0 -0
@@ -1614,6 +1614,7 @@ store_dma_desc_info_packed(struct
 vring_used_elem_packed *s_ring,
 
Quoted 5 lines

lib/vhost/virtio_net.c store_dma_desc_info_packed(struct · line 1617

Quoted 2 lines
lib/vhost/virtio_net.c +0 -0
 	if (d_idx + count <= ring_size) {
 		rte_memcpy(d_ring + d_idx, s_ring + s_idx, count *

elem_size);

Quoted 1 line
lib/vhost/virtio_net.c +1 -0
+

Maybe it's a typo. I'll fix it.

Thanks,
Cheng

Quoted 99 lines

Do we need a blank line here?

Thanks,
Chenbo

Quoted 15 lines
lib/vhost/virtio_net.c +1 -1
 	} else {
 		uint16_t size = ring_size - d_idx;
@@ -2036,7 +2037,7 @@ virtio_dev_rx_async_submit_packed(struct
 virtio_net *dev,
 
 		slot_idx = (vq->async_pkts_idx + num_async_pkts) % vq-
 size;
 		if (it_pool[it_idx].count) {
-			uint16_t from, to;
+			uint16_t from;
 
lib/vhost/virtio_net.c +0 -0
 			async_descs_idx += num_descs;
 			async_fill_desc(&tdes[pkt_burst_idx++],

lib/vhost/virtio_net.c virtio_dev_rx_async_submit_packed(struct · line 2062

Quoted 8 lines
lib/vhost/virtio_net.c +0 -2
@@ -2055,11 +2056,13 @@ virtio_dev_rx_async_submit_packed(struct
 virtio_net *dev,
 			 * descriptors.
 			 */
 			from = vq->shadow_used_idx - num_buffers;
-			to = vq->async_buffer_idx_packed % vq->size;
 			store_dma_desc_info_packed(vq-
 shadow_used_packed,
-					vq->async_buffers_packed, vq->size,

from, to,

lib/vhost/virtio_net.c virtio_dev_rx_async_submit_packed(struct · line 2063

Quoted 2 lines
lib/vhost/virtio_net.c +1 -0
 num_buffers);
+					vq->async_buffers_packed, vq->size,

from,

lib/vhost/virtio_net.c virtio_dev_rx_async_submit_packed(struct · line 2064

Quoted 1 line
lib/vhost/virtio_net.c +1 -0
+					vq->async_buffer_idx_packed,

num_buffers);

lib/vhost/virtio_net.c

Quoted 7 lines
lib/vhost/virtio_net.c +2 -0
 			vq->async_buffer_idx_packed += num_buffers;
+			if (vq->async_buffer_idx_packed >= vq->size)
+				vq->async_buffer_idx_packed -= vq->size;
 			vq->shadow_used_idx -= num_buffers;
lib/vhost/virtio_net.c +0 -0
 		} else {
 			comp_pkts[num_done_pkts++] = pkts[pkt_idx]; @@

-2112,6 +2115,8 @@

Quoted 2 lines

virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
dma_error_handler_packed(vq, async_descs,

async_descs_idx,

Quoted 2 lines

slot_idx, pkt_err,
&pkt_idx, &num_async_pkts,

&num_done_pkts);

Quoted 15 lines
lib/vhost/virtio_net.c +3 -1
 	vq->async_pkts_idx += num_async_pkts;
+	if (vq->async_pkts_idx >= vq->size)
+		vq->async_pkts_idx -= vq->size;
 	*comp_count = num_done_pkts;
 
 	if (likely(vq->shadow_used_idx)) {
@@ -2160,7 +2165,7 @@ write_back_completed_descs_packed(struct
 vhost_virtqueue *vq,
 	uint16_t from, to;
 
 	do {
-		from = vq->last_async_buffer_idx_packed % vq->size;
+		from = vq->last_async_buffer_idx_packed;
 		to = (from + nr_left) % vq->size;
 		if (to > from) {
Quoted 3 lines

vhost_update_used_packed(vq, vq-
async_buffers_packed + from, to -
from); @@ -2169,7 +2174,7 @@

write_back_completed_descs_packed(struct

lib/vhost/virtio_net.c

Quoted 6 lines

vhost_virtqueue *vq,

lib/vhost/virtio_net.c +0 -0
 		} else {
 			vhost_update_used_packed(vq, vq-

async_buffers_packed + from,

lib/vhost/virtio_net.c +0 -1
 				vq->size - from);
-			vq->last_async_buffer_idx_packed += vq->size -

from;

lib/vhost/virtio_net.c uint16_t

Quoted 5 lines
lib/vhost/virtio_net.c +1 -0
+			vq->last_async_buffer_idx_packed = 0;
 			nr_left -= vq->size - from;
 		}
 	} while (nr_left > 0);
@@ -2252,10 +2257,13 @@ uint16_t

rte_vhost_poll_enqueue_completed(int

Quoted 19 lines
lib/vhost/virtio_net.c +5 -2
 vid, uint16_t queue_id,
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
-		if (vq_is_packed(dev))
+		if (vq_is_packed(dev)) {
 			vq->last_async_buffer_idx_packed += n_buffers;
-		else
+			if (vq->last_async_buffer_idx_packed >= vq->size)
+				vq->last_async_buffer_idx_packed -= vq-
 size;
+		} else {
 			vq->last_async_desc_idx_split += n_descs;
+		}
 	}

done:
--
2.29.2

#3 lore raw

PATCH v2 1/1 vhost: fix index overflow for packed ring in async vhost

In reply to Cheng Jiang

We introduced some new indexes in packed ring of async vhost. They will eventually overflow and lead to errors if the ring size is not a power of 2. This patch is to check and keep these indexes within a reasonable range.

Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")
---
 lib/vhost/virtio_net.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
lib/vhost/virtio_net.c +14 -7
index f4a2c88d8b..bfb2bf8fc4 100644
@@ -2036,7 +2036,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 
 		slot_idx = (vq->async_pkts_idx + num_async_pkts) % vq->size;
 		if (it_pool[it_idx].count) {
-			uint16_t from, to;
+			uint16_t from;
 
 			async_descs_idx += num_descs;
 			async_fill_desc(&tdes[pkt_burst_idx++],
@@ -2055,11 +2055,13 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 			 * descriptors.
 			 */
 			from = vq->shadow_used_idx - num_buffers;
-			to = vq->async_buffer_idx_packed % vq->size;
 			store_dma_desc_info_packed(vq->shadow_used_packed,
-					vq->async_buffers_packed, vq->size, from, to, num_buffers);
+					vq->async_buffers_packed, vq->size, from,
+					vq->async_buffer_idx_packed, num_buffers);
 
 			vq->async_buffer_idx_packed += num_buffers;
+			if (vq->async_buffer_idx_packed >= vq->size)
+				vq->async_buffer_idx_packed -= vq->size;
 			vq->shadow_used_idx -= num_buffers;
 		} else {
 			comp_pkts[num_done_pkts++] = pkts[pkt_idx];
@@ -2112,6 +2114,8 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 		dma_error_handler_packed(vq, async_descs, async_descs_idx, slot_idx, pkt_err,
 					&pkt_idx, &num_async_pkts, &num_done_pkts);
 	vq->async_pkts_idx += num_async_pkts;
+	if (vq->async_pkts_idx >= vq->size)
+		vq->async_pkts_idx -= vq->size;
 	*comp_count = num_done_pkts;
 
 	if (likely(vq->shadow_used_idx)) {
@@ -2160,7 +2164,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue *vq,
 	uint16_t from, to;
 
 	do {
-		from = vq->last_async_buffer_idx_packed % vq->size;
+		from = vq->last_async_buffer_idx_packed;
 		to = (from + nr_left) % vq->size;
 		if (to > from) {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from, to - from);
@@ -2169,7 +2173,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue *vq,
 		} else {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from,
 				vq->size - from);
-			vq->last_async_buffer_idx_packed += vq->size - from;
+			vq->last_async_buffer_idx_packed = 0;
 			nr_left -= vq->size - from;
 		}
 	} while (nr_left > 0);
@@ -2252,10 +2256,13 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
-		if (vq_is_packed(dev))
+		if (vq_is_packed(dev)) {
 			vq->last_async_buffer_idx_packed += n_buffers;
-		else
+			if (vq->last_async_buffer_idx_packed >= vq->size)
+				vq->last_async_buffer_idx_packed -= vq->size;
+		} else {
 			vq->last_async_desc_idx_split += n_descs;
+		}
 	}
 
 done:
Signature · 1 line
2.29.2
Reviewed-by on v2 1/1
#4 lore raw

Re: [dpdk-dev] [PATCH v2] vhost: fix index overflow for packed ring in async vhost

Quoted 100 lines

-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Thursday, July 15, 2021 5:51 PM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: fix index overflow for packed ring in async vhost

We introduced some new indexes in packed ring of async vhost. They will eventually overflow and lead to errors if the ring size is not a power of 2. This patch is to check and keep these indexes within a reasonable range.

Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")
---
 lib/vhost/virtio_net.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
lib/vhost/virtio_net.c +5 -3
index f4a2c88d8b..bfb2bf8fc4 100644
@@ -2036,7 +2036,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 
 		slot_idx = (vq->async_pkts_idx + num_async_pkts) % vq->size;
 		if (it_pool[it_idx].count) {
-			uint16_t from, to;
+			uint16_t from;
 
 			async_descs_idx += num_descs;
 			async_fill_desc(&tdes[pkt_burst_idx++],
@@ -2055,11 +2055,13 @@ virtio_dev_rx_async_submit_packed(struct virtio_net
 *dev,
 			 * descriptors.
 			 */
 			from = vq->shadow_used_idx - num_buffers;
-			to = vq->async_buffer_idx_packed % vq->size;
 			store_dma_desc_info_packed(vq->shadow_used_packed,
-					vq->async_buffers_packed, vq->size, from, to,
 num_buffers);
+					vq->async_buffers_packed, vq->size, from,
+					vq->async_buffer_idx_packed, num_buffers);
 
 			vq->async_buffer_idx_packed += num_buffers;
+			if (vq->async_buffer_idx_packed >= vq->size)
+				vq->async_buffer_idx_packed -= vq->size;
 			vq->shadow_used_idx -= num_buffers;
lib/vhost/virtio_net.c +2 -0
 		} else {
 			comp_pkts[num_done_pkts++] = pkts[pkt_idx];
@@ -2112,6 +2114,8 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev,
 		dma_error_handler_packed(vq, async_descs, async_descs_idx,
 slot_idx, pkt_err,
 					&pkt_idx, &num_async_pkts, &num_done_pkts);
 	vq->async_pkts_idx += num_async_pkts;
+	if (vq->async_pkts_idx >= vq->size)
+		vq->async_pkts_idx -= vq->size;
 	*comp_count = num_done_pkts;
 
lib/vhost/virtio_net.c +1 -1
 	if (likely(vq->shadow_used_idx)) {
@@ -2160,7 +2164,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue
 *vq,
 	uint16_t from, to;
 
 	do {
-		from = vq->last_async_buffer_idx_packed % vq->size;
+		from = vq->last_async_buffer_idx_packed;
 		to = (from + nr_left) % vq->size;
 		if (to > from) {

vhost_update_used_packed(vq, vq->async_buffers_packed + from,
to - from);

lib/vhost/virtio_net.c +1 -1
@@ -2169,7 +2173,7 @@ write_back_completed_descs_packed(struct vhost_virtqueue
 *vq,
 		} else {
 			vhost_update_used_packed(vq, vq->async_buffers_packed + from,
 				vq->size - from);
-			vq->last_async_buffer_idx_packed += vq->size - from;
+			vq->last_async_buffer_idx_packed = 0;
 			nr_left -= vq->size - from;
 		}
lib/vhost/virtio_net.c +5 -2
 	} while (nr_left > 0);
@@ -2252,10 +2256,13 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid,
 uint16_t queue_id,
 			vhost_vring_call_split(dev, vq);
 		}
 	} else {
-		if (vq_is_packed(dev))
+		if (vq_is_packed(dev)) {
 			vq->last_async_buffer_idx_packed += n_buffers;
-		else
+			if (vq->last_async_buffer_idx_packed >= vq->size)
+				vq->last_async_buffer_idx_packed -= vq->size;
+		} else {
 			vq->last_async_desc_idx_split += n_descs;
+		}
 	}
 
Quoted 3 lines

done:
--
2.29.2

Applied
#5 lore raw

Re: [dpdk-dev] [PATCH v2] vhost: fix index overflow for packed ring in async vhost

In reply to Cheng Jiang
Quoted 14 lines

-----Original Message-----
From: Jiang, Cheng1 <[email protected]>
Sent: Thursday, July 15, 2021 5:51 PM
To: [email protected]; Xia, Chenbo <[email protected]>
Cc: [email protected]; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Jiang, Cheng1 <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: fix index overflow for packed ring in async vhost

We introduced some new indexes in packed ring of async vhost. They will eventually overflow and lead to errors if the ring size is not a power of 2. This patch is to check and keep these indexes within a reasonable range.

Quoted 7 lines
Fixes 873e8dad6f49 ("vhost: support packed ring in async datapath")

---
--
2.29.2

Applied to next-virtio/main, thanks.