net/bonding: fix memory leak on closing device

Message ID 20210915050802.454669-1-dapengx.yu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/bonding: fix memory leak on closing device |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
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/Intel-compilation success Compilation OK
ci/intel-Testing fail Testing issues
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Yu, DapengX Sept. 15, 2021, 5:08 a.m. UTC
  From: Dapeng Yu <dapengx.yu@intel.com>

If the bond device was created by vdev mode, the kvlist was not free
after the bond device was closed.

This patch fixes it.

Fixes: 144dc4739975 ("net/bonding: fix leak on remove")
Cc: stable@dpdk.org

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
---
 drivers/net/bonding/rte_eth_bond_pmd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

humin (Q) Sept. 15, 2021, 6:58 a.m. UTC | #1
Hi, dapengx,
	Why not free internals->kvlist at the end of "bond_ethdev_configure" ? 
Does it call some bugs?

在 2021/9/15 13:08, dapengx.yu@intel.com 写道:
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> If the bond device was created by vdev mode, the kvlist was not free
> after the bond device was closed.
> 
> This patch fixes it.
> 
> Fixes: 144dc4739975 ("net/bonding: fix leak on remove")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>   drivers/net/bonding/rte_eth_bond_pmd.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
> index a6755661c4..2e96b850fb 100644
> --- a/drivers/net/bonding/rte_eth_bond_pmd.c
> +++ b/drivers/net/bonding/rte_eth_bond_pmd.c
> @@ -2163,6 +2163,9 @@ bond_ethdev_close(struct rte_eth_dev *dev)
>   	 */
>   	rte_mempool_free(internals->mode6.mempool);
>   
> +	if (internals->kvlist != NULL)
> +		rte_kvargs_free(internals->kvlist);
> +
>   	return 0;
>   }
>   
> @@ -3475,8 +3478,6 @@ bond_remove(struct rte_vdev_device *dev)
>   		ret = bond_ethdev_stop(eth_dev);
>   		bond_ethdev_close(eth_dev);
>   	}
> -	if (internals->kvlist != NULL)
> -		rte_kvargs_free(internals->kvlist);
>   	rte_eth_dev_release_port(eth_dev);
>   
>   	return ret;
>
  
Yu, DapengX Sept. 15, 2021, 7:18 a.m. UTC | #2
> -----Original Message-----
> From: Min Hu (Connor) <humin29@huawei.com>
> Sent: Wednesday, September 15, 2021 2:59 PM
> To: Yu, DapengX <dapengx.yu@intel.com>; Chas Williams <chas3@att.com>
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: Re: [PATCH] net/bonding: fix memory leak on closing device
> 
> Hi, dapengx,
> 	Why not free internals->kvlist at the end of
> "bond_ethdev_configure" ?
> Does it call some bugs?

Just try not to deviate too much from the previous fix: 144dc4739975 ("net/bonding: fix leak on remove")
Since it is reasonable.
And releasing port resource in bond_ethdev_close() is in order to
avoid that memory leak detect tool to find memory leak after device is closed.

free internals->kvlist at the end of "bond_ethdev_configure" is also ok.

> 
> 在 2021/9/15 13:08, dapengx.yu@intel.com 写道:
> > From: Dapeng Yu <dapengx.yu@intel.com>
> >
> > If the bond device was created by vdev mode, the kvlist was not free
> > after the bond device was closed.
> >
> > This patch fixes it.
> >
> > Fixes: 144dc4739975 ("net/bonding: fix leak on remove")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> > ---
> >   drivers/net/bonding/rte_eth_bond_pmd.c | 5 +++--
> >   1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c
> > b/drivers/net/bonding/rte_eth_bond_pmd.c
> > index a6755661c4..2e96b850fb 100644
> > --- a/drivers/net/bonding/rte_eth_bond_pmd.c
> > +++ b/drivers/net/bonding/rte_eth_bond_pmd.c
> > @@ -2163,6 +2163,9 @@ bond_ethdev_close(struct rte_eth_dev *dev)
> >   	 */
> >   	rte_mempool_free(internals->mode6.mempool);
> >
> > +	if (internals->kvlist != NULL)
> > +		rte_kvargs_free(internals->kvlist);
> > +
> >   	return 0;
> >   }
> >
> > @@ -3475,8 +3478,6 @@ bond_remove(struct rte_vdev_device *dev)
> >   		ret = bond_ethdev_stop(eth_dev);
> >   		bond_ethdev_close(eth_dev);
> >   	}
> > -	if (internals->kvlist != NULL)
> > -		rte_kvargs_free(internals->kvlist);
> >   	rte_eth_dev_release_port(eth_dev);
> >
> >   	return ret;
> >
  
humin (Q) Sept. 15, 2021, 8:16 a.m. UTC | #3
Acked-by: Min Hu (Connor) <humin29@huawei.com>

在 2021/9/15 15:18, Yu, DapengX 写道:
> 
> 
>> -----Original Message-----
>> From: Min Hu (Connor) <humin29@huawei.com>
>> Sent: Wednesday, September 15, 2021 2:59 PM
>> To: Yu, DapengX <dapengx.yu@intel.com>; Chas Williams <chas3@att.com>
>> Cc: dev@dpdk.org; stable@dpdk.org
>> Subject: Re: [PATCH] net/bonding: fix memory leak on closing device
>>
>> Hi, dapengx,
>> 	Why not free internals->kvlist at the end of
>> "bond_ethdev_configure" ?
>> Does it call some bugs?
> 
> Just try not to deviate too much from the previous fix: 144dc4739975 ("net/bonding: fix leak on remove")
> Since it is reasonable.
> And releasing port resource in bond_ethdev_close() is in order to
> avoid that memory leak detect tool to find memory leak after device is closed.
> 
> free internals->kvlist at the end of "bond_ethdev_configure" is also ok.
> 
>>
>> 在 2021/9/15 13:08, dapengx.yu@intel.com 写道:
>>> From: Dapeng Yu <dapengx.yu@intel.com>
>>>
>>> If the bond device was created by vdev mode, the kvlist was not free
>>> after the bond device was closed.
>>>
>>> This patch fixes it.
>>>
>>> Fixes: 144dc4739975 ("net/bonding: fix leak on remove")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
>>> ---
>>>    drivers/net/bonding/rte_eth_bond_pmd.c | 5 +++--
>>>    1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c
>>> b/drivers/net/bonding/rte_eth_bond_pmd.c
>>> index a6755661c4..2e96b850fb 100644
>>> --- a/drivers/net/bonding/rte_eth_bond_pmd.c
>>> +++ b/drivers/net/bonding/rte_eth_bond_pmd.c
>>> @@ -2163,6 +2163,9 @@ bond_ethdev_close(struct rte_eth_dev *dev)
>>>    	 */
>>>    	rte_mempool_free(internals->mode6.mempool);
>>>
>>> +	if (internals->kvlist != NULL)
>>> +		rte_kvargs_free(internals->kvlist);
>>> +
>>>    	return 0;
>>>    }
>>>
>>> @@ -3475,8 +3478,6 @@ bond_remove(struct rte_vdev_device *dev)
>>>    		ret = bond_ethdev_stop(eth_dev);
>>>    		bond_ethdev_close(eth_dev);
>>>    	}
>>> -	if (internals->kvlist != NULL)
>>> -		rte_kvargs_free(internals->kvlist);
>>>    	rte_eth_dev_release_port(eth_dev);
>>>
>>>    	return ret;
>>>
> .
>
  
Ferruh Yigit Sept. 21, 2021, 8:04 a.m. UTC | #4
On 9/15/2021 9:16 AM, Min Hu (Connor) wrote:


<...>

>>> 在 2021/9/15 13:08, dapengx.yu@intel.com 写道:
>>>> From: Dapeng Yu <dapengx.yu@intel.com>
>>>>
>>>> If the bond device was created by vdev mode, the kvlist was not free
>>>> after the bond device was closed.
>>>>
>>>> This patch fixes it.
>>>>
>>>> Fixes: 144dc4739975 ("net/bonding: fix leak on remove")
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> Acked-by: Min Hu (Connor) <humin29@huawei.com>
> 

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

Patch

diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index a6755661c4..2e96b850fb 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2163,6 +2163,9 @@  bond_ethdev_close(struct rte_eth_dev *dev)
 	 */
 	rte_mempool_free(internals->mode6.mempool);
 
+	if (internals->kvlist != NULL)
+		rte_kvargs_free(internals->kvlist);
+
 	return 0;
 }
 
@@ -3475,8 +3478,6 @@  bond_remove(struct rte_vdev_device *dev)
 		ret = bond_ethdev_stop(eth_dev);
 		bond_ethdev_close(eth_dev);
 	}
-	if (internals->kvlist != NULL)
-		rte_kvargs_free(internals->kvlist);
 	rte_eth_dev_release_port(eth_dev);
 
 	return ret;