public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes
@ 2026-01-15 22:47 Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

Hi,

During testing some not so happy code paths in a debugging (lockdep,
kmemleak, etc) kernel, found a few issues.

No code changes, just rebased against 'dmaengine/next'. The cover
letter was edited to remove not helpful text.

Cheers,

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
Changes in v2:
- Fixed messing up the definition of FLR (Function Level
  Reset) (Nathan Lynch)
- Simplified callers of idxd_device_config(), moved a common check,
  and locking to inside the function (Dave Jiang);
- For idxd DMA backend, ->terminate_all() now flushes all pending
  descriptors (Dave Jiang);
- For idxd DMA backend, ->device_synchronize() now waits for submitted
  operations to finish (Dave Jiang);
- Link to v1: https://lore.kernel.org/r/20250804-idxd-fix-flr-on-kernel-queues-v3-v1-0-4e020fbf52c1@intel.com

---
Vinicius Costa Gomes (10):
      dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config()
      dmaengine: idxd: Fix crash when the event log is disabled
      dmaengine: idxd: Fix possible invalid memory access after FLR
      dmaengine: idxd: Flush kernel workqueues on Function Level Reset
      dmaengine: idxd: Flush all pending descriptors
      dmaengine: idxd: Wait for submitted operations on .device_synchronize()
      dmaengine: idxd: Fix not releasing workqueue on .release()
      dmaengine: idxd: Fix memory leak when a wq is reset
      dmaengine: idxd: Fix freeing the allocated ida too late
      dmaengine: idxd: Fix leaking event log memory

 drivers/dma/idxd/cdev.c   |  8 ++++----
 drivers/dma/idxd/device.c | 43 +++++++++++++++++++++++++++++--------------
 drivers/dma/idxd/dma.c    | 18 ++++++++++++++++++
 drivers/dma/idxd/idxd.h   |  1 +
 drivers/dma/idxd/init.c   | 14 +++++++-------
 drivers/dma/idxd/irq.c    | 16 ++++++++++++++++
 drivers/dma/idxd/sysfs.c  |  1 +
 7 files changed, 76 insertions(+), 25 deletions(-)
---
base-commit: 3c8a86ed002ab8fb287ee4ec92f0fd6ac5b291d2
change-id: 20250804-idxd-fix-flr-on-kernel-queues-v3-13f37abd7178

Best regards,
--  
Vinicius


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

* [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config()
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-16 20:08   ` Dave Jiang
  2026-01-15 22:47 ` [PATCH RESEND v2 02/10] dmaengine: idxd: Fix crash when the event log is disabled Vinicius Costa Gomes
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

Move the check for IDXD_FLAG_CONFIGURABLE and the locking to "inside"
idxd_device_config(), as this is common to all callers, and the one
that wasn't holding the lock was an error (that was causing the
lockdep warning).

Suggested-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/device.c | 17 +++++++----------
 drivers/dma/idxd/init.c   | 10 ++++------
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index c26128529ff4..a704475d87b3 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1125,7 +1125,11 @@ int idxd_device_config(struct idxd_device *idxd)
 {
 	int rc;
 
-	lockdep_assert_held(&idxd->dev_lock);
+	guard(spinlock)(&idxd->dev_lock);
+
+	if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
+		return 0;
+
 	rc = idxd_wqs_setup(idxd);
 	if (rc < 0)
 		return rc;
@@ -1454,11 +1458,7 @@ int idxd_drv_enable_wq(struct idxd_wq *wq)
 		}
 	}
 
-	rc = 0;
-	spin_lock(&idxd->dev_lock);
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
-		rc = idxd_device_config(idxd);
-	spin_unlock(&idxd->dev_lock);
+	rc = idxd_device_config(idxd);
 	if (rc < 0) {
 		dev_dbg(dev, "Writing wq %d config failed: %d\n", wq->id, rc);
 		goto err;
@@ -1554,10 +1554,7 @@ int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
 	}
 
 	/* Device configuration */
-	spin_lock(&idxd->dev_lock);
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
-		rc = idxd_device_config(idxd);
-	spin_unlock(&idxd->dev_lock);
+	rc = idxd_device_config(idxd);
 	if (rc < 0)
 		return -ENXIO;
 
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index fb80803d5b57..dd32b81a3108 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1104,12 +1104,10 @@ static void idxd_reset_done(struct pci_dev *pdev)
 	idxd_device_config_restore(idxd, idxd->idxd_saved);
 
 	/* Re-configure IDXD device if allowed. */
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) {
-		rc = idxd_device_config(idxd);
-		if (rc < 0) {
-			dev_err(dev, "HALT: %s config fails\n", idxd_name);
-			goto out;
-		}
+	rc = idxd_device_config(idxd);
+	if (rc < 0) {
+		dev_err(dev, "HALT: %s config fails\n", idxd_name);
+		goto out;
 	}
 
 	/* Bind IDXD device to driver. */

-- 
2.52.0


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

* [PATCH RESEND v2 02/10] dmaengine: idxd: Fix crash when the event log is disabled
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 03/10] dmaengine: idxd: Fix possible invalid memory access after FLR Vinicius Costa Gomes
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

If reporting errors to the event log is not supported by the hardware,
and an error that causes Function Level Reset (FLR) is received, the
driver will try to restore the event log even if it was not allocated.

Also, only try to free the event log if it was properly allocated.

Fixes: 6078a315aec1 ("dmaengine: idxd: Add idxd_device_config_save() and idxd_device_config_restore() helpers")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/device.c | 3 +++
 drivers/dma/idxd/init.c   | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index a704475d87b3..5265925f3076 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -831,6 +831,9 @@ static void idxd_device_evl_free(struct idxd_device *idxd)
 	struct device *dev = &idxd->pdev->dev;
 	struct idxd_evl *evl = idxd->evl;
 
+	if (!evl)
+		return;
+
 	gencfg.bits = ioread32(idxd->reg_base + IDXD_GENCFG_OFFSET);
 	if (!gencfg.evl_en)
 		return;
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index dd32b81a3108..1c3f9bc7364b 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -973,7 +973,8 @@ static void idxd_device_config_restore(struct idxd_device *idxd,
 
 	idxd->rdbuf_limit = idxd_saved->saved_idxd.rdbuf_limit;
 
-	idxd->evl->size = saved_evl->size;
+	if (idxd->evl)
+		idxd->evl->size = saved_evl->size;
 
 	for (i = 0; i < idxd->max_groups; i++) {
 		struct idxd_group *saved_group, *group;

-- 
2.52.0


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

* [PATCH RESEND v2 03/10] dmaengine: idxd: Fix possible invalid memory access after FLR
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 02/10] dmaengine: idxd: Fix crash when the event log is disabled Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset Vinicius Costa Gomes
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

In the case that the first Function Level Reset (FLR) concludes
correctly, but in the second FLR the scratch area for the saved
configuration cannot be allocated, it's possible for a invalid memory
access to happen.

Always set the deallocated scratch area to NULL after FLR completes.

Fixes: 98d187a98903 ("dmaengine: idxd: Enable Function Level Reset (FLR) for halt")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 1c3f9bc7364b..f1cfc7790d95 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1146,6 +1146,7 @@ static void idxd_reset_done(struct pci_dev *pdev)
 	}
 out:
 	kfree(idxd->idxd_saved);
+	idxd->idxd_saved = NULL;
 }
 
 static const struct pci_error_handlers idxd_error_handler = {

-- 
2.52.0


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

* [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (2 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 03/10] dmaengine: idxd: Fix possible invalid memory access after FLR Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-16 20:16   ` Dave Jiang
  2026-01-15 22:47 ` [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors Vinicius Costa Gomes
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

When a Function Level Reset (FLR) happens, terminate the pending
descriptors that were issued by in-kernel users and disable the
interrupts associated with those. They will be re-enabled after FLR
finishes.

idxd_wq_flush_desc() is declared on idxd.h because it's going to be
used in by the DMA backend in a future patch.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/device.c | 20 ++++++++++++++++++++
 drivers/dma/idxd/idxd.h   |  1 +
 drivers/dma/idxd/irq.c    | 16 ++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 5265925f3076..b8422dc7d2ca 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1339,6 +1339,11 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
 
 	free_irq(ie->vector, ie);
 	idxd_flush_pending_descs(ie);
+
+	/* The interrupt might have been already released by FLR */
+	if (ie->int_handle == INVALID_INT_HANDLE)
+		return;
+
 	if (idxd->request_int_handles)
 		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
 	idxd_device_clear_perm_entry(idxd, ie);
@@ -1347,6 +1352,21 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
 	ie->pasid = IOMMU_PASID_INVALID;
 }
 
+void idxd_wq_flush_descs(struct idxd_wq *wq)
+{
+	struct idxd_irq_entry *ie = &wq->ie;
+	struct idxd_device *idxd = wq->idxd;
+
+	if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
+		return;
+
+	idxd_flush_pending_descs(ie);
+	if (idxd->request_int_handles)
+		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
+	idxd_device_clear_perm_entry(idxd, ie);
+	ie->int_handle = INVALID_INT_HANDLE;
+}
+
 int idxd_wq_request_irq(struct idxd_wq *wq)
 {
 	struct idxd_device *idxd = wq->idxd;
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index ea8c4daed38d..ce78b9a7c641 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -803,6 +803,7 @@ void idxd_wq_quiesce(struct idxd_wq *wq);
 int idxd_wq_init_percpu_ref(struct idxd_wq *wq);
 void idxd_wq_free_irq(struct idxd_wq *wq);
 int idxd_wq_request_irq(struct idxd_wq *wq);
+void idxd_wq_flush_descs(struct idxd_wq *wq);
 
 /* submission */
 int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
index 1107db3ce0a3..8d0eaf5029fa 100644
--- a/drivers/dma/idxd/irq.c
+++ b/drivers/dma/idxd/irq.c
@@ -397,6 +397,17 @@ static void idxd_device_flr(struct work_struct *work)
 		dev_err(&idxd->pdev->dev, "FLR failed\n");
 }
 
+static void idxd_wqs_flush_descs(struct idxd_device *idxd)
+{
+	int i;
+
+	for (i = 0; i < idxd->max_wqs; i++) {
+		struct idxd_wq *wq = idxd->wqs[i];
+
+		idxd_wq_flush_descs(wq);
+	}
+}
+
 static irqreturn_t idxd_halt(struct idxd_device *idxd)
 {
 	union gensts_reg gensts;
@@ -415,6 +426,11 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
 		} else if (gensts.reset_type == IDXD_DEVICE_RESET_FLR) {
 			idxd->state = IDXD_DEV_HALTED;
 			idxd_mask_error_interrupts(idxd);
+			/* Flush all pending descriptors, and disable
+			 * interrupts, they will be re-enabled when FLR
+			 * concludes.
+			 */
+			idxd_wqs_flush_descs(idxd);
 			dev_dbg(&idxd->pdev->dev,
 				"idxd halted, doing FLR. After FLR, configs are restored\n");
 			INIT_WORK(&idxd->work, idxd_device_flr);

-- 
2.52.0


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

* [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (3 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-16 20:22   ` Dave Jiang
  2026-01-15 22:47 ` [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize() Vinicius Costa Gomes
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

When used as a dmaengine, the DMA "core" might ask the driver to
terminate all pending requests, when that happens, flush all pending
descriptors.

In this context, flush means removing the requests from the pending
lists, so even if they are completed after, the user is not notified.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/dma.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
index dbecd699237e..e4f9788aa635 100644
--- a/drivers/dma/idxd/dma.c
+++ b/drivers/dma/idxd/dma.c
@@ -194,6 +194,15 @@ static void idxd_dma_release(struct dma_device *device)
 	kfree(idxd_dma);
 }
 
+static int idxd_dma_terminate_all(struct dma_chan *c)
+{
+	struct idxd_wq *wq = to_idxd_wq(c);
+
+	idxd_wq_flush_descs(wq);
+
+	return 0;
+}
+
 int idxd_register_dma_device(struct idxd_device *idxd)
 {
 	struct idxd_dma_dev *idxd_dma;
@@ -224,6 +233,7 @@ int idxd_register_dma_device(struct idxd_device *idxd)
 	dma->device_issue_pending = idxd_dma_issue_pending;
 	dma->device_alloc_chan_resources = idxd_dma_alloc_chan_resources;
 	dma->device_free_chan_resources = idxd_dma_free_chan_resources;
+	dma->device_terminate_all = idxd_dma_terminate_all;
 
 	rc = dma_async_device_register(dma);
 	if (rc < 0) {

-- 
2.52.0


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

* [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize()
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (4 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-16 20:27   ` Dave Jiang
  2026-01-15 22:47 ` [PATCH RESEND v2 07/10] dmaengine: idxd: Fix not releasing workqueue on .release() Vinicius Costa Gomes
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

When the dmaengine "core" asks the driver to synchronize, send a Drain
operation to the device workqueue, which will wait for the already
submitted operations to finish.

Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/dma.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
index e4f9788aa635..9937b671f637 100644
--- a/drivers/dma/idxd/dma.c
+++ b/drivers/dma/idxd/dma.c
@@ -203,6 +203,13 @@ static int idxd_dma_terminate_all(struct dma_chan *c)
 	return 0;
 }
 
+static void idxd_dma_synchronize(struct dma_chan *c)
+{
+	struct idxd_wq *wq = to_idxd_wq(c);
+
+	idxd_wq_drain(wq);
+}
+
 int idxd_register_dma_device(struct idxd_device *idxd)
 {
 	struct idxd_dma_dev *idxd_dma;
@@ -234,6 +241,7 @@ int idxd_register_dma_device(struct idxd_device *idxd)
 	dma->device_alloc_chan_resources = idxd_dma_alloc_chan_resources;
 	dma->device_free_chan_resources = idxd_dma_free_chan_resources;
 	dma->device_terminate_all = idxd_dma_terminate_all;
+	dma->device_synchronize = idxd_dma_synchronize;
 
 	rc = dma_async_device_register(dma);
 	if (rc < 0) {

-- 
2.52.0


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

* [PATCH RESEND v2 07/10] dmaengine: idxd: Fix not releasing workqueue on .release()
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (5 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize() Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 08/10] dmaengine: idxd: Fix memory leak when a wq is reset Vinicius Costa Gomes
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

The workqueue associated with an DSA/IAA device is not released when
the object is freed.

Fixes: 47c16ac27d4c ("dmaengine: idxd: fix idxd conf_dev 'struct device' lifetime")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
index cc2c83d7f710..6d251095c350 100644
--- a/drivers/dma/idxd/sysfs.c
+++ b/drivers/dma/idxd/sysfs.c
@@ -1836,6 +1836,7 @@ static void idxd_conf_device_release(struct device *dev)
 {
 	struct idxd_device *idxd = confdev_to_idxd(dev);
 
+	destroy_workqueue(idxd->wq);
 	kfree(idxd->groups);
 	bitmap_free(idxd->wq_enable_map);
 	kfree(idxd->wqs);

-- 
2.52.0


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

* [PATCH RESEND v2 08/10] dmaengine: idxd: Fix memory leak when a wq is reset
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (6 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 07/10] dmaengine: idxd: Fix not releasing workqueue on .release() Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 09/10] dmaengine: idxd: Fix freeing the allocated ida too late Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 10/10] dmaengine: idxd: Fix leaking event log memory Vinicius Costa Gomes
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

idxd_wq_disable_cleanup() which is called from the reset path for a
workqueue, sets the wq type to NONE, which for other parts of the
driver mean that the wq is empty (all its resources were released).

Only set the wq type to NONE after its resources are released.

Fixes: da32b28c95a7 ("dmaengine: idxd: cleanup workqueue config after disabling")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index b8422dc7d2ca..6de61f0d486f 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -175,6 +175,7 @@ void idxd_wq_free_resources(struct idxd_wq *wq)
 	free_descs(wq);
 	dma_free_coherent(dev, wq->compls_size, wq->compls, wq->compls_addr);
 	sbitmap_queue_free(&wq->sbq);
+	wq->type = IDXD_WQT_NONE;
 }
 EXPORT_SYMBOL_NS_GPL(idxd_wq_free_resources, "IDXD");
 
@@ -382,7 +383,6 @@ static void idxd_wq_disable_cleanup(struct idxd_wq *wq)
 	lockdep_assert_held(&wq->wq_lock);
 	wq->state = IDXD_WQ_DISABLED;
 	memset(wq->wqcfg, 0, idxd->wqcfg_size);
-	wq->type = IDXD_WQT_NONE;
 	wq->threshold = 0;
 	wq->priority = 0;
 	wq->enqcmds_retries = IDXD_ENQCMDS_RETRIES;
@@ -1556,7 +1556,6 @@ void idxd_drv_disable_wq(struct idxd_wq *wq)
 	idxd_wq_reset(wq);
 	idxd_wq_free_resources(wq);
 	percpu_ref_exit(&wq->wq_active);
-	wq->type = IDXD_WQT_NONE;
 	wq->client_count = 0;
 }
 EXPORT_SYMBOL_NS_GPL(idxd_drv_disable_wq, "IDXD");

-- 
2.52.0


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

* [PATCH RESEND v2 09/10] dmaengine: idxd: Fix freeing the allocated ida too late
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (7 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 08/10] dmaengine: idxd: Fix memory leak when a wq is reset Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  2026-01-15 22:47 ` [PATCH RESEND v2 10/10] dmaengine: idxd: Fix leaking event log memory Vinicius Costa Gomes
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

It can happen that when the cdev .release() is called, the driver
already called ida_destroy(). Move ida_free() to the _del() path.

We see with DEBUG_KOBJECT_RELEASE enabled and forcing an early PCI
unbind.

Fixes: 04922b7445a1 ("dmaengine: idxd: fix cdev setup and free device lifetime issues")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/cdev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index 7e4715f92773..4105688cf3f0 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -158,11 +158,7 @@ static const struct device_type idxd_cdev_file_type = {
 static void idxd_cdev_dev_release(struct device *dev)
 {
 	struct idxd_cdev *idxd_cdev = dev_to_cdev(dev);
-	struct idxd_cdev_context *cdev_ctx;
-	struct idxd_wq *wq = idxd_cdev->wq;
 
-	cdev_ctx = &ictx[wq->idxd->data->type];
-	ida_free(&cdev_ctx->minor_ida, idxd_cdev->minor);
 	kfree(idxd_cdev);
 }
 
@@ -582,11 +578,15 @@ int idxd_wq_add_cdev(struct idxd_wq *wq)
 
 void idxd_wq_del_cdev(struct idxd_wq *wq)
 {
+	struct idxd_cdev_context *cdev_ctx;
 	struct idxd_cdev *idxd_cdev;
 
 	idxd_cdev = wq->idxd_cdev;
 	wq->idxd_cdev = NULL;
 	cdev_device_del(&idxd_cdev->cdev, cdev_dev(idxd_cdev));
+
+	cdev_ctx = &ictx[wq->idxd->data->type];
+	ida_free(&cdev_ctx->minor_ida, idxd_cdev->minor);
 	put_device(cdev_dev(idxd_cdev));
 }
 

-- 
2.52.0


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

* [PATCH RESEND v2 10/10] dmaengine: idxd: Fix leaking event log memory
  2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
                   ` (8 preceding siblings ...)
  2026-01-15 22:47 ` [PATCH RESEND v2 09/10] dmaengine: idxd: Fix freeing the allocated ida too late Vinicius Costa Gomes
@ 2026-01-15 22:47 ` Vinicius Costa Gomes
  9 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-15 22:47 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams
  Cc: dmaengine, linux-kernel, Vinicius Costa Gomes

During the device remove process, the device is reset, causing the
configuration registers to go back to their default state, which is
zero. As the driver is checking if the event log support was enabled
before deallocating, it will fail if a reset happened before.

Do not check if the support was enabled, the check for 'idxd->evl'
being valid (only allocated if the HW capability is available) is
enough.

Fixes: 244da66cda35 ("dmaengine: idxd: setup event log configuration")
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
 drivers/dma/idxd/device.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 6de61f0d486f..be6ba88d1577 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -834,10 +834,6 @@ static void idxd_device_evl_free(struct idxd_device *idxd)
 	if (!evl)
 		return;
 
-	gencfg.bits = ioread32(idxd->reg_base + IDXD_GENCFG_OFFSET);
-	if (!gencfg.evl_en)
-		return;
-
 	mutex_lock(&evl->lock);
 	gencfg.evl_en = 0;
 	iowrite32(gencfg.bits, idxd->reg_base + IDXD_GENCFG_OFFSET);

-- 
2.52.0


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

* Re: [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config()
  2026-01-15 22:47 ` [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
@ 2026-01-16 20:08   ` Dave Jiang
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Jiang @ 2026-01-16 20:08 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Vinod Koul, Dan Williams; +Cc: dmaengine, linux-kernel



On 1/15/26 3:47 PM, Vinicius Costa Gomes wrote:
> Move the check for IDXD_FLAG_CONFIGURABLE and the locking to "inside"
> idxd_device_config(), as this is common to all callers, and the one
> that wasn't holding the lock was an error (that was causing the
> lockdep warning).
> 
> Suggested-by: Dave Jiang <dave.jiang@intel.com>
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>


> ---
>  drivers/dma/idxd/device.c | 17 +++++++----------
>  drivers/dma/idxd/init.c   | 10 ++++------
>  2 files changed, 11 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
> index c26128529ff4..a704475d87b3 100644
> --- a/drivers/dma/idxd/device.c
> +++ b/drivers/dma/idxd/device.c
> @@ -1125,7 +1125,11 @@ int idxd_device_config(struct idxd_device *idxd)
>  {
>  	int rc;
>  
> -	lockdep_assert_held(&idxd->dev_lock);
> +	guard(spinlock)(&idxd->dev_lock);
> +
> +	if (!test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
> +		return 0;
> +
>  	rc = idxd_wqs_setup(idxd);
>  	if (rc < 0)
>  		return rc;
> @@ -1454,11 +1458,7 @@ int idxd_drv_enable_wq(struct idxd_wq *wq)
>  		}
>  	}
>  
> -	rc = 0;
> -	spin_lock(&idxd->dev_lock);
> -	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
> -		rc = idxd_device_config(idxd);
> -	spin_unlock(&idxd->dev_lock);
> +	rc = idxd_device_config(idxd);
>  	if (rc < 0) {
>  		dev_dbg(dev, "Writing wq %d config failed: %d\n", wq->id, rc);
>  		goto err;
> @@ -1554,10 +1554,7 @@ int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
>  	}
>  
>  	/* Device configuration */
> -	spin_lock(&idxd->dev_lock);
> -	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
> -		rc = idxd_device_config(idxd);
> -	spin_unlock(&idxd->dev_lock);
> +	rc = idxd_device_config(idxd);
>  	if (rc < 0)
>  		return -ENXIO;
>  
> diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
> index fb80803d5b57..dd32b81a3108 100644
> --- a/drivers/dma/idxd/init.c
> +++ b/drivers/dma/idxd/init.c
> @@ -1104,12 +1104,10 @@ static void idxd_reset_done(struct pci_dev *pdev)
>  	idxd_device_config_restore(idxd, idxd->idxd_saved);
>  
>  	/* Re-configure IDXD device if allowed. */
> -	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags)) {
> -		rc = idxd_device_config(idxd);
> -		if (rc < 0) {
> -			dev_err(dev, "HALT: %s config fails\n", idxd_name);
> -			goto out;
> -		}
> +	rc = idxd_device_config(idxd);
> +	if (rc < 0) {
> +		dev_err(dev, "HALT: %s config fails\n", idxd_name);
> +		goto out;
>  	}
>  
>  	/* Bind IDXD device to driver. */
> 


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

* Re: [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset
  2026-01-15 22:47 ` [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset Vinicius Costa Gomes
@ 2026-01-16 20:16   ` Dave Jiang
  2026-01-17  1:18     ` Vinicius Costa Gomes
  0 siblings, 1 reply; 16+ messages in thread
From: Dave Jiang @ 2026-01-16 20:16 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Vinod Koul, Dan Williams; +Cc: dmaengine, linux-kernel



On 1/15/26 3:47 PM, Vinicius Costa Gomes wrote:
> When a Function Level Reset (FLR) happens, terminate the pending
> descriptors that were issued by in-kernel users and disable the
> interrupts associated with those. They will be re-enabled after FLR
> finishes.
> 
> idxd_wq_flush_desc() is declared on idxd.h because it's going to be
> used in by the DMA backend in a future patch.
> 
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
> ---
>  drivers/dma/idxd/device.c | 20 ++++++++++++++++++++
>  drivers/dma/idxd/idxd.h   |  1 +
>  drivers/dma/idxd/irq.c    | 16 ++++++++++++++++
>  3 files changed, 37 insertions(+)
> 
> diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
> index 5265925f3076..b8422dc7d2ca 100644
> --- a/drivers/dma/idxd/device.c
> +++ b/drivers/dma/idxd/device.c
> @@ -1339,6 +1339,11 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
>  
>  	free_irq(ie->vector, ie);
>  	idxd_flush_pending_descs(ie);
> +
> +	/* The interrupt might have been already released by FLR */
> +	if (ie->int_handle == INVALID_INT_HANDLE)
> +		return;
> +
>  	if (idxd->request_int_handles)
>  		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
>  	idxd_device_clear_perm_entry(idxd, ie);
> @@ -1347,6 +1352,21 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
>  	ie->pasid = IOMMU_PASID_INVALID;
>  }
>  
> +void idxd_wq_flush_descs(struct idxd_wq *wq)
> +{
> +	struct idxd_irq_entry *ie = &wq->ie;
> +	struct idxd_device *idxd = wq->idxd;
> +
Should it take a wq lock for this function?

DJ

> +	if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
> +		return;
> +
> +	idxd_flush_pending_descs(ie);
> +	if (idxd->request_int_handles)
> +		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
> +	idxd_device_clear_perm_entry(idxd, ie);
> +	ie->int_handle = INVALID_INT_HANDLE;
> +}
> +
>  int idxd_wq_request_irq(struct idxd_wq *wq)
>  {
>  	struct idxd_device *idxd = wq->idxd;
> diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
> index ea8c4daed38d..ce78b9a7c641 100644
> --- a/drivers/dma/idxd/idxd.h
> +++ b/drivers/dma/idxd/idxd.h
> @@ -803,6 +803,7 @@ void idxd_wq_quiesce(struct idxd_wq *wq);
>  int idxd_wq_init_percpu_ref(struct idxd_wq *wq);
>  void idxd_wq_free_irq(struct idxd_wq *wq);
>  int idxd_wq_request_irq(struct idxd_wq *wq);
> +void idxd_wq_flush_descs(struct idxd_wq *wq);
>  
>  /* submission */
>  int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
> diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
> index 1107db3ce0a3..8d0eaf5029fa 100644
> --- a/drivers/dma/idxd/irq.c
> +++ b/drivers/dma/idxd/irq.c
> @@ -397,6 +397,17 @@ static void idxd_device_flr(struct work_struct *work)
>  		dev_err(&idxd->pdev->dev, "FLR failed\n");
>  }
>  
> +static void idxd_wqs_flush_descs(struct idxd_device *idxd)
> +{
> +	int i;
> +
> +	for (i = 0; i < idxd->max_wqs; i++) {
> +		struct idxd_wq *wq = idxd->wqs[i];
> +
> +		idxd_wq_flush_descs(wq);
> +	}
> +}
> +
>  static irqreturn_t idxd_halt(struct idxd_device *idxd)
>  {
>  	union gensts_reg gensts;
> @@ -415,6 +426,11 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
>  		} else if (gensts.reset_type == IDXD_DEVICE_RESET_FLR) {
>  			idxd->state = IDXD_DEV_HALTED;
>  			idxd_mask_error_interrupts(idxd);
> +			/* Flush all pending descriptors, and disable
> +			 * interrupts, they will be re-enabled when FLR
> +			 * concludes.
> +			 */
> +			idxd_wqs_flush_descs(idxd);
>  			dev_dbg(&idxd->pdev->dev,
>  				"idxd halted, doing FLR. After FLR, configs are restored\n");
>  			INIT_WORK(&idxd->work, idxd_device_flr);
> 


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

* Re: [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors
  2026-01-15 22:47 ` [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors Vinicius Costa Gomes
@ 2026-01-16 20:22   ` Dave Jiang
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Jiang @ 2026-01-16 20:22 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Vinod Koul, Dan Williams; +Cc: dmaengine, linux-kernel



On 1/15/26 3:47 PM, Vinicius Costa Gomes wrote:
> When used as a dmaengine, the DMA "core" might ask the driver to
> terminate all pending requests, when that happens, flush all pending
> descriptors.
> 
> In this context, flush means removing the requests from the pending
> lists, so even if they are completed after, the user is not notified.
> 
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  drivers/dma/idxd/dma.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
> index dbecd699237e..e4f9788aa635 100644
> --- a/drivers/dma/idxd/dma.c
> +++ b/drivers/dma/idxd/dma.c
> @@ -194,6 +194,15 @@ static void idxd_dma_release(struct dma_device *device)
>  	kfree(idxd_dma);
>  }
>  
> +static int idxd_dma_terminate_all(struct dma_chan *c)
> +{
> +	struct idxd_wq *wq = to_idxd_wq(c);
> +
> +	idxd_wq_flush_descs(wq);
> +
> +	return 0;
> +}
> +
>  int idxd_register_dma_device(struct idxd_device *idxd)
>  {
>  	struct idxd_dma_dev *idxd_dma;
> @@ -224,6 +233,7 @@ int idxd_register_dma_device(struct idxd_device *idxd)
>  	dma->device_issue_pending = idxd_dma_issue_pending;
>  	dma->device_alloc_chan_resources = idxd_dma_alloc_chan_resources;
>  	dma->device_free_chan_resources = idxd_dma_free_chan_resources;
> +	dma->device_terminate_all = idxd_dma_terminate_all;
>  
>  	rc = dma_async_device_register(dma);
>  	if (rc < 0) {
> 


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

* Re: [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize()
  2026-01-15 22:47 ` [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize() Vinicius Costa Gomes
@ 2026-01-16 20:27   ` Dave Jiang
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Jiang @ 2026-01-16 20:27 UTC (permalink / raw)
  To: Vinicius Costa Gomes, Vinod Koul, Dan Williams; +Cc: dmaengine, linux-kernel



On 1/15/26 3:47 PM, Vinicius Costa Gomes wrote:
> When the dmaengine "core" asks the driver to synchronize, send a Drain
> operation to the device workqueue, which will wait for the already
> submitted operations to finish.
> 
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>


> ---
>  drivers/dma/idxd/dma.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
> index e4f9788aa635..9937b671f637 100644
> --- a/drivers/dma/idxd/dma.c
> +++ b/drivers/dma/idxd/dma.c
> @@ -203,6 +203,13 @@ static int idxd_dma_terminate_all(struct dma_chan *c)
>  	return 0;
>  }
>  
> +static void idxd_dma_synchronize(struct dma_chan *c)
> +{
> +	struct idxd_wq *wq = to_idxd_wq(c);
> +
> +	idxd_wq_drain(wq);
> +}
> +
>  int idxd_register_dma_device(struct idxd_device *idxd)
>  {
>  	struct idxd_dma_dev *idxd_dma;
> @@ -234,6 +241,7 @@ int idxd_register_dma_device(struct idxd_device *idxd)
>  	dma->device_alloc_chan_resources = idxd_dma_alloc_chan_resources;
>  	dma->device_free_chan_resources = idxd_dma_free_chan_resources;
>  	dma->device_terminate_all = idxd_dma_terminate_all;
> +	dma->device_synchronize = idxd_dma_synchronize;
>  
>  	rc = dma_async_device_register(dma);
>  	if (rc < 0) {
> 


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

* Re: [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset
  2026-01-16 20:16   ` Dave Jiang
@ 2026-01-17  1:18     ` Vinicius Costa Gomes
  0 siblings, 0 replies; 16+ messages in thread
From: Vinicius Costa Gomes @ 2026-01-17  1:18 UTC (permalink / raw)
  To: Dave Jiang, Vinod Koul, Dan Williams; +Cc: dmaengine, linux-kernel

Dave Jiang <dave.jiang@intel.com> writes:

> On 1/15/26 3:47 PM, Vinicius Costa Gomes wrote:
>> When a Function Level Reset (FLR) happens, terminate the pending
>> descriptors that were issued by in-kernel users and disable the
>> interrupts associated with those. They will be re-enabled after FLR
>> finishes.
>> 
>> idxd_wq_flush_desc() is declared on idxd.h because it's going to be
>> used in by the DMA backend in a future patch.
>> 
>> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
>> ---
>>  drivers/dma/idxd/device.c | 20 ++++++++++++++++++++
>>  drivers/dma/idxd/idxd.h   |  1 +
>>  drivers/dma/idxd/irq.c    | 16 ++++++++++++++++
>>  3 files changed, 37 insertions(+)
>> 
>> diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
>> index 5265925f3076..b8422dc7d2ca 100644
>> --- a/drivers/dma/idxd/device.c
>> +++ b/drivers/dma/idxd/device.c
>> @@ -1339,6 +1339,11 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
>>  
>>  	free_irq(ie->vector, ie);
>>  	idxd_flush_pending_descs(ie);
>> +
>> +	/* The interrupt might have been already released by FLR */
>> +	if (ie->int_handle == INVALID_INT_HANDLE)
>> +		return;
>> +
>>  	if (idxd->request_int_handles)
>>  		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
>>  	idxd_device_clear_perm_entry(idxd, ie);
>> @@ -1347,6 +1352,21 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
>>  	ie->pasid = IOMMU_PASID_INVALID;
>>  }
>>  
>> +void idxd_wq_flush_descs(struct idxd_wq *wq)
>> +{
>> +	struct idxd_irq_entry *ie = &wq->ie;
>> +	struct idxd_device *idxd = wq->idxd;
>> +
> Should it take a wq lock for this function?
>

Good catch. Will take a another look and see if I am missing any locks
elsewhere.


Cheers,
-- 
Vinicius

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

end of thread, other threads:[~2026-01-17  1:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-15 22:47 [PATCH RESEND v2 00/10] dmaengine: idxd: Memory leak and FLR fixes Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 01/10] dmaengine: idxd: Fix lockdep warnings when calling idxd_device_config() Vinicius Costa Gomes
2026-01-16 20:08   ` Dave Jiang
2026-01-15 22:47 ` [PATCH RESEND v2 02/10] dmaengine: idxd: Fix crash when the event log is disabled Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 03/10] dmaengine: idxd: Fix possible invalid memory access after FLR Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 04/10] dmaengine: idxd: Flush kernel workqueues on Function Level Reset Vinicius Costa Gomes
2026-01-16 20:16   ` Dave Jiang
2026-01-17  1:18     ` Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 05/10] dmaengine: idxd: Flush all pending descriptors Vinicius Costa Gomes
2026-01-16 20:22   ` Dave Jiang
2026-01-15 22:47 ` [PATCH RESEND v2 06/10] dmaengine: idxd: Wait for submitted operations on .device_synchronize() Vinicius Costa Gomes
2026-01-16 20:27   ` Dave Jiang
2026-01-15 22:47 ` [PATCH RESEND v2 07/10] dmaengine: idxd: Fix not releasing workqueue on .release() Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 08/10] dmaengine: idxd: Fix memory leak when a wq is reset Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 09/10] dmaengine: idxd: Fix freeing the allocated ida too late Vinicius Costa Gomes
2026-01-15 22:47 ` [PATCH RESEND v2 10/10] dmaengine: idxd: Fix leaking event log memory Vinicius Costa Gomes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox