* [PATCH v2 0/8] dmaengine: idxd: More error handling fixes
@ 2026-11-25 23:48 Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:48 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes, Steve Wahl,
stable, Jingyi Li, Bogdan Codres, Zhenzhong Duan
This series fixes error handling in the idxd driver.
1/8 and 3/8 fix crashes seen in a kdump kernel, where the device reset
fails during probe. 2/8 fixes the same kind of double free for failures
after idxd_setup_internals(). Jingyi Li tested them on 10 systems with
DSA. 1/8 to 3/8 should be backported together: with only 1/8, a probe
failure after idxd_setup_internals() still destroys the workqueue
twice, and a failed device reset still double frees in idxd_free().
4/8 to 6/8 fix the device registration, idxd_cdev_open() and WQ setup
error paths.
7/8 and 8/8 fix terminate_all(). Since v7.0 it releases the WQ's
interrupt handle, so later transfers on the channel fail with "Device
error 0x19". It also sleeps, and frees descriptors the device may still
use.
7/8 and 8/8 overlap with two patches of Daniel Byrne's series, "dmaengine:
idxd: keep the interrupt handle across terminate_all" and "dmaengine:
idxd: quarantine terminate_all's descriptor slots until the device has
drained":
https://lore.kernel.org/r/20261019150630.4026341-7-daniel1.byrne@intel.com
https://lore.kernel.org/r/20261019150630.4026341-10-daniel1.byrne@intel.com
Left for a separate series: currently, on a shared WQ, two opens by
the same mm share one PASID entry, and closing the first one removes
it, so the completion records of the other's page faults are
dropped (pointed out by Sashiko on v1 5/6). Proper support will be
added on a later series.
An AI coding assistant was used to triage the v1 review comments, to
help write and review the v2 changes to 4/8 and 5/8, to help write 6/8,
8/8 and the INVALID_INT_HANDLE check in 7/8, and with the testing.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
Changes in v2:
- 1/8, 3/8: use () after function names (Frank); add my Signed-off-by
instead of the Acked-by (Dave)
- 1/8, 2/8, 3/8: add Cc: stable and Jingyi's Tested-by
- Move "Fix potential double free on probe error path" (v1 3/6) to 2/8,
next to 1/8, as they need to be backported together
- 2/8: keep flushing the device workqueue in idxd_cleanup_internals(),
before the registers are unmapped (added after Jingyi's Tested-by and
Dave's Reviewed-by)
- 4/8: also stop the registration error paths from dropping the
device references that idxd_cleanup() drops again (Sashiko)
- 5/8: fail the open on xa_insert() errors other than -EBUSY (Sashiko),
and disable the PASID of a dedicated WQ when ida_alloc() fails
(Sashiko)
- New 6/8: initialize the WQ XArray before the WQ can be released
- 7/8 (v1 6/6): don't release an interrupt handle that is already
invalid (Sashiko); add Cc: stable
- New 8/8: don't sleep or free descriptors in terminate_all(), leave
that to synchronize(), after the drain (Sashiko)
- Link to v1: https://patch.msgid.link/20261012-wt-idxd-fixes-v1-0-30a35a445077@intel.com
---
Steve Wahl (2):
dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq
dmaengine: idxd: fix duplicate memory frees on initialization error path
Vinicius Costa Gomes (6):
dmaengine: idxd: Fix potential double free on probe error path
dmaengine: idxd: Fix the device registration error paths
dmaengine: idxd: Fix error handling in idxd_cdev_open()
dmaengine: idxd: Initialize the WQ XArray before the WQ can be released
dmaengine: idxd: Do not release interrupt handles on terminate_all()
dmaengine: idxd: Don't flush the descriptors on terminate_all()
drivers/dma/idxd/cdev.c | 12 ++++++++++--
drivers/dma/idxd/device.c | 24 ++++++++++++++++++------
drivers/dma/idxd/dma.c | 47 ++++++++++++++++++++++++++++++++++++++---------
drivers/dma/idxd/idxd.h | 4 ++++
drivers/dma/idxd/init.c | 27 ++++++++++-----------------
drivers/dma/idxd/irq.c | 1 +
drivers/dma/idxd/sysfs.c | 43 +++++++++++++------------------------------
7 files changed, 94 insertions(+), 64 deletions(-)
---
base-commit: d460a02aa0ac6ba9e5d87f8462f75d78be83146e
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git fixes
change-id: 20260803-wt-idxd-fixes-1a06bb69b1e0
Best regards,
--
Vinicius
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
@ 2026-11-25 23:48 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path Vinicius Costa Gomes
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:48 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes, Steve Wahl,
stable, Jingyi Li
From: Steve Wahl <steve.wahl@hpe.com>
Error paths within idxd_pci_probe_alloc() and related functions end up
calling destroy_workqueue() with a null pointer, from
idxd_conf_device_release() via put_device(), because that allocation has
not yet occurred when the error is hit.
This was encountered running in a kexec'd kdump kernel with reduced
resources, causing the "Device is HALTED!" branch in
idxd_device_init_reset() to be taken.
In idxd_conf_device_release(), check that the workqueue has been
allocated before trying to destroy it.
Fixes: 3d33de353b1f ("dmaengine: idxd: Fix not releasing workqueue on .release()")
Cc: stable@vger.kernel.org
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Tested-by: Jingyi Li <jinli@purestorage.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/sysfs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
index 6d251095c350..d5ffc641c856 100644
--- a/drivers/dma/idxd/sysfs.c
+++ b/drivers/dma/idxd/sysfs.c
@@ -1836,7 +1836,8 @@ static void idxd_conf_device_release(struct device *dev)
{
struct idxd_device *idxd = confdev_to_idxd(dev);
- destroy_workqueue(idxd->wq);
+ if (idxd->wq)
+ destroy_workqueue(idxd->wq);
kfree(idxd->groups);
bitmap_free(idxd->wq_enable_map);
kfree(idxd->wqs);
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization " Vinicius Costa Gomes
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes, stable, Jingyi Li
On the probe error path, put_device() calls idxd_conf_device_release().
It frees idxd->wq and the wqs, engines, groups and wq_enable_map arrays.
idxd_cleanup_internals(), the idxd_clean_*() helpers and the
idxd_setup_*() error paths free the same objects again.
Commit ec2d428b2e32 ("dmaengine: idxd: fix double free of wq, engine,
and group structs") removed the duplicate frees of the wq, engine and
group structs, but left these. Remove them.
Keep flushing the workqueue in idxd_cleanup_internals(). Work queued by
the misc interrupt uses the registers, which are unmapped before the
release callback runs.
Fixes: 3d33de353b1f ("dmaengine: idxd: Fix not releasing workqueue on .release()")
Cc: stable@vger.kernel.org # 6.6.x: ec2d428b2e32: dmaengine: idxd: fix double free of wq, engine, and group structs
Cc: stable@vger.kernel.org # 6.6.x
Link: https://lore.kernel.org/all/20260615103932.61828-1-bogdan.codres@windriver.com/
Tested-by: Jingyi Li <jinli@purestorage.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/init.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 4b827a329756..9aab57a4b13e 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -166,8 +166,6 @@ static void idxd_clean_wqs(struct idxd_device *idxd)
conf_dev = wq_confdev(idxd->wqs[i]);
put_device(conf_dev);
}
- bitmap_free(idxd->wq_enable_map);
- kfree(idxd->wqs);
}
static int idxd_setup_wqs(struct idxd_device *idxd)
@@ -245,11 +243,8 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
conf_dev = wq_confdev(idxd->wqs[i]);
put_device(conf_dev);
}
- bitmap_free(idxd->wq_enable_map);
err_free_wqs:
- kfree(idxd->wqs);
-
return rc;
}
@@ -262,7 +257,6 @@ static void idxd_clean_engines(struct idxd_device *idxd)
conf_dev = engine_confdev(idxd->engines[i]);
put_device(conf_dev);
}
- kfree(idxd->engines);
}
static int idxd_setup_engines(struct idxd_device *idxd)
@@ -308,7 +302,6 @@ static int idxd_setup_engines(struct idxd_device *idxd)
conf_dev = engine_confdev(idxd->engines[i]);
put_device(conf_dev);
}
- kfree(idxd->engines);
return rc;
}
@@ -320,7 +313,6 @@ static void idxd_clean_groups(struct idxd_device *idxd)
for (i = 0; i < idxd->max_groups; i++) {
put_device(group_confdev(idxd->groups[i]));
}
- kfree(idxd->groups);
}
static int idxd_setup_groups(struct idxd_device *idxd)
@@ -378,17 +370,17 @@ static int idxd_setup_groups(struct idxd_device *idxd)
group = idxd->groups[i];
put_device(group_confdev(group));
}
- kfree(idxd->groups);
return rc;
}
static void idxd_cleanup_internals(struct idxd_device *idxd)
{
+ /* Queued work uses the groups, engines, WQs and the registers */
+ flush_workqueue(idxd->wq);
idxd_clean_groups(idxd);
idxd_clean_engines(idxd);
idxd_clean_wqs(idxd);
- destroy_workqueue(idxd->wq);
}
static int idxd_init_evl(struct idxd_device *idxd)
@@ -459,7 +451,6 @@ static int idxd_setup_internals(struct idxd_device *idxd)
return 0;
err_evl:
- destroy_workqueue(idxd->wq);
err_wkq_create:
idxd_clean_groups(idxd);
err_group:
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization error path
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths Vinicius Costa Gomes
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes, Steve Wahl,
stable, Bogdan Codres, Jingyi Li
From: Steve Wahl <steve.wahl@hpe.com>
Error paths within idxd_pci_probe_alloc() and related functions end up
attempting to free memory already freed from idxd_conf_device_release()
via put_device().
This was encountered running in a kexec'd kdump kernel with reduced
resources, causing the "Device is HALTED!" branch in
idxd_device_init_reset() to be taken.
[ 18.628791] idxd 0000:00:01.0: Device is HALTED!
[ 18.631447] idxd 0000:00:01.0: Intel(R) IDXD DMA Engine init failed
[ 18.631450] ------------[ cut here ]------------
[ 18.631451] ida_free called for id=0 which is not allocated.
[ 18.631462] WARNING: CPU: 0 PID: 11 at lib/idr.c:525 ida_free+0xd3/0x130
[ 18.631474] CPU: 0 UID: 0 PID: 11 Comm: kworker/0:1 Not tainted 6.12.0-1-rt-amd64 #1
[ 18.631477] Hardware name: Dell Inc. PowerEdge XR8720t/0J91KV, BIOS 1.1.3 02/03/2026
[ 18.631478] Workqueue: events work_for_cpu_fn
[ 18.631480] RIP: 0010:ida_free+0xd3/0x130
[ 18.631492] Call Trace:
[ 18.631494] <TASK>
[ 18.631495] idxd_pci_probe+0x1b0/0x1860 [idxd]
[ 18.631506] local_pci_probe+0x43/0xa0
[ 18.631508] work_for_cpu_fn+0x13/0x20
[ 18.631510] process_one_work+0x179/0x390
[ 18.631512] worker_thread+0x237/0x340
[ 18.631517] kthread+0xc6/0x100
[ 18.631520] ret_from_fork+0x2d/0x50
[ 18.631524] ret_from_fork_asm+0x1a/0x30
[ 18.631526] </TASK>
In idxd_free() and idxd_alloc(), do not attempt to free allocations that
will already have been freed.
Fixes: 90022b3a6981 ("dmaengine: idxd: fix memory leak in error handling path of idxd_pci_probe")
Fixes: 46a5cca76c76 ("dmaengine: idxd: fix memory leak in error handling path of idxd_alloc")
Cc: stable@vger.kernel.org
Reported-by: Bogdan Codres <bogdan.codres@windriver.com>
Link: https://lore.kernel.org/all/akLBL7b2h73pK0AC@ilogsc-qemu.local/
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Tested-by: Jingyi Li <jinli@purestorage.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/init.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 9aab57a4b13e..9cfb165a1569 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -572,9 +572,6 @@ static void idxd_free(struct idxd_device *idxd)
return;
put_device(idxd_confdev(idxd));
- bitmap_free(idxd->opcap_bmap);
- ida_free(&idxd_ida, idxd->id);
- kfree(idxd);
}
static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)
@@ -614,8 +611,13 @@ static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_d
return idxd;
err_name:
+ /*
+ * once device_initialize(conf_dev) is called,
+ * put_device(conf_dev) will end up calling
+ * idxd_conf_device_release() which will free the rest.
+ */
put_device(conf_dev);
- bitmap_free(idxd->opcap_bmap);
+ return NULL;
err_opcap:
ida_free(&idxd_ida, idxd->id);
err_ida:
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
` (2 preceding siblings ...)
2026-11-25 23:49 ` [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization " Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() Vinicius Costa Gomes
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes
idxd_setup_*() takes a reference on each wq, engine and group device,
and idxd_cleanup_internals() drops it. When registering the devices
fails, the error paths drop it first:
idxd_pci_probe_alloc()
|-idxd_register_devices()
| \-idxd_register_{wq,engine,group}_devices()
| put_device() or device_unregister() on each device.
| The last reference is gone, the device is freed.
|
\-idxd_cleanup()
\-idxd_cleanup_internals()
put_device() on each device again, use-after-free.
idxd_register_devices() does the same, with device_unregister(), for
the devices registered before the failure.
The rollback in the helpers is also off by one. With j = i - 1 and
while (j--), it skips the last device added. When the first device
fails, j starts at -1 and the loop walks off the front of the array.
Only device_del() the devices that were added, and leave the references
to idxd_cleanup_internals().
Fixes: 7c5dd23e57c1 ("dmaengine: idxd: fix wq conf_dev 'struct device' lifetime")
Fixes: 75b911309060 ("dmaengine: idxd: fix engine conf_dev lifetime")
Fixes: defe49f96012 ("dmaengine: idxd: fix group conf_dev lifetime")
Fixes: ddf742d4f3f1 ("dmaengine: idxd: Add missing cleanup for early error out in probe call")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/sysfs.c | 40 +++++++++++-----------------------------
1 file changed, 11 insertions(+), 29 deletions(-)
diff --git a/drivers/dma/idxd/sysfs.c b/drivers/dma/idxd/sysfs.c
index d5ffc641c856..87fa4f43e27c 100644
--- a/drivers/dma/idxd/sysfs.c
+++ b/drivers/dma/idxd/sysfs.c
@@ -1864,7 +1864,7 @@ const struct device_type iax_device_type = {
static int idxd_register_engine_devices(struct idxd_device *idxd)
{
struct idxd_engine *engine;
- int i, j, rc;
+ int i, rc;
for (i = 0; i < idxd->max_engines; i++) {
engine = idxd->engines[i];
@@ -1876,15 +1876,9 @@ static int idxd_register_engine_devices(struct idxd_device *idxd)
return 0;
cleanup:
- j = i - 1;
- for (; i < idxd->max_engines; i++) {
+ while (i--) {
engine = idxd->engines[i];
- put_device(engine_confdev(engine));
- }
-
- while (j--) {
- engine = idxd->engines[j];
- device_unregister(engine_confdev(engine));
+ device_del(engine_confdev(engine));
}
return rc;
}
@@ -1892,7 +1886,7 @@ static int idxd_register_engine_devices(struct idxd_device *idxd)
static int idxd_register_group_devices(struct idxd_device *idxd)
{
struct idxd_group *group;
- int i, j, rc;
+ int i, rc;
for (i = 0; i < idxd->max_groups; i++) {
group = idxd->groups[i];
@@ -1904,15 +1898,9 @@ static int idxd_register_group_devices(struct idxd_device *idxd)
return 0;
cleanup:
- j = i - 1;
- for (; i < idxd->max_groups; i++) {
+ while (i--) {
group = idxd->groups[i];
- put_device(group_confdev(group));
- }
-
- while (j--) {
- group = idxd->groups[j];
- device_unregister(group_confdev(group));
+ device_del(group_confdev(group));
}
return rc;
}
@@ -1920,7 +1908,7 @@ static int idxd_register_group_devices(struct idxd_device *idxd)
static int idxd_register_wq_devices(struct idxd_device *idxd)
{
struct idxd_wq *wq;
- int i, rc, j;
+ int i, rc;
for (i = 0; i < idxd->max_wqs; i++) {
wq = idxd->wqs[i];
@@ -1932,15 +1920,9 @@ static int idxd_register_wq_devices(struct idxd_device *idxd)
return 0;
cleanup:
- j = i - 1;
- for (; i < idxd->max_wqs; i++) {
+ while (i--) {
wq = idxd->wqs[i];
- put_device(wq_confdev(wq));
- }
-
- while (j--) {
- wq = idxd->wqs[j];
- device_unregister(wq_confdev(wq));
+ device_del(wq_confdev(wq));
}
return rc;
}
@@ -1976,10 +1958,10 @@ int idxd_register_devices(struct idxd_device *idxd)
err_group:
for (i = 0; i < idxd->max_engines; i++)
- device_unregister(engine_confdev(idxd->engines[i]));
+ device_del(engine_confdev(idxd->engines[i]));
err_engine:
for (i = 0; i < idxd->max_wqs; i++)
- device_unregister(wq_confdev(idxd->wqs[i]));
+ device_del(wq_confdev(idxd->wqs[i]));
err_wq:
device_del(idxd_confdev(idxd));
return rc;
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open()
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
` (3 preceding siblings ...)
2026-11-25 23:49 ` [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released Vinicius Costa Gomes
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes
Three error paths of idxd_cdev_open() are wrong:
- An ida_alloc() failure jumps to failed_ida without setting rc. The
open usually returns 0 after freeing its context, and the release of
the file then uses the freed filp->private_data.
- xa_insert() errors other than -EBUSY are ignored. The open succeeds
without the context in the xarray, and the completion records of its
page faults are dropped.
- On a dedicated WQ, the failed_ida path doesn't undo
idxd_wq_set_pasid(). The WQ keeps the PASID of an SVA bind that is
released right after.
Set rc on the ida_alloc() failure. Fail the open on xa_insert() errors
other than -EBUSY, and fix the "exist -> exists" typo in its warning.
Disable the PASID of a dedicated WQ on the failed_ida path, as
idxd_file_dev_release() does.
Fixes: e6fd6d7e5f0f ("dmaengine: idxd: add a device to represent the file opened")
Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/cdev.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index f1af7f0d25d3..9343deb2e858 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -264,8 +264,12 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
mutex_lock(&wq->uc_lock);
rc = xa_insert(&wq->upasid_xa, pasid, ctx, GFP_KERNEL);
mutex_unlock(&wq->uc_lock);
- if (rc < 0)
- dev_warn(dev, "PASID entry already exist in xarray.\n");
+ if (rc == -EBUSY) {
+ /* Another open of this WQ by the same mm added it */
+ dev_warn(dev, "PASID entry already exists in xarray.\n");
+ } else if (rc < 0) {
+ goto failed_get_pasid;
+ }
if (wq_dedicated(wq)) {
rc = idxd_wq_set_pasid(wq, pasid);
@@ -279,6 +283,7 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
idxd_cdev = wq->idxd_cdev;
ctx->id = ida_alloc(&file_ida, GFP_KERNEL);
if (ctx->id < 0) {
+ rc = ctx->id;
dev_warn(dev, "ida alloc failure\n");
goto failed_ida;
}
@@ -311,6 +316,9 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
put_device(fdev);
return rc;
failed_ida:
+ if (device_user_pasid_enabled(idxd) && wq_dedicated(wq) &&
+ idxd_wq_disable_pasid(wq) < 0)
+ dev_err(dev, "wq disable pasid failed.\n");
failed_set_pasid:
if (device_user_pasid_enabled(idxd))
idxd_xa_pasid_remove(ctx);
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
` (4 preceding siblings ...)
2026-11-25 23:49 ` [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all() Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors " Vinicius Costa Gomes
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes
idxd_setup_wqs() initializes wq->upasid_xa and wq->uc_lock last. Its
error paths call put_device() on the WQ device before that, and the
release callback, idxd_conf_wq_release(), calls xa_destroy() on the
uninitialized XArray.
Initialize both before device_initialize().
Fixes: b022f59725f0 ("dmaengine: idxd: add idxd_copy_cr() to copy user completion record during page fault handling")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 9cfb165a1569..e5b797c0ffef 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -197,6 +197,8 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
conf_dev = wq_confdev(wq);
wq->id = i;
wq->idxd = idxd;
+ mutex_init(&wq->uc_lock);
+ xa_init(&wq->upasid_xa);
device_initialize(conf_dev);
conf_dev->parent = idxd_confdev(idxd);
conf_dev->bus = &dsa_bus_type;
@@ -231,8 +233,6 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
}
bitmap_copy(wq->opcap_bmap, idxd->opcap_bmap, IDXD_MAX_OPCAP_BITS);
}
- mutex_init(&wq->uc_lock);
- xa_init(&wq->upasid_xa);
idxd->wqs[i] = wq;
}
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all()
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
` (5 preceding siblings ...)
2026-11-25 23:49 ` [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors " Vinicius Costa Gomes
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes, stable, Zhenzhong Duan
idxd_dma_terminate_all() calls idxd_wq_flush_descs(), which also
releases the WQ's interrupt handle. The WQ stays enabled, but the
handle is never requested again, so the device fails every later
descriptor with "Device error 0x19" (invalid interrupt handle).
dmatest shows it on its second run on a channel.
Move the release to idxd_wq_release_int_handle(), called only from the
FLR path, which needs both. Skip a handle that is already invalid, as a
failed refresh after a revoke leaves it.
Fixes: 2a93f5747d0e ("dmaengine: idxd: Flush all pending descriptors")
Cc: stable@vger.kernel.org # 7.0.x
Reported-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/device.c | 15 ++++++++++++++-
drivers/dma/idxd/idxd.h | 1 +
drivers/dma/idxd/irq.c | 1 +
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 131138483b87..21a0c32325ea 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1349,6 +1349,16 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
}
void idxd_wq_flush_descs(struct idxd_wq *wq)
+{
+ guard(mutex)(&wq->wq_lock);
+
+ if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
+ return;
+
+ idxd_flush_pending_descs(&wq->ie);
+}
+
+void idxd_wq_release_int_handle(struct idxd_wq *wq)
{
struct idxd_irq_entry *ie = &wq->ie;
struct idxd_device *idxd = wq->idxd;
@@ -1358,7 +1368,10 @@ void idxd_wq_flush_descs(struct idxd_wq *wq)
if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
return;
- idxd_flush_pending_descs(ie);
+ /* Revoked and not re-acquired, or released by an earlier 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);
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index ce78b9a7c641..f4aed90560e0 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -804,6 +804,7 @@ 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);
+void idxd_wq_release_int_handle(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 6a25e1fd0e62..26d75d744797 100644
--- a/drivers/dma/idxd/irq.c
+++ b/drivers/dma/idxd/irq.c
@@ -405,6 +405,7 @@ static void idxd_wqs_flush_descs(struct idxd_device *idxd)
struct idxd_wq *wq = idxd->wqs[i];
idxd_wq_flush_descs(wq);
+ idxd_wq_release_int_handle(wq);
}
}
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors on terminate_all()
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
` (6 preceding siblings ...)
2026-11-25 23:49 ` [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all() Vinicius Costa Gomes
@ 2026-11-25 23:49 ` Vinicius Costa Gomes
7 siblings, 0 replies; 9+ messages in thread
From: Vinicius Costa Gomes @ 2026-11-25 23:49 UTC (permalink / raw)
To: Dave Jiang, Vinod Koul, Frank Li, Fenghua Yu, Shuai Xue
Cc: dmaengine, linux-kernel, Vinicius Costa Gomes
idxd_dma_terminate_all() has two problems:
- It unmaps and frees the pending descriptors while the device may
still process them. The device can then write to unmapped buffers,
or to the completion record of a reused descriptor.
- It takes wq->wq_lock, a mutex, but terminate_all() can be called from
atomic context and must not sleep.
terminate_all() only has to keep the callbacks of the terminated
transfers from running. Mark the channel terminated, and skip the
callbacks while it is marked. synchronize() does the rest:
idxd_dma_synchronize()
|-idxd_wq_drain()
| The device has completed every descriptor.
|-synchronize_irq()
| The IRQ thread has put back what it found still running.
|-idxd_flush_pending_descs()
|-synchronize_irq()
| The IRQ thread is done with what it took before the flush.
\-Clear the mark.
The flush holds a wq_active reference, not wq->wq_lock:
dma_release_channel() calls synchronize() with dma_list_mutex held, and
idxd_dmaengine_drv_remove() takes dma_list_mutex under wq->wq_lock. The
remove path waits for the wq_active references before it frees the
descriptors.
Calling dma_async_issue_pending() between terminate_all() and
synchronize() is undefined in the dmaengine API. idxd starts descriptors
at tx_submit(), so this also relies on clients not submitting in that
window: then the descriptors completed while the channel is marked were
all submitted before the terminate.
Some users, like ntb_transport, terminate and release the channel
without calling synchronize(). The mark is still cleared, as
dma_release_channel() calls synchronize() itself.
Fixes: 2a93f5747d0e ("dmaengine: idxd: Flush all pending descriptors")
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
drivers/dma/idxd/device.c | 9 ++++-----
drivers/dma/idxd/dma.c | 47 ++++++++++++++++++++++++++++++++++++++---------
drivers/dma/idxd/idxd.h | 3 +++
3 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 21a0c32325ea..91cad6b0f955 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -1269,7 +1269,7 @@ int idxd_device_load_config(struct idxd_device *idxd)
return 0;
}
-static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)
+void idxd_flush_pending_descs(struct idxd_irq_entry *ie)
{
struct idxd_desc *desc, *itr;
struct llist_node *head;
@@ -1293,10 +1293,9 @@ static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)
list_del(&desc->list);
ctype = desc->completion->status ? IDXD_COMPLETE_NORMAL : IDXD_COMPLETE_ABORT;
/*
- * wq is being disabled. Any remaining descriptors are
- * likely to be stuck and can be dropped. callback could
- * point to code that is no longer accessible, for example
- * if dmatest module has been unloaded.
+ * No callbacks: the transfers were terminated, or the WQ
+ * is being disabled or reset and they may point to
+ * unloaded code.
*/
tx = &desc->txd;
tx->callback = NULL;
diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
index 9937b671f637..f8ce06274ef4 100644
--- a/drivers/dma/idxd/dma.c
+++ b/drivers/dma/idxd/dma.c
@@ -7,17 +7,20 @@
#include <linux/device.h>
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/dmaengine.h>
+#include <linux/interrupt.h>
#include <uapi/linux/idxd.h>
#include "../dmaengine.h"
#include "registers.h"
#include "idxd.h"
-static inline struct idxd_wq *to_idxd_wq(struct dma_chan *c)
+static inline struct idxd_dma_chan *to_idxd_dma_chan(struct dma_chan *c)
{
- struct idxd_dma_chan *idxd_chan;
+ return container_of(c, struct idxd_dma_chan, chan);
+}
- idxd_chan = container_of(c, struct idxd_dma_chan, chan);
- return idxd_chan->wq;
+static inline struct idxd_wq *to_idxd_wq(struct dma_chan *c)
+{
+ return to_idxd_dma_chan(c)->wq;
}
void idxd_dma_complete_txd(struct idxd_desc *desc,
@@ -47,7 +50,8 @@ void idxd_dma_complete_txd(struct idxd_desc *desc,
if (complete && tx->cookie) {
dma_cookie_complete(tx);
dma_descriptor_unmap(tx);
- dmaengine_desc_get_callback_invoke(tx, &res);
+ if (!READ_ONCE(to_idxd_dma_chan(tx->chan)->terminated))
+ dmaengine_desc_get_callback_invoke(tx, &res);
tx->callback = NULL;
tx->callback_result = NULL;
}
@@ -196,18 +200,43 @@ static void idxd_dma_release(struct dma_device *device)
static int idxd_dma_terminate_all(struct dma_chan *c)
{
- struct idxd_wq *wq = to_idxd_wq(c);
-
- idxd_wq_flush_descs(wq);
+ /* The device still runs them, synchronize() waits for it */
+ WRITE_ONCE(to_idxd_dma_chan(c)->terminated, true);
return 0;
}
static void idxd_dma_synchronize(struct dma_chan *c)
{
- struct idxd_wq *wq = to_idxd_wq(c);
+ struct idxd_dma_chan *idxd_chan = to_idxd_dma_chan(c);
+ struct idxd_wq *wq = idxd_chan->wq;
idxd_wq_drain(wq);
+ if (!READ_ONCE(idxd_chan->terminated))
+ return;
+
+ /*
+ * Not wq_lock: dma_release_channel() calls this under dma_list_mutex,
+ * which the WQ removal takes under wq_lock. The removal waits for
+ * wq_active instead.
+ */
+ if (!percpu_ref_tryget_live(&wq->wq_active)) {
+ wait_for_completion(&wq->wq_resurrect);
+ /* The WQ is quiesced, disabling it flushes them */
+ if (!percpu_ref_tryget_live(&wq->wq_active))
+ return;
+ }
+
+ /*
+ * The IRQ thread can still put back the descriptors it saw running
+ * before the drain, or complete the ones it took: wait for it on both
+ * sides of the flush.
+ */
+ synchronize_irq(wq->ie.vector);
+ idxd_flush_pending_descs(&wq->ie);
+ synchronize_irq(wq->ie.vector);
+ WRITE_ONCE(idxd_chan->terminated, false);
+ percpu_ref_put(&wq->wq_active);
}
int idxd_register_dma_device(struct idxd_device *idxd)
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index f4aed90560e0..3d0747be193a 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -185,6 +185,8 @@ enum idxd_op_type {
struct idxd_dma_chan {
struct dma_chan chan;
struct idxd_wq *wq;
+ /* Set by terminate_all(), until synchronize() */
+ bool terminated;
};
struct idxd_wq {
@@ -803,6 +805,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_flush_pending_descs(struct idxd_irq_entry *ie);
void idxd_wq_flush_descs(struct idxd_wq *wq);
void idxd_wq_release_int_handle(struct idxd_wq *wq);
--
2.56.1
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-25 23:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization " Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all() Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors " 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
all inboxes | Powered by JetHome®