[PATCH v2 10/10] dmaengine: idxd: test a queue under its lock before quiescing it
From: Daniel Byrne
Date: Mon Nov 30 2026 - 14:54:26 EST
idxd_wqs_quiesce() tests a queue's state and type without wq_lock and
takes the lock only for the quiesce itself. The enable and the disable
of a queue run under that lock from end to end, so the test can pass
while one of them is under way, and the quiesce then runs once it is
through. An enable that failed after it had stored the queue enabled
never initialized wq_active, and a disable has released it by then.
Either way percpu_ref_kill() works on a reference that has no data and
dereferences NULL.
The halt handler calls this for a halt that a system reset recovers
from, and the interrupt thread calls it when it cannot allocate the
work item for a revoked interrupt handle.
Test the queue again once the lock is held. A queue that reads enabled
there has its reference. The test without the lock stays, as a filter
that keeps the thread off a lock it must not wait for. Both callers run
in the interrupt thread that also completes the device commands, and a
queue's lock is held across such commands. The enable of a kernel queue
and a cdev open issue theirs under the lock of a queue that does not
read as an enabled kernel queue yet, so the filter skips that queue and
the thread never waits for its lock. Taking every queue's lock here
would let the thread and such a waiter wait for each other. An unbind
issues its commands under the lock of a queue that does read as one, and
the thread waits behind it, as it did before.
Fixes: 5b0c68c473a1 ("dmaengine: idxd: support reporting of halt interrupt")
Cc: stable@xxxxxxxxxxxxxxx # 5.13+
Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
---
New in v2.
drivers/dma/idxd/init.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 4b827a329756..4f3693fb7975 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1242,8 +1242,26 @@ void idxd_wqs_quiesce(struct idxd_device *idxd)
for (i = 0; i < idxd->max_wqs; i++) {
wq = idxd->wqs[i];
+ /*
+ * Skip a queue that does not read as an enabled kernel
+ * queue without taking its lock. This runs in the thread
+ * that completes the device commands, and the enable of a
+ * kernel queue and a cdev open hold the lock of such a
+ * queue while they wait for a command. An unbind holds the
+ * lock of an enabled kernel queue across its commands, and
+ * this waits behind it.
+ */
+ if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
+ continue;
+ /*
+ * Test again under the lock. The enable and the disable of
+ * a queue hold it from end to end, so a queue that reads
+ * enabled here has its reference.
+ */
+ mutex_lock(&wq->wq_lock);
if (wq->state == IDXD_WQ_ENABLED && wq->type == IDXD_WQT_KERNEL)
- idxd_wq_quiesce(wq);
+ __idxd_wq_quiesce(wq);
+ mutex_unlock(&wq->wq_lock);
}
}
--
2.43.0