[PATCH 12/17] dmaengine: idxd: hold device commands off while the reset re-creates its interrupts
From: Daniel Byrne
Date: Mon Oct 19 2026 - 12:28:31 EST
The re-probe after a reset frees the misc interrupt and the MSI-X
vectors and requests them again. A device command whose completion
interrupt arrives in between is never completed, so its owner times
out and fences the device that was just reset, and the rebind in
idxd_reset_done() then fails.
Wait for the running command before the vectors are freed, since its
interrupt still arrives, and then hold IDXD_FLAG_CMD_RUNNING without an
owner until the interrupts are back, so that commands issued meanwhile
wait as they wait for any running command. A halt's recovery may forget
the hold, so it is released only if no newer command owns the state.
Assisted-by: Claude:claude-opus-5-5
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
---
drivers/dma/idxd/device.c | 44 +++++++++++++++++++++++++++++++++++++++
drivers/dma/idxd/idxd.h | 2 ++
drivers/dma/idxd/init.c | 10 +++++++++
3 files changed, 56 insertions(+)
diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index d3b95593a686..222c201669bd 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -724,6 +724,50 @@ void idxd_cmd_reset_state(struct idxd_device *idxd)
spin_unlock_irqrestore(&idxd->cmd_lock, flags);
}
+/*
+ * Hold device commands off while the re-probe after a reset frees the
+ * interrupts and requests them again. A command whose completion
+ * interrupt comes while the misc vector is gone is never completed, and
+ * its owner would time out and fence the device that was just reset.
+ * The running command, if any, is waited for first: its owner gives up
+ * within its timeout, and the misc vector still takes its interrupt.
+ * RUNNING is then held without an owner, and new commands wait for it
+ * as for any running command. Returns false, holding nothing, when a
+ * command timed out, since commands then fail fast anyway.
+ */
+bool idxd_cmd_hold(struct idxd_device *idxd, u32 *seq)
+{
+ bool held = false;
+
+ spin_lock_irq(&idxd->cmd_lock);
+ wait_event_lock_irq(idxd->cmd_waitq,
+ !test_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags) ||
+ test_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags),
+ idxd->cmd_lock);
+ if (!test_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags)) {
+ __set_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags);
+ *seq = ++idxd->cmd_seq;
+ held = true;
+ }
+ spin_unlock_irq(&idxd->cmd_lock);
+ return held;
+}
+
+/*
+ * End a hold taken by idxd_cmd_hold(). A halt's recovery may have
+ * forgotten the hold meanwhile and let another command run, which then
+ * has an owner or a newer sequence number, and its state is left alone.
+ */
+void idxd_cmd_unhold(struct idxd_device *idxd, u32 seq)
+{
+ spin_lock_irq(&idxd->cmd_lock);
+ if (idxd->cmd_seq == seq && !idxd->cmd_done) {
+ __clear_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags);
+ wake_up(&idxd->cmd_waitq);
+ }
+ spin_unlock_irq(&idxd->cmd_lock);
+}
+
int idxd_device_enable(struct idxd_device *idxd)
{
struct device *dev = &idxd->pdev->dev;
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index c04a2855aa3f..9d88b0d82fee 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -794,6 +794,8 @@ int idxd_device_disable(struct idxd_device *idxd);
int idxd_device_reset(struct idxd_device *idxd);
void idxd_device_clear_state(struct idxd_device *idxd);
void idxd_cmd_reset_state(struct idxd_device *idxd);
+bool idxd_cmd_hold(struct idxd_device *idxd, u32 *seq);
+void idxd_cmd_unhold(struct idxd_device *idxd, u32 seq);
int idxd_device_config(struct idxd_device *idxd);
int idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
int idxd_device_load_config(struct idxd_device *idxd);
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index a037a6e76362..312b4670b3e8 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -1212,6 +1212,14 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,
}
if (!alloc_idxd) {
+ bool held;
+ u32 seq;
+
+ /*
+ * Commands complete through the misc interrupt, which is
+ * gone until it is requested again.
+ */
+ held = idxd_cmd_hold(idxd, &seq);
/* Release interrupts in the IDXD device. */
idxd_cleanup_interrupts(idxd);
@@ -1219,6 +1227,8 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,
rc = idxd_setup_interrupts(idxd);
if (rc)
dev_warn(dev, "IDXD interrupts failed to setup\n");
+ if (held)
+ idxd_cmd_unhold(idxd, seq);
}
dev_info(&pdev->dev, "Intel(R) Accelerator Device (v%x)\n",
--
2.43.0