net/virtio: fix vectorized path receive oversized packets

Message ID 20210926092842.26103-1-yong.liu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: fix vectorized path receive oversized packets |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Marvin Liu Sept. 26, 2021, 9:28 a.m. UTC
  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 <yong.liu@intel.com>
  

Comments

Maxime Coquelin Oct. 15, 2021, 12:20 p.m. UTC | #1
On 9/26/21 11:28, Marvin Liu wrote:
> 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 <yong.liu@intel.com>
> 
> 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])) {
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Maxime Coquelin Oct. 21, 2021, 12:28 p.m. UTC | #2
On 9/26/21 11:28, Marvin Liu wrote:
> 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 <yong.liu@intel.com>
> 
> 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])) {
> 


Applied to dpdk-next-virtio/main.

Thanks,
Maxime
  

Patch

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])) {