From 99ebada2d6d9db23be39f737f26c7bf5f0a26b9c Mon Sep 17 00:00:00 2001 From: Marvin Liu Date: Sun, 26 Sep 2021 17:28:42 +0800 Subject: [PATCH] net/virtio: fix oversized packets in vectorized Rx 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") Cc: stable@dpdk.org Signed-off-by: Marvin Liu Reviewed-by: Maxime Coquelin --- drivers/net/virtio/virtio_rxtx_packed.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx_packed.c b/drivers/net/virtio/virtio_rxtx_packed.c index ab489a58af..45cf39df22 100644 --- a/drivers/net/virtio/virtio_rxtx_packed.c +++ b/drivers/net/virtio/virtio_rxtx_packed.c @@ -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])) { -- 2.20.1