ethdev: fix memory leak on removing eth rxtx callback

Message ID 20181121131127.28528-1-wanlebing@didichuxing.com (mailing list archive)
State Rejected, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: fix memory leak on removing eth rxtx callback |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

lebing wan Nov. 21, 2018, 1:11 p.m. UTC
  eth rxtx callback is dynamically allocated using rte_zmalloc()
but not released. Fix it by calling rte_free() to free callback
when removing rxtx callback.

Signed-off-by: wanlebing <wanlebing@didichuxing.com>
Signed-off-by: wanlebing <wanlebing@gmail.com>
---
 lib/librte_ethdev/rte_ethdev.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Ferruh Yigit Nov. 21, 2018, 2:48 p.m. UTC | #1
On 11/21/2018 1:11 PM, wanlebing wrote:
> eth rxtx callback is dynamically allocated using rte_zmalloc()
> but not released. Fix it by calling rte_free() to free callback
> when removing rxtx callback.

I guess they are not freed intentionally because there is no safe way to do it.
I remember Konstantin sent an RFC in the past to rework the callbacks, cc'ed him
for more details.

> 
> Signed-off-by: wanlebing <wanlebing@didichuxing.com>
> Signed-off-by: wanlebing <wanlebing@gmail.com>
> ---
>  lib/librte_ethdev/rte_ethdev.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> index 5f858174b..f00311047 100644
> --- a/lib/librte_ethdev/rte_ethdev.c
> +++ b/lib/librte_ethdev/rte_ethdev.c
> @@ -3926,6 +3926,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
>  		if (cb == user_cb) {
>  			/* Remove the user cb from the callback list. */
>  			*prev_cb = cb->next;
> +			rte_free(cb);
>  			ret = 0;
>  			break;
>  		}
> @@ -3960,6 +3961,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
>  		if (cb == user_cb) {
>  			/* Remove the user cb from the callback list. */
>  			*prev_cb = cb->next;
> +			rte_free(cb);
>  			ret = 0;
>  			break;
>  		}
>
  
lebing wan Nov. 22, 2018, 2:32 a.m. UTC | #2
cc konstantin.ananyev

konstantin.ananyev, please help.

Ferruh Yigit <ferruh.yigit@intel.com> 于2018年11月21日周三 下午10:48写道:

> On 11/21/2018 1:11 PM, wanlebing wrote:
> > eth rxtx callback is dynamically allocated using rte_zmalloc()
> > but not released. Fix it by calling rte_free() to free callback
> > when removing rxtx callback.
>
> I guess they are not freed intentionally because there is no safe way to
> do it.
> I remember Konstantin sent an RFC in the past to rework the callbacks,
> cc'ed him
> for more details.
>
> >
> > Signed-off-by: wanlebing <wanlebing@didichuxing.com>
> > Signed-off-by: wanlebing <wanlebing@gmail.com>
> > ---
> >  lib/librte_ethdev/rte_ethdev.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_ethdev/rte_ethdev.c
> b/lib/librte_ethdev/rte_ethdev.c
> > index 5f858174b..f00311047 100644
> > --- a/lib/librte_ethdev/rte_ethdev.c
> > +++ b/lib/librte_ethdev/rte_ethdev.c
> > @@ -3926,6 +3926,7 @@ rte_eth_remove_rx_callback(uint16_t port_id,
> uint16_t queue_id,
> >               if (cb == user_cb) {
> >                       /* Remove the user cb from the callback list. */
> >                       *prev_cb = cb->next;
> > +                     rte_free(cb);
> >                       ret = 0;
> >                       break;
> >               }
> > @@ -3960,6 +3961,7 @@ rte_eth_remove_tx_callback(uint16_t port_id,
> uint16_t queue_id,
> >               if (cb == user_cb) {
> >                       /* Remove the user cb from the callback list. */
> >                       *prev_cb = cb->next;
> > +                     rte_free(cb);
> >                       ret = 0;
> >                       break;
> >               }
> >
>
>
  
lebing wan Nov. 23, 2018, 2:25 a.m. UTC | #3
Any update?

Ferruh Yigit <ferruh.yigit@intel.com> 于2018年11月21日周三 下午10:48写道:

> On 11/21/2018 1:11 PM, wanlebing wrote:
> > eth rxtx callback is dynamically allocated using rte_zmalloc()
> > but not released. Fix it by calling rte_free() to free callback
> > when removing rxtx callback.
>
> I guess they are not freed intentionally because there is no safe way to
> do it.
> I remember Konstantin sent an RFC in the past to rework the callbacks,
> cc'ed him
> for more details.
>
> >
> > Signed-off-by: wanlebing <wanlebing@didichuxing.com>
> > Signed-off-by: wanlebing <wanlebing@gmail.com>
> > ---
> >  lib/librte_ethdev/rte_ethdev.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_ethdev/rte_ethdev.c
> b/lib/librte_ethdev/rte_ethdev.c
> > index 5f858174b..f00311047 100644
> > --- a/lib/librte_ethdev/rte_ethdev.c
> > +++ b/lib/librte_ethdev/rte_ethdev.c
> > @@ -3926,6 +3926,7 @@ rte_eth_remove_rx_callback(uint16_t port_id,
> uint16_t queue_id,
> >               if (cb == user_cb) {
> >                       /* Remove the user cb from the callback list. */
> >                       *prev_cb = cb->next;
> > +                     rte_free(cb);
> >                       ret = 0;
> >                       break;
> >               }
> > @@ -3960,6 +3961,7 @@ rte_eth_remove_tx_callback(uint16_t port_id,
> uint16_t queue_id,
> >               if (cb == user_cb) {
> >                       /* Remove the user cb from the callback list. */
> >                       *prev_cb = cb->next;
> > +                     rte_free(cb);
> >                       ret = 0;
> >                       break;
> >               }
> >
>
>
  
Ananyev, Konstantin Nov. 23, 2018, 9:13 a.m. UTC | #4
> -----Original Message-----
> From: Yigit, Ferruh
> Sent: Wednesday, November 21, 2018 2:49 PM
> To: wanlebing <wanlebing@gmail.com>; dev@dpdk.org; Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Cc: wanlebing <wanlebing@didichuxing.com>
> Subject: Re: [dpdk-dev] [PATCH] ethdev: fix memory leak on removing eth rxtx callback
> 
> On 11/21/2018 1:11 PM, wanlebing wrote:
> > eth rxtx callback is dynamically allocated using rte_zmalloc()
> > but not released. Fix it by calling rte_free() to free callback
> > when removing rxtx callback.
> 
> I guess they are not freed intentionally because there is no safe way to do it.

That's right - we can't free it here without extra synchronization.

> I remember Konstantin sent an RFC in the past to rework the callbacks, cc'ed him
> for more details.

Following RFC was submitted:
http://patches.dpdk.org/patch/31867/

Though there was a concern that it would introduce some performance
degradation on low-end arm machines, so it is deferred right now.
Konstantin 

> 
> >
> > Signed-off-by: wanlebing <wanlebing@didichuxing.com>
> > Signed-off-by: wanlebing <wanlebing@gmail.com>
> > ---
> >  lib/librte_ethdev/rte_ethdev.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
> > index 5f858174b..f00311047 100644
> > --- a/lib/librte_ethdev/rte_ethdev.c
> > +++ b/lib/librte_ethdev/rte_ethdev.c
> > @@ -3926,6 +3926,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
> >  		if (cb == user_cb) {
> >  			/* Remove the user cb from the callback list. */
> >  			*prev_cb = cb->next;
> > +			rte_free(cb);
> >  			ret = 0;
> >  			break;
> >  		}
> > @@ -3960,6 +3961,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
> >  		if (cb == user_cb) {
> >  			/* Remove the user cb from the callback list. */
> >  			*prev_cb = cb->next;
> > +			rte_free(cb);
> >  			ret = 0;
> >  			break;
> >  		}
> >
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 5f858174b..f00311047 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -3926,6 +3926,7 @@  rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
 		if (cb == user_cb) {
 			/* Remove the user cb from the callback list. */
 			*prev_cb = cb->next;
+			rte_free(cb);
 			ret = 0;
 			break;
 		}
@@ -3960,6 +3961,7 @@  rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
 		if (cb == user_cb) {
 			/* Remove the user cb from the callback list. */
 			*prev_cb = cb->next;
+			rte_free(cb);
 			ret = 0;
 			break;
 		}