DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1 0/2] fix memory leak
@ 2023-07-05  9:25 Wenjun Wu
  2023-07-05  9:25 ` [PATCH v1 1/2] bus/vdev: " Wenjun Wu
  2023-07-05  9:25 ` [PATCH v1 2/2] examples/multi_process: " Wenjun Wu
  0 siblings, 2 replies; 6+ messages in thread
From: Wenjun Wu @ 2023-07-05  9:25 UTC (permalink / raw)
  To: dev, anatoly.burakov, qi.z.zhang; +Cc: simei.su, Wenjun Wu

This patch set fix memory leak in vdev and example hotplug_mp.

Wenjun Wu (2):
  bus/vdev: fix memory leak
  examples/multi_process: fix memory leak

 drivers/bus/vdev/vdev.c                      |  5 +++++
 examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++
 2 files changed, 27 insertions(+)

-- 
2.34.1


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

* [PATCH v1 1/2] bus/vdev: fix memory leak
  2023-07-05  9:25 [PATCH v1 0/2] fix memory leak Wenjun Wu
@ 2023-07-05  9:25 ` Wenjun Wu
  2023-07-06  0:48   ` fengchengwen
  2023-07-05  9:25 ` [PATCH v1 2/2] examples/multi_process: " Wenjun Wu
  1 sibling, 1 reply; 6+ messages in thread
From: Wenjun Wu @ 2023-07-05  9:25 UTC (permalink / raw)
  To: dev, anatoly.burakov, qi.z.zhang; +Cc: simei.su, Wenjun Wu, stable

In hotplug usecase, devargs will be allocated in secondary process
in the function alloc_devargs. Since it will not be insert into the
devarg_list, it will have no chance to be freed.

This patch adds additional memory free for device structure member devargs
in the secondary process in rte_vdev_uninit.

Fixes: f5b2eff0847d ("bus/vdev: fix devargs after multi-process bus scan")
Cc: stable@dpdk.org

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
---
 drivers/bus/vdev/vdev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 7974b27295..3f4e6a1b55 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -373,6 +373,11 @@ rte_vdev_uninit(const char *name)
 
 	TAILQ_REMOVE(&vdev_device_list, dev, next);
 	rte_devargs_remove(dev->device.devargs);
+	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+	    dev->device.devargs != NULL) {
+		rte_devargs_reset(dev->device.devargs);
+		free(dev->device.devargs);
+	}
 	free(dev);
 
 unlock:
-- 
2.34.1


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

* [PATCH v1 2/2] examples/multi_process: fix memory leak
  2023-07-05  9:25 [PATCH v1 0/2] fix memory leak Wenjun Wu
  2023-07-05  9:25 ` [PATCH v1 1/2] bus/vdev: " Wenjun Wu
@ 2023-07-05  9:25 ` Wenjun Wu
  2023-07-06  1:02   ` fengchengwen
  1 sibling, 1 reply; 6+ messages in thread
From: Wenjun Wu @ 2023-07-05  9:25 UTC (permalink / raw)
  To: dev, anatoly.burakov, qi.z.zhang; +Cc: simei.su, Wenjun Wu, stable

The device should be detached before quit, otherwise it will
cause memory leak.

Fixes: 05f1d6842fc3 ("examples/multi_process: add hotplug sample")
Cc: stable@dpdk.org

Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
---
 examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
index 88f44e00a0..143d57eeb6 100644
--- a/examples/multi_process/hotplug_mp/commands.c
+++ b/examples/multi_process/hotplug_mp/commands.c
@@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,
 			    struct cmdline *cl,
 			    __rte_unused void *data)
 {
+	uint16_t port_id;
+	char dev_name[RTE_DEV_NAME_MAX_LEN];
+	struct rte_devargs da;
+
+	RTE_ETH_FOREACH_DEV(port_id) {
+		rte_eth_dev_get_name_by_port(port_id, dev_name);
+		memset(&da, 0, sizeof(da));
+
+		if (rte_devargs_parsef(&da, "%s", dev_name)) {
+			cmdline_printf(cl,
+				       "cannot parse devargs for device %s\n",
+				       dev_name);
+		}
+		printf("detaching before quit...\n");
+		if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
+			cmdline_printf(cl, "detached device %s\n",
+				da.name);
+		else
+			cmdline_printf(cl, "failed to detach device %s\n",
+				da.name);
+
+	}
 	cmdline_quit(cl);
 }
 
-- 
2.34.1


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

* Re: [PATCH v1 1/2] bus/vdev: fix memory leak
  2023-07-05  9:25 ` [PATCH v1 1/2] bus/vdev: " Wenjun Wu
@ 2023-07-06  0:48   ` fengchengwen
  0 siblings, 0 replies; 6+ messages in thread
From: fengchengwen @ 2023-07-06  0:48 UTC (permalink / raw)
  To: Wenjun Wu, dev, anatoly.burakov, qi.z.zhang; +Cc: simei.su, stable

On 2023/7/5 17:25, Wenjun Wu wrote:
> In hotplug usecase, devargs will be allocated in secondary process
> in the function alloc_devargs. Since it will not be insert into the
> devarg_list, it will have no chance to be freed.
> 
> This patch adds additional memory free for device structure member devargs
> in the secondary process in rte_vdev_uninit.
> 
> Fixes: f5b2eff0847d ("bus/vdev: fix devargs after multi-process bus scan")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
> ---
>  drivers/bus/vdev/vdev.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
> index 7974b27295..3f4e6a1b55 100644
> --- a/drivers/bus/vdev/vdev.c
> +++ b/drivers/bus/vdev/vdev.c
> @@ -373,6 +373,11 @@ rte_vdev_uninit(const char *name)
>  
>  	TAILQ_REMOVE(&vdev_device_list, dev, next);
>  	rte_devargs_remove(dev->device.devargs);
> +	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
> +	    dev->device.devargs != NULL) {

The prerequisite is that rte_vdev_init is invoked only in main process.

Suggest more general impl:
	ret = rte_devargs_remove(dev->device.devargs);
	if (ret != 0) {
		rte_devargs_reset(dev->device.devargs);
		free(dev->device.devargs);
	}

> +		rte_devargs_reset(dev->device.devargs);
> +		free(dev->device.devargs);
> +	}
>  	free(dev);
>  
>  unlock:
> 

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

* Re: [PATCH v1 2/2] examples/multi_process: fix memory leak
  2023-07-05  9:25 ` [PATCH v1 2/2] examples/multi_process: " Wenjun Wu
@ 2023-07-06  1:02   ` fengchengwen
  2023-07-06  5:10     ` Wu, Wenjun1
  0 siblings, 1 reply; 6+ messages in thread
From: fengchengwen @ 2023-07-06  1:02 UTC (permalink / raw)
  To: Wenjun Wu, dev, anatoly.burakov, qi.z.zhang; +Cc: simei.su, stable

On 2023/7/5 17:25, Wenjun Wu wrote:
> The device should be detached before quit, otherwise it will
> cause memory leak.

Which memory will leak?

For mp, if secondary process quit, it only needs to properly handle the memory shared with other process.

> 
> Fixes: 05f1d6842fc3 ("examples/multi_process: add hotplug sample")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
> ---
>  examples/multi_process/hotplug_mp/commands.c | 22 ++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c
> index 88f44e00a0..143d57eeb6 100644
> --- a/examples/multi_process/hotplug_mp/commands.c
> +++ b/examples/multi_process/hotplug_mp/commands.c
> @@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void *parsed_result,
>  			    struct cmdline *cl,
>  			    __rte_unused void *data)
>  {
> +	uint16_t port_id;
> +	char dev_name[RTE_DEV_NAME_MAX_LEN];
> +	struct rte_devargs da;
> +
> +	RTE_ETH_FOREACH_DEV(port_id) {
> +		rte_eth_dev_get_name_by_port(port_id, dev_name);
> +		memset(&da, 0, sizeof(da));
> +
> +		if (rte_devargs_parsef(&da, "%s", dev_name)) {
> +			cmdline_printf(cl,
> +				       "cannot parse devargs for device %s\n",
> +				       dev_name);
> +		}
> +		printf("detaching before quit...\n");
> +		if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name))
> +			cmdline_printf(cl, "detached device %s\n",
> +				da.name);
> +		else
> +			cmdline_printf(cl, "failed to detach device %s\n",
> +				da.name);
> +
> +	}
>  	cmdline_quit(cl);
>  }
>  
> 

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

* RE: [PATCH v1 2/2] examples/multi_process: fix memory leak
  2023-07-06  1:02   ` fengchengwen
@ 2023-07-06  5:10     ` Wu, Wenjun1
  0 siblings, 0 replies; 6+ messages in thread
From: Wu, Wenjun1 @ 2023-07-06  5:10 UTC (permalink / raw)
  To: fengchengwen, dev, Burakov, Anatoly, Zhang, Qi Z; +Cc: Su, Simei, stable

Hi Chengwen,

Thanks for reviewing.
The memory leak occurs similar as what mentioned in https://patches.dpdk.org/project/dpdk/patch/20230705092511.362484-2-wenjun1.wu@intel.com/.
I will perfect the commit description in V2 version.

Thanks,
Wenjun

> -----Original Message-----
> From: fengchengwen <fengchengwen@huawei.com>
> Sent: Thursday, July 6, 2023 9:02 AM
> To: Wu, Wenjun1 <wenjun1.wu@intel.com>; dev@dpdk.org; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> Cc: Su, Simei <simei.su@intel.com>; stable@dpdk.org
> Subject: Re: [PATCH v1 2/2] examples/multi_process: fix memory leak
> 
> On 2023/7/5 17:25, Wenjun Wu wrote:
> > The device should be detached before quit, otherwise it will cause
> > memory leak.
> 
> Which memory will leak?
> 
> For mp, if secondary process quit, it only needs to properly handle the
> memory shared with other process.
> 
> >
> > Fixes: 05f1d6842fc3 ("examples/multi_process: add hotplug sample")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Wenjun Wu <wenjun1.wu@intel.com>
> > ---
> >  examples/multi_process/hotplug_mp/commands.c | 22
> > ++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> >
> > diff --git a/examples/multi_process/hotplug_mp/commands.c
> > b/examples/multi_process/hotplug_mp/commands.c
> > index 88f44e00a0..143d57eeb6 100644
> > --- a/examples/multi_process/hotplug_mp/commands.c
> > +++ b/examples/multi_process/hotplug_mp/commands.c
> > @@ -52,6 +52,28 @@ static void cmd_quit_parsed(__rte_unused void
> *parsed_result,
> >  			    struct cmdline *cl,
> >  			    __rte_unused void *data)
> >  {
> > +	uint16_t port_id;
> > +	char dev_name[RTE_DEV_NAME_MAX_LEN];
> > +	struct rte_devargs da;
> > +
> > +	RTE_ETH_FOREACH_DEV(port_id) {
> > +		rte_eth_dev_get_name_by_port(port_id, dev_name);
> > +		memset(&da, 0, sizeof(da));
> > +
> > +		if (rte_devargs_parsef(&da, "%s", dev_name)) {
> > +			cmdline_printf(cl,
> > +				       "cannot parse devargs for device %s\n",
> > +				       dev_name);
> > +		}
> > +		printf("detaching before quit...\n");
> > +		if (!rte_eal_hotplug_remove(rte_bus_name(da.bus),
> da.name))
> > +			cmdline_printf(cl, "detached device %s\n",
> > +				da.name);
> > +		else
> > +			cmdline_printf(cl, "failed to detach device %s\n",
> > +				da.name);
> > +
> > +	}
> >  	cmdline_quit(cl);
> >  }
> >
> >

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

end of thread, other threads:[~2023-07-06  5:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-05  9:25 [PATCH v1 0/2] fix memory leak Wenjun Wu
2023-07-05  9:25 ` [PATCH v1 1/2] bus/vdev: " Wenjun Wu
2023-07-06  0:48   ` fengchengwen
2023-07-05  9:25 ` [PATCH v1 2/2] examples/multi_process: " Wenjun Wu
2023-07-06  1:02   ` fengchengwen
2023-07-06  5:10     ` Wu, Wenjun1

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