DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/iavf: fix mbuf leak
@ 2021-09-10  8:23 Qiming Chen
  2021-09-10  8:31 ` [dpdk-dev] [PATCH v2] " Qiming Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Qiming Chen @ 2021-09-10  8:23 UTC (permalink / raw)
  To: dev; +Cc: beilei.xing, jingjing.wu, Qiming Chen, stable

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
---
 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);
 		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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2] net/iavf: fix mbuf leak
  2021-09-10  8:23 [dpdk-dev] [PATCH] net/iavf: fix mbuf leak Qiming Chen
@ 2021-09-10  8:31 ` Qiming Chen
  2021-09-15  3:27   ` Zhang, Qi Z
  2021-09-16 14:04   ` Qiming Chen
  0 siblings, 2 replies; 5+ messages in thread
From: Qiming Chen @ 2021-09-10  8:31 UTC (permalink / raw)
  To: dev; +Cc: beilei.xing, jingjing.wu, Qiming Chen, stable

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);
 		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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/iavf: fix mbuf leak
  2021-09-10  8:31 ` [dpdk-dev] [PATCH v2] " Qiming Chen
@ 2021-09-15  3:27   ` Zhang, Qi Z
  2021-09-16 14:04   ` Qiming Chen
  1 sibling, 0 replies; 5+ messages in thread
From: Zhang, Qi Z @ 2021-09-15  3:27 UTC (permalink / raw)
  To: Qiming Chen, dev; +Cc: Xing, Beilei, Wu, Jingjing, stable



> -----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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [PATCH v2] net/iavf: fix mbuf leak
  2021-09-10  8:31 ` [dpdk-dev] [PATCH v2] " Qiming Chen
  2021-09-15  3:27   ` Zhang, Qi Z
@ 2021-09-16 14:04   ` Qiming Chen
  2021-09-22  7:04     ` Zhang, Qi Z
  1 sibling, 1 reply; 5+ messages in thread
From: Qiming Chen @ 2021-09-16 14:04 UTC (permalink / raw)
  To: dev; +Cc: beilei.xing, jingjing.wu, Qiming Chen, stable

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:
  Solve the potential mbuf leak of the alloc_rxq_mbufs function itself.
---
 drivers/net/iavf/iavf_rxtx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/iavf/iavf_rxtx.c b/drivers/net/iavf/iavf_rxtx.c
index e33fe4576b..7ec4f241e2 100644
--- a/drivers/net/iavf/iavf_rxtx.c
+++ b/drivers/net/iavf/iavf_rxtx.c
@@ -274,11 +274,15 @@ alloc_rxq_mbufs(struct iavf_rx_queue *rxq)
 	volatile union iavf_rx_desc *rxd;
 	struct rte_mbuf *mbuf = NULL;
 	uint64_t dma_addr;
-	uint16_t i;
+	uint16_t i, j;
 
 	for (i = 0; i < rxq->nb_rx_desc; i++) {
 		mbuf = rte_mbuf_raw_alloc(rxq->mp);
 		if (unlikely(!mbuf)) {
+			for (j = 0; j < i; j++) {
+				rte_pktmbuf_free_seg(rxq->sw_ring[j]);
+				rxq->sw_ring[j] = NULL;
+			}
 			PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
 			return -ENOMEM;
 		}
@@ -848,12 +852,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;
 }
-- 
2.30.1.windows.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/iavf: fix mbuf leak
  2021-09-16 14:04   ` Qiming Chen
@ 2021-09-22  7:04     ` Zhang, Qi Z
  0 siblings, 0 replies; 5+ messages in thread
From: Zhang, Qi Z @ 2021-09-22  7:04 UTC (permalink / raw)
  To: Qiming Chen, dev; +Cc: Xing, Beilei, Wu, Jingjing, stable



> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Qiming Chen
> Sent: Thursday, September 16, 2021 10:04 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>

Acked-by: Qi Zhang <qi.z.zhang@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-22  7:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10  8:23 [dpdk-dev] [PATCH] net/iavf: fix mbuf leak Qiming Chen
2021-09-10  8:31 ` [dpdk-dev] [PATCH v2] " Qiming Chen
2021-09-15  3:27   ` Zhang, Qi Z
2021-09-16 14:04   ` Qiming Chen
2021-09-22  7:04     ` Zhang, Qi Z

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).