Skip to contentSkip to conversation

net/virtio: fix vectorized path receive oversized packets

PATCH Applied Marvin Liu 2 participants 3 messages Sep 26, 2021 – Oct 21, 2021 Network drivers

lore
Share & tools
lore

Marvin Liu

author
#0 lore raw

PATCH 1/1 net/virtio: fix vectorized path receive oversized packets

If packed ring size is not power of two, it is possible that remained number less than one batch and meanwhile batch operation can pass. This will cause incorrect remained number calculation and then lead to receiving oversized packets. The patch fixed the issue by added remained number check before batch operation.

Fixes 77d66da83834 ("net/virtio: add vectorized packed ring Rx")
drivers/net/virtio/virtio_rxtx_packed.c +7 -5
index ab489a58af..45cf39df22 100644
@@ -95,11 +95,13 @@ virtio_recv_pkts_packed_vec(void *rx_queue,
 		num = num - ((vq->vq_used_cons_idx + num) % PACKED_BATCH_SIZE);
 
 	while (num) {
-		if (!virtqueue_dequeue_batch_packed_vec(rxvq,
-					&rx_pkts[nb_rx])) {
-			nb_rx += PACKED_BATCH_SIZE;
-			num -= PACKED_BATCH_SIZE;
-			continue;
+		if (num >= PACKED_BATCH_SIZE) {
+			if (!virtqueue_dequeue_batch_packed_vec(rxvq,
+						&rx_pkts[nb_rx])) {
+				nb_rx += PACKED_BATCH_SIZE;
+				num -= PACKED_BATCH_SIZE;
+				continue;
+			}
 		}
 		if (!virtqueue_dequeue_single_packed_vec(rxvq,
 					&rx_pkts[nb_rx])) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Marvin Liu

If packed ring size is not power of two, it is possible that remained number less than one batch and meanwhile batch operation can pass. This will cause incorrect remained number calculation and then lead to receiving oversized packets. The patch fixed the issue by added remained number check before batch operation.

Fixes 77d66da83834 ("net/virtio: add vectorized packed ring Rx")
drivers/net/virtio/virtio_rxtx_packed.c +0 -5
index ab489a58af..45cf39df22 100644
@@ -95,11 +95,13 @@ virtio_recv_pkts_packed_vec(void *rx_queue,
  		num = num - ((vq->vq_used_cons_idx + num) % PACKED_BATCH_SIZE);
 
  	while (num) {
-		if (!virtqueue_dequeue_batch_packed_vec(rxvq,
-					&rx_pkts[nb_rx])) {
-			nb_rx += PACKED_BATCH_SIZE;
-			num -= PACKED_BATCH_SIZE;
-			continue;

drivers/net/virtio/virtio_rxtx_packed.c virtio_recv_pkts_packed_vec(void *rx_queue, · line 107

Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed.c +7 -0
+		if (num >= PACKED_BATCH_SIZE) {
+			if (!virtqueue_dequeue_batch_packed_vec(rxvq,
+						&rx_pkts[nb_rx])) {
+				nb_rx += PACKED_BATCH_SIZE;
+				num -= PACKED_BATCH_SIZE;
+				continue;
+			}
  		}
  		if (!virtqueue_dequeue_single_packed_vec(rxvq,
  					&rx_pkts[nb_rx])) {

Thanks,
Maxime

#2 lore raw
In reply to Marvin Liu
Quoted 25 lines · Marvin Liu

If packed ring size is not power of two, it is possible that remained number less than one batch and meanwhile batch operation can pass. This will cause incorrect remained number calculation and then lead to receiving oversized packets. The patch fixed the issue by added remained number check before batch operation.

Fixes 77d66da83834 ("net/virtio: add vectorized packed ring Rx")
drivers/net/virtio/virtio_rxtx_packed.c +0 -5
index ab489a58af..45cf39df22 100644
@@ -95,11 +95,13 @@ virtio_recv_pkts_packed_vec(void *rx_queue,
  		num = num - ((vq->vq_used_cons_idx + num) % PACKED_BATCH_SIZE);
 
  	while (num) {
-		if (!virtqueue_dequeue_batch_packed_vec(rxvq,
-					&rx_pkts[nb_rx])) {
-			nb_rx += PACKED_BATCH_SIZE;
-			num -= PACKED_BATCH_SIZE;
-			continue;

drivers/net/virtio/virtio_rxtx_packed.c virtio_recv_pkts_packed_vec(void *rx_queue, · line 107

Quoted 10 lines
drivers/net/virtio/virtio_rxtx_packed.c +7 -0
+		if (num >= PACKED_BATCH_SIZE) {
+			if (!virtqueue_dequeue_batch_packed_vec(rxvq,
+						&rx_pkts[nb_rx])) {
+				nb_rx += PACKED_BATCH_SIZE;
+				num -= PACKED_BATCH_SIZE;
+				continue;
+			}
  		}
  		if (!virtqueue_dequeue_single_packed_vec(rxvq,
  					&rx_pkts[nb_rx])) {

Applied to dpdk-next-virtio/main.

Thanks,
Maxime