[v2] net/iavf: fix mbuf leak

Message ID 20210910083138.12867-1-chenqiming_huawei@163.com (mailing list archive)
State Changes Requested, archived
Delegated to: Qi Zhang
Headers
Series [v2] net/iavf: fix mbuf leak |

Checks

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

Commit Message

Qiming Chen Sept. 10, 2021, 8:31 a.m. UTC
  In the iavf_dev_rx_queue_start function, if the iavf_switch_queue
or iavf_switch_queue_lv function fails, the previously applied mbuf
is not released, resulting in leakage. The patch fixes the problem.

Fixes: 9cf9c02bf6ee ("net/iavf: add enable/disable queues for large VF")
Cc: stable@dpdk.org

Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
---
v2:
  Modify coding style warning.
---
 drivers/net/iavf/iavf_rxtx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Qi Zhang Sept. 15, 2021, 3:27 a.m. UTC | #1
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Qiming Chen
> Sent: Friday, September 10, 2021 4:32 PM
> To: dev@dpdk.org
> Cc: Xing, Beilei <beilei.xing@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>;
> Qiming Chen <chenqiming_huawei@163.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH v2] net/iavf: fix mbuf leak
> 
> In the iavf_dev_rx_queue_start function, if the iavf_switch_queue or
> iavf_switch_queue_lv function fails, the previously applied mbuf is not
> released, resulting in leakage. The patch fixes the problem.
> 
> Fixes: 9cf9c02bf6ee ("net/iavf: add enable/disable queues for large VF")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Qiming Chen <chenqiming_huawei@163.com>
> ---
> v2:
>   Modify coding style warning.
> ---
>  drivers/net/iavf/iavf_rxtx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c index
> e33fe4576b..55393a9400 100644
> --- a/drivers/net/iavf/iavf_rxtx.c
> +++ b/drivers/net/iavf/iavf_rxtx.c
> @@ -848,12 +848,14 @@ iavf_dev_rx_queue_start(struct rte_eth_dev *dev,
> uint16_t rx_queue_id)
>  	else
>  		err = iavf_switch_queue_lv(adapter, rx_queue_id, true, true);
> 
> -	if (err)
> +	if (err) {
> +		release_rxq_mbufs(rxq);

This looks good, but I saw another potential memory leak in " alloc_rxq_mbufs",
It is the case when only part of the memory are available, the already allocated mbuf not be released before return -ENOMEM

for (i = 0; i < rxq->nb_rx_desc; i++) {
            	mbuf = rte_mbuf_raw_alloc(rxq->mp);
                if (unlikely(!mbuf)) {
                        PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
                        return -ENOMEM;
                }
Do you mind to merge them into the same patch?  Thanks.

>  		PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
>  			    rx_queue_id);
> -	else
> +	} else {
>  		dev->data->rx_queue_state[rx_queue_id] =
>  			RTE_ETH_QUEUE_STATE_STARTED;
> +	}
> 
>  	return err;
>  }
> --
> 2.30.1.windows.1
  

Patch

diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c
index e33fe4576b..55393a9400 100644
--- a/drivers/net/iavf/iavf_rxtx.c
+++ b/drivers/net/iavf/iavf_rxtx.c
@@ -848,12 +848,14 @@  iavf_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 	else
 		err = iavf_switch_queue_lv(adapter, rx_queue_id, true, true);
 
-	if (err)
+	if (err) {
+		release_rxq_mbufs(rxq);
 		PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
 			    rx_queue_id);
-	else
+	} else {
 		dev->data->rx_queue_state[rx_queue_id] =
 			RTE_ETH_QUEUE_STATE_STARTED;
+	}
 
 	return err;
 }