patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
@ 2020-09-29 13:44 wangyunjian
  2020-09-30 22:27 ` Long Li
  2020-10-07  2:06 ` [dpdk-stable] [dpdk-dev] [PATCH v2] " wangyunjian
  0 siblings, 2 replies; 6+ messages in thread
From: wangyunjian @ 2020-09-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: sthemmin, kys, haiyangz, longli, jerry.lilijun, xudingke,
	Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

In hn_dev_tx_queue_setup() allocated memory for txq,
we should free it when error happens, otherwise it
will lead to memory leak.

Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/netvsc/hn_rxtx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
index 65f1abae5..8c94e7ee3 100644
--- a/drivers/net/netvsc/hn_rxtx.c
+++ b/drivers/net/netvsc/hn_rxtx.c
@@ -273,6 +273,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
 			     nb_desc - 3,
 			     tx_free_thresh, dev->data->port_id, queue_idx);
+		rte_free(txq);
 		return -EINVAL;
 	}
 
-- 
2.23.0


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

* Re: [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
  2020-09-29 13:44 [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path wangyunjian
@ 2020-09-30 22:27 ` Long Li
  2020-10-02 14:25   ` Yunjian Wang
  2020-10-07  2:06 ` [dpdk-stable] [dpdk-dev] [PATCH v2] " wangyunjian
  1 sibling, 1 reply; 6+ messages in thread
From: Long Li @ 2020-09-30 22:27 UTC (permalink / raw)
  To: wangyunjian, dev
  Cc: Stephen Hemminger, KY Srinivasan, Haiyang Zhang, jerry.lilijun,
	xudingke, stable

>Subject: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
>
>From: Yunjian Wang <wangyunjian@huawei.com>
>
>In hn_dev_tx_queue_setup() allocated memory for txq, we should free it
>when error happens, otherwise it will lead to memory leak.
>
>Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>Cc: stable@dpdk.org
>
>Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>---
> drivers/net/netvsc/hn_rxtx.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
>index 65f1abae5..8c94e7ee3 100644
>--- a/drivers/net/netvsc/hn_rxtx.c
>+++ b/drivers/net/netvsc/hn_rxtx.c
>@@ -273,6 +273,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
> 			     nb_desc - 3,
> 			     tx_free_thresh, dev->data->port_id, queue_idx);
>+		rte_free(txq);
> 		return -EINVAL;
> 	}
>
>--
>2.23.0

How about checking for tx_free_thresh at the beginning of the function, before calling txq = rte_zmalloc_socket()? 

This way, you don't' need to call rte_free() on error.

Long

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

* Re: [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
  2020-09-30 22:27 ` Long Li
@ 2020-10-02 14:25   ` Yunjian Wang
  0 siblings, 0 replies; 6+ messages in thread
From: Yunjian Wang @ 2020-10-02 14:25 UTC (permalink / raw)
  To: Long Li, wangyunjian, dev
  Cc: Stephen Hemminger, KY Srinivasan, Haiyang Zhang, jerry.lilijun,
	xudingke, stable

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Long Li
> Sent: Thursday, October 1, 2020 6:27 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Stephen Hemminger <sthemmin@microsoft.com>; KY Srinivasan
> <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>;
> jerry.lilijun@huawei.com; xudingke@huawei.com; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
> 
> >Subject: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
> >
> >From: Yunjian Wang <wangyunjian@huawei.com>
> >
> >In hn_dev_tx_queue_setup() allocated memory for txq, we should free it
> >when error happens, otherwise it will lead to memory leak.
> >
> >Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx
> >descriptors")
> >Cc: stable@dpdk.org
> >
> >Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> >---
> > drivers/net/netvsc/hn_rxtx.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> >diff --git a/drivers/net/netvsc/hn_rxtx.c
> >b/drivers/net/netvsc/hn_rxtx.c index 65f1abae5..8c94e7ee3 100644
> >--- a/drivers/net/netvsc/hn_rxtx.c
> >+++ b/drivers/net/netvsc/hn_rxtx.c
> >@@ -273,6 +273,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> > 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
> > 			     nb_desc - 3,
> > 			     tx_free_thresh, dev->data->port_id, queue_idx);
> >+		rte_free(txq);
> > 		return -EINVAL;
> > 	}
> >
> >--
> >2.23.0
> 
> How about checking for tx_free_thresh at the beginning of the function,
> before calling txq = rte_zmalloc_socket()?
> 
> This way, you don't' need to call rte_free() on error.

OK, I will fix it in next version.

Thanks,
Yunjian

> 
> Long


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

* [dpdk-stable] [dpdk-dev] [PATCH v2] net/netvsc: fix txq leak in error path
  2020-09-29 13:44 [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path wangyunjian
  2020-09-30 22:27 ` Long Li
@ 2020-10-07  2:06 ` wangyunjian
  2020-10-09  3:53   ` Long Li
  1 sibling, 1 reply; 6+ messages in thread
From: wangyunjian @ 2020-10-07  2:06 UTC (permalink / raw)
  To: dev
  Cc: longli, sthemmin, kys, haiyangz, jerry.lilijun, xudingke,
	Yunjian Wang, stable

From: Yunjian Wang <wangyunjian@huawei.com>

In hn_dev_tx_queue_setup() allocated memory for txq, we don't free it
when error happens and it will lead to memory leak.

We can check for tx_free_thresh at the beginning of the function to
fix it, before calling txq = rte_zmalloc_socket().

Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
  fix code styles suggested by Long Li
---
 drivers/net/netvsc/hn_rxtx.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
index 65f1abae5..5d59db513 100644
--- a/drivers/net/netvsc/hn_rxtx.c
+++ b/drivers/net/netvsc/hn_rxtx.c
@@ -252,16 +252,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq), RTE_CACHE_LINE_SIZE,
-				 socket_id);
-	if (!txq)
-		return -ENOMEM;
-
-	txq->hv = hv;
-	txq->chan = hv->channels[queue_idx];
-	txq->port_id = dev->data->port_id;
-	txq->queue_id = queue_idx;
-
 	tx_free_thresh = tx_conf->tx_free_thresh;
 	if (tx_free_thresh == 0)
 		tx_free_thresh = RTE_MIN(nb_desc / 4,
@@ -276,6 +266,15 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq), RTE_CACHE_LINE_SIZE,
+				 socket_id);
+	if (!txq)
+		return -ENOMEM;
+
+	txq->hv = hv;
+	txq->chan = hv->channels[queue_idx];
+	txq->port_id = dev->data->port_id;
+	txq->queue_id = queue_idx;
 	txq->free_thresh = tx_free_thresh;
 
 	snprintf(name, sizeof(name),
-- 
2.23.0


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

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] net/netvsc: fix txq leak in error path
  2020-10-07  2:06 ` [dpdk-stable] [dpdk-dev] [PATCH v2] " wangyunjian
@ 2020-10-09  3:53   ` Long Li
  2020-10-09 11:36     ` Ferruh Yigit
  0 siblings, 1 reply; 6+ messages in thread
From: Long Li @ 2020-10-09  3:53 UTC (permalink / raw)
  To: wangyunjian, dev
  Cc: Stephen Hemminger, KY Srinivasan, Haiyang Zhang, jerry.lilijun,
	xudingke, stable

>Subject: [dpdk-dev] [PATCH v2] net/netvsc: fix txq leak in error path
>
>From: Yunjian Wang <wangyunjian@huawei.com>
>
>In hn_dev_tx_queue_setup() allocated memory for txq, we don't free it
>when error happens and it will lead to memory leak.
>
>We can check for tx_free_thresh at the beginning of the function to fix it,
>before calling txq = rte_zmalloc_socket().
>
>Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>Cc: stable@dpdk.org
>
>Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>

Acked-by: Long Li <longli@microsoft.com>
>---
>v2:
>  fix code styles suggested by Long Li
>---
> drivers/net/netvsc/hn_rxtx.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
>diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
>index 65f1abae5..5d59db513 100644
>--- a/drivers/net/netvsc/hn_rxtx.c
>+++ b/drivers/net/netvsc/hn_rxtx.c
>@@ -252,16 +252,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
>
> 	PMD_INIT_FUNC_TRACE();
>
>-	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq),
>RTE_CACHE_LINE_SIZE,
>-				 socket_id);
>-	if (!txq)
>-		return -ENOMEM;
>-
>-	txq->hv = hv;
>-	txq->chan = hv->channels[queue_idx];
>-	txq->port_id = dev->data->port_id;
>-	txq->queue_id = queue_idx;
>-
> 	tx_free_thresh = tx_conf->tx_free_thresh;
> 	if (tx_free_thresh == 0)
> 		tx_free_thresh = RTE_MIN(nb_desc / 4, @@ -276,6 +266,15
>@@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> 		return -EINVAL;
> 	}
>
>+	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq),
>RTE_CACHE_LINE_SIZE,
>+				 socket_id);
>+	if (!txq)
>+		return -ENOMEM;
>+
>+	txq->hv = hv;
>+	txq->chan = hv->channels[queue_idx];
>+	txq->port_id = dev->data->port_id;
>+	txq->queue_id = queue_idx;
> 	txq->free_thresh = tx_free_thresh;
>
> 	snprintf(name, sizeof(name),
>--
>2.23.0


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

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] net/netvsc: fix txq leak in error path
  2020-10-09  3:53   ` Long Li
@ 2020-10-09 11:36     ` Ferruh Yigit
  0 siblings, 0 replies; 6+ messages in thread
From: Ferruh Yigit @ 2020-10-09 11:36 UTC (permalink / raw)
  To: Long Li, wangyunjian, dev
  Cc: Stephen Hemminger, KY Srinivasan, Haiyang Zhang, jerry.lilijun,
	xudingke, stable

On 10/9/2020 4:53 AM, Long Li wrote:
>> Subject: [dpdk-dev] [PATCH v2] net/netvsc: fix txq leak in error path
>>
>> From: Yunjian Wang <wangyunjian@huawei.com>
>>
>> In hn_dev_tx_queue_setup() allocated memory for txq, we don't free it
>> when error happens and it will lead to memory leak.
>>
>> We can check for tx_free_thresh at the beginning of the function to fix it,
>> before calling txq = rte_zmalloc_socket().
>>
>> Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> 
> Acked-by: Long Li <longli@microsoft.com>
 >

Applied to dpdk-next-net/main, thanks.

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

end of thread, other threads:[~2020-10-09 11:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 13:44 [dpdk-stable] [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path wangyunjian
2020-09-30 22:27 ` Long Li
2020-10-02 14:25   ` Yunjian Wang
2020-10-07  2:06 ` [dpdk-stable] [dpdk-dev] [PATCH v2] " wangyunjian
2020-10-09  3:53   ` Long Li
2020-10-09 11:36     ` Ferruh Yigit

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git