From patchwork Sun Sep 26 09:28:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Liu X-Patchwork-Id: 99660 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 752BAA0548; Sun, 26 Sep 2021 04:07:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EEBED4003D; Sun, 26 Sep 2021 04:07:43 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id E43D34003C; Sun, 26 Sep 2021 04:07:41 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10118"; a="287973198" X-IronPort-AV: E=Sophos;i="5.85,322,1624345200"; d="scan'208";a="287973198" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2021 19:07:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,322,1624345200"; d="scan'208";a="552322990" Received: from npg-dpdk-virtual-marvin-dev.sh.intel.com ([10.67.118.197]) by FMSMGA003.fm.intel.com with ESMTP; 25 Sep 2021 19:07:39 -0700 From: Marvin Liu To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, Marvin Liu , stable@dpdk.org Date: Sun, 26 Sep 2021 17:28:42 +0800 Message-Id: <20210926092842.26103-1-yong.liu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] net/virtio: fix vectorized path receive oversized packets X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 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])) {