DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] bus: fix memleak during pci device cleanup
@ 2022-10-19 10:49 Kevin Laatz
  2022-10-19 11:40 ` David Marchand
  2022-10-19 12:37 ` [PATCH v2] " Kevin Laatz
  0 siblings, 2 replies; 6+ messages in thread
From: Kevin Laatz @ 2022-10-19 10:49 UTC (permalink / raw)
  To: dev; +Cc: Kevin Laatz, Bruce Richardson, Morten Brørup

During PCI bus device cleanup some interrupt handle pointers and the
bus_info pointer are not being free'd, leading to memory leaks.
This patch fixes the memory leaks by ensuring they are free'd during
device cleanup on exit.

Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
---
 drivers/bus/pci/pci_common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 7f598667fe..330a41ed12 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -456,6 +456,20 @@ pci_cleanup(void)
 		}
 		dev->driver = NULL;
 		dev->device.driver = NULL;
+
+		/* free interrupt handles */
+		if (dev->intr_handle != NULL) {
+			rte_intr_instance_free(dev->intr_handle);
+			dev->intr_handle = NULL;
+			rte_intr_instance_free(dev->vfio_req_intr_handle);
+			dev->vfio_req_intr_handle = NULL;
+		}
+
+		if (dev->bus_info != NULL) {
+			free(dev->bus_info);
+			dev->bus_info = NULL;
+		}
+
 		free(dev);
 	}
 
-- 
2.31.1


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

* Re: [PATCH] bus: fix memleak during pci device cleanup
  2022-10-19 10:49 [PATCH] bus: fix memleak during pci device cleanup Kevin Laatz
@ 2022-10-19 11:40 ` David Marchand
  2022-10-19 12:37 ` [PATCH v2] " Kevin Laatz
  1 sibling, 0 replies; 6+ messages in thread
From: David Marchand @ 2022-10-19 11:40 UTC (permalink / raw)
  To: Kevin Laatz; +Cc: dev, Bruce Richardson, Morten Brørup

On Wed, Oct 19, 2022 at 12:46 PM Kevin Laatz <kevin.laatz@intel.com> wrote:
>
> During PCI bus device cleanup some interrupt handle pointers and the
> bus_info pointer are not being free'd, leading to memory leaks.
> This patch fixes the memory leaks by ensuring they are free'd during
> device cleanup on exit.
>
> Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
>
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
>  drivers/bus/pci/pci_common.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
> index 7f598667fe..330a41ed12 100644
> --- a/drivers/bus/pci/pci_common.c
> +++ b/drivers/bus/pci/pci_common.c
> @@ -456,6 +456,20 @@ pci_cleanup(void)
>                 }
>                 dev->driver = NULL;
>                 dev->device.driver = NULL;
> +
> +               /* free interrupt handles */
> +               if (dev->intr_handle != NULL) {

rte_intr_instance_free already handles NULL, no need for the check.

> +                       rte_intr_instance_free(dev->intr_handle);
> +                       dev->intr_handle = NULL;
> +                       rte_intr_instance_free(dev->vfio_req_intr_handle);
> +                       dev->vfio_req_intr_handle = NULL;
> +               }
> +
> +               if (dev->bus_info != NULL) {

Idem.


> +                       free(dev->bus_info);
> +                       dev->bus_info = NULL;
> +               }
> +
>                 free(dev);
>         }
>
> --
> 2.31.1
>


-- 
David Marchand


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

* [PATCH v2] bus: fix memleak during pci device cleanup
  2022-10-19 10:49 [PATCH] bus: fix memleak during pci device cleanup Kevin Laatz
  2022-10-19 11:40 ` David Marchand
@ 2022-10-19 12:37 ` Kevin Laatz
  2022-10-20  5:31   ` Li, WeiyuanX
  2022-10-20  9:19   ` David Marchand
  1 sibling, 2 replies; 6+ messages in thread
From: Kevin Laatz @ 2022-10-19 12:37 UTC (permalink / raw)
  To: dev; +Cc: Kevin Laatz, Morten Brørup, Bruce Richardson

During PCI bus device cleanup some interrupt handle pointers and the
bus_info pointer are not being free'd, leading to memory leaks.
This patch fixes the memory leaks by ensuring they are free'd during
device cleanup on exit.

Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>

---
v2: remove redundant NULL checks
---
 drivers/bus/pci/pci_common.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 7f598667fe..71cd3f59ad 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -456,6 +456,16 @@ pci_cleanup(void)
 		}
 		dev->driver = NULL;
 		dev->device.driver = NULL;
+
+		/* free interrupt handles */
+		rte_intr_instance_free(dev->intr_handle);
+		dev->intr_handle = NULL;
+		rte_intr_instance_free(dev->vfio_req_intr_handle);
+		dev->vfio_req_intr_handle = NULL;
+
+		free(dev->bus_info);
+		dev->bus_info = NULL;
+
 		free(dev);
 	}
 
-- 
2.31.1


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

* RE: [PATCH v2] bus: fix memleak during pci device cleanup
  2022-10-19 12:37 ` [PATCH v2] " Kevin Laatz
@ 2022-10-20  5:31   ` Li, WeiyuanX
  2022-10-20  9:19   ` David Marchand
  1 sibling, 0 replies; 6+ messages in thread
From: Li, WeiyuanX @ 2022-10-20  5:31 UTC (permalink / raw)
  To: Laatz, Kevin, dev; +Cc: Laatz, Kevin, Morten Brørup, Richardson, Bruce

> -----Original Message-----
> From: Kevin Laatz <kevin.laatz@intel.com>
> Sent: Wednesday, October 19, 2022 8:38 PM
> To: dev@dpdk.org
> Cc: Laatz, Kevin <kevin.laatz@intel.com>; Morten Brørup
> <mb@smartsharesystems.com>; Richardson, Bruce
> <bruce.richardson@intel.com>
> Subject: [PATCH v2] bus: fix memleak during pci device cleanup
> 
> During PCI bus device cleanup some interrupt handle pointers and the
> bus_info pointer are not being free'd, leading to memory leaks.
> This patch fixes the memory leaks by ensuring they are free'd during device
> cleanup on exit.
> 
> Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
> 
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> 
> ---
Tested-by: Weiyuan Li <weiyuanx.li@intel.com>

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

* Re: [PATCH v2] bus: fix memleak during pci device cleanup
  2022-10-19 12:37 ` [PATCH v2] " Kevin Laatz
  2022-10-20  5:31   ` Li, WeiyuanX
@ 2022-10-20  9:19   ` David Marchand
  2022-10-20 11:31     ` David Marchand
  1 sibling, 1 reply; 6+ messages in thread
From: David Marchand @ 2022-10-20  9:19 UTC (permalink / raw)
  To: Kevin Laatz; +Cc: dev, Morten Brørup, Bruce Richardson

On Wed, Oct 19, 2022 at 2:35 PM Kevin Laatz <kevin.laatz@intel.com> wrote:
>
> During PCI bus device cleanup some interrupt handle pointers and the
> bus_info pointer are not being free'd, leading to memory leaks.
> This patch fixes the memory leaks by ensuring they are free'd during
> device cleanup on exit.
>
> Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
>
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
>
> ---
> v2: remove redundant NULL checks
> ---
>  drivers/bus/pci/pci_common.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
> index 7f598667fe..71cd3f59ad 100644
> --- a/drivers/bus/pci/pci_common.c
> +++ b/drivers/bus/pci/pci_common.c
> @@ -456,6 +456,16 @@ pci_cleanup(void)
>                 }
>                 dev->driver = NULL;
>                 dev->device.driver = NULL;
> +
> +               /* free interrupt handles */
> +               rte_intr_instance_free(dev->intr_handle);
> +               dev->intr_handle = NULL;
> +               rte_intr_instance_free(dev->vfio_req_intr_handle);
> +               dev->vfio_req_intr_handle = NULL;
> +
> +               free(dev->bus_info);
> +               dev->bus_info = NULL;
> +
>                 free(dev);

I'll do an update when applying: here, it is better to use
pci_free(dev); which was introduced at the same time bus_info was.

>         }
>
> --
> 2.31.1
>

Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


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

* Re: [PATCH v2] bus: fix memleak during pci device cleanup
  2022-10-20  9:19   ` David Marchand
@ 2022-10-20 11:31     ` David Marchand
  0 siblings, 0 replies; 6+ messages in thread
From: David Marchand @ 2022-10-20 11:31 UTC (permalink / raw)
  To: Kevin Laatz; +Cc: dev, Morten Brørup, Bruce Richardson, weiyuanx.li

On Thu, Oct 20, 2022 at 11:19 AM David Marchand
<david.marchand@redhat.com> wrote:
> On Wed, Oct 19, 2022 at 2:35 PM Kevin Laatz <kevin.laatz@intel.com> wrote:
> >
> > During PCI bus device cleanup some interrupt handle pointers and the
> > bus_info pointer are not being free'd, leading to memory leaks.
> > This patch fixes the memory leaks by ensuring they are free'd during
> > device cleanup on exit.
> >
> > Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
> >
> > Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Tested-by: Weiyuan Li <weiyuanx.li@intel.com>
> Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied with suggested update, thanks.


-- 
David Marchand


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

end of thread, other threads:[~2022-10-20 11:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 10:49 [PATCH] bus: fix memleak during pci device cleanup Kevin Laatz
2022-10-19 11:40 ` David Marchand
2022-10-19 12:37 ` [PATCH v2] " Kevin Laatz
2022-10-20  5:31   ` Li, WeiyuanX
2022-10-20  9:19   ` David Marchand
2022-10-20 11:31     ` David Marchand

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