Skip to contentSkip to conversation

Fix IDXD PCI device close

PATCH Superseded Kevin Laatz 3 participants 31 messages Apr 8, 2022 – Jul 5, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix IDXD PCI device close

This patchset addresses the device close for IDXD PCI devices. Initially, there was a memory leak reported by ASAN for the 'pci' member of the 'idxd_dmadev' struct due to a missing free. In addition, this patch set corrects the behaviour of the device close function to ensure the cleanup is completed as expected.

Applications which use DMA devices should call rte_dma_close() for each device probed in order to ensure proper cleanup of the devices. This has been added to applications where DMA devices are commonly used.

Kevin Laatz (5):
dma/idxd: fix memory leak in pci close
dma/idxd: fix memory leak due to free on incorrect pointer app/test: close dma devices during cleanup app/testpmd: stop and close dmadevs at exit examples/dma: fix missing dma close

 app/test-pmd/testpmd.c           |  9 ++++++++
 app/test/test.c                  |  6 ++++++
 drivers/dma/idxd/idxd_common.c   |  1 +
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 36 +++++++++++++++++++++++++-------
 examples/dma/dmafwd.c            |  6 ++++++
 6 files changed, 52 insertions(+), 8 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/5 dma/idxd: fix memory leak in pci close

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_common.c   |  1 +
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 34 +++++++++++++++++++++++++-------
 3 files changed, 30 insertions(+), 7 deletions(-)
drivers/dma/idxd/idxd_common.c +1 -0
index ea6413cc7a..57c4c1655d 100644
@@ -597,6 +597,7 @@ idxd_dmadev_create(const char *name, struct rte_device *dev,
 	dmadev->fp_obj->dev_private = idxd;
 
 	idxd->dmadev->state = RTE_DMA_DEV_READY;
+	rte_atomic16_inc(&idxd->u.pci->ref_count);
 
 	return 0;
 
drivers/dma/idxd/idxd_internal.h +2 -0
index 3375600217..180a8587c6 100644
@@ -7,6 +7,7 @@
 
 #include <rte_dmadev_pmd.h>
 #include <rte_spinlock.h>
+#include <rte_atomic.h>
 
 #include "idxd_hw_defs.h"
 
@@ -33,6 +34,7 @@ struct idxd_pci_common {
 	rte_spinlock_t lk;
 
 	uint8_t wq_cfg_sz;
+	rte_atomic16_t ref_count;
 	volatile struct rte_idxd_bar0 *regs;
 	volatile uint32_t *wq_regs_base;
 	volatile struct rte_idxd_grpcfg *grp_regs;
drivers/dma/idxd/idxd_pci.c +27 -7
index 9ca1ec64e9..7036eb938d 100644
@@ -6,6 +6,7 @@
 #include <rte_devargs.h>
 #include <rte_dmadev_pmd.h>
 #include <rte_malloc.h>
+#include <rte_atomic.h>
 
 #include "idxd_internal.h"
 
@@ -115,20 +116,38 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 {
 	struct idxd_dmadev *idxd = dev->fp_obj->dev_private;
 	uint8_t err_code;
+	int is_last_wq;
 
-	/* disable the device */
-	err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
-	if (err_code) {
-		IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
-		return err_code;
+	if (idxd_is_wq_enabled(idxd)) {
+		/* disable the wq */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_wq);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling wq: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD WQ disabled OK");
 	}
-	IDXD_PMD_DEBUG("IDXD Device disabled OK");
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
 	rte_free(idxd->batch_idx_ring);
 	rte_free(idxd->desc_ring);
 
+	/* if this is the last WQ on the device, disable the device and free
+	 * the PCI struct
+	 */
+	is_last_wq = rte_atomic16_dec_and_test(&idxd->u.pci->ref_count);
+	if (is_last_wq) {
+		/* disable the device */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD device disabled OK");
+		rte_free(idxd->u.pci);
+	}
+
 	return 0;
 }
 
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
 	uint8_t lg2_max_batch, lg2_max_copy_size;
 	unsigned int i, err_code;
 
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);
 	if (pci == NULL) {
 		IDXD_PMD_ERR("%s: Can't allocate memory", __func__);
 		err_code = -1;
 		goto err;
 	}
+	memset(pci, 0, sizeof(*pci));
 	rte_spinlock_init(&pci->lk);
 
 	/* assign the bar registers, and then configure device */
Signature · 1 line
2.31.1
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] dma/idxd: fix memory leak in pci close

Quoted 6 lines · Kevin Laatz

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Quoted 7 lines
Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")

---

#3 lore raw

PATCH 2/5 dma/idxd: fix memory leak due to free on incorrect pointer

In reply to Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.
This patch fixes this memleak by calling free on the correct pointer.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +1 -1
index 7036eb938d..fdb1f15750 100644
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 
 	/* if this is the last WQ on the device, disable the device and free
Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH 2/5] dma/idxd: fix memory leak due to free on incorrect pointer

Quoted 20 lines · Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.
This patch fixes this memleak by calling free on the correct pointer.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +0 -0
index 7036eb938d..fdb1f15750 100644

drivers/dma/idxd/idxd_pci.c idxd_pci_dev_close(struct rte_dma_dev *dev) · line 135

Quoted 7 lines
drivers/dma/idxd/idxd_pci.c +1 -1
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 

This is largely my fault, I expect, for being "smart" and allocating the memory for both arrays from the one allocation. To clarify things, we need to:
1) update the commit log message explaining why it's the wrong pointer, i.e. that the two are in the one memory reservation
2) similarly add a comment to the rte_free call noting that it frees the idx_ring too.

Alternatively, we can also consider adjusting the allocation code so both arrays are allocated separately, and on free are freed similarly. We would, however, need to double check that doing so introduces no perf hit.

/Bruce

#5 lore raw

Re: [PATCH 2/5] dma/idxd: fix memory leak due to free on incorrect pointer

Quoted 36 lines · Bruce Richardson
Quoted 20 lines · Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.
This patch fixes this memleak by calling free on the correct pointer.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
  drivers/dma/idxd/idxd_pci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +0 -0
index 7036eb938d..fdb1f15750 100644

drivers/dma/idxd/idxd_pci.c idxd_pci_dev_close(struct rte_dma_dev *dev) · line 135

Quoted 7 lines
drivers/dma/idxd/idxd_pci.c +1 -1
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
  	/* free device memory */
  	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
  	rte_free(idxd->desc_ring);
 

This is largely my fault, I expect, for being "smart" and allocating the memory for both arrays from the one allocation. To clarify things, we need to:
1) update the commit log message explaining why it's the wrong pointer, i.e. that the two are in the one memory reservation
2) similarly add a comment to the rte_free call noting that it frees the idx_ring too.

Quoted 4 lines

Alternatively, we can also consider adjusting the allocation code so both arrays are allocated separately, and on free are freed similarly. We would, however, need to double check that doing so introduces no perf hit.

I'll add explanations/comments where needed in v2, thanks for the feedback.

Kevin

#6 lore raw

PATCH 3/5 app/test: close dma devices during cleanup

In reply to Kevin Laatz

DMA devices are created during PCI probe of EAL init. These devices need to be closed in order to perform necessary cleanup for those devices. This patch adds the call to close() for all DMA devices.

---
 app/test/test.c | 6 ++++++
 1 file changed, 6 insertions(+)
app/test/test.c +6 -0
index e69cae3eea..cc986e5cc9 100644
@@ -24,6 +24,7 @@ extern cmdline_parse_ctx_t main_ctx[];
 #include <rte_cycles.h>
 #include <rte_log.h>
 #include <rte_string_fns.h>
+#include <rte_dmadev.h>
 #ifdef RTE_LIB_TIMER
 #include <rte_timer.h>
 #endif
@@ -244,6 +245,11 @@ main(int argc, char **argv)
 #ifdef RTE_LIB_TIMER
 	rte_timer_subsystem_finalize();
 #endif
+
+	/* close all dmadevs */
+	RTE_DMA_FOREACH_DEV(i)
+		rte_dma_close(i);
+
 	rte_eal_cleanup();
 	return ret;
 }
Signature · 1 line
2.31.1
#7 lore raw

Re: [PATCH 3/5] app/test: close dma devices during cleanup

Quoted 7 lines · Kevin Laatz

DMA devices are created during PCI probe of EAL init. These devices need to be closed in order to perform necessary cleanup for those devices. This patch adds the call to close() for all DMA devices.

6 ++++++ 1 file changed, 6 insertions(+)

Just to clarify the situation here - on EAL init, all buses are probed and all devices initialized. On eal_cleanup/rte_exit the inverse does not happen, then, i.e. all probed devices on all buses are not closed, right? This would seem a better option than requiring each application to manually close all devices even if it never used them. However, it is probably a bigger and more complex change.

/Bruce

#8 lore raw

Re: [PATCH 3/5] app/test: close dma devices during cleanup

Quoted 8 lines · Bruce Richardson
Quoted 7 lines · Kevin Laatz

DMA devices are created during PCI probe of EAL init. These devices need to be closed in order to perform necessary cleanup for those devices. This patch adds the call to close() for all DMA devices.

6 ++++++ 1 file changed, 6 insertions(+)

Quoted 6 lines

Just to clarify the situation here - on EAL init, all buses are probed and all devices initialized. On eal_cleanup/rte_exit the inverse does not happen, then, i.e. all probed devices on all buses are not closed, right? This would seem a better option than requiring each application to manually close all devices even if it never used them. However, it is probably a bigger and more complex change.

+1, precisely.

I've prepared an RFC to explore option of adding bus cleanup to eal_cleanup() to start a discussion on that option.

https://patches.dpdk.org/project/dpdk/patch/[email protected]/

BR,
Kevin

#9 lore raw

PATCH 4/5 app/testpmd: stop and close dmadevs at exit

In reply to Kevin Laatz

DMA devices are created during PCI probe in EAL init. In order to perform cleanup for those devices, they need to be stopped and closed. This patch adds the necessary cleanup to ensure clean exit.

---
 app/test-pmd/testpmd.c | 9 +++++++++
 1 file changed, 9 insertions(+)
app/test-pmd/testpmd.c +9 -0
index fe2ce19f99..438749c5b8 100644
@@ -45,6 +45,7 @@
 #include <rte_pci.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
+#include <rte_dmadev.h>
 #include <rte_dev.h>
 #include <rte_string_fns.h>
 #ifdef RTE_NET_IXGBE
@@ -3402,6 +3403,14 @@ pmd_test_exit(void)
 		}
 	}
 
+	/* stop and close all dmadevs */
+	RTE_DMA_FOREACH_DEV(i) {
+		printf("\nStopping and closing dmadev %d...\n", i);
+		fflush(stdout);
+		rte_dma_stop(i);
+		rte_dma_close(i);
+	}
+
 	if (hot_plug) {
 		ret = rte_dev_event_monitor_stop();
 		if (ret) {
Signature · 1 line
2.31.1
#10 lore raw

Re: [PATCH 4/5] app/testpmd: stop and close dmadevs at exit

Quoted 14 lines · Kevin Laatz

DMA devices are created during PCI probe in EAL init. In order to perform cleanup for those devices, they need to be stopped and closed. This patch adds the necessary cleanup to ensure clean exit.

---
 app/test-pmd/testpmd.c | 9 +++++++++
 1 file changed, 9 insertions(+)
app/test-pmd/testpmd.c +0 -0
index fe2ce19f99..438749c5b8 100644

app/test-pmd/testpmd.c line 48

Quoted 4 lines
app/test-pmd/testpmd.c +1 -0
@@ -45,6 +45,7 @@
 #include <rte_pci.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
+#include <rte_dmadev.h>

This addition triggers a build error for me, as the header is not found. Does dmadev need to be added as a testpmd dependency in this case?

#11 lore raw

PATCH 5/5 examples/dma: fix missing dma close

In reply to Kevin Laatz

The application stops all dmadevs that it used but never closed any, meaning device cleanup was not done.
This patch adds device cleanup for all dmadevs. All devices need to be closed for completeness, since devices not used by the application may also have been created during PCI probe of EAL init.

Fixes d047310407a3 ("examples/ioat: port application to dmadev API")
---
 examples/dma/dmafwd.c | 6 ++++++
 1 file changed, 6 insertions(+)
examples/dma/dmafwd.c +6 -0
index 608487e35c..4c612a0e0b 100644
@@ -1097,6 +1097,12 @@ main(int argc, char **argv)
 			rte_ring_free(cfg.ports[i].rx_to_tx_ring);
 	}
 
+	/* close all dmadevs */
+	RTE_DMA_FOREACH_DEV(i) {
+		printf("Closing dmadev %d\n", i);
+		rte_dma_close(i);
+	}
+
 	/* clean up the EAL */
 	rte_eal_cleanup();
 
Signature · 1 line
2.31.1
#12 lore raw
In reply to Kevin Laatz
Quoted 6 lines

Kevin Laatz (5):
dma/idxd: fix memory leak in pci close
dma/idxd: fix memory leak due to free on incorrect pointer app/test: close dma devices during cleanup app/testpmd: stop and close dmadevs at exit examples/dma: fix missing dma close

Any news about the v2?

#13 lore raw
Quoted 8 lines · Thomas Monjalon
Quoted 6 lines

Kevin Laatz (5):
dma/idxd: fix memory leak in pci close
dma/idxd: fix memory leak due to free on incorrect pointer app/test: close dma devices during cleanup app/testpmd: stop and close dmadevs at exit examples/dma: fix missing dma close

Any news about the v2?

Hi Thomas,

No v2 yet since we might be able to drop the application changes from this patchset - depending on the changes in the series adding bus cleanup to EAL cleanup [1].

Ideally I would like to rework this bug fix to utilize the changes proposed in [1], so there is a dependency there. That would allow us to fix this bug without adding dma_close() to all applications.

/Kevin

[1] https://patches.dpdk.org/project/dpdk/list/?series=23151

#14 lore raw
Quoted 11 lines · Kevin Laatz
Quoted 8 lines · Thomas Monjalon
Quoted 6 lines

Kevin Laatz (5):
   dma/idxd: fix memory leak in pci close
   dma/idxd: fix memory leak due to free on incorrect pointer app/test: close dma devices during cleanup app/testpmd: stop and close dmadevs at exit examples/dma: fix missing dma close

Any news about the v2?

Hi Thomas,

Quoted 7 lines

No v2 yet since we might be able to drop the application changes from this patchset - depending on the changes in the series adding bus cleanup to EAL cleanup [1].

Ideally I would like to rework this bug fix to utilize the changes proposed in [1], so there is a dependency there. That would allow us to fix this bug without adding dma_close() to all applications.

/Kevin

[1] https://patches.dpdk.org/project/dpdk/list/?series=23151

v6 of the EAL patch is up: https://patches.dpdk.org/project/dpdk/patch/[email protected]/

/Kevin

#15 lore raw

v2 cover Fix IDXD PCI device close

In reply to Kevin Laatz

This patchset addresses the device close for IDXD PCI devices. Initially, there was a memory leak reported by ASAN for the 'pci' member of the 'idxd_dmadev' struct due to a missing free. In addition, this patch set corrects the behaviour of the device close function to ensure the cleanup is completed correctly.

Depends-on: patch-112376 ("eal: add device removal in rte cleanup")

---
v2:
* remove changes to applications (no longer needed with EAL changes)
* add fix for NULL pointer dereference in pci remove

Kevin Laatz (3):
dma/idxd: fix memory leak in pci close
dma/idxd: fix memory leak due to free on incorrect pointer dma/idxd: fix null pointer dereference during pci remove

 drivers/dma/idxd/idxd_common.c   |  2 ++
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 44 +++++++++++++++++++++++---------
 3 files changed, 36 insertions(+), 12 deletions(-)
Signature · 1 line
2.31.1
#16 lore raw

PATCH v2 1/3 dma/idxd: fix memory leak in pci close

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_common.c   |  2 ++
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 34 +++++++++++++++++++++++++-------
 3 files changed, 31 insertions(+), 7 deletions(-)
drivers/dma/idxd/idxd_common.c +2 -0
index c77200a457..d347bbed21 100644
@@ -620,6 +620,8 @@ idxd_dmadev_create(const char *name, struct rte_device *dev,
 	dmadev->fp_obj->dev_private = idxd;
 
 	idxd->dmadev->state = RTE_DMA_DEV_READY;
+	if (idxd->u.pci != NULL)
+		rte_atomic16_inc(&idxd->u.pci->ref_count);
 
 	return 0;
 
drivers/dma/idxd/idxd_internal.h +2 -0
index 3375600217..180a8587c6 100644
@@ -7,6 +7,7 @@
 
 #include <rte_dmadev_pmd.h>
 #include <rte_spinlock.h>
+#include <rte_atomic.h>
 
 #include "idxd_hw_defs.h"
 
@@ -33,6 +34,7 @@ struct idxd_pci_common {
 	rte_spinlock_t lk;
 
 	uint8_t wq_cfg_sz;
+	rte_atomic16_t ref_count;
 	volatile struct rte_idxd_bar0 *regs;
 	volatile uint32_t *wq_regs_base;
 	volatile struct rte_idxd_grpcfg *grp_regs;
drivers/dma/idxd/idxd_pci.c +27 -7
index 65c6bbf4c1..918981f2ea 100644
@@ -6,6 +6,7 @@
 #include <rte_devargs.h>
 #include <rte_dmadev_pmd.h>
 #include <rte_malloc.h>
+#include <rte_atomic.h>
 
 #include "idxd_internal.h"
 
@@ -115,20 +116,38 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 {
 	struct idxd_dmadev *idxd = dev->fp_obj->dev_private;
 	uint8_t err_code;
+	int is_last_wq;
 
-	/* disable the device */
-	err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
-	if (err_code) {
-		IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
-		return err_code;
+	if (idxd_is_wq_enabled(idxd)) {
+		/* disable the wq */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_wq);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling wq: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD WQ disabled OK");
 	}
-	IDXD_PMD_DEBUG("IDXD Device disabled OK");
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
 	rte_free(idxd->batch_idx_ring);
 	rte_free(idxd->desc_ring);
 
+	/* if this is the last WQ on the device, disable the device and free
+	 * the PCI struct
+	 */
+	is_last_wq = rte_atomic16_dec_and_test(&idxd->u.pci->ref_count);
+	if (is_last_wq) {
+		/* disable the device */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD device disabled OK");
+		rte_free(idxd->u.pci);
+	}
+
 	return 0;
 }
 
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
 	uint8_t lg2_max_batch, lg2_max_copy_size;
 	unsigned int i, err_code;
 
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);
 	if (pci == NULL) {
 		IDXD_PMD_ERR("%s: Can't allocate memory", __func__);
 		err_code = -1;
 		goto err;
 	}
+	memset(pci, 0, sizeof(*pci));
 	rte_spinlock_init(&pci->lk);
 
 	/* assign the bar registers, and then configure device */
Signature · 1 line
2.31.1
#17 lore raw

Re: [PATCH v2 1/3] dma/idxd: fix memory leak in pci close

Quoted 10 lines · Kevin Laatz

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Quoted 8 lines
---
 drivers/dma/idxd/idxd_common.c   |  2 ++
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 34 +++++++++++++++++++++++++-------
 3 files changed, 31 insertions(+), 7 deletions(-)

Some comments inline below.

/Bruce

drivers/dma/idxd/idxd_common.c idxd_dmadev_create(const char *name, struct rte_device *dev, · line 627

Quoted 13 lines
drivers/dma/idxd/idxd_common.c +2 -0
index c77200a457..d347bbed21 100644
@@ -620,6 +620,8 @@ idxd_dmadev_create(const char *name, struct rte_device *dev,
 	dmadev->fp_obj->dev_private = idxd;
 
 	idxd->dmadev->state = RTE_DMA_DEV_READY;
+	if (idxd->u.pci != NULL)
+		rte_atomic16_inc(&idxd->u.pci->ref_count);
 
 	return 0;
 

I don't think this belongs in the common code. Can it be put somewhere in the pci-specific driver code to avoid issues, e.g. after idxd_dmadev_create returns in probe_pci() function.

Quoted 78 lines
drivers/dma/idxd/idxd_internal.h +2 -0
index 3375600217..180a8587c6 100644
@@ -7,6 +7,7 @@
 
 #include <rte_dmadev_pmd.h>
 #include <rte_spinlock.h>
+#include <rte_atomic.h>
 
 #include "idxd_hw_defs.h"
 
@@ -33,6 +34,7 @@ struct idxd_pci_common {
 	rte_spinlock_t lk;
 
 	uint8_t wq_cfg_sz;
+	rte_atomic16_t ref_count;
 	volatile struct rte_idxd_bar0 *regs;
 	volatile uint32_t *wq_regs_base;
 	volatile struct rte_idxd_grpcfg *grp_regs;
drivers/dma/idxd/idxd_pci.c +25 -6
index 65c6bbf4c1..918981f2ea 100644
@@ -6,6 +6,7 @@
 #include <rte_devargs.h>
 #include <rte_dmadev_pmd.h>
 #include <rte_malloc.h>
+#include <rte_atomic.h>
 
 #include "idxd_internal.h"
 
@@ -115,20 +116,38 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 {
 	struct idxd_dmadev *idxd = dev->fp_obj->dev_private;
 	uint8_t err_code;
+	int is_last_wq;
 
-	/* disable the device */
-	err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
-	if (err_code) {
-		IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
-		return err_code;
+	if (idxd_is_wq_enabled(idxd)) {
+		/* disable the wq */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_wq);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling wq: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD WQ disabled OK");
 	}
-	IDXD_PMD_DEBUG("IDXD Device disabled OK");
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
 	rte_free(idxd->batch_idx_ring);
 	rte_free(idxd->desc_ring);
 
+	/* if this is the last WQ on the device, disable the device and free
+	 * the PCI struct
+	 */
+	is_last_wq = rte_atomic16_dec_and_test(&idxd->u.pci->ref_count);
+	if (is_last_wq) {
+		/* disable the device */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD device disabled OK");
+		rte_free(idxd->u.pci);
+	}
+
 	return 0;
 }
 

drivers/dma/idxd/idxd_pci.c init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd, · line 181

Quoted 5 lines
drivers/dma/idxd/idxd_pci.c +1 -1
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
 	uint8_t lg2_max_batch, lg2_max_copy_size;
 	unsigned int i, err_code;
 
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);

Any particular reason for the change from regular malloc to rte_malloc?

Quoted 12 lines
drivers/dma/idxd/idxd_pci.c +1 -0
 	if (pci == NULL) {
 		IDXD_PMD_ERR("%s: Can't allocate memory", __func__);
 		err_code = -1;
 		goto err;
 	}
+	memset(pci, 0, sizeof(*pci));
 	rte_spinlock_init(&pci->lk);
 
 	/* assign the bar registers, and then configure device */
Signature · 1 line
2.31.1
#18 lore raw

Re: [PATCH v2 1/3] dma/idxd: fix memory leak in pci close

Quoted 34 lines · Bruce Richardson
Quoted 10 lines · Kevin Laatz

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Quoted 8 lines
---
  drivers/dma/idxd/idxd_common.c   |  2 ++
  drivers/dma/idxd/idxd_internal.h |  2 ++
  drivers/dma/idxd/idxd_pci.c      | 34 +++++++++++++++++++++++++-------
  3 files changed, 31 insertions(+), 7 deletions(-)

Some comments inline below.

/Bruce

Quoted 11 lines
drivers/dma/idxd/idxd_common.c +2 -0
index c77200a457..d347bbed21 100644
@@ -620,6 +620,8 @@ idxd_dmadev_create(const char *name, struct rte_device *dev,
  	dmadev->fp_obj->dev_private = idxd;
 
  	idxd->dmadev->state = RTE_DMA_DEV_READY;
+	if (idxd->u.pci != NULL)
+		rte_atomic16_inc(&idxd->u.pci->ref_count);
 
Quoted 5 lines

drivers/dma/idxd/idxd_common.c idxd_dmadev_create(const char *name, struct rte_device *dev, · line 627

Quoted 2 lines
drivers/dma/idxd/idxd_common.c +0 -0
  	return 0;
 

I don't think this belongs in the common code. Can it be put somewhere in the pci-specific driver code to avoid issues, e.g. after idxd_dmadev_create returns in probe_pci() function.

Sure, I'll look to move it in v3.

[snip]

Quoted 8 lines
drivers/dma/idxd/idxd_pci.c +1 -1
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
  	uint8_t lg2_max_batch, lg2_max_copy_size;
  	unsigned int i, err_code;
 
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);

Any particular reason for the change from regular malloc to rte_malloc?

Mainly consistency, its the only place in the driver where malloc is used instead of rte_malloc.

I have no strong preference here - I can remove the change for v3.

/Kevin

#19 lore raw

Re: [PATCH v2 1/3] dma/idxd: fix memory leak in pci close

Quoted 51 lines · Kevin Laatz
Quoted 23 lines · Bruce Richardson
Quoted 10 lines · Kevin Laatz

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Quoted 8 lines
---
  drivers/dma/idxd/idxd_common.c   |  2 ++
  drivers/dma/idxd/idxd_internal.h |  2 ++
  drivers/dma/idxd/idxd_pci.c      | 34 +++++++++++++++++++++++++-------
  3 files changed, 31 insertions(+), 7 deletions(-)

Some comments inline below.

/Bruce

Quoted 13 lines

drivers/dma/idxd/idxd_common.c idxd_dmadev_create(const char *name, struct rte_device *dev, · line 624

Quoted 10 lines
drivers/dma/idxd/idxd_common.c +2 -0
index c77200a457..d347bbed21 100644
@@ -620,6 +620,8 @@ idxd_dmadev_create(const char *name, struct rte_device *dev,
  	dmadev->fp_obj->dev_private = idxd;
  	idxd->dmadev->state = RTE_DMA_DEV_READY;
+	if (idxd->u.pci != NULL)
+		rte_atomic16_inc(&idxd->u.pci->ref_count);
  	return 0;

I don't think this belongs in the common code. Can it be put somewhere in the pci-specific driver code to avoid issues, e.g. after idxd_dmadev_create returns in probe_pci() function.

Sure, I'll look to move it in v3.

[snip]

Quoted 6 lines
drivers/dma/idxd/idxd_pci.c +1 -1
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
  	uint8_t lg2_max_batch, lg2_max_copy_size;
  	unsigned int i, err_code;
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);

Any particular reason for the change from regular malloc to rte_malloc?

Mainly consistency, its the only place in the driver where malloc is used instead of rte_malloc.

Quoted 2 lines

I have no strong preference here - I can remove the change for v3.

If it's inconsistent with the rest, please do keep the change in v3.

#20 lore raw

PATCH v2 2/3 dma/idxd: fix memory leak due to free on incorrect pointer

In reply to Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.
This patch fixes this memleak by calling free on the correct pointer.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +1 -1
index 918981f2ea..9349c56b3f 100644
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 
 	/* if this is the last WQ on the device, disable the device and free
Signature · 1 line
2.31.1
#21 lore raw

Re: [PATCH v2 2/3] dma/idxd: fix memory leak due to free on incorrect pointer

Quoted 4 lines · Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.

I think you need to explain that the two rings are beside each other in memory and we need to free using the pointer to the start of the block, rather than the pointer to the middle of it.

Quoted 7 lines

This patch fixes this memleak by calling free on the correct pointer.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")

With more explanation in the commit log

Quoted 20 lines
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +1 -1
index 918981f2ea..9349c56b3f 100644
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 
 	/* if this is the last WQ on the device, disable the device and free
Signature · 1 line
2.31.1
#22 lore raw

Re: [PATCH v2 2/3] dma/idxd: fix memory leak due to free on incorrect pointer

Quoted 12 lines · Bruce Richardson
Quoted 4 lines · Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring', causing a memleak from the pointer that should have been free'd.

I think you need to explain that the two rings are beside each other in memory and we need to free using the pointer to the start of the block, rather than the pointer to the middle of it.

Quoted 2 lines

This patch fixes this memleak by calling free on the correct pointer.

Quoted 8 lines
Quoted 5 lines
Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")

With more explanation in the commit log

Correction (obviously!)

#23 lore raw

PATCH v2 3/3 dma/idxd: fix null pointer dereference during pci remove

In reply to Kevin Laatz

The 'info' struct was being declared as a NULL pointer. If a NULL pointer is passed to 'rte_dma_info_get', EINVAL is returned and the struct is not populated. This subsequently causes a segfault when dereferencing 'info'.

This patch fixes the issue by simply declaring 'info' as a variable and passing its address to 'rte_dma_info_get'.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dma/idxd/idxd_pci.c +4 -4
index 9349c56b3f..3c1effeb84 100644
@@ -379,10 +379,10 @@ idxd_dmadev_remove_pci(struct rte_pci_device *dev)
 	IDXD_PMD_INFO("Closing %s on NUMA node %d", name, dev->device.numa_node);
 
 	RTE_DMA_FOREACH_DEV(i) {
-		struct rte_dma_info *info = {0};
-		rte_dma_info_get(i, info);
-		if (strncmp(name, info->dev_name, strlen(name)) == 0)
-			idxd_dmadev_destroy(info->dev_name);
+		struct rte_dma_info info;
+		rte_dma_info_get(i, &info);
+		if (strncmp(name, info.dev_name, strlen(name)) == 0)
+			idxd_dmadev_destroy(info.dev_name);
 	}
 
 	return 0;
Signature · 1 line
2.31.1
Acked-by on v2 3/3
#24 lore raw

Re: [PATCH v2 3/3] dma/idxd: fix null pointer dereference during pci remove

Quoted 6 lines · Kevin Laatz

The 'info' struct was being declared as a NULL pointer. If a NULL pointer is passed to 'rte_dma_info_get', EINVAL is returned and the struct is not populated. This subsequently causes a segfault when dereferencing 'info'.

This patch fixes the issue by simply declaring 'info' as a variable and

s/as a variable/on the stack/

Quoted 6 lines

passing its address to 'rte_dma_info_get'.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Quoted 26 lines
---
 drivers/dma/idxd/idxd_pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dma/idxd/idxd_pci.c +4 -4
index 9349c56b3f..3c1effeb84 100644
@@ -379,10 +379,10 @@ idxd_dmadev_remove_pci(struct rte_pci_device *dev)
 	IDXD_PMD_INFO("Closing %s on NUMA node %d", name, dev->device.numa_node);
 
 	RTE_DMA_FOREACH_DEV(i) {
-		struct rte_dma_info *info = {0};
-		rte_dma_info_get(i, info);
-		if (strncmp(name, info->dev_name, strlen(name)) == 0)
-			idxd_dmadev_destroy(info->dev_name);
+		struct rte_dma_info info;
+		rte_dma_info_get(i, &info);
+		if (strncmp(name, info.dev_name, strlen(name)) == 0)
+			idxd_dmadev_destroy(info.dev_name);
 	}
 
 	return 0;
Signature · 1 line
2.31.1
#25 lore raw

v3 cover Fix IDXD PCI device close

In reply to Kevin Laatz

This patchset addresses the device close for IDXD PCI devices. Initially, there was a memory leak reported by ASAN for the 'pci' member of the 'idxd_dmadev' struct due to a missing free. In addition, this patch set corrects the behaviour of the device close function to ensure the cleanup is completed correctly.

Depends-on: patch-112376 ("eal: add device removal in rte cleanup")

---
v3:
* move ref_count increment from common create to pci probe
* improve commit messages

v2:
* remove changes to applications (no longer needed with EAL changes)
* add fix for NULL pointer dereference in pci remove

Kevin Laatz (3):
dma/idxd: fix memory leak in pci close
dma/idxd: fix memory leak due to free on incorrect pointer dma/idxd: fix null pointer dereference during pci remove

 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 45 +++++++++++++++++++++++---------
 2 files changed, 35 insertions(+), 12 deletions(-)
Signature · 1 line
2.31.1
#26 lore raw

PATCH v3 1/3 dma/idxd: fix memory leak in pci close

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")

--
v3: move ref_count increment to pci probe

---
 drivers/dma/idxd/idxd_internal.h |  2 ++
 drivers/dma/idxd/idxd_pci.c      | 35 +++++++++++++++++++++++++-------
 2 files changed, 30 insertions(+), 7 deletions(-)
drivers/dma/idxd/idxd_internal.h +2 -0
index 3375600217..180a8587c6 100644
@@ -7,6 +7,7 @@
 
 #include <rte_dmadev_pmd.h>
 #include <rte_spinlock.h>
+#include <rte_atomic.h>
 
 #include "idxd_hw_defs.h"
 
@@ -33,6 +34,7 @@ struct idxd_pci_common {
 	rte_spinlock_t lk;
 
 	uint8_t wq_cfg_sz;
+	rte_atomic16_t ref_count;
 	volatile struct rte_idxd_bar0 *regs;
 	volatile uint32_t *wq_regs_base;
 	volatile struct rte_idxd_grpcfg *grp_regs;
drivers/dma/idxd/idxd_pci.c +28 -7
index 65c6bbf4c1..fb618d34b6 100644
@@ -6,6 +6,7 @@
 #include <rte_devargs.h>
 #include <rte_dmadev_pmd.h>
 #include <rte_malloc.h>
+#include <rte_atomic.h>
 
 #include "idxd_internal.h"
 
@@ -115,20 +116,38 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 {
 	struct idxd_dmadev *idxd = dev->fp_obj->dev_private;
 	uint8_t err_code;
+	int is_last_wq;
 
-	/* disable the device */
-	err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
-	if (err_code) {
-		IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
-		return err_code;
+	if (idxd_is_wq_enabled(idxd)) {
+		/* disable the wq */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_wq);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling wq: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD WQ disabled OK");
 	}
-	IDXD_PMD_DEBUG("IDXD Device disabled OK");
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
 	rte_free(idxd->batch_idx_ring);
 	rte_free(idxd->desc_ring);
 
+	/* if this is the last WQ on the device, disable the device and free
+	 * the PCI struct
+	 */
+	is_last_wq = rte_atomic16_dec_and_test(&idxd->u.pci->ref_count);
+	if (is_last_wq) {
+		/* disable the device */
+		err_code = idxd_pci_dev_command(idxd, idxd_disable_dev);
+		if (err_code) {
+			IDXD_PMD_ERR("Error disabling device: code %#x", err_code);
+			return err_code;
+		}
+		IDXD_PMD_DEBUG("IDXD device disabled OK");
+		rte_free(idxd->u.pci);
+	}
+
 	return 0;
 }
 
@@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct idxd_dmadev *idxd,
 	uint8_t lg2_max_batch, lg2_max_copy_size;
 	unsigned int i, err_code;
 
-	pci = malloc(sizeof(*pci));
+	pci = rte_malloc(NULL, sizeof(*pci), 0);
 	if (pci == NULL) {
 		IDXD_PMD_ERR("%s: Can't allocate memory", __func__);
 		err_code = -1;
 		goto err;
 	}
+	memset(pci, 0, sizeof(*pci));
 	rte_spinlock_init(&pci->lk);
 
 	/* assign the bar registers, and then configure device */
@@ -330,6 +350,7 @@ idxd_dmadev_probe_pci(struct rte_pci_driver *drv, struct rte_pci_device *dev)
 				free(idxd.u.pci);
 			return ret;
 		}
+		rte_atomic16_inc(&idxd.u.pci->ref_count);
 	}
 
 	return 0;
Signature · 1 line
2.31.1
Acked-by on v3 1/3
#27 lore raw

Re: [PATCH v3 1/3] dma/idxd: fix memory leak in pci close

Quoted 10 lines · Kevin Laatz

ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev' struct.

This is fixed by free'ing the struct when the last queue on the PCI device is being closed.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Quoted 6 lines

--
v3: move ref_count increment to pci probe
---

#28 lore raw

PATCH v3 2/3 dma/idxd: fix memory leak due to free on incorrect pointer

In reply to Kevin Laatz

During PCI device close, any allocated memory needs to be free'd. Currently, one of the free's is being called on an incorrect idxd_dmadev struct member, namely 'batch_idx_ring'.

At device creation, memory is allocated for both 'batch_comp_ring' and 'batch_idx_ring' simultaeneously. Calling free only on 'batch_idx_ring' meant the first half of this memory was not being free'd, leading to the memleak.

This patch fixes this memleak by calling free on 'batch_comp_ring' which will free the memory for both rings.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/idxd/idxd_pci.c +1 -1
index fb618d34b6..2c3b01cd2b 100644
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 
 	/* if this is the last WQ on the device, disable the device and free
Signature · 1 line
2.31.1
#29 lore raw

PATCH v3 3/3 dma/idxd: fix null pointer dereference during pci remove

In reply to Kevin Laatz

The 'info' struct was being declared as a NULL pointer. If a NULL pointer is passed to 'rte_dma_info_get', EINVAL is returned and the struct is not populated. This subsequently causes a segfault when dereferencing 'info'.

This patch fixes the issue by simply declaring 'info' on the stack and passing its address to 'rte_dma_info_get'.

Fixes 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
---
 drivers/dma/idxd/idxd_pci.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/dma/idxd/idxd_pci.c +4 -4
index 2c3b01cd2b..2f8ec06d9e 100644
@@ -380,10 +380,10 @@ idxd_dmadev_remove_pci(struct rte_pci_device *dev)
 	IDXD_PMD_INFO("Closing %s on NUMA node %d", name, dev->device.numa_node);
 
 	RTE_DMA_FOREACH_DEV(i) {
-		struct rte_dma_info *info = {0};
-		rte_dma_info_get(i, info);
-		if (strncmp(name, info->dev_name, strlen(name)) == 0)
-			idxd_dmadev_destroy(info->dev_name);
+		struct rte_dma_info info;
+		rte_dma_info_get(i, &info);
+		if (strncmp(name, info.dev_name, strlen(name)) == 0)
+			idxd_dmadev_destroy(info.dev_name);
 	}
 
 	return 0;
Signature · 1 line
2.31.1
#30 lore raw
In reply to Kevin Laatz

04/07/2022 17:27, Kevin Laatz:

Quoted 7 lines

This patchset addresses the device close for IDXD PCI devices. Initially, there was a memory leak reported by ASAN for the 'pci' member of the 'idxd_dmadev' struct due to a missing free. In addition, this patch set corrects the behaviour of the device close function to ensure the cleanup is completed correctly.

Depends-on: patch-112376 ("eal: add device removal in rte cleanup")

I assume it is not a real dependency.
We can fix closing without calling the close function in EAL cleanup.

Applied, thanks.