net/virtio: fix memory leak of interrupt handle

Message ID 20210726144205.177-1-clgx0086@163.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series net/virtio: fix memory leak of interrupt handle |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/github-robot success github build: passed
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Gaoxiang Liu July 26, 2021, 2:42 p.m. UTC
  Free memory of interrupt handle in virtio_user_dev_uninit() to
avoid memory leak.
when virtio user dev closes, memory of interrupt handle is not freed
that is allocated in virtio_user_fill_intr_handle().

Fixes: 3d4fb6fd2505 <"net/virtio-user: support Rx interrupt">

Signed-off-by: Gaoxiang Liu <clgx0086@163.com>
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Chenbo Xia July 27, 2021, 1:52 a.m. UTC | #1
Hi Gaoxiang,

> -----Original Message-----
> From: Gaoxiang Liu <clgx0086@163.com>
> Sent: Monday, July 26, 2021 10:42 PM
> To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org; liugaoxiang@huawei.com
> Cc: Gaoxiang Liu <clgx0086@163.com>
> Subject: [PATCH] net/virtio: fix memory leak of interrupt handle
> 
> Free memory of interrupt handle in virtio_user_dev_uninit() to
> avoid memory leak.
> when virtio user dev closes, memory of interrupt handle is not freed
> that is allocated in virtio_user_fill_intr_handle().
> 
> Fixes: 3d4fb6fd2505 <"net/virtio-user: support Rx interrupt">
> 

Please note two things here:

1. Next time you send a v2 patch, please add the prefix like:
	[v2] net/virtio: fix memory leak of interrupt handle

2. We prefer '()' rather than '<>' for fix line and you may miss one comment
that we need cc stable tag for most fixes:
	Fixes: 3d4fb6fd2505 ("net/virtio-user: support Rx interrupt")
	Cc: stable@dpdk.org

And no need to send v3, I will help you fix it when applying. Welcome to DPDK!

For this patch:

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

> Signed-off-by: Gaoxiang Liu <clgx0086@163.com>
> ---
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 1cd1e95f4..16c58710d 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -654,6 +654,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
> *path, int queues,
>  void
>  virtio_user_dev_uninit(struct virtio_user_dev *dev)
>  {
> +	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
> +
> +	if (eth_dev->intr_handle) {
> +		free(eth_dev->intr_handle);
> +		eth_dev->intr_handle = NULL;
> +	}
> +
>  	virtio_user_stop_device(dev);
> 
>  	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
> --
> 2.32.0
  
Chenbo Xia July 27, 2021, 1:54 a.m. UTC | #2
Missed R-by of Maxime will also be added when applying.

/Chenbo

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Xia, Chenbo
> Sent: Tuesday, July 27, 2021 9:53 AM
> To: Gaoxiang Liu <clgx0086@163.com>; dev@dpdk.org; liugaoxiang@huawei.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: Re: [dpdk-dev] [PATCH] net/virtio: fix memory leak of interrupt
> handle
> 
> Hi Gaoxiang,
> 
> > -----Original Message-----
> > From: Gaoxiang Liu <clgx0086@163.com>
> > Sent: Monday, July 26, 2021 10:42 PM
> > To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org; liugaoxiang@huawei.com
> > Cc: Gaoxiang Liu <clgx0086@163.com>
> > Subject: [PATCH] net/virtio: fix memory leak of interrupt handle
> >
> > Free memory of interrupt handle in virtio_user_dev_uninit() to
> > avoid memory leak.
> > when virtio user dev closes, memory of interrupt handle is not freed
> > that is allocated in virtio_user_fill_intr_handle().
> >
> > Fixes: 3d4fb6fd2505 <"net/virtio-user: support Rx interrupt">
> >
> 
> Please note two things here:
> 
> 1. Next time you send a v2 patch, please add the prefix like:
> 	[v2] net/virtio: fix memory leak of interrupt handle
> 
> 2. We prefer '()' rather than '<>' for fix line and you may miss one comment
> that we need cc stable tag for most fixes:
> 	Fixes: 3d4fb6fd2505 ("net/virtio-user: support Rx interrupt")
> 	Cc: stable@dpdk.org
> 
> And no need to send v3, I will help you fix it when applying. Welcome to DPDK!
> 
> For this patch:
> 
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
> 
> > Signed-off-by: Gaoxiang Liu <clgx0086@163.com>
> > ---
> >  drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > index 1cd1e95f4..16c58710d 100644
> > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > @@ -654,6 +654,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
> > *path, int queues,
> >  void
> >  virtio_user_dev_uninit(struct virtio_user_dev *dev)
> >  {
> > +	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
> > +
> > +	if (eth_dev->intr_handle) {
> > +		free(eth_dev->intr_handle);
> > +		eth_dev->intr_handle = NULL;
> > +	}
> > +
> >  	virtio_user_stop_device(dev);
> >
> >  	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
> > --
> > 2.32.0
  
Chenbo Xia July 28, 2021, 6:51 a.m. UTC | #3
> -----Original Message-----
> From: Gaoxiang Liu <clgx0086@163.com>
> Sent: Monday, July 26, 2021 10:42 PM
> To: Xia, Chenbo <chenbo.xia@intel.com>; dev@dpdk.org; liugaoxiang@huawei.com
> Cc: Gaoxiang Liu <clgx0086@163.com>
> Subject: [PATCH] net/virtio: fix memory leak of interrupt handle
> 
> Free memory of interrupt handle in virtio_user_dev_uninit() to
> avoid memory leak.
> when virtio user dev closes, memory of interrupt handle is not freed
> that is allocated in virtio_user_fill_intr_handle().
> 
> Fixes: 3d4fb6fd2505 <"net/virtio-user: support Rx interrupt">
> 
> Signed-off-by: Gaoxiang Liu <clgx0086@163.com>
> ---
>  drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 1cd1e95f4..16c58710d 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -654,6 +654,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
> *path, int queues,
>  void
>  virtio_user_dev_uninit(struct virtio_user_dev *dev)
>  {
> +	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
> +
> +	if (eth_dev->intr_handle) {
> +		free(eth_dev->intr_handle);
> +		eth_dev->intr_handle = NULL;
> +	}
> +
>  	virtio_user_stop_device(dev);
> 
>  	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
> --
> 2.32.0

Applied to next-virtio/main. Thanks!
  

Patch

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 1cd1e95f4..16c58710d 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -654,6 +654,13 @@  virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 void
 virtio_user_dev_uninit(struct virtio_user_dev *dev)
 {
+	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
+
+	if (eth_dev->intr_handle) {
+		free(eth_dev->intr_handle);
+		eth_dev->intr_handle = NULL;
+	}
+
 	virtio_user_stop_device(dev);
 
 	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);