From patchwork Thu Aug 31 12:33:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 130986 X-Patchwork-Delegate: qi.z.zhang@intel.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 EA2F141FDD; Thu, 31 Aug 2023 14:34:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6E85F402A0; Thu, 31 Aug 2023 14:33:58 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 56AB540294; Thu, 31 Aug 2023 14:33:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693485236; x=1725021236; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dNHN+xna00zMIdi2cuOsslBvvYiBON4ybUk45AVelSs=; b=M4TGAFcxahYizmAKue1X0cyTvtbNVoY+5Vq/1K3wRRkEOh8KAuv2eOLW SsMU3hfJHbtXjmAXKQ0qonjs2YMIkdTIAqg0hFdEEOV890cPAh4DmJOEv yG1zuBnUUpnnsyfpi79BdAmLTFZFLfPAo0H3BKMmRuwIjeGbgfZzhJnNg 93YOYndRdzfu9eqIpOHyPVbD9LGU8t/lYZJZdSf8H3c3qFi2LmJZl3T7z 6wLwdToKBjD5ENMBvaezLN4j1GEQ+lZ1JgPW9cy+mwI319Qin7CGrR/g2 JTMfF2bYbB7btT5D+l0tLfyIvcVgv1WT3bI+jdVnuCCLT91a5+k/4K4Qc w==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="439873991" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="439873991" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 05:33:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="913230934" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="913230934" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga005.jf.intel.com with ESMTP; 31 Aug 2023 05:33:54 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , wenzhuo.lu@intel.com, jingjing.wu@intel.com, stable@dpdk.org Subject: [PATCH v2 2/4] net/iavf: fix buffer leak on Tx queue stop Date: Thu, 31 Aug 2023 13:33:35 +0100 Message-Id: <20230831123337.871496-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230831123337.871496-1-bruce.richardson@intel.com> References: <20230830155919.592390-1-bruce.richardson@intel.com> <20230831123337.871496-1-bruce.richardson@intel.com> MIME-Version: 1.0 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 When a queue is stopped all buffers are meant to released from it, and then a new set of buffers reallocated on start. For the iavf code when using vector Tx, some buffers were left in the ring, and so those buffers were leaked. The buffers were missed as the release code only handled one side of a wrap-around case in the ring. Fix the issue by doing a single iteration of the ring freeing all buffers in it, handling wraparound through a simple post-increment check. Fixes: 319c421f3890 ("net/avf: enable SSE Rx Tx") Fixes: 9ab9514c150e ("net/iavf: enable AVX512 for Tx") Cc: wenzhuo.lu@intel.com Cc: jingjing.wu@intel.com Cc: stable@dpdk.org Signed-off-by: Bruce Richardson Acked-by: Wenzhuo Lu --- drivers/net/iavf/iavf_rxtx_vec_avx512.c | 17 ++++++++--------- drivers/net/iavf/iavf_rxtx_vec_common.h | 11 +++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/net/iavf/iavf_rxtx_vec_avx512.c b/drivers/net/iavf/iavf_rxtx_vec_avx512.c index 3e66df5341..48337d5e03 100644 --- a/drivers/net/iavf/iavf_rxtx_vec_avx512.c +++ b/drivers/net/iavf/iavf_rxtx_vec_avx512.c @@ -2460,20 +2460,19 @@ iavf_tx_queue_release_mbufs_avx512(struct iavf_tx_queue *txq) { unsigned int i; const uint16_t max_desc = (uint16_t)(txq->nb_tx_desc - 1); + const uint16_t end_desc = txq->tx_tail >> txq->use_ctx; /* next empty slot */ + const uint16_t wrap_point = txq->nb_tx_desc >> txq->use_ctx; /* end of SW ring */ struct iavf_tx_vec_entry *swr = (void *)txq->sw_ring; if (!txq->sw_ring || txq->nb_free == max_desc) return; - i = (txq->next_dd >> txq->use_ctx) + 1 - - (txq->rs_thresh >> txq->use_ctx); - - if (txq->tx_tail < i) { - for (; i < (unsigned int)(txq->nb_tx_desc >> txq->use_ctx); i++) { - rte_pktmbuf_free_seg(swr[i].mbuf); - swr[i].mbuf = NULL; - } - i = 0; + i = (txq->next_dd - txq->rs_thresh + 1) >> txq->use_ctx; + while (i != end_desc) { + rte_pktmbuf_free_seg(swr[i].mbuf); + swr[i].mbuf = NULL; + if (++i == wrap_point) + i = 0; } } diff --git a/drivers/net/iavf/iavf_rxtx_vec_common.h b/drivers/net/iavf/iavf_rxtx_vec_common.h index ddb13ce8c3..1fac957fe1 100644 --- a/drivers/net/iavf/iavf_rxtx_vec_common.h +++ b/drivers/net/iavf/iavf_rxtx_vec_common.h @@ -186,12 +186,11 @@ _iavf_tx_queue_release_mbufs_vec(struct iavf_tx_queue *txq) return; i = txq->next_dd - txq->rs_thresh + 1; - if (txq->tx_tail < i) { - for (; i < txq->nb_tx_desc; i++) { - rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf); - txq->sw_ring[i].mbuf = NULL; - } - i = 0; + while (i != txq->tx_tail) { + rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf); + txq->sw_ring[i].mbuf = NULL; + if (++i == txq->nb_tx_desc) + i = 0; } }