AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/20 19:04 flow patch-triage
4m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series modifies the Intel Data Accelerator (IDXD / DSA / IAA) driver along with adding a helper function, dma_async_device_channel_add(), in dmaengine.c whose sole caller is the IDXD driver. Intel DSA and IAA devices require physical Intel Xeon hardware (Sapphire Rapids and newer) and are not emulated in standard QEMU or GCE virtualized environments. Consequently, all modified and added code paths are structurally unreachable in standard fuzzing environments.",
  "WorthFuzzing": false
}

1/1 2026/10/20 19:04 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit bc21bcfdd383961d945cc5eff49e22a96bda3407\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Oct 20 19:04:01 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c\nindex c71763047126a..ced78c985d1c0 100644\n--- a/drivers/dma/dmaengine.c\n+++ b/drivers/dma/dmaengine.c\n@@ -1155,6 +1155,47 @@ int dma_async_device_channel_register(struct dma_device *device,\n }\n EXPORT_SYMBOL_GPL(dma_async_device_channel_register);\n \n+/**\n+ * dma_async_device_channel_add - register a channel and make it available\n+ * @device: the dmaengine device, DMA_PRIVATE and registered already\n+ * @chan: the channel, not on @device's channel list\n+ * @name: the channel's name, or NULL for the default one\n+ *\n+ * Channel requests walk the channel list of every registered device under\n+ * dma_list_mutex and may hand out any listed channel that has no client.\n+ * A channel added to a registered device is therefore linked to the list\n+ * only once it is registered, and under that mutex, so that a request\n+ * never finds it half initialized. The driver's own state behind the\n+ * channel must be complete before the call. A channel that fails to\n+ * register is not linked.\n+ *\n+ * Only a DMA_PRIVATE device may add channels this way. The channel list\n+ * of a public device is also walked under RCU alone, and its channels\n+ * hold references for the dmaengine_get() users, which this function\n+ * does not take.\n+ *\n+ * Return: 0 on success or a negative errno.\n+ */\n+int dma_async_device_channel_add(struct dma_device *device,\n+\t\t\t\t struct dma_chan *chan, const char *name)\n+{\n+\tint rc;\n+\n+\tif (WARN_ON_ONCE(!dma_has_cap(DMA_PRIVATE, device-\u003ecap_mask)))\n+\t\treturn -EINVAL;\n+\n+\trc = __dma_async_device_channel_register(device, chan, name);\n+\tif (rc \u003c 0)\n+\t\treturn rc;\n+\n+\tmutex_lock(\u0026dma_list_mutex);\n+\tlist_add_tail(\u0026chan-\u003edevice_node, \u0026device-\u003echannels);\n+\tdma_channel_rebalance();\n+\tmutex_unlock(\u0026dma_list_mutex);\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(dma_async_device_channel_add);\n+\n static void __dma_async_device_channel_unregister(struct dma_device *device,\n \t\t\t\t\t\t  struct dma_chan *chan)\n {\ndiff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c\nindex 82b07cf942ef8..4cfa77c727193 100644\n--- a/drivers/dma/idxd/cdev.c\n+++ b/drivers/dma/idxd/cdev.c\n@@ -120,30 +120,53 @@ static void idxd_file_dev_release(struct device *dev)\n \tstruct idxd_user_context *ctx = dev_to_uctx(dev);\n \tstruct idxd_wq *wq = ctx-\u003ewq;\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n-\tint rc;\n+\tint rc, drained = 0;\n \n \tida_free(\u0026file_ida, ctx-\u003eid);\n \n \t/* Wait for in-flight operations to complete. */\n \tif (wq_shared(wq)) {\n-\t\tidxd_device_drain_pasid(idxd, ctx-\u003epasid);\n+\t\tdrained = idxd_device_drain_pasid(idxd, ctx-\u003epasid);\n \t} else {\n \t\tif (device_user_pasid_enabled(idxd)) {\n-\t\t\t/* The wq disable in the disable pasid function will drain the wq */\n+\t\t\t/*\n+\t\t\t * The wq disable in the disable pasid function drains\n+\t\t\t * the wq. A drain that never completed leaves the\n+\t\t\t * PASID in the queue's configuration with the\n+\t\t\t * descriptors still in it. A failure after the drain,\n+\t\t\t * re-enabling the queue for instance, does not.\n+\t\t\t */\n \t\t\trc = idxd_wq_disable_pasid(wq);\n-\t\t\tif (rc \u003c 0)\n-\t\t\t\tdev_err(dev, \"wq disable pasid failed.\\n\");\n+\t\t\tif (rc \u003c 0) {\n+\t\t\t\tdev_err(dev, \"wq disable pasid failed: %d\\n\", rc);\n+\t\t\t\tif (rc == -ETIMEDOUT)\n+\t\t\t\t\tdrained = rc;\n+\t\t\t}\n \t\t} else {\n-\t\t\tidxd_wq_drain(wq);\n+\t\t\tdrained = idxd_wq_drain(wq);\n \t\t}\n \t}\n \n+\t/*\n+\t * A drain that never completed leaves this context's descriptors\n+\t * in the device, tagged with its PASID. Unbinding the PASID would\n+\t * let it be reused by another process while the device can still\n+\t * issue DMA with it, so the binding, the PASID lookup entry and the\n+\t * context are leaked instead.\n+\t */\n+\tif (drained) {\n+\t\tdev_err(dev, \"pasid %u: drain timed out, leaking the context and its PASID binding\\n\",\n+\t\t\tctx-\u003epasid);\n+\t\tgoto put_wq;\n+\t}\n+\n \tif (ctx-\u003esva) {\n \t\tidxd_cdev_evl_drain_pasid(wq, ctx-\u003epasid);\n \t\tiommu_sva_unbind_device(ctx-\u003esva);\n \t\tidxd_xa_pasid_remove(ctx);\n \t}\n \tkfree(ctx);\n+put_wq:\n \tmutex_lock(\u0026wq-\u003ewq_lock);\n \tidxd_wq_put(wq);\n \tmutex_unlock(\u0026wq-\u003ewq_lock);\n@@ -592,6 +615,26 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)\n \tput_device(cdev_dev(idxd_cdev));\n }\n \n+/*\n+ * The event log walk tests the fault workqueue and queues on it, and the\n+ * drain of a closing context's PASID tests it and drains it, both under\n+ * the log's lock, which neither the probe nor the remove otherwise takes.\n+ * The workqueue is therefore detached and destroyed under that lock. A\n+ * walk or a drain that finds it gone knows that its work has run.\n+ */\n+static void idxd_user_wq_destroy_fault_wq(struct idxd_wq *wq)\n+{\n+\tstruct idxd_evl *evl = wq-\u003eidxd-\u003eevl;\n+\n+\tif (evl)\n+\t\tmutex_lock(\u0026evl-\u003elock);\n+\twq-\u003etype = IDXD_WQT_NONE;\n+\tdestroy_workqueue(wq-\u003ewq);\n+\twq-\u003ewq = NULL;\n+\tif (evl)\n+\t\tmutex_unlock(\u0026evl-\u003elock);\n+}\n+\n static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)\n {\n \tstruct device *dev = \u0026idxd_dev-\u003econf_dev;\n@@ -653,8 +696,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)\n err_cdev:\n \tidxd_drv_disable_wq(wq);\n err:\n-\tdestroy_workqueue(wq-\u003ewq);\n-\twq-\u003etype = IDXD_WQT_NONE;\n+\tidxd_user_wq_destroy_fault_wq(wq);\n wq_err:\n \tmutex_unlock(\u0026wq-\u003ewq_lock);\n \treturn rc;\n@@ -667,9 +709,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev)\n \tmutex_lock(\u0026wq-\u003ewq_lock);\n \tidxd_wq_del_cdev(wq);\n \tidxd_drv_disable_wq(wq);\n-\twq-\u003etype = IDXD_WQT_NONE;\n-\tdestroy_workqueue(wq-\u003ewq);\n-\twq-\u003ewq = NULL;\n+\tidxd_user_wq_destroy_fault_wq(wq);\n \tmutex_unlock(\u0026wq-\u003ewq_lock);\n }\n \ndiff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c\nindex 131138483b877..5ccdc5ff8d53d 100644\n--- a/drivers/dma/idxd/device.c\n+++ b/drivers/dma/idxd/device.c\n@@ -12,10 +12,14 @@\n #include \"idxd.h\"\n #include \"registers.h\"\n \n+/* generous bound: drain of a loaded WQ is the slowest legitimate command */\n+#define IDXD_CMD_TIMEOUT_MS\t30000\n+\n static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\n \t\t\t  u32 *status);\n static void idxd_device_wqs_clear_state(struct idxd_device *idxd);\n static void idxd_wq_disable_cleanup(struct idxd_wq *wq);\n+static inline bool idxd_device_is_halted(struct idxd_device *idxd);\n static int idxd_wq_config_write(struct idxd_wq *wq);\n \n /* Interrupt control bits */\n@@ -115,6 +119,9 @@ int idxd_wq_alloc_resources(struct idxd_wq *wq)\n \tif (wq-\u003etype != IDXD_WQT_KERNEL)\n \t\treturn 0;\n \n+\t/* A fresh pool: nothing outstanding can land in it. */\n+\twq-\u003estuck = false;\n+\tINIT_LIST_HEAD(\u0026wq-\u003equarantine);\n \tnum_descs = wq_dedicated(wq) ? wq-\u003esize : wq-\u003ethreshold;\n \twq-\u003enum_descs = num_descs;\n \n@@ -167,10 +174,18 @@ EXPORT_SYMBOL_NS_GPL(idxd_wq_alloc_resources, \"IDXD\");\n void idxd_wq_free_resources(struct idxd_wq *wq)\n {\n \tstruct device *dev = \u0026wq-\u003eidxd-\u003epdev-\u003edev;\n+\tLIST_HEAD(dead_descs);\n \n \tif (wq-\u003etype != IDXD_WQT_KERNEL)\n \t\treturn;\n \n+\t/*\n+\t * The disable frees the pool only after its drain and its reset\n+\t * completed, and a failed enable has run nothing, so the device no\n+\t * longer reaches what a quarantined descriptor maps.\n+\t */\n+\tidxd_wq_quarantine_take(wq, \u0026dead_descs);\n+\tidxd_wq_quarantine_free(wq, \u0026dead_descs);\n \tfree_hw_descs(wq);\n \tfree_descs(wq);\n \tdma_free_coherent(dev, wq-\u003ecompls_size, wq-\u003ecompls, wq-\u003ecompls_addr);\n@@ -209,6 +224,7 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n \tu32 status, operand;\n+\tint rc;\n \n \tdev_dbg(dev, \"Disabling WQ %d\\n\", wq-\u003eid);\n \n@@ -226,8 +242,14 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)\n \t * To make sure pending translations are drained before WQ\n \t * attributes are changed, we use a WQ Drain followed by WQ Reset and\n \t * then restore the WQ configuration.\n+\t *\n+\t * A drain that timed out leaves descriptors in the queue. Report\n+\t * it instead of resetting, so that the caller keeps whatever those\n+\t * descriptors can still reach, a PASID for instance.\n \t */\n-\tidxd_wq_drain(wq);\n+\trc = idxd_wq_drain(wq);\n+\tif (rc)\n+\t\treturn rc;\n \n \toperand = BIT(wq-\u003eid % 16) | ((wq-\u003eid / 16) \u003c\u003c 16);\n \tidxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, \u0026status);\n@@ -247,36 +269,72 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)\n \treturn 0;\n }\n \n-void idxd_wq_drain(struct idxd_wq *wq)\n+/*\n+ * The result of a drain or a reset. IDXD_CMDSTS_HW_ERR stands for a\n+ * command that timed out, or was refused after one did, and then the\n+ * device may still run what it holds. It is also the device's own code\n+ * for a hardware error, after which the specification has software read\n+ * GENSTS. Both leave the device enabled unless it halted, and a halted\n+ * device runs nothing until it is reset, so what it holds is then as\n+ * gone as after a drain and that is not a timeout.\n+ */\n+static int idxd_cmd_drain_result(struct idxd_device *idxd, u32 status)\n+{\n+\tif (status != IDXD_CMDSTS_HW_ERR || idxd_device_is_halted(idxd))\n+\t\treturn 0;\n+\treturn -ETIMEDOUT;\n+}\n+\n+/*\n+ * Returns -ETIMEDOUT when the command never completed, or was refused\n+ * because an earlier one never did, in which case descriptors may still\n+ * be in the device and the caller must not free anything it can write\n+ * into.\n+ */\n+int idxd_wq_drain(struct idxd_wq *wq)\n {\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n-\tu32 operand;\n+\tu32 operand, status;\n \n \tif (wq-\u003estate != IDXD_WQ_ENABLED) {\n \t\tdev_dbg(dev, \"WQ %d in wrong state: %d\\n\", wq-\u003eid, wq-\u003estate);\n-\t\treturn;\n+\t\treturn 0;\n \t}\n \n \tdev_dbg(dev, \"Draining WQ %d\\n\", wq-\u003eid);\n \toperand = BIT(wq-\u003eid % 16) | ((wq-\u003eid / 16) \u003c\u003c 16);\n-\tidxd_cmd_exec(idxd, IDXD_CMD_DRAIN_WQ, operand, NULL);\n+\tidxd_cmd_exec(idxd, IDXD_CMD_DRAIN_WQ, operand, \u0026status);\n+\treturn idxd_cmd_drain_result(idxd, status);\n }\n \n-void idxd_wq_reset(struct idxd_wq *wq)\n+int idxd_wq_reset(struct idxd_wq *wq)\n {\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n-\tu32 operand;\n+\tu32 operand, status;\n+\tint rc;\n \n \tif (wq-\u003estate != IDXD_WQ_ENABLED) {\n \t\tdev_dbg(dev, \"WQ %d in wrong state: %d\\n\", wq-\u003eid, wq-\u003estate);\n-\t\treturn;\n+\t\treturn 0;\n \t}\n \n \toperand = BIT(wq-\u003eid % 16) | ((wq-\u003eid / 16) \u003c\u003c 16);\n-\tidxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, NULL);\n+\tidxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, \u0026status);\n+\t/*\n+\t * A reset that timed out, or was refused after a command did,\n+\t * leaves the queue enabled in the device on its configuration.\n+\t * Its software state stays enabled too, as after a failed\n+\t * idxd_wq_disable(), so that the queue is neither reconfigured nor\n+\t * enabled again on a configuration the device does not run until\n+\t * a device disable or reset has stopped it.\n+\t */\n+\trc = idxd_cmd_drain_result(idxd, status);\n+\tif (rc)\n+\t\treturn rc;\n \tidxd_wq_disable_cleanup(wq);\n+\treturn 0;\n }\n \n int idxd_wq_map_portal(struct idxd_wq *wq)\n@@ -425,13 +483,32 @@ int idxd_wq_init_percpu_ref(struct idxd_wq *wq)\n }\n EXPORT_SYMBOL_NS_GPL(idxd_wq_init_percpu_ref, \"IDXD\");\n \n-void __idxd_wq_quiesce(struct idxd_wq *wq)\n+/*\n+ * Kill wq_active and wait for the last submitter to drop its reference.\n+ * Every killer runs under wq_lock and waits before it unlocks, so a\n+ * reference found dying here was killed and waited out by an earlier\n+ * caller, such as a halt flush that did not revive the queue. Killing\n+ * it again would drop the count below zero and wait forever. A\n+ * reference that percpu_ref_exit() released reads as dying too, so a\n+ * queue the device re-enabled behind an unbind is skipped as well.\n+ * Returns whether this call killed the reference.\n+ */\n+bool idxd_wq_kill(struct idxd_wq *wq)\n {\n \tlockdep_assert_held(\u0026wq-\u003ewq_lock);\n+\tif (percpu_ref_is_dying(\u0026wq-\u003ewq_active))\n+\t\treturn false;\n \treinit_completion(\u0026wq-\u003ewq_resurrect);\n \tpercpu_ref_kill(\u0026wq-\u003ewq_active);\n-\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n \twait_for_completion(\u0026wq-\u003ewq_dead);\n+\treturn true;\n+}\n+\n+void __idxd_wq_quiesce(struct idxd_wq *wq)\n+{\n+\tidxd_wq_kill(wq);\n+\t/* Let parked submitters retry and fail on the dead reference. */\n+\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n }\n EXPORT_SYMBOL_NS_GPL(__idxd_wq_quiesce, \"IDXD\");\n \n@@ -498,7 +575,7 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\n \tunion idxd_command_reg cmd;\n \tDECLARE_COMPLETION_ONSTACK(done);\n \tu32 stat;\n-\tunsigned long flags;\n+\tunsigned long flags, left;\n \n \tif (idxd_device_is_halted(idxd)) {\n \t\tdev_warn(\u0026idxd-\u003epdev-\u003edev, \"Device is HALTED!\\n\");\n@@ -507,21 +584,69 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\n \t\treturn;\n \t}\n \n+\tif (test_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags)) {\n+\t\tdev_warn(\u0026idxd-\u003epdev-\u003edev,\n+\t\t\t \"Not sending command %#x: an earlier device command timed out, device needs a reset\\n\",\n+\t\t\t cmd_code);\n+\t\tif (status)\n+\t\t\t*status = IDXD_CMDSTS_HW_ERR;\n+\t\treturn;\n+\t}\n+\n \tmemset(\u0026cmd, 0, sizeof(cmd));\n \tcmd.cmd = cmd_code;\n \tcmd.operand = operand;\n \tcmd.int_req = 1;\n \n \tspin_lock_irqsave(\u0026idxd-\u003ecmd_lock, flags);\n-\twait_event_lock_irq(idxd-\u003ecmd_waitq,\n-\t\t\t    !test_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags),\n-\t\t\t    idxd-\u003ecmd_lock);\n+\t/*\n+\t * Wait for the running command, if any. Only its owner can tell\n+\t * that it is stuck, so this wait does not declare a timeout of its\n+\t * own: its budget covers one owner and restarts whenever another\n+\t * command starts running, and it ends early when the owner gives\n+\t * up and marks the device. Several healthy commands queued behind\n+\t * one another therefore never add up to a false timeout.\n+\t */\n+\twhile (test_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags)) {\n+\t\tu32 seq = idxd-\u003ecmd_seq;\n+\n+\t\tif (test_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags)) {\n+\t\t\tspin_unlock_irqrestore(\u0026idxd-\u003ecmd_lock, flags);\n+\t\t\tdev_err(\u0026idxd-\u003epdev-\u003edev,\n+\t\t\t\t\"not sending command %#x: the running device command timed out, device needs a reset\\n\",\n+\t\t\t\tcmd_code);\n+\t\t\tif (status)\n+\t\t\t\t*status = IDXD_CMDSTS_HW_ERR;\n+\t\t\treturn;\n+\t\t}\n+\t\tif (!wait_event_lock_irq_timeout(idxd-\u003ecmd_waitq,\n+\t\t\t\t!test_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags) ||\n+\t\t\t\ttest_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags) ||\n+\t\t\t\tidxd-\u003ecmd_seq != seq,\n+\t\t\t\tidxd-\u003ecmd_lock,\n+\t\t\t\tmsecs_to_jiffies(IDXD_CMD_TIMEOUT_MS))) {\n+\t\t\t/*\n+\t\t\t * The owner started before this wait and has the\n+\t\t\t * same budget, so its own timeout is due; it marks\n+\t\t\t * the device and wakes this queue. Give up without\n+\t\t\t * marking anything here.\n+\t\t\t */\n+\t\t\tspin_unlock_irqrestore(\u0026idxd-\u003ecmd_lock, flags);\n+\t\t\tdev_err(\u0026idxd-\u003epdev-\u003edev,\n+\t\t\t\t\"timed out waiting for the running device command before %#x\\n\",\n+\t\t\t\tcmd_code);\n+\t\t\tif (status)\n+\t\t\t\t*status = IDXD_CMDSTS_HW_ERR;\n+\t\t\treturn;\n+\t\t}\n+\t}\n \n \tdev_dbg(\u0026idxd-\u003epdev-\u003edev, \"%s: sending cmd: %#x op: %#x\\n\",\n \t\t__func__, cmd_code, operand);\n \n \tidxd-\u003ecmd_status = 0;\n \t__set_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags);\n+\tidxd-\u003ecmd_seq++;\n \tidxd-\u003ecmd_done = \u0026done;\n \tiowrite32(cmd.bits, idxd-\u003ereg_base + IDXD_CMD_OFFSET);\n \n@@ -530,9 +655,57 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\n \t * the command completes via interrupt.\n \t */\n \tspin_unlock_irqrestore(\u0026idxd-\u003ecmd_lock, flags);\n-\twait_for_completion(\u0026done);\n-\tstat = ioread32(idxd-\u003ereg_base + IDXD_CMDSTS_OFFSET);\n+\tleft = wait_for_completion_timeout(\u0026done,\n+\t\t\t\tmsecs_to_jiffies(IDXD_CMD_TIMEOUT_MS));\n \tspin_lock(\u0026idxd-\u003ecmd_lock);\n+\t/*\n+\t * A reset, or the recovery from a halt, forgot this command\n+\t * meanwhile, and another may be running by now. Forgetting the\n+\t * command completes the wait, but it can also happen between the\n+\t * interrupt's completion and this lock, or after the wait ran out,\n+\t * so ownership is checked whichever way the wait ended. The device\n+\t * is not stuck on this command, and the command state belongs to\n+\t * whatever runs now. Mark nothing and leave that state alone, even\n+\t * if this command completed just before the reset or the halt: its\n+\t * status can no longer be trusted.\n+\t */\n+\tif (idxd-\u003ecmd_done != \u0026done) {\n+\t\tspin_unlock(\u0026idxd-\u003ecmd_lock);\n+\t\tdev_err(\u0026idxd-\u003epdev-\u003edev,\n+\t\t\t\"device command %#x was ended by a reset\\n\",\n+\t\t\tcmd_code);\n+\t\tif (status)\n+\t\t\t*status = IDXD_CMDSTS_HW_ERR;\n+\t\treturn;\n+\t}\n+\t/* A timeout, unless the interrupt beat the lock. */\n+\tif (!left \u0026\u0026 !completion_done(\u0026done)) {\n+\t\t/*\n+\t\t * The device did not complete the command. Detach the\n+\t\t * on-stack completion so a late interrupt cannot touch it,\n+\t\t * and leave IDXD_FLAG_CMD_RUNNING set: the device may still\n+\t\t * be executing, so no further commands may be issued.\n+\t\t * IDXD_FLAG_CMD_TIMEDOUT makes waiters and future callers\n+\t\t * fail fast; a late completion interrupt or a device reset\n+\t\t * clears both flags.\n+\t\t */\n+\t\tidxd-\u003ecmd_done = NULL;\n+\t\tset_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags);\n+\t\twake_up(\u0026idxd-\u003ecmd_waitq);\n+\t\tspin_unlock(\u0026idxd-\u003ecmd_lock);\n+\t\tdev_err(\u0026idxd-\u003epdev-\u003edev,\n+\t\t\t\"device command %#x timed out, device needs a reset\\n\",\n+\t\t\tcmd_code);\n+\t\tif (status)\n+\t\t\t*status = IDXD_CMDSTS_HW_ERR;\n+\t\treturn;\n+\t}\n+\t/*\n+\t * Read the status while this command still owns the register: no\n+\t * other command is written before RUNNING is cleared below.\n+\t */\n+\tstat = ioread32(idxd-\u003ereg_base + IDXD_CMDSTS_OFFSET);\n+\tidxd-\u003ecmd_done = NULL;\n \tif (status)\n \t\t*status = stat;\n \tidxd-\u003ecmd_status = stat \u0026 GENMASK(7, 0);\n@@ -543,6 +716,77 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\n \tspin_unlock(\u0026idxd-\u003ecmd_lock);\n }\n \n+/*\n+ * Forget the running command, whether its owner still waits for it or\n+ * has given up on it. Called when the device has been reset or has\n+ * halted, so the command can no longer be executing. A waiting owner is\n+ * woken instead of sleeping out its timeout. It finds that it no longer\n+ * owns the command and returns without touching the command state,\n+ * which belongs to whatever command runs next.\n+ */\n+void idxd_cmd_reset_state(struct idxd_device *idxd)\n+{\n+\tunsigned long flags;\n+\n+\tspin_lock_irqsave(\u0026idxd-\u003ecmd_lock, flags);\n+\t/*\n+\t * The completion is on the owner's stack. It is valid while\n+\t * cmd_done points to it, since the owner clears cmd_done, or sees\n+\t * that it points elsewhere, under cmd_lock before it returns.\n+\t */\n+\tif (idxd-\u003ecmd_done)\n+\t\tcomplete(idxd-\u003ecmd_done);\n+\tidxd-\u003ecmd_done = NULL;\n+\t__clear_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags);\n+\tclear_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags);\n+\twake_up(\u0026idxd-\u003ecmd_waitq);\n+\tspin_unlock_irqrestore(\u0026idxd-\u003ecmd_lock, flags);\n+}\n+\n+/*\n+ * Hold device commands off while the re-probe after a reset frees the\n+ * interrupts and requests them again. A command whose completion\n+ * interrupt comes while the misc vector is gone is never completed, and\n+ * its owner would time out and fence the device that was just reset.\n+ * The running command, if any, is waited for first: its owner gives up\n+ * within its timeout, and the misc vector still takes its interrupt.\n+ * RUNNING is then held without an owner, and new commands wait for it\n+ * as for any running command. Returns false, holding nothing, when a\n+ * command timed out, since commands then fail fast anyway.\n+ */\n+bool idxd_cmd_hold(struct idxd_device *idxd, u32 *seq)\n+{\n+\tbool held = false;\n+\n+\tspin_lock_irq(\u0026idxd-\u003ecmd_lock);\n+\twait_event_lock_irq(idxd-\u003ecmd_waitq,\n+\t\t\t    !test_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags) ||\n+\t\t\t    test_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags),\n+\t\t\t    idxd-\u003ecmd_lock);\n+\tif (!test_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags)) {\n+\t\t__set_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags);\n+\t\t*seq = ++idxd-\u003ecmd_seq;\n+\t\theld = true;\n+\t}\n+\tspin_unlock_irq(\u0026idxd-\u003ecmd_lock);\n+\treturn held;\n+}\n+\n+/*\n+ * End a hold taken by idxd_cmd_hold(). A halt's recovery may have\n+ * forgotten the hold meanwhile and let another command run, which then\n+ * has an owner or a newer sequence number, and its state is left alone.\n+ */\n+void idxd_cmd_unhold(struct idxd_device *idxd, u32 seq)\n+{\n+\tspin_lock_irq(\u0026idxd-\u003ecmd_lock);\n+\tif (idxd-\u003ecmd_seq == seq \u0026\u0026 !idxd-\u003ecmd_done) {\n+\t\t__clear_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags);\n+\t\twake_up(\u0026idxd-\u003ecmd_waitq);\n+\t}\n+\tspin_unlock_irq(\u0026idxd-\u003ecmd_lock);\n+}\n+\n int idxd_device_enable(struct idxd_device *idxd)\n {\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n@@ -578,9 +822,16 @@ int idxd_device_disable(struct idxd_device *idxd)\n \n \tidxd_cmd_exec(idxd, IDXD_CMD_DISABLE_DEVICE, 0, \u0026status);\n \n-\t/* If the command is successful or if the device was disabled */\n+\t/*\n+\t * The command succeeded, or the device was already disabled. The\n+\t * error code is a value, not a bit mask, so compare it whole. A\n+\t * refused command reports IDXD_CMDSTS_HW_ERR, which shares a bit\n+\t * with the already-disabled code but leaves the device enabled,\n+\t * and clearing the software state of an enabled device lets a\n+\t * later teardown free memory the device still writes.\n+\t */\n \tif (status != IDXD_CMDSTS_SUCCESS \u0026\u0026\n-\t    !(status \u0026 IDXD_CMDSTS_ERR_DIS_DEV_EN)) {\n+\t    (status \u0026 IDXD_CMDSTS_ERR_MASK) != IDXD_CMDSTS_ERR_DIS_DEV_EN) {\n \t\tdev_dbg(dev, \"%s: err_code: %#x\\n\", __func__, status);\n \t\treturn -ENXIO;\n \t}\n@@ -589,24 +840,41 @@ int idxd_device_disable(struct idxd_device *idxd)\n \treturn 0;\n }\n \n-void idxd_device_reset(struct idxd_device *idxd)\n+/*\n+ * Returns -ENXIO when the device refused or never ran the reset. The\n+ * software state is cleared only after a reset that ran, since clearing\n+ * it for an enabled device lets a later teardown free memory the device\n+ * still writes.\n+ */\n+int idxd_device_reset(struct idxd_device *idxd)\n {\n-\tidxd_cmd_exec(idxd, IDXD_CMD_RESET_DEVICE, 0, NULL);\n+\tu32 status;\n+\n+\tidxd_cmd_exec(idxd, IDXD_CMD_RESET_DEVICE, 0, \u0026status);\n+\tif (status != IDXD_CMDSTS_SUCCESS) {\n+\t\tdev_dbg(\u0026idxd-\u003epdev-\u003edev, \"%s: err_code: %#x\\n\", __func__, status);\n+\t\treturn -ENXIO;\n+\t}\n \tidxd_device_clear_state(idxd);\n \tspin_lock(\u0026idxd-\u003edev_lock);\n \tidxd_unmask_error_interrupts(idxd);\n \tspin_unlock(\u0026idxd-\u003edev_lock);\n+\treturn 0;\n }\n \n-void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid)\n+/* Returns -ETIMEDOUT when the drain was never run or never completed. */\n+int idxd_device_drain_pasid(struct idxd_device *idxd, int pasid)\n {\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n-\tu32 operand;\n+\tu32 operand, status;\n \n \toperand = pasid;\n \tdev_dbg(dev, \"cmd: %u operand: %#x\\n\", IDXD_CMD_DRAIN_PASID, operand);\n-\tidxd_cmd_exec(idxd, IDXD_CMD_DRAIN_PASID, operand, NULL);\n+\tidxd_cmd_exec(idxd, IDXD_CMD_DRAIN_PASID, operand, \u0026status);\n+\tif (idxd_cmd_drain_result(idxd, status))\n+\t\treturn -ETIMEDOUT;\n \tdev_dbg(dev, \"pasid %d drained\\n\", pasid);\n+\treturn 0;\n }\n \n int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,\n@@ -644,31 +912,20 @@ int idxd_device_release_int_handle(struct idxd_device *idxd, int handle,\n {\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n \tu32 operand, status;\n-\tunion idxd_command_reg cmd;\n \n \tif (!(idxd-\u003ehw.cmd_cap \u0026 BIT(IDXD_CMD_RELEASE_INT_HANDLE)))\n \t\treturn -EOPNOTSUPP;\n \n \tdev_dbg(dev, \"release int handle, handle %d\\n\", handle);\n \n-\tmemset(\u0026cmd, 0, sizeof(cmd));\n \toperand = handle \u0026 GENMASK(15, 0);\n \n \tif (irq_type == IDXD_IRQ_IMS)\n \t\toperand |= CMD_INT_HANDLE_IMS;\n \n-\tcmd.cmd = IDXD_CMD_RELEASE_INT_HANDLE;\n-\tcmd.operand = operand;\n-\n \tdev_dbg(dev, \"cmd: %u operand: %#x\\n\", IDXD_CMD_RELEASE_INT_HANDLE, operand);\n \n-\tspin_lock(\u0026idxd-\u003ecmd_lock);\n-\tiowrite32(cmd.bits, idxd-\u003ereg_base + IDXD_CMD_OFFSET);\n-\n-\twhile (ioread32(idxd-\u003ereg_base + IDXD_CMDSTS_OFFSET) \u0026 IDXD_CMDSTS_ACTIVE)\n-\t\tcpu_relax();\n-\tstatus = ioread32(idxd-\u003ereg_base + IDXD_CMDSTS_OFFSET);\n-\tspin_unlock(\u0026idxd-\u003ecmd_lock);\n+\tidxd_cmd_exec(idxd, IDXD_CMD_RELEASE_INT_HANDLE, operand, \u0026status);\n \n \tif ((status \u0026 IDXD_CMDSTS_ERR_MASK) != IDXD_CMDSTS_SUCCESS) {\n \t\tdev_dbg(dev, \"release int handle failed: %#x\\n\", status);\n@@ -1269,11 +1526,14 @@ int idxd_device_load_config(struct idxd_device *idxd)\n \treturn 0;\n }\n \n-static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)\n+static void idxd_flush_pending_descs(struct idxd_irq_entry *ie,\n+\t\t\t\t     bool keep_callbacks, bool quarantine)\n {\n+\tstruct idxd_wq *wq = ie_to_wq(ie);\n \tstruct idxd_desc *desc, *itr;\n \tstruct llist_node *head;\n \tLIST_HEAD(flist);\n+\tLIST_HEAD(qlist);\n \tenum idxd_complete_type ctype;\n \n \tspin_lock(\u0026ie-\u003elist_lock);\n@@ -1283,6 +1543,28 @@ static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)\n \t\t\tlist_add_tail(\u0026desc-\u003elist, \u0026ie-\u003ework_list);\n \t}\n \n+\t/*\n+\t * A halt flush that delivers the callbacks of a dmaengine queue\n+\t * leaves its descriptors to the interrupt thread, which runs them\n+\t * without wq_lock, as it runs every completion. A callback may\n+\t * terminate the channel, which takes that lock, and the halt flush\n+\t * holds it. The halted device writes no record any more, so one it\n+\t * never finished is marked aborted for the thread to complete.\n+\t */\n+\tif (keep_callbacks \u0026\u0026 idxd_wq_has_txd(wq)) {\n+\t\tbool wake = false;\n+\n+\t\tlist_for_each_entry(desc, \u0026ie-\u003ework_list, list) {\n+\t\t\tif (!desc-\u003ecompletion-\u003estatus)\n+\t\t\t\tdesc-\u003ecompletion-\u003estatus = IDXD_COMP_DESC_ABORT;\n+\t\t\twake = true;\n+\t\t}\n+\t\tspin_unlock(\u0026ie-\u003elist_lock);\n+\t\tif (wake)\n+\t\t\tirq_wake_thread(ie-\u003evector, ie);\n+\t\treturn;\n+\t}\n+\n \tlist_for_each_entry_safe(desc, itr, \u0026ie-\u003ework_list, list)\n \t\tlist_move_tail(\u0026desc-\u003elist, \u0026flist);\n \tspin_unlock(\u0026ie-\u003elist_lock);\n@@ -1293,16 +1575,123 @@ static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)\n \t\tlist_del(\u0026desc-\u003elist);\n \t\tctype = desc-\u003ecompletion-\u003estatus ? IDXD_COMPLETE_NORMAL : IDXD_COMPLETE_ABORT;\n \t\t/*\n-\t\t * wq is being disabled. Any remaining descriptors are\n-\t\t * likely to be stuck and can be dropped. callback could\n-\t\t * point to code that is no longer accessible, for example\n-\t\t * if dmatest module has been unloaded.\n+\t\t * Another driver's descriptor carries that driver's request\n+\t\t * in place of a txd, and a client may still wait for it, so it\n+\t\t * goes back through that driver's completion. The completion\n+\t\t * reads the outcome from the record, which the device never\n+\t\t * wrote for an unfinished descriptor. Only a dmaengine channel\n+\t\t * terminates, so nothing of such a queue is quarantined.\n+\t\t */\n+\t\tif (!idxd_wq_has_txd(wq)) {\n+\t\t\tif (ctype == IDXD_COMPLETE_ABORT)\n+\t\t\t\tdesc-\u003ecompletion-\u003estatus = IDXD_COMP_DESC_ABORT;\n+\t\t\tidxd_desc_complete(desc, ctype, true);\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/*\n+\t\t * wq is being disabled or terminated. Any remaining\n+\t\t * descriptors are likely to be stuck and can be dropped.\n+\t\t * With no client left the callback could point to code that\n+\t\t * is no longer accessible (dmatest unloaded), and a client's\n+\t\t * own terminate must not get it, so it is stripped. A halt\n+\t\t * that delivers the callbacks left them to the thread above.\n \t\t */\n \t\ttx = \u0026desc-\u003etxd;\n \t\ttx-\u003ecallback = NULL;\n \t\ttx-\u003ecallback_result = NULL;\n-\t\tidxd_dma_complete_txd(desc, ctype, true, NULL, NULL);\n+\t\t/*\n+\t\t * A descriptor the device has not finished still has its\n+\t\t * completion record to write. A flush that leaves the\n+\t\t * device running keeps its slot out of use, or the record\n+\t\t * would land on the slot's next owner and complete it with\n+\t\t * this descriptor's status. Its unmap data stays with the\n+\t\t * slot as well, since the device may still access what it\n+\t\t * maps, and an address released now could be mapped again\n+\t\t * for someone else before the late access.\n+\t\t */\n+\t\tif (quarantine \u0026\u0026 ctype == IDXD_COMPLETE_ABORT) {\n+\t\t\tstruct dmaengine_unmap_data *unmap = tx-\u003eunmap;\n+\n+\t\t\ttx-\u003eunmap = NULL;\n+\t\t\tidxd_dma_complete_txd(desc, ctype, false, NULL, NULL);\n+\t\t\ttx-\u003eunmap = unmap;\n+\t\t\tlist_add_tail(\u0026desc-\u003elist, \u0026qlist);\n+\t\t\tcontinue;\n+\t\t}\n+\t\t/*\n+\t\t * The abort type keeps a record that reports a revoked\n+\t\t * interrupt handle from being resubmitted. The device is done\n+\t\t * with it, and with the handle kept across a terminate the\n+\t\t * copy would run once the client may have freed its memory.\n+\t\t */\n+\t\tidxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT, true, NULL,\n+\t\t\t\t      NULL);\n \t}\n+\n+\tif (list_empty(\u0026qlist))\n+\t\treturn;\n+\tspin_lock(\u0026ie-\u003elist_lock);\n+\tlist_splice_tail(\u0026qlist, \u0026wq-\u003equarantine);\n+\tspin_unlock(\u0026ie-\u003elist_lock);\n+}\n+\n+/*\n+ * Take what terminate_all has quarantined so far. A drain covers only\n+ * what the device held when it was issued, so a synchronize takes the\n+ * quarantine before it drains and frees it if the drain completed. A\n+ * descriptor terminated meanwhile waits for the next one. The list lock\n+ * serialises this with the flush that adds to the quarantine and with a\n+ * halt or a teardown that frees it all.\n+ */\n+void idxd_wq_quarantine_take(struct idxd_wq *wq, struct list_head *list)\n+{\n+\tspin_lock(\u0026wq-\u003eie.list_lock);\n+\tlist_splice_init(\u0026wq-\u003equarantine, list);\n+\tspin_unlock(\u0026wq-\u003eie.list_lock);\n+}\n+\n+/* The drain did not complete: the device may still run them. */\n+void idxd_wq_quarantine_put_back(struct idxd_wq *wq, struct list_head *list)\n+{\n+\tspin_lock(\u0026wq-\u003eie.list_lock);\n+\tlist_splice(list, \u0026wq-\u003equarantine);\n+\tspin_unlock(\u0026wq-\u003eie.list_lock);\n+}\n+\n+/*\n+ * Nothing the device holds can write their completion records, or reach\n+ * the memory their unmap data maps, any more. The unmap data goes before\n+ * the slot, which a new owner may take at once.\n+ */\n+void idxd_wq_quarantine_free(struct idxd_wq *wq, struct list_head *list)\n+{\n+\tstruct idxd_desc *desc, *itr;\n+\n+\tlist_for_each_entry_safe(desc, itr, list, list) {\n+\t\tlist_del(\u0026desc-\u003elist);\n+\t\tdma_descriptor_unmap(\u0026desc-\u003etxd);\n+\t\tidxd_free_desc(wq, desc);\n+\t}\n+}\n+\n+/*\n+ * A halt killed every descriptor the device held: the quarantined slots\n+ * are free, and the fence a failed drain raised can be lifted. The halt\n+ * flush calls this under wq_lock, since an unbind racing the halt may\n+ * free the pool.\n+ */\n+void idxd_wq_halt_release(struct idxd_wq *wq)\n+{\n+\tLIST_HEAD(dead_descs);\n+\n+\tlockdep_assert_held(\u0026wq-\u003ewq_lock);\n+\n+\tif (wq-\u003estate != IDXD_WQ_ENABLED || wq-\u003etype != IDXD_WQT_KERNEL)\n+\t\treturn;\n+\n+\tidxd_wq_quarantine_take(wq, \u0026dead_descs);\n+\tidxd_wq_quarantine_free(wq, \u0026dead_descs);\n+\tWRITE_ONCE(wq-\u003estuck, false);\n }\n \n static void idxd_device_set_perm_entry(struct idxd_device *idxd,\n@@ -1334,12 +1723,18 @@ void idxd_wq_free_irq(struct idxd_wq *wq)\n \t\treturn;\n \n \tfree_irq(ie-\u003evector, ie);\n-\tidxd_flush_pending_descs(ie);\n+\tidxd_flush_pending_descs(ie, false, false);\n \n-\t/* The interrupt might have been already released by FLR */\n+\t/* FLR revokes every handle; the halt path marks them invalid. */\n \tif (ie-\u003eint_handle == INVALID_INT_HANDLE)\n \t\treturn;\n \n+\t/*\n+\t * The release waits for a running command like any other command.\n+\t * It is not sent, or does not complete, only on a halted device or\n+\t * after a command timed out, and the reset such a device needs\n+\t * revokes the handle. The handle is forgotten in any case.\n+\t */\n \tif (idxd-\u003erequest_int_handles)\n \t\tidxd_device_release_int_handle(idxd, ie-\u003eint_handle, IDXD_IRQ_MSIX);\n \tidxd_device_clear_perm_entry(idxd, ie);\n@@ -1348,21 +1743,49 @@ void idxd_wq_free_irq(struct idxd_wq *wq)\n \tie-\u003epasid = IOMMU_PASID_INVALID;\n }\n \n-void idxd_wq_flush_descs(struct idxd_wq *wq)\n+/*\n+ * @keep_callbacks: deliver the flushed descriptors' completions to the\n+ * client, aborted, or with their hardware status where the device had\n+ * already finished them. A client's own terminate_all must not get them\n+ * (the dmaengine contract); a device halt with a client still holding the\n+ * channel must, or the client waits for them forever. The interrupt\n+ * thread delivers them, outside wq_lock.\n+ * @quarantine: the device keeps running, so the slots of the descriptors\n+ * it has not finished stay out of use until a drain covers them. A halt\n+ * has killed them and frees their slots at once.\n+ * The caller holds wq_lock.\n+ */\n+void __idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,\n+\t\t\t   bool quarantine)\n {\n \tstruct idxd_irq_entry *ie = \u0026wq-\u003eie;\n-\tstruct idxd_device *idxd = wq-\u003eidxd;\n+\tbool killed = false;\n \n-\tguard(mutex)(\u0026wq-\u003ewq_lock);\n+\tlockdep_assert_held(\u0026wq-\u003ewq_lock);\n \n \tif (wq-\u003estate != IDXD_WQ_ENABLED || wq-\u003etype != IDXD_WQT_KERNEL)\n \t\treturn;\n \n-\tidxd_flush_pending_descs(ie);\n-\tif (idxd-\u003erequest_int_handles)\n-\t\tidxd_device_release_int_handle(idxd, ie-\u003eint_handle, IDXD_IRQ_MSIX);\n-\tidxd_device_clear_perm_entry(idxd, ie);\n-\tie-\u003eint_handle = INVALID_INT_HANDLE;\n+\t/*\n+\t * A submitter between its list add and its portal write holds\n+\t * wq_active. Waiting for the reference to die puts every listed\n+\t * descriptor in the device, where the drain that frees the\n+\t * quarantine covers it. A halt flush has done this itself.\n+\t */\n+\tif (quarantine)\n+\t\tkilled = idxd_wq_kill(wq);\n+\tidxd_flush_pending_descs(ie, keep_callbacks, quarantine);\n+\tif (killed) {\n+\t\tpercpu_ref_reinit(\u0026wq-\u003ewq_active);\n+\t\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n+\t}\n+}\n+\n+void idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,\n+\t\t\t bool quarantine)\n+{\n+\tguard(mutex)(\u0026wq-\u003ewq_lock);\n+\t__idxd_wq_flush_descs(wq, keep_callbacks, quarantine);\n }\n \n int idxd_wq_request_irq(struct idxd_wq *wq)\n@@ -1415,6 +1838,16 @@ int idxd_drv_enable_wq(struct idxd_wq *wq)\n \n \tlockdep_assert_held(\u0026wq-\u003ewq_lock);\n \n+\t/*\n+\t * The device remove releases the queues' drivers before it disables\n+\t * the device, so the device still reads enabled meanwhile.\n+\t */\n+\tif (test_bit(IDXD_FLAG_REMOVING, \u0026idxd-\u003eflags)) {\n+\t\tidxd-\u003ecmd_status = IDXD_SCMD_DEV_NOT_ENABLED;\n+\t\trc = -ENODEV;\n+\t\tgoto err;\n+\t}\n+\n \tif (idxd-\u003estate != IDXD_DEV_ENABLED) {\n \t\tidxd-\u003ecmd_status = IDXD_SCMD_DEV_NOT_ENABLED;\n \t\tgoto err;\n@@ -1541,6 +1974,7 @@ void idxd_drv_disable_wq(struct idxd_wq *wq)\n {\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n+\tint rc;\n \n \tlockdep_assert_held(\u0026wq-\u003ewq_lock);\n \n@@ -1549,10 +1983,19 @@ void idxd_drv_disable_wq(struct idxd_wq *wq)\n \t\t\t wq-\u003eid, idxd_wq_refcount(wq));\n \n \tidxd_wq_unmap_portal(wq);\n-\tidxd_wq_drain(wq);\n+\trc = idxd_wq_drain(wq);\n \tidxd_wq_free_irq(wq);\n-\tidxd_wq_reset(wq);\n-\tidxd_wq_free_resources(wq);\n+\trc |= idxd_wq_reset(wq);\n+\t/*\n+\t * A drain or reset that never completed leaves descriptors in the\n+\t * device, and their completion records live in the memory freed\n+\t * here. Leak it; the device writing into freed memory is worse.\n+\t */\n+\tif (rc)\n+\t\tdev_err(dev, \"wq %d: drain or reset timed out, leaking its descriptor memory\\n\",\n+\t\t\twq-\u003eid);\n+\telse\n+\t\tidxd_wq_free_resources(wq);\n \tpercpu_ref_exit(\u0026wq-\u003ewq_active);\n \twq-\u003eclient_count = 0;\n }\n@@ -1563,6 +2006,9 @@ int idxd_device_drv_probe(struct idxd_dev *idxd_dev)\n \tstruct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);\n \tint rc = 0;\n \n+\tif (test_bit(IDXD_FLAG_REMOVING, \u0026idxd-\u003eflags))\n+\t\treturn -ENODEV;\n+\n \t/*\n \t * Device should be in disabled state for the idxd_drv to load. If it's in\n \t * enabled state, then the device was altered outside of driver's control.\n@@ -1617,23 +2063,41 @@ void idxd_device_drv_remove(struct idxd_dev *idxd_dev)\n {\n \tstruct device *dev = \u0026idxd_dev-\u003econf_dev;\n \tstruct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);\n+\tbool stopped;\n \tint i;\n \n \tfor (i = 0; i \u003c idxd-\u003emax_wqs; i++) {\n \t\tstruct idxd_wq *wq = idxd-\u003ewqs[i];\n \t\tstruct device *wq_dev = wq_confdev(wq);\n \n-\t\tif (wq-\u003estate == IDXD_WQ_DISABLED)\n-\t\t\tcontinue;\n-\t\tdev_warn(dev, \"Active wq %d on disable %s.\\n\", i, dev_name(wq_dev));\n+\t\t/*\n+\t\t * A halt's clear_state leaves a bound queue DISABLED while\n+\t\t * its driver still holds the queue's channel and resources.\n+\t\t * Release every bound driver, not only the enabled queues',\n+\t\t * before the dma_device below frees their channels. For a\n+\t\t * queue without a driver the release is a no-op.\n+\t\t */\n+\t\tif (wq-\u003estate != IDXD_WQ_DISABLED)\n+\t\t\tdev_warn(dev, \"Active wq %d on disable %s.\\n\", i,\n+\t\t\t\t dev_name(wq_dev));\n \t\tdevice_release_driver(wq_dev);\n \t}\n \n \tidxd_unregister_dma_device(idxd);\n-\tidxd_device_disable(idxd);\n-\tif (test_bit(IDXD_FLAG_CONFIGURABLE, \u0026idxd-\u003eflags))\n-\t\tidxd_device_reset(idxd);\n-\tidxd_device_evl_free(idxd);\n+\t/*\n+\t * A disable or a reset that ran, or found the device disabled or\n+\t * halted, leaves nothing in flight. Both are refused after a device\n+\t * command timed out, and the device then stays enabled with whatever\n+\t * it holds, so what it may still write is kept.\n+\t */\n+\tstopped = !idxd_device_disable(idxd);\n+\tif (test_bit(IDXD_FLAG_CONFIGURABLE, \u0026idxd-\u003eflags) \u0026\u0026\n+\t    !idxd_device_reset(idxd))\n+\t\tstopped = true;\n+\tif (stopped)\n+\t\tidxd_device_evl_free(idxd);\n+\telse\n+\t\tdev_err(dev, \"device still enabled after a command timeout, leaking the event log\\n\");\n }\n \n static enum idxd_dev_type dev_types[] = {\ndiff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c\nindex 9937b671f6376..0a7517cb51f29 100644\n--- a/drivers/dma/idxd/dma.c\n+++ b/drivers/dma/idxd/dma.c\n@@ -115,7 +115,8 @@ idxd_dma_submit_memcpy(struct dma_chan *c, dma_addr_t dma_dest,\n \tif (wq-\u003estate != IDXD_WQ_ENABLED)\n \t\treturn NULL;\n \n-\tif (len \u003e idxd-\u003emax_xfer_bytes)\n+\t/* The work queue's configured limit is what the hardware enforces. */\n+\tif (len \u003e idxd-\u003emax_xfer_bytes || len \u003e wq-\u003emax_xfer_bytes)\n \t\treturn NULL;\n \n \top_flag_setup(flags, \u0026desc_flags);\n@@ -198,7 +199,18 @@ static int idxd_dma_terminate_all(struct dma_chan *c)\n {\n \tstruct idxd_wq *wq = to_idxd_wq(c);\n \n-\tidxd_wq_flush_descs(wq);\n+\tguard(mutex)(\u0026wq-\u003ewq_lock);\n+\t/*\n+\t * A descriptor that completed with a revoked interrupt handle is\n+\t * resubmitted by a work item. One submitted before this terminate\n+\t * may reach that work after the flush, from the interrupt thread or\n+\t * from a work item queued earlier, and is cancelled there rather\n+\t * than run with its callback once the client may have freed its\n+\t * memory.\n+\t */\n+\tWRITE_ONCE(wq-\u003eterminate_gen, wq-\u003eterminate_gen + 1);\n+\t/* The device keeps running what the lists held. See synchronize. */\n+\t__idxd_wq_flush_descs(wq, false, true);\n \n \treturn 0;\n }\n@@ -206,8 +218,38 @@ static int idxd_dma_terminate_all(struct dma_chan *c)\n static void idxd_dma_synchronize(struct dma_chan *c)\n {\n \tstruct idxd_wq *wq = to_idxd_wq(c);\n+\tLIST_HEAD(quarantined);\n \n-\tidxd_wq_drain(wq);\n+\t/*\n+\t * dmaengine_synchronize() promises the client that its memory may\n+\t * be freed afterwards. A drain that completed keeps that promise,\n+\t * and nothing the device held before it is left to write a\n+\t * completion record, so the slots terminate_all quarantined are\n+\t * free again. A drain that never completed, or that was refused\n+\t * because an earlier command never did, leaves the client's\n+\t * descriptors in a device that may still run them. The channel\n+\t * release path runs this under dma_list_mutex, and a device that\n+\t * refused the drain offers nothing to wait for, so waiting longer\n+\t * here would hold up every dmaengine user for nothing. The driver\n+\t * cannot keep the promise for the client's memory then and says so.\n+\t * It keeps its own memory safe: the quarantined slots stay out of\n+\t * use and the queue takes no new descriptor until a later drain\n+\t * completes or a halt kills what the device holds, so a late\n+\t * completion record lands in a slot nobody reuses, and\n+\t * idxd_drv_disable_wq() leaks what the device may still write.\n+\t * Only a device reset ends the exposure of the client's memory.\n+\t */\n+\tidxd_wq_quarantine_take(wq, \u0026quarantined);\n+\tif (!idxd_wq_drain(wq)) {\n+\t\tidxd_wq_quarantine_free(wq, \u0026quarantined);\n+\t\tWRITE_ONCE(wq-\u003estuck, false);\n+\t\treturn;\n+\t}\n+\tidxd_wq_quarantine_put_back(wq, \u0026quarantined);\n+\tWRITE_ONCE(wq-\u003estuck, true);\n+\tdev_err_ratelimited(\u0026wq-\u003eidxd-\u003epdev-\u003edev,\n+\t\t\t    \"wq %d: drain failed. Its descriptors may still complete and it takes no new work until a drain completes or the device is reset\\n\",\n+\t\t\t    wq-\u003eid);\n }\n \n int idxd_register_dma_device(struct idxd_device *idxd)\n@@ -278,7 +320,7 @@ static int idxd_register_dma_channel(struct idxd_wq *wq)\n \n \tchan = \u0026idxd_chan-\u003echan;\n \tchan-\u003edevice = dma;\n-\tlist_add_tail(\u0026chan-\u003edevice_node, \u0026dma-\u003echannels);\n+\tidxd_chan-\u003ewq = wq;\n \n \tfor (i = 0; i \u003c wq-\u003enum_descs; i++) {\n \t\tstruct idxd_desc *desc = wq-\u003edescs[i];\n@@ -287,14 +329,20 @@ static int idxd_register_dma_channel(struct idxd_wq *wq)\n \t\tdesc-\u003etxd.tx_submit = idxd_dma_tx_submit;\n \t}\n \n-\trc = dma_async_device_channel_register(dma, chan, NULL);\n+\t/*\n+\t * The dma_device is registered already, so a channel request may\n+\t * take the channel as soon as it is on the device's list. The core\n+\t * links it only once it is registered, and everything a client\n+\t * reaches through it is set up by then. What follows serves the\n+\t * unbind, which cannot run before this probe returns.\n+\t */\n+\trc = dma_async_device_channel_add(dma, chan, NULL);\n \tif (rc \u003c 0) {\n \t\tkfree(idxd_chan);\n \t\treturn rc;\n \t}\n \n \twq-\u003eidxd_chan = idxd_chan;\n-\tidxd_chan-\u003ewq = wq;\n \tget_device(wq_confdev(wq));\n \n \treturn 0;\ndiff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h\nindex ce78b9a7c641c..b0cfd71011742 100644\n--- a/drivers/dma/idxd/idxd.h\n+++ b/drivers/dma/idxd/idxd.h\n@@ -224,6 +224,21 @@ struct idxd_wq {\n \tstruct idxd_desc **descs;\n \tstruct sbitmap_queue sbq;\n \tstruct idxd_dma_chan *idxd_chan;\n+\tbool stuck;\t\t/* a drain failed with the device enabled: the\n+\t\t\t\t * outstanding descriptors may complete at any\n+\t\t\t\t * time, so no slot is reused until a later\n+\t\t\t\t * drain completes or a halt kills them\n+\t\t\t\t */\n+\tu16 terminate_gen;\t/* bumps on every terminate_all, under\n+\t\t\t\t * wq_lock before its kill\n+\t\t\t\t */\n+\tstruct list_head quarantine;\t/* descriptors a terminate_all took\n+\t\t\t\t\t * off the lists while the device\n+\t\t\t\t\t * still held them. Their slots, with\n+\t\t\t\t\t * their unmap data, are freed once a\n+\t\t\t\t\t * drain that covers them completes or\n+\t\t\t\t\t * the device stops. Under ie.list_lock.\n+\t\t\t\t\t */\n \tchar name[WQ_NAME_SIZE + 1];\n \tu64 max_xfer_bytes;\n \tu32 max_batch_size;\n@@ -267,8 +282,10 @@ enum idxd_device_state {\n enum idxd_device_flag {\n \tIDXD_FLAG_CONFIGURABLE = 0,\n \tIDXD_FLAG_CMD_RUNNING,\n+\tIDXD_FLAG_CMD_TIMEDOUT,\n \tIDXD_FLAG_PASID_ENABLED,\n \tIDXD_FLAG_USER_PASID_ENABLED,\n+\tIDXD_FLAG_REMOVING,\t/* PCI remove under way, refuse binds */\n };\n \n struct idxd_dma_dev {\n@@ -331,6 +348,7 @@ struct idxd_device {\n \tspinlock_t dev_lock;\t/* spinlock for device */\n \tspinlock_t cmd_lock;\t/* spinlock for device commands */\n \tstruct completion *cmd_done;\n+\tu32 cmd_seq;\t\t/* bumps when a command starts running */\n \tstruct idxd_group **groups;\n \tstruct idxd_wq **wqs;\n \tstruct idxd_engine **engines;\n@@ -429,6 +447,9 @@ struct idxd_desc {\n \tstruct list_head list;\n \tint id;\n \tint cpu;\n+\tu16 terminate_gen;\t/* the queue's terminate_gen at an\n+\t\t\t\t * interrupt-armed submit\n+\t\t\t\t */\n \tstruct idxd_wq *wq;\n };\n \n@@ -740,6 +761,16 @@ void idxd_dma_complete_txd(struct idxd_desc *desc,\n \t\t\t   enum idxd_complete_type comp_type,\n \t\t\t   bool free_desc, void *ctx, u32 *status);\n \n+/*\n+ * Whether the queue's descriptors are dmaengine transactions. Another\n+ * driver, such as iaa_crypto, keeps its own context where they keep\n+ * their txd.\n+ */\n+static inline bool idxd_wq_has_txd(struct idxd_wq *wq)\n+{\n+\treturn wq_to_idxd_drv(wq)-\u003edesc_complete == idxd_dma_complete_txd;\n+}\n+\n static inline void idxd_desc_complete(struct idxd_desc *desc,\n \t\t\t\t      enum idxd_complete_type comp_type,\n \t\t\t\t      bool free_desc)\n@@ -776,10 +807,13 @@ void idxd_drv_disable_wq(struct idxd_wq *wq);\n int idxd_device_init_reset(struct idxd_device *idxd);\n int idxd_device_enable(struct idxd_device *idxd);\n int idxd_device_disable(struct idxd_device *idxd);\n-void idxd_device_reset(struct idxd_device *idxd);\n+int idxd_device_reset(struct idxd_device *idxd);\n void idxd_device_clear_state(struct idxd_device *idxd);\n+void idxd_cmd_reset_state(struct idxd_device *idxd);\n+bool idxd_cmd_hold(struct idxd_device *idxd, u32 *seq);\n+void idxd_cmd_unhold(struct idxd_device *idxd, u32 seq);\n int idxd_device_config(struct idxd_device *idxd);\n-void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);\n+int idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);\n int idxd_device_load_config(struct idxd_device *idxd);\n int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,\n \t\t\t\t   enum idxd_interrupt_type irq_type);\n@@ -792,21 +826,30 @@ int idxd_wq_alloc_resources(struct idxd_wq *wq);\n void idxd_wq_free_resources(struct idxd_wq *wq);\n int idxd_wq_enable(struct idxd_wq *wq);\n int idxd_wq_disable(struct idxd_wq *wq, bool reset_config);\n-void idxd_wq_drain(struct idxd_wq *wq);\n-void idxd_wq_reset(struct idxd_wq *wq);\n+int idxd_wq_drain(struct idxd_wq *wq);\n+int idxd_wq_reset(struct idxd_wq *wq);\n int idxd_wq_map_portal(struct idxd_wq *wq);\n void idxd_wq_unmap_portal(struct idxd_wq *wq);\n int idxd_wq_set_pasid(struct idxd_wq *wq, int pasid);\n int idxd_wq_disable_pasid(struct idxd_wq *wq);\n+bool idxd_wq_kill(struct idxd_wq *wq);\n void __idxd_wq_quiesce(struct idxd_wq *wq);\n void idxd_wq_quiesce(struct idxd_wq *wq);\n int idxd_wq_init_percpu_ref(struct idxd_wq *wq);\n void idxd_wq_free_irq(struct idxd_wq *wq);\n int idxd_wq_request_irq(struct idxd_wq *wq);\n-void idxd_wq_flush_descs(struct idxd_wq *wq);\n+void __idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,\n+\t\t\t   bool quarantine);\n+void idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,\n+\t\t\t bool quarantine);\n+void idxd_wq_quarantine_take(struct idxd_wq *wq, struct list_head *list);\n+void idxd_wq_quarantine_put_back(struct idxd_wq *wq, struct list_head *list);\n+void idxd_wq_quarantine_free(struct idxd_wq *wq, struct list_head *list);\n+void idxd_wq_halt_release(struct idxd_wq *wq);\n \n /* submission */\n int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);\n+int idxd_resubmit_desc(struct idxd_wq *wq, struct idxd_desc *desc);\n struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype);\n int idxd_enqcmds(struct idxd_wq *wq, void __iomem *portal, const void *desc);\n \ndiff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c\nindex 4b827a3297564..312b4670b3e82 100644\n--- a/drivers/dma/idxd/init.c\n+++ b/drivers/dma/idxd/init.c\n@@ -213,6 +213,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)\n \t\tinit_waitqueue_head(\u0026wq-\u003eerr_queue);\n \t\tinit_completion(\u0026wq-\u003ewq_dead);\n \t\tinit_completion(\u0026wq-\u003ewq_resurrect);\n+\t\tINIT_LIST_HEAD(\u0026wq-\u003equarantine);\n \t\twq-\u003emax_xfer_bytes = WQ_DEFAULT_MAX_XFER;\n \t\tidxd_wq_set_max_batch_size(idxd-\u003edata-\u003etype, wq, WQ_DEFAULT_MAX_BATCH);\n \t\tidxd_wq_set_init_max_sgl_size(idxd, wq);\n@@ -1057,6 +1058,15 @@ static void idxd_reset_done(struct pci_dev *pdev)\n \tstruct device *dev;\n \tint rc, i;\n \n+\t/*\n+\t * A reset ends any command, including one that had timed out. The\n+\t * PCI core resets the device even when the preparation failed and\n+\t * the device is not rebound, and it calls this after a reset that\n+\t * failed as well, which cannot be told apart here. Like the rebind\n+\t * below, this assumes that the reset ran.\n+\t */\n+\tidxd_cmd_reset_state(idxd);\n+\n \tif (!idxd-\u003eidxd_saved)\n \t\treturn;\n \n@@ -1202,6 +1212,14 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,\n \t}\n \n \tif (!alloc_idxd) {\n+\t\tbool held;\n+\t\tu32 seq;\n+\n+\t\t/*\n+\t\t * Commands complete through the misc interrupt, which is\n+\t\t * gone until it is requested again.\n+\t\t */\n+\t\theld = idxd_cmd_hold(idxd, \u0026seq);\n \t\t/* Release interrupts in the IDXD device. */\n \t\tidxd_cleanup_interrupts(idxd);\n \n@@ -1209,6 +1227,8 @@ int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,\n \t\trc = idxd_setup_interrupts(idxd);\n \t\tif (rc)\n \t\t\tdev_warn(dev, \"IDXD interrupts failed to setup\\n\");\n+\t\tif (held)\n+\t\t\tidxd_cmd_unhold(idxd, seq);\n \t}\n \n \tdev_info(\u0026pdev-\u003edev, \"Intel(R) Accelerator Device (v%x)\\n\",\n@@ -1267,25 +1287,55 @@ static void idxd_remove(struct pci_dev *pdev)\n {\n \tstruct idxd_device *idxd = pci_get_drvdata(pdev);\n \n+\t/*\n+\t * The devices on the dsa bus stay registered, and so open to a\n+\t * sysfs bind, until the unregisters below. A bind during the\n+\t * removal would re-probe the device or enable one of its queues\n+\t * while they are torn down, and the PCI device lock held here does\n+\t * not exclude it, so the probes test this first. The command path\n+\t * changes IDXD_FLAG_CMD_RUNNING in the same word with non-atomic\n+\t * bit operations under cmd_lock, which would lose a bit set\n+\t * concurrently, so the flag is set under that lock too.\n+\t */\n+\tspin_lock_irq(\u0026idxd-\u003ecmd_lock);\n+\tset_bit(IDXD_FLAG_REMOVING, \u0026idxd-\u003eflags);\n+\tspin_unlock_irq(\u0026idxd-\u003ecmd_lock);\n+\t/*\n+\t * The idxd sub-driver's remove walks idxd-\u003ewqs to disable the\n+\t * active queues, and each wq is freed with its conf_dev. Unbind\n+\t * that driver while the queues still exist.\n+\t */\n+\tdevice_release_driver(idxd_confdev(idxd));\n+\t/*\n+\t * Disable the device while the queues still exist too. The\n+\t * sub-driver's remove leaves the device enabled when a command has\n+\t * timed out, a late completion can clear that state at any time,\n+\t * and the disable below then clears the queues' software state.\n+\t */\n+\tidxd_shutdown(pdev);\n \tidxd_unregister_devices(idxd);\n \t/*\n-\t * When -\u003erelease() is called for the idxd-\u003econf_dev, it frees all the memory related\n-\t * to the idxd context. The driver still needs those bits in order to do the rest of\n-\t * the cleanup. However, we do need to unbound the idxd sub-driver. So take a ref\n-\t * on the device here to hold off the freeing while allowing the idxd sub-driver\n-\t * to unbind.\n+\t * When -\u003erelease() is called for the idxd-\u003econf_dev, it frees all\n+\t * the memory related to the idxd context. The driver still needs\n+\t * those bits in order to do the rest of the cleanup, so take a ref\n+\t * on the device here to hold off the freeing until that is done.\n \t */\n \tget_device(idxd_confdev(idxd));\n \tdevice_unregister(idxd_confdev(idxd));\n-\tidxd_shutdown(pdev);\n \tidxd_device_remove_debugfs(idxd);\n \tperfmon_pmu_remove(idxd);\n \tidxd_cleanup_interrupts(idxd);\n \tif (device_pasid_enabled(idxd))\n \t\tidxd_disable_system_pasid(idxd);\n \tpci_iounmap(pdev, idxd-\u003ereg_base);\n-\tput_device(idxd_confdev(idxd));\n \tpci_disable_device(pdev);\n+\t/*\n+\t * Bus mastering is off, so nothing the device holds can complete.\n+\t * The store comes before the reference taken above is dropped:\n+\t * that reference is the last one, and its release frees the device.\n+\t */\n+\tidxd-\u003estate = IDXD_DEV_DISABLED;\n+\tput_device(idxd_confdev(idxd));\n }\n \n static struct pci_driver idxd_pci_driver = {\ndiff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c\nindex 6a25e1fd0e62c..8217698056bb4 100644\n--- a/drivers/dma/idxd/irq.c\n+++ b/drivers/dma/idxd/irq.c\n@@ -35,7 +35,14 @@ static void idxd_device_reinit(struct work_struct *work)\n \tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n \tint rc, i;\n \n-\tidxd_device_reset(idxd);\n+\t/*\n+\t * The halt ended whatever command was running, and a command that\n+\t * timed out before the halt would otherwise refuse the reset.\n+\t */\n+\tidxd_cmd_reset_state(idxd);\n+\trc = idxd_device_reset(idxd);\n+\tif (rc \u003c 0)\n+\t\tgoto out;\n \trc = idxd_device_config(idxd);\n \tif (rc \u003c 0)\n \t\tgoto out;\n@@ -108,6 +115,11 @@ static void idxd_abort_invalid_int_handle_descs(struct idxd_irq_entry *ie)\n \tstruct idxd_desc *d, *t;\n \tstruct llist_node *head;\n \n+\t/*\n+\t * An unbind frees the descriptors and the allocator under\n+\t * wq_lock, so they are completed under it as well.\n+\t */\n+\tlockdep_assert_held(\u0026ie_to_wq(ie)-\u003ewq_lock);\n \tspin_lock(\u0026ie-\u003elist_lock);\n \thead = llist_del_all(\u0026ie-\u003epending_llist);\n \tif (head) {\n@@ -135,6 +147,7 @@ static void idxd_int_handle_revoke(struct work_struct *work)\n \tstruct pci_dev *pdev = idxd-\u003epdev;\n \tstruct device *dev = \u0026pdev-\u003edev;\n \tint i, new_handle, rc;\n+\tbool killed;\n \n \tif (!idxd-\u003erequest_int_handles) {\n \t\tkfree(revoke);\n@@ -159,15 +172,31 @@ static void idxd_int_handle_revoke(struct work_struct *work)\n \t\t\tcontinue;\n \n \t\trc = idxd_device_request_int_handle(idxd, i, \u0026new_handle, IDXD_IRQ_MSIX);\n-\t\tif (rc \u003c 0) {\n+\t\tif (rc \u003c 0)\n \t\t\tdev_warn(dev, \"get int handle %d failed: %d\\n\", i, rc);\n+\n+\t\t/*\n+\t\t * The request runs without wq_lock, so that a reset can end\n+\t\t * it, and the queue may have been unbound meanwhile. An\n+\t\t * unbind invalidates the handle in the same wq_lock hold\n+\t\t * that unmaps the portal and frees the descriptors, so a\n+\t\t * handle still valid under the lock means that the queue\n+\t\t * still has its portal, its descriptors and its completion\n+\t\t * handler. Everything below, the drain included, stays in\n+\t\t * this hold.\n+\t\t */\n+\t\tguard(mutex)(\u0026wq-\u003ewq_lock);\n+\t\tif (ie-\u003eint_handle == INVALID_INT_HANDLE)\n+\t\t\tcontinue;\n+\n+\t\tif (rc \u003c 0) {\n \t\t\t/*\n \t\t\t * Failed to acquire new interrupt handle. Kill the WQ\n \t\t\t * and release all the pending submitters. The submitters will\n \t\t\t * get error return code and handle appropriately.\n \t\t\t */\n \t\t\tie-\u003eint_handle = INVALID_INT_HANDLE;\n-\t\t\tidxd_wq_quiesce(wq);\n+\t\t\t__idxd_wq_quiesce(wq);\n \t\t\tidxd_abort_invalid_int_handle_descs(ie);\n \t\t\tcontinue;\n \t\t}\n@@ -186,21 +215,20 @@ static void idxd_int_handle_revoke(struct work_struct *work)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tmutex_lock(\u0026wq-\u003ewq_lock);\n-\t\treinit_completion(\u0026wq-\u003ewq_resurrect);\n-\n-\t\t/* Kill percpu_ref to pause additional descriptor submissions */\n-\t\tpercpu_ref_kill(\u0026wq-\u003ewq_active);\n-\n-\t\t/* Wait for all submitters quiesce before we change interrupt handle */\n-\t\twait_for_completion(\u0026wq-\u003ewq_dead);\n+\t\t/*\n+\t\t * Kill percpu_ref to pause additional descriptor submissions\n+\t\t * and wait for all submitters to quiesce before we change\n+\t\t * the interrupt handle. A queue a halt already killed and did\n+\t\t * not revive is left dead.\n+\t\t */\n+\t\tkilled = idxd_wq_kill(wq);\n \n \t\tie-\u003eint_handle = new_handle;\n \n \t\t/* Revive percpu ref and wake up all the waiting submitters */\n-\t\tpercpu_ref_reinit(\u0026wq-\u003ewq_active);\n+\t\tif (killed)\n+\t\t\tpercpu_ref_reinit(\u0026wq-\u003ewq_active);\n \t\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n-\t\tmutex_unlock(\u0026wq-\u003ewq_lock);\n \n \t\t/*\n \t\t * The delay here is to wait for all possible MOVDIR64B that\n@@ -331,10 +359,28 @@ static void process_evl_entry(struct idxd_device *idxd,\n \t\t\tif (!entry_head-\u003ercr \u0026\u0026 status == DSA_COMP_DRAIN_EVL)\n \t\t\t\treturn;\n \n+\t\t\tstruct idxd_wq *wq = idxd-\u003ewqs[entry_head-\u003ewq_idx];\n+\n+\t\t\t/*\n+\t\t\t * The fault worker only does user-context work,\n+\t\t\t * copying the completion record through the wq's\n+\t\t\t * PASID xarray, which is populated by cdev opens\n+\t\t\t * alone. A kernel WQ has no cdev workqueue and no\n+\t\t\t * user contexts, so queueing could only warn and\n+\t\t\t * drop the record. Note it and move on. The user\n+\t\t\t * driver detaches the workqueue under evl-\u003elock,\n+\t\t\t * which this walk holds, so the one tested here is\n+\t\t\t * the one queued on.\n+\t\t\t */\n+\t\t\tif (!is_idxd_wq_user(wq) || !wq-\u003ewq) {\n+\t\t\t\tdev_warn_ratelimited(dev,\n+\t\t\t\t\t\"EVL fault on kernel wq %d, status %#x\\n\",\n+\t\t\t\t\twq-\u003eid, status);\n+\t\t\t\treturn;\n+\t\t\t}\n+\n \t\t\tfault = kmem_cache_alloc(idxd-\u003eevl_cache, GFP_ATOMIC);\n \t\t\tif (fault) {\n-\t\t\t\tstruct idxd_wq *wq = idxd-\u003ewqs[entry_head-\u003ewq_idx];\n-\n \t\t\t\tfault-\u003ewq = wq;\n \t\t\t\tfault-\u003estatus = status;\n \t\t\t\tmemcpy(\u0026fault-\u003eentry, entry_head, ent_size);\n@@ -397,14 +443,61 @@ static void idxd_device_flr(struct work_struct *work)\n \t\tdev_err(\u0026idxd-\u003epdev-\u003edev, \"FLR failed\\n\");\n }\n \n-static void idxd_wqs_flush_descs(struct idxd_device *idxd)\n+/*\n+ * Complete what the halted engines will never finish, or a client waiting\n+ * on one of those descriptors waits forever. The flush hands descriptors\n+ * back, so no submitter may still own one: a submitter that passed the\n+ * state check before the halt can hold a descriptor on the pending list\n+ * while its ENQCMDS retries, and it aborts and frees that descriptor\n+ * itself when the submit fails. Killing wq_active and waiting for the\n+ * last submitter to drop its reference orders the flush after that.\n+ * Each queue is handled in one hold of wq_lock, from the state check\n+ * through the revive. A driver remove that quiesces the queue in one\n+ * hold and disables it in another, as iaa_crypto's does, would otherwise\n+ * find the reference dying between the kill and the revive, skip its\n+ * own kill, and have the revive undo its quiesce before its disable\n+ * frees the queue.\n+ * @resurrect: revive the queues afterwards for a reset that keeps them.\n+ */\n+static void idxd_wqs_halt_flush(struct idxd_device *idxd, bool resurrect)\n {\n+\tbool killed;\n \tint i;\n \n \tfor (i = 0; i \u003c idxd-\u003emax_wqs; i++) {\n \t\tstruct idxd_wq *wq = idxd-\u003ewqs[i];\n \n-\t\tidxd_wq_flush_descs(wq);\n+\t\tmutex_lock(\u0026wq-\u003ewq_lock);\n+\t\tif (wq-\u003estate != IDXD_WQ_ENABLED || wq-\u003etype != IDXD_WQT_KERNEL) {\n+\t\t\tmutex_unlock(\u0026wq-\u003ewq_lock);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tkilled = idxd_wq_kill(wq);\n+\t\t__idxd_wq_flush_descs(wq, idxd_wq_refcount(wq) \u003e 0, false);\n+\t\tidxd_wq_halt_release(wq);\n+\n+\t\tif (resurrect) {\n+\t\t\t/*\n+\t\t\t * Revive only what this flush killed, and only if no\n+\t\t\t * failed interrupt handle revoke killed it for good,\n+\t\t\t * which leaves the handle invalid. The state changes\n+\t\t\t * without the lock only to enabled, in the reinit of\n+\t\t\t * an earlier halt, or on a queue that an FLR recovery\n+\t\t\t * has unbound, whose reference reads as dying, so this\n+\t\t\t * flush did not kill it. A reference an earlier halt\n+\t\t\t * left dead stays dead, since that halt's recovery\n+\t\t\t * unbinds the queue. The revive has to stay in this\n+\t\t\t * hold: moved to the reinit, it would reopen the\n+\t\t\t * window described above.\n+\t\t\t */\n+\t\t\tif (killed \u0026\u0026 wq-\u003eie.int_handle != INVALID_INT_HANDLE)\n+\t\t\t\tpercpu_ref_reinit(\u0026wq-\u003ewq_active);\n+\t\t\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n+\t\t} else {\n+\t\t\t/* Let blocked submitters retry and fail on the state. */\n+\t\t\tcomplete_all(\u0026wq-\u003ewq_resurrect);\n+\t\t}\n+\t\tmutex_unlock(\u0026wq-\u003ewq_lock);\n \t}\n }\n \n@@ -416,6 +509,8 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)\n \tif (gensts.state == IDXD_DEVICE_STATE_HALT) {\n \t\tidxd-\u003estate = IDXD_DEV_HALTED;\n \t\tif (gensts.reset_type == IDXD_DEVICE_RESET_SOFTWARE) {\n+\t\t\t/* The reinit below re-enables the queues, so revive them. */\n+\t\t\tidxd_wqs_halt_flush(idxd, true);\n \t\t\t/*\n \t\t\t * If we need a software reset, we will throw the work\n \t\t\t * on a system workqueue in order to allow interrupts\n@@ -424,13 +519,23 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)\n \t\t\tINIT_WORK(\u0026idxd-\u003ework, idxd_device_reinit);\n \t\t\tqueue_work(idxd-\u003ewq, \u0026idxd-\u003ework);\n \t\t} else if (gensts.reset_type == IDXD_DEVICE_RESET_FLR) {\n+\t\t\tint i;\n+\n \t\t\tidxd-\u003estate = IDXD_DEV_HALTED;\n \t\t\tidxd_mask_error_interrupts(idxd);\n-\t\t\t/* Flush all pending descriptors, and disable\n-\t\t\t * interrupts, they will be re-enabled when FLR\n-\t\t\t * concludes.\n+\t\t\t/*\n+\t\t\t * Flush all pending descriptors. The FLR revokes every\n+\t\t\t * interrupt handle, so mark them invalid here without a\n+\t\t\t * device command; they are requested again when a work\n+\t\t\t * queue is re-enabled after the reset.\n \t\t\t */\n-\t\t\tidxd_wqs_flush_descs(idxd);\n+\t\t\tidxd_wqs_halt_flush(idxd, false);\n+\t\t\tfor (i = 0; i \u003c idxd-\u003emax_wqs; i++) {\n+\t\t\t\tstruct idxd_wq *wq = idxd-\u003ewqs[i];\n+\n+\t\t\t\tif (wq-\u003etype == IDXD_WQT_KERNEL)\n+\t\t\t\t\tWRITE_ONCE(wq-\u003eie.int_handle, INVALID_INT_HANDLE);\n+\t\t\t}\n \t\t\tdev_dbg(\u0026idxd-\u003epdev-\u003edev,\n \t\t\t\t\"idxd halted, doing FLR. After FLR, configs are restored\\n\");\n \t\t\tINIT_WORK(\u0026idxd-\u003ework, idxd_device_flr);\n@@ -438,7 +543,8 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)\n \n \t\t} else {\n \t\t\tidxd-\u003estate = IDXD_DEV_HALTED;\n-\t\t\tidxd_wqs_quiesce(idxd);\n+\t\t\t/* Same as above: nothing in flight will ever complete. */\n+\t\t\tidxd_wqs_halt_flush(idxd, false);\n \t\t\tidxd_wqs_unmap_portal(idxd);\n \t\t\tidxd_device_clear_state(idxd);\n \t\t\tdev_err(\u0026idxd-\u003epdev-\u003edev,\n@@ -522,7 +628,25 @@ irqreturn_t idxd_misc_thread(int vec, void *data)\n \n \tif (cause \u0026 IDXD_INTC_CMD) {\n \t\tval |= IDXD_INTC_CMD;\n-\t\tcomplete(idxd-\u003ecmd_done);\n+\t\t/*\n+\t\t * cmd_done is cleared under cmd_lock when idxd_cmd_exec()\n+\t\t * gives up on a command: the completion lives on its stack,\n+\t\t * so a late interrupt must not touch it.\n+\t\t */\n+\t\tspin_lock(\u0026idxd-\u003ecmd_lock);\n+\t\tif (idxd-\u003ecmd_done) {\n+\t\t\tcomplete(idxd-\u003ecmd_done);\n+\t\t} else if (test_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags)) {\n+\t\t\t/*\n+\t\t\t * The command its owner gave up on has finished after\n+\t\t\t * all. The device is usable again, so let the queue go.\n+\t\t\t */\n+\t\t\t__clear_bit(IDXD_FLAG_CMD_RUNNING, \u0026idxd-\u003eflags);\n+\t\t\tclear_bit(IDXD_FLAG_CMD_TIMEDOUT, \u0026idxd-\u003eflags);\n+\t\t\twake_up(\u0026idxd-\u003ecmd_waitq);\n+\t\t\tdev_warn(dev, \"a timed-out device command completed late\\n\");\n+\t\t}\n+\t\tspin_unlock(\u0026idxd-\u003ecmd_lock);\n \t}\n \n \tif (cause \u0026 IDXD_INTC_OCCUPY) {\n@@ -556,22 +680,27 @@ static void idxd_int_handle_resubmit_work(struct work_struct *work)\n \tint rc;\n \n \tdesc-\u003ecompletion-\u003estatus = 0;\n-\trc = idxd_submit_desc(wq, desc);\n+\trc = idxd_resubmit_desc(wq, desc);\n \tif (rc \u003c 0) {\n \t\tdev_dbg(\u0026wq-\u003eidxd-\u003epdev-\u003edev, \"Failed to resubmit desc %d to wq %d.\\n\",\n \t\t\tdesc-\u003eid, wq-\u003eid);\n \t\t/*\n-\t\t * If the error is not -EAGAIN, it means the submission failed due to wq\n-\t\t * has been killed instead of ENQCMDS failure. Here the driver needs to\n-\t\t * notify the submitter of the failure by reporting abort status.\n-\t\t *\n-\t\t * -EAGAIN comes from ENQCMDS failure. idxd_submit_desc() will handle the\n-\t\t * abort.\n+\t\t * The submission failed because the device is not enabled,\n+\t\t * because the wq has been killed or because ENQCMDS failed,\n+\t\t * and in each case the descriptor is on no list. Here the\n+\t\t * driver needs to notify the submitter of the failure by\n+\t\t * reporting abort status. The submit has dropped its\n+\t\t * wq_active reference by now, so a callback that submits or\n+\t\t * terminates does not wait for it. A descriptor submitted\n+\t\t * before a terminate_all, which cancels its resubmission,\n+\t\t * gets no callback, since its client terminated it.\n \t\t */\n-\t\tif (rc != -EAGAIN) {\n-\t\t\tdesc-\u003ecompletion-\u003estatus = IDXD_COMP_DESC_ABORT;\n-\t\t\tidxd_desc_complete(desc, IDXD_COMPLETE_ABORT, false);\n+\t\tif (desc-\u003eterminate_gen != READ_ONCE(wq-\u003eterminate_gen)) {\n+\t\t\tdesc-\u003etxd.callback = NULL;\n+\t\t\tdesc-\u003etxd.callback_result = NULL;\n \t\t}\n+\t\tdesc-\u003ecompletion-\u003estatus = IDXD_COMP_DESC_ABORT;\n+\t\tidxd_desc_complete(desc, IDXD_COMPLETE_ABORT, false);\n \t\tidxd_free_desc(wq, desc);\n \t}\n \tkfree(irw);\n@@ -597,31 +726,39 @@ static void irq_process_pending_llist(struct idxd_irq_entry *irq_entry)\n {\n \tstruct idxd_desc *desc, *t;\n \tstruct llist_node *head;\n+\tLIST_HEAD(flist);\n \n-\thead = llist_del_all(\u0026irq_entry-\u003epending_llist);\n-\tif (!head)\n+\tif (llist_empty(\u0026irq_entry-\u003epending_llist))\n \t\treturn;\n \n+\t/*\n+\t * Sort under the list lock, as the submit abort does. A descriptor\n+\t * still waiting on the hardware reaches the work list within the\n+\t * same hold, so the abort of a failed submission, which searches\n+\t * both lists under the lock, always finds its own descriptor.\n+\t */\n+\tspin_lock(\u0026irq_entry-\u003elist_lock);\n+\thead = llist_del_all(\u0026irq_entry-\u003epending_llist);\n \tllist_for_each_entry_safe(desc, t, head, llnode) {\n \t\tu8 status = desc-\u003ecompletion-\u003estatus \u0026 DSA_COMP_STATUS_MASK;\n \n-\t\tif (status) {\n-\t\t\t/*\n-\t\t\t * Check against the original status as ABORT is software defined\n-\t\t\t * and 0xff, which DSA_COMP_STATUS_MASK can mask out.\n-\t\t\t */\n-\t\t\tif (unlikely(desc-\u003ecompletion-\u003estatus == IDXD_COMP_DESC_ABORT)) {\n-\t\t\t\tidxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true);\n-\t\t\t\tcontinue;\n-\t\t\t}\n+\t\tif (status)\n+\t\t\tlist_add_tail(\u0026desc-\u003elist, \u0026flist);\n+\t\telse\n+\t\t\tlist_add_tail(\u0026desc-\u003elist, \u0026irq_entry-\u003ework_list);\n+\t}\n+\tspin_unlock(\u0026irq_entry-\u003elist_lock);\n \n+\tlist_for_each_entry_safe(desc, t, \u0026flist, list) {\n+\t\tlist_del(\u0026desc-\u003elist);\n+\t\t/*\n+\t\t * Check against the original status as ABORT is software\n+\t\t * defined and 0xff, which DSA_COMP_STATUS_MASK can mask out.\n+\t\t */\n+\t\tif (unlikely(desc-\u003ecompletion-\u003estatus == IDXD_COMP_DESC_ABORT))\n+\t\t\tidxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true);\n+\t\telse\n \t\t\tidxd_desc_complete(desc, IDXD_COMPLETE_NORMAL, true);\n-\t\t} else {\n-\t\t\tspin_lock(\u0026irq_entry-\u003elist_lock);\n-\t\t\tlist_add_tail(\u0026desc-\u003elist,\n-\t\t\t\t      \u0026irq_entry-\u003ework_list);\n-\t\t\tspin_unlock(\u0026irq_entry-\u003elist_lock);\n-\t\t}\n \t}\n }\n \n@@ -673,18 +810,19 @@ irqreturn_t idxd_wq_thread(int irq, void *data)\n \t * submmiter adds all the submitted descriptor after sending it to\n \t * the workqueue. It's a lockless singly linked list. The work_list\n \t * is the common linux double linked list. We are in a scenario of\n-\t * multiple producers and a single consumer. The producers are all\n-\t * the kernel submitters of descriptors, and the consumer is the\n-\t * kernel irq handler thread for the msix vector when using threaded\n-\t * irq. To work with the restrictions of llist to remain lockless,\n-\t * we are doing the following steps:\n+\t * multiple producers and several consumers. The producers are all\n+\t * the kernel submitters of descriptors, and they add to the llist\n+\t * without a lock. The consumers are the kernel irq handler thread\n+\t * for the msix vector when using threaded irq, the abort of a\n+\t * failed submission, the interrupt handle abort and the flushes,\n+\t * and each empties the llist under the list lock. The thread does\n+\t * so in these steps:\n \t * 1. Iterate through the work_list and process any completed\n \t *    descriptor. Delete the completed entries during iteration.\n-\t * 2. llist_del_all() from the pending list.\n-\t * 3. Iterate through the llist that was deleted from the pending list\n-\t *    and process the completed entries.\n-\t * 4. If the entry is still waiting on hardware, list_add_tail() to\n-\t *    the work_list.\n+\t * 2. Under the list lock, llist_del_all() from the pending list and\n+\t *    move each entry still waiting on hardware to the work_list and\n+\t *    each completed one to a private list.\n+\t * 3. Process the entries of the private list outside the lock.\n \t */\n \tirq_process_work_list(irq_entry);\n \tirq_process_pending_llist(irq_entry);\ndiff --git a/drivers/dma/idxd/submit.c b/drivers/dma/idxd/submit.c\nindex 03217041b8b3e..469a0cadb984d 100644\n--- a/drivers/dma/idxd/submit.c\n+++ b/drivers/dma/idxd/submit.c\n@@ -1,6 +1,7 @@\n // SPDX-License-Identifier: GPL-2.0\n /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */\n #include \u003clinux/init.h\u003e\n+#include \u003clinux/interrupt.h\u003e\n #include \u003clinux/kernel.h\u003e\n #include \u003clinux/module.h\u003e\n #include \u003clinux/pci.h\u003e\n@@ -34,6 +35,13 @@ struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)\n \n \tif (idxd-\u003estate != IDXD_DEV_ENABLED)\n \t\treturn ERR_PTR(-EIO);\n+\t/*\n+\t * A failed drain left descriptors the device may still complete.\n+\t * No slot is reused until a later drain completes or a halt kills\n+\t * them.\n+\t */\n+\tif (READ_ONCE(wq-\u003estuck))\n+\t\treturn ERR_PTR(-ENXIO);\n \n \tsbq = \u0026wq-\u003esbq;\n \tidx = sbitmap_queue_get(sbq, \u0026cpu);\n@@ -44,6 +52,21 @@ struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)\n \t\treturn __get_desc(wq, idx, cpu);\n \t}\n \n+\t/*\n+\t * A dying reference whose resurrect has completed belongs to a\n+\t * queue quiesced for good: no kill in progress will revive it, and\n+\t * every submission fails. Waiting for a slot there gains nothing\n+\t * and may never end. The teardown flush and the interrupt thread\n+\t * free the slot of each descriptor they complete only when its\n+\t * completion returns, and iaa_crypto's verify of a compression\n+\t * allocates from inside one. The two reads are not atomic, so an\n+\t * allocation that races a revive can fail like a request the kill\n+\t * caught.\n+\t */\n+\tif (data_race(percpu_ref_is_dying(\u0026wq-\u003ewq_active)) \u0026\u0026\n+\t    completion_done(\u0026wq-\u003ewq_resurrect))\n+\t\treturn ERR_PTR(-ENXIO);\n+\n \tws = \u0026sbq-\u003ews[0];\n \tfor (;;) {\n \t\tsbitmap_prepare_to_wait(sbq, ws, \u0026wait, TASK_INTERRUPTIBLE);\n@@ -85,23 +108,16 @@ static struct idxd_desc *list_abort_desc(struct idxd_wq *wq, struct idxd_irq_ent\n \t\t}\n \t}\n \n-\t/*\n-\t * At this point, the desc needs to be aborted is held by the completion\n-\t * handler where it has taken it off the pending list but has not added to the\n-\t * work list. It will be cleaned up by the interrupt handler when it sees the\n-\t * IDXD_COMP_DESC_ABORT for completion status.\n-\t */\n \treturn NULL;\n }\n \n static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,\n-\t\t\t     struct idxd_desc *desc)\n+\t\t\t     struct idxd_desc *desc, bool submitter_cleans)\n {\n \tstruct idxd_desc *d, *t, *found = NULL;\n \tstruct llist_node *head;\n-\tLIST_HEAD(flist);\n+\tbool wake = false;\n \n-\tdesc-\u003ecompletion-\u003estatus = IDXD_COMP_DESC_ABORT;\n \t/*\n \t * Grab the list lock so it will block the irq thread handler. This allows the\n \t * abort code to locate the descriptor need to be aborted.\n@@ -115,10 +131,19 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,\n \t\t\t\tcontinue;\n \t\t\t}\n \n+\t\t\t/*\n+\t\t\t * A completion runs a client's callback or another\n+\t\t\t * driver's handler, and either may submit or terminate\n+\t\t\t * and so wait for a killer, which waits for this\n+\t\t\t * submitter's wq_active reference. iaa_crypto's verify\n+\t\t\t * of a compression may also wait for a free descriptor\n+\t\t\t * while this submitter holds one. A finished\n+\t\t\t * descriptor therefore goes on the work list for the\n+\t\t\t * interrupt thread, as one still in flight does.\n+\t\t\t */\n \t\t\tif (d-\u003ecompletion-\u003estatus)\n-\t\t\t\tlist_add_tail(\u0026d-\u003elist, \u0026flist);\n-\t\t\telse\n-\t\t\t\tlist_add_tail(\u0026d-\u003elist, \u0026ie-\u003ework_list);\n+\t\t\t\twake = true;\n+\t\t\tlist_add_tail(\u0026d-\u003elist, \u0026ie-\u003ework_list);\n \t\t}\n \t}\n \n@@ -126,19 +151,45 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,\n \t\tfound = list_abort_desc(wq, ie, desc);\n \tspin_unlock(\u0026ie-\u003elist_lock);\n \n-\tif (found)\n-\t\tidxd_dma_complete_txd(found, IDXD_COMPLETE_ABORT, false,\n-\t\t\t\t      NULL, NULL);\n+\t/*\n+\t * Their interrupts may have run the thread before they reached the\n+\t * work list, so it is woken again.\n+\t */\n+\tif (wake)\n+\t\tirq_wake_thread(ie-\u003evector, ie);\n \n \t/*\n-\t * completing the descriptor will return desc to allocator and\n-\t * the desc can be acquired by a different process and the\n-\t * desc-\u003elist can be modified.  Delete desc from list so the\n-\t * list traversing does not get corrupted by the other process.\n+\t * The device never took the descriptor, so its record is still\n+\t * clear. While this submitter holds wq_active, only the interrupt\n+\t * thread and another submitter's abort may take descriptors off\n+\t * the lists, and both sort them under the list lock and leave one\n+\t * with a clear record on a list. A flush takes them all, so every\n+\t * flusher must kill wq_active and wait for this reference before\n+\t * it takes the lists, and nothing may revive the reference before\n+\t * the flush runs. The error path of iaa_crypto_probe() breaks the\n+\t * rule: it disables a queue it has already published without a\n+\t * quiesce. Otherwise the search finds the descriptor, and once off\n+\t * the lists it is the submitter's alone. Marking it aborted before\n+\t * that would let another context that saw the mark on a list\n+\t * complete and free it, and the caller frees it as well.\n+\t */\n+\tWARN_ON_ONCE(!found);\n+\t/*\n+\t * When the failing submission is a client's tx_submit(), the\n+\t * client learns of it from the return value and owns the cleanup,\n+\t * and a callback on top of that would complete the descriptor\n+\t * twice. A dmaengine descriptor then only has its cookie completed\n+\t * and its unmap data released here, with the callbacks stripped.\n+\t * Nothing reads its record before the caller frees it, so it is\n+\t * not marked. An internal resubmission reports the abort through\n+\t * the callback, which its worker runs once the submit has dropped\n+\t * its reference. Another driver's submitter cleans up all of its\n+\t * own, and only dmaengine descriptors are resubmitted.\n \t */\n-\tlist_for_each_entry_safe(d, t, \u0026flist, list) {\n-\t\tlist_del_init(\u0026d-\u003elist);\n-\t\tidxd_dma_complete_txd(d, IDXD_COMPLETE_ABORT, true,\n+\tif (found \u0026\u0026 submitter_cleans \u0026\u0026 idxd_wq_has_txd(wq)) {\n+\t\tdesc-\u003etxd.callback = NULL;\n+\t\tdesc-\u003etxd.callback_result = NULL;\n+\t\tidxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT, false,\n \t\t\t\t      NULL, NULL);\n \t}\n }\n@@ -167,7 +218,8 @@ int idxd_enqcmds(struct idxd_wq *wq, void __iomem *portal, const void *desc)\n \treturn rc;\n }\n \n-int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n+static int __idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc,\n+\t\t\t      bool submitter_cleans)\n {\n \tstruct idxd_device *idxd = wq-\u003eidxd;\n \tstruct idxd_irq_entry *ie = NULL;\n@@ -184,6 +236,35 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n \t\t\treturn -ENXIO;\n \t}\n \n+\t/*\n+\t * A software-reset halt revives wq_active before its reinit enables\n+\t * the device again. A submitter that passed the check above before\n+\t * the halt and got its reference after the revive would post to the\n+\t * halted device, which drops the descriptor, and nothing would\n+\t * complete an interrupt-armed one. The halt stores the state before\n+\t * its kill and revives the reference after the wait. The barrier\n+\t * pairs with the release in percpu_ref_reinit() and orders this\n+\t * read after the tryget that saw the revive.\n+\t */\n+\tsmp_rmb();\n+\tif (idxd-\u003estate != IDXD_DEV_ENABLED) {\n+\t\tpercpu_ref_put(\u0026wq-\u003ewq_active);\n+\t\treturn -EIO;\n+\t}\n+\t/*\n+\t * A resubmission of a descriptor first submitted before a\n+\t * terminate_all is cancelled. The terminate bumps the generation\n+\t * before its kill, so the barrier above orders this read too. A\n+\t * resubmission that read the old one is on the pending list when\n+\t * the terminate's flush runs, since the kill waits for it, or has\n+\t * failed with its stamp unchanged.\n+\t */\n+\tif (!submitter_cleans \u0026\u0026\n+\t    desc-\u003eterminate_gen != READ_ONCE(wq-\u003eterminate_gen)) {\n+\t\tpercpu_ref_put(\u0026wq-\u003ewq_active);\n+\t\treturn -ECANCELED;\n+\t}\n+\n \tportal = idxd_wq_portal_addr(wq);\n \n \t/*\n@@ -193,6 +274,12 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n \tif (desc_flags \u0026 IDXD_OP_FLAG_RCI) {\n \t\tie = \u0026wq-\u003eie;\n \t\tdesc-\u003ehw-\u003eint_handle = ie-\u003eint_handle;\n+\t\t/*\n+\t\t * A resubmission keeps the stamp of the client's submit, so\n+\t\t * the resubmit work sees every terminate since then.\n+\t\t */\n+\t\tif (submitter_cleans)\n+\t\t\tdesc-\u003eterminate_gen = READ_ONCE(wq-\u003eterminate_gen);\n \t\tllist_add(\u0026desc-\u003ellnode, \u0026ie-\u003epending_llist);\n \t}\n \n@@ -208,10 +295,18 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n \t} else {\n \t\trc = idxd_enqcmds(wq, portal, desc-\u003ehw);\n \t\tif (rc \u003c 0) {\n-\t\t\tpercpu_ref_put(\u0026wq-\u003ewq_active);\n-\t\t\t/* abort operation frees the descriptor */\n+\t\t\t/*\n+\t\t\t * Abort before dropping the reference: a halt flush\n+\t\t\t * waits for wq_active to die before it takes the\n+\t\t\t * pending descriptors, and this one must not still be\n+\t\t\t * listed when it does. The abort takes the descriptor\n+\t\t\t * off the lists and runs no callback, which could wait\n+\t\t\t * for this reference to die. The caller completes or\n+\t\t\t * frees the descriptor.\n+\t\t\t */\n \t\t\tif (ie)\n-\t\t\t\tllist_abort_desc(wq, ie, desc);\n+\t\t\t\tllist_abort_desc(wq, ie, desc, submitter_cleans);\n+\t\t\tpercpu_ref_put(\u0026wq-\u003ewq_active);\n \t\t\treturn rc;\n \t\t}\n \t}\n@@ -219,4 +314,15 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n \tpercpu_ref_put(\u0026wq-\u003ewq_active);\n \treturn 0;\n }\n+/* A client submission: on failure the return value is the notification. */\n+int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n+{\n+\treturn __idxd_submit_desc(wq, desc, true);\n+}\n EXPORT_SYMBOL_NS_GPL(idxd_submit_desc, \"IDXD\");\n+\n+/* The driver's own resubmission: a failure must still call the client back. */\n+int idxd_resubmit_desc(struct idxd_wq *wq, struct idxd_desc *desc)\n+{\n+\treturn __idxd_submit_desc(wq, desc, false);\n+}\ndiff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h\nindex fe33a20abc614..4178248611d9d 100644\n--- a/include/linux/dmaengine.h\n+++ b/include/linux/dmaengine.h\n@@ -1751,6 +1751,8 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)\n int dma_async_device_register(struct dma_device *device);\n int dmaenginem_async_device_register(struct dma_device *device);\n void dma_async_device_unregister(struct dma_device *device);\n+int dma_async_device_channel_add(struct dma_device *device,\n+\t\t\t\t struct dma_chan *chan, const char *name);\n int dma_async_device_channel_register(struct dma_device *device,\n \t\t\t\t      struct dma_chan *chan,\n \t\t\t\t      const char *name);\n"
}

2/1 2026/10/20 19:04 agent patch-evaluator
4m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series modifies the Intel Data Accelerator (IDXD / DSA / IAA) driver along with adding a helper function, dma_async_device_channel_add(), in dmaengine.c whose sole caller is the IDXD driver. Intel DSA and IAA devices require physical Intel Xeon hardware (Sapphire Rapids and newer) and are not emulated in standard QEMU or GCE virtualized environments. Consequently, all modified and added code paths are structurally unreachable in standard fuzzing environments.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit bc21bcfdd383961d945cc5eff49e22a96bda3407
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Oct 20 19:04:01 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index c71763047126a..ced78c985d1c0 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1155,6 +1155,47 @@ int dma_async_device_channel_register(struct dma_device *device,
 }
 EXPORT_SYMBOL_GPL(dma_async_device_channel_register);
 
+/**
+ * dma_async_device_channel_add - register a channel and make it available
+ * @device: the dmaengine device, DMA_PRIVATE and registered already
+ * @chan: the channel, not on @device's channel list
+ * @name: the channel's name, or NULL for the default one
+ *
+ * Channel requests walk the channel list of every registered device under
+ * dma_list_mutex and may hand out any listed channel that has no client.
+ * A channel added to a registered device is therefore linked to the list
+ * only once it is registered, and under that mutex, so that a request
+ * never finds it half initialized. The driver's own state behind the
+ * channel must be complete before the call. A channel that fails to
+ * register is not linked.
+ *
+ * Only a DMA_PRIVATE device may add channels this way. The channel list
+ * of a public device is also walked under RCU alone, and its channels
+ * hold references for the dmaengine_get() users, which this function
+ * does not take.
+ *
+ * Return: 0 on success or a negative errno.
+ */
+int dma_async_device_channel_add(struct dma_device *device,
+				 struct dma_chan *chan, const char *name)
+{
+	int rc;
+
+	if (WARN_ON_ONCE(!dma_has_cap(DMA_PRIVATE, device->cap_mask)))
+		return -EINVAL;
+
+	rc = __dma_async_device_channel_register(device, chan, name);
+	if (rc < 0)
+		return rc;
+
+	mutex_lock(&dma_list_mutex);
+	list_add_tail(&chan->device_node, &device->channels);
+	dma_channel_rebalance();
+	mutex_unlock(&dma_list_mutex);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dma_async_device_channel_add);
+
 static void __dma_async_device_channel_unregister(struct dma_device *device,
 						  struct dma_chan *chan)
 {
diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index 82b07cf942ef8..4cfa77c727193 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -120,30 +120,53 @@ static void idxd_file_dev_release(struct device *dev)
 	struct idxd_user_context *ctx = dev_to_uctx(dev);
 	struct idxd_wq *wq = ctx->wq;
 	struct idxd_device *idxd = wq->idxd;
-	int rc;
+	int rc, drained = 0;
 
 	ida_free(&file_ida, ctx->id);
 
 	/* Wait for in-flight operations to complete. */
 	if (wq_shared(wq)) {
-		idxd_device_drain_pasid(idxd, ctx->pasid);
+		drained = idxd_device_drain_pasid(idxd, ctx->pasid);
 	} else {
 		if (device_user_pasid_enabled(idxd)) {
-			/* The wq disable in the disable pasid function will drain the wq */
+			/*
+			 * The wq disable in the disable pasid function drains
+			 * the wq. A drain that never completed leaves the
+			 * PASID in the queue's configuration with the
+			 * descriptors still in it. A failure after the drain,
+			 * re-enabling the queue for instance, does not.
+			 */
 			rc = idxd_wq_disable_pasid(wq);
-			if (rc < 0)
-				dev_err(dev, "wq disable pasid failed.\n");
+			if (rc < 0) {
+				dev_err(dev, "wq disable pasid failed: %d\n", rc);
+				if (rc == -ETIMEDOUT)
+					drained = rc;
+			}
 		} else {
-			idxd_wq_drain(wq);
+			drained = idxd_wq_drain(wq);
 		}
 	}
 
+	/*
+	 * A drain that never completed leaves this context's descriptors
+	 * in the device, tagged with its PASID. Unbinding the PASID would
+	 * let it be reused by another process while the device can still
+	 * issue DMA with it, so the binding, the PASID lookup entry and the
+	 * context are leaked instead.
+	 */
+	if (drained) {
+		dev_err(dev, "pasid %u: drain timed out, leaking the context and its PASID binding\n",
+			ctx->pasid);
+		goto put_wq;
+	}
+
 	if (ctx->sva) {
 		idxd_cdev_evl_drain_pasid(wq, ctx->pasid);
 		iommu_sva_unbind_device(ctx->sva);
 		idxd_xa_pasid_remove(ctx);
 	}
 	kfree(ctx);
+put_wq:
 	mutex_lock(&wq->wq_lock);
 	idxd_wq_put(wq);
 	mutex_unlock(&wq->wq_lock);
@@ -592,6 +615,26 @@ void idxd_wq_del_cdev(struct idxd_wq *wq)
 	put_device(cdev_dev(idxd_cdev));
 }
 
+/*
+ * The event log walk tests the fault workqueue and queues on it, and the
+ * drain of a closing context's PASID tests it and drains it, both under
+ * the log's lock, which neither the probe nor the remove otherwise takes.
+ * The workqueue is therefore detached and destroyed under that lock. A
+ * walk or a drain that finds it gone knows that its work has run.
+ */
+static void idxd_user_wq_destroy_fault_wq(struct idxd_wq *wq)
+{
+	struct idxd_evl *evl = wq->idxd->evl;
+
+	if (evl)
+		mutex_lock(&evl->lock);
+	wq->type = IDXD_WQT_NONE;
+	destroy_workqueue(wq->wq);
+	wq->wq = NULL;
+	if (evl)
+		mutex_unlock(&evl->lock);
+}
+
 static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
 {
 	struct device *dev = &idxd_dev->conf_dev;
@@ -653,8 +696,7 @@ static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)
 err_cdev:
 	idxd_drv_disable_wq(wq);
 err:
-	destroy_workqueue(wq->wq);
-	wq->type = IDXD_WQT_NONE;
+	idxd_user_wq_destroy_fault_wq(wq);
 wq_err:
 	mutex_unlock(&wq->wq_lock);
 	return rc;
@@ -667,9 +709,7 @@ static void idxd_user_drv_remove(struct idxd_dev *idxd_dev)
 	mutex_lock(&wq->wq_lock);
 	idxd_wq_del_cdev(wq);
 	idxd_drv_disable_wq(wq);
-	wq->type = IDXD_WQT_NONE;
-	destroy_workqueue(wq->wq);
-	wq->wq = NULL;
+	idxd_user_wq_destroy_fault_wq(wq);
 	mutex_unlock(&wq->wq_lock);
 }
 
diff --git a/drivers/dma/idxd/device.c b/drivers/dma/idxd/device.c
index 131138483b877..5ccdc5ff8d53d 100644
--- a/drivers/dma/idxd/device.c
+++ b/drivers/dma/idxd/device.c
@@ -12,10 +12,14 @@
 #include "idxd.h"
 #include "registers.h"
 
+/* generous bound: drain of a loaded WQ is the slowest legitimate command */
+#define IDXD_CMD_TIMEOUT_MS	30000
+
 static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,
 			  u32 *status);
 static void idxd_device_wqs_clear_state(struct idxd_device *idxd);
 static void idxd_wq_disable_cleanup(struct idxd_wq *wq);
+static inline bool idxd_device_is_halted(struct idxd_device *idxd);
 static int idxd_wq_config_write(struct idxd_wq *wq);
 
 /* Interrupt control bits */
@@ -115,6 +119,9 @@ int idxd_wq_alloc_resources(struct idxd_wq *wq)
 	if (wq->type != IDXD_WQT_KERNEL)
 		return 0;
 
+	/* A fresh pool: nothing outstanding can land in it. */
+	wq->stuck = false;
+	INIT_LIST_HEAD(&wq->quarantine);
 	num_descs = wq_dedicated(wq) ? wq->size : wq->threshold;
 	wq->num_descs = num_descs;
 
@@ -167,10 +174,18 @@ EXPORT_SYMBOL_NS_GPL(idxd_wq_alloc_resources, "IDXD");
 void idxd_wq_free_resources(struct idxd_wq *wq)
 {
 	struct device *dev = &wq->idxd->pdev->dev;
+	LIST_HEAD(dead_descs);
 
 	if (wq->type != IDXD_WQT_KERNEL)
 		return;
 
+	/*
+	 * The disable frees the pool only after its drain and its reset
+	 * completed, and a failed enable has run nothing, so the device no
+	 * longer reaches what a quarantined descriptor maps.
+	 */
+	idxd_wq_quarantine_take(wq, &dead_descs);
+	idxd_wq_quarantine_free(wq, &dead_descs);
 	free_hw_descs(wq);
 	free_descs(wq);
 	dma_free_coherent(dev, wq->compls_size, wq->compls, wq->compls_addr);
@@ -209,6 +224,7 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)
 	struct idxd_device *idxd = wq->idxd;
 	struct device *dev = &idxd->pdev->dev;
 	u32 status, operand;
+	int rc;
 
 	dev_dbg(dev, "Disabling WQ %d\n", wq->id);
 
@@ -226,8 +242,14 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)
 	 * To make sure pending translations are drained before WQ
 	 * attributes are changed, we use a WQ Drain followed by WQ Reset and
 	 * then restore the WQ configuration.
+	 *
+	 * A drain that timed out leaves descriptors in the queue. Report
+	 * it instead of resetting, so that the caller keeps whatever those
+	 * descriptors can still reach, a PASID for instance.
 	 */
-	idxd_wq_drain(wq);
+	rc = idxd_wq_drain(wq);
+	if (rc)
+		return rc;
 
 	operand = BIT(wq->id % 16) | ((wq->id / 16) << 16);
 	idxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, &status);
@@ -247,36 +269,72 @@ int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)
 	return 0;
 }
 
-void idxd_wq_drain(struct idxd_wq *wq)
+/*
+ * The result of a drain or a reset. IDXD_CMDSTS_HW_ERR stands for a
+ * command that timed out, or was refused after one did, and then the
+ * device may still run what it holds. It is also the device's own code
+ * for a hardware error, after which the specification has software read
+ * GENSTS. Both leave the device enabled unless it halted, and a halted
+ * device runs nothing until it is reset, so what it holds is then as
+ * gone as after a drain and that is not a timeout.
+ */
+static int idxd_cmd_drain_result(struct idxd_device *idxd, u32 status)
+{
+	if (status != IDXD_CMDSTS_HW_ERR || idxd_device_is_halted(idxd))
+		return 0;
+	return -ETIMEDOUT;
+}
+
+/*
+ * Returns -ETIMEDOUT when the command never completed, or was refused
+ * because an earlier one never did, in which case descriptors may still
+ * be in the device and the caller must not free anything it can write
+ * into.
+ */
+int idxd_wq_drain(struct idxd_wq *wq)
 {
 	struct idxd_device *idxd = wq->idxd;
 	struct device *dev = &idxd->pdev->dev;
-	u32 operand;
+	u32 operand, status;
 
 	if (wq->state != IDXD_WQ_ENABLED) {
 		dev_dbg(dev, "WQ %d in wrong state: %d\n", wq->id, wq->state);
-		return;
+		return 0;
 	}
 
 	dev_dbg(dev, "Draining WQ %d\n", wq->id);
 	operand = BIT(wq->id % 16) | ((wq->id / 16) << 16);
-	idxd_cmd_exec(idxd, IDXD_CMD_DRAIN_WQ, operand, NULL);
+	idxd_cmd_exec(idxd, IDXD_CMD_DRAIN_WQ, operand, &status);
+	return idxd_cmd_drain_result(idxd, status);
 }
 
-void idxd_wq_reset(struct idxd_wq *wq)
+int idxd_wq_reset(struct idxd_wq *wq)
 {
 	struct idxd_device *idxd = wq->idxd;
 	struct device *dev = &idxd->pdev->dev;
-	u32 operand;
+	u32 operand, status;
+	int rc;
 
 	if (wq->state != IDXD_WQ_ENABLED) {
 		dev_dbg(dev, "WQ %d in wrong state: %d\n", wq->id, wq->state);
-		return;
+		return 0;
 	}
 
 	operand = BIT(wq->id % 16) | ((wq->id / 16) << 16);
-	idxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, NULL);
+	idxd_cmd_exec(idxd, IDXD_CMD_RESET_WQ, operand, &status);
+	/*
+	 * A reset that timed out, or was refused after a command did,
+	 * leaves the queue enabled in the device on its configuration.
+	 * Its software state stays enabled too, as after a failed
+	 * idxd_wq_disable(), so that the queue is neither reconfigured nor
+	 * enabled again on a configuration the device does not run until
+	 * a device disable or reset has stopped it.
+	 */
+	rc = idxd_cmd_drain_result(idxd, status);
+	if (rc)
+		return rc;
 	idxd_wq_disable_cleanup(wq);
+	return 0;
 }
 
 int idxd_wq_map_portal(struct idxd_wq *wq)
@@ -425,13 +483,32 @@ int idxd_wq_init_percpu_ref(struct idxd_wq *wq)
 }
 EXPORT_SYMBOL_NS_GPL(idxd_wq_init_percpu_ref, "IDXD");
 
-void __idxd_wq_quiesce(struct idxd_wq *wq)
+/*
+ * Kill wq_active and wait for the last submitter to drop its reference.
+ * Every killer runs under wq_lock and waits before it unlocks, so a
+ * reference found dying here was killed and waited out by an earlier
+ * caller, such as a halt flush that did not revive the queue. Killing
+ * it again would drop the count below zero and wait forever. A
+ * reference that percpu_ref_exit() released reads as dying too, so a
+ * queue the device re-enabled behind an unbind is skipped as well.
+ * Returns whether this call killed the reference.
+ */
+bool idxd_wq_kill(struct idxd_wq *wq)
 {
 	lockdep_assert_held(&wq->wq_lock);
+	if (percpu_ref_is_dying(&wq->wq_active))
+		return false;
 	reinit_completion(&wq->wq_resurrect);
 	percpu_ref_kill(&wq->wq_active);
-	complete_all(&wq->wq_resurrect);
 	wait_for_completion(&wq->wq_dead);
+	return true;
+}
+
+void __idxd_wq_quiesce(struct idxd_wq *wq)
+{
+	idxd_wq_kill(wq);
+	/* Let parked submitters retry and fail on the dead reference. */
+	complete_all(&wq->wq_resurrect);
 }
 EXPORT_SYMBOL_NS_GPL(__idxd_wq_quiesce, "IDXD");
 
@@ -498,7 +575,7 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,
 	union idxd_command_reg cmd;
 	DECLARE_COMPLETION_ONSTACK(done);
 	u32 stat;
-	unsigned long flags;
+	unsigned long flags, left;
 
 	if (idxd_device_is_halted(idxd)) {
 		dev_warn(&idxd->pdev->dev, "Device is HALTED!\n");
@@ -507,21 +584,69 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,
 		return;
 	}
 
+	if (test_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags)) {
+		dev_warn(&idxd->pdev->dev,
+			 "Not sending command %#x: an earlier device command timed out, device needs a reset\n",
+			 cmd_code);
+		if (status)
+			*status = IDXD_CMDSTS_HW_ERR;
+		return;
+	}
+
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.cmd = cmd_code;
 	cmd.operand = operand;
 	cmd.int_req = 1;
 
 	spin_lock_irqsave(&idxd->cmd_lock, flags);
-	wait_event_lock_irq(idxd->cmd_waitq,
-			    !test_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags),
-			    idxd->cmd_lock);
+	/*
+	 * Wait for the running command, if any. Only its owner can tell
+	 * that it is stuck, so this wait does not declare a timeout of its
+	 * own: its budget covers one owner and restarts whenever another
+	 * command starts running, and it ends early when the owner gives
+	 * up and marks the device. Several healthy commands queued behind
+	 * one another therefore never add up to a false timeout.
+	 */
+	while (test_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags)) {
+		u32 seq = idxd->cmd_seq;
+
+		if (test_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags)) {
+			spin_unlock_irqrestore(&idxd->cmd_lock, flags);
+			dev_err(&idxd->pdev->dev,
+				"not sending command %#x: the running device command timed out, device needs a reset\n",
+				cmd_code);
+			if (status)
+				*status = IDXD_CMDSTS_HW_ERR;
+			return;
+		}
+		if (!wait_event_lock_irq_timeout(idxd->cmd_waitq,
+				!test_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags) ||
+				test_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags) ||
+				idxd->cmd_seq != seq,
+				idxd->cmd_lock,
+				msecs_to_jiffies(IDXD_CMD_TIMEOUT_MS))) {
+			/*
+			 * The owner started before this wait and has the
+			 * same budget, so its own timeout is due; it marks
+			 * the device and wakes this queue. Give up without
+			 * marking anything here.
+			 */
+			spin_unlock_irqrestore(&idxd->cmd_lock, flags);
+			dev_err(&idxd->pdev->dev,
+				"timed out waiting for the running device command before %#x\n",
+				cmd_code);
+			if (status)
+				*status = IDXD_CMDSTS_HW_ERR;
+			return;
+		}
+	}
 
 	dev_dbg(&idxd->pdev->dev, "%s: sending cmd: %#x op: %#x\n",
 		__func__, cmd_code, operand);
 
 	idxd->cmd_status = 0;
 	__set_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags);
+	idxd->cmd_seq++;
 	idxd->cmd_done = &done;
 	iowrite32(cmd.bits, idxd->reg_base + IDXD_CMD_OFFSET);
 
@@ -530,9 +655,57 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,
 	 * the command completes via interrupt.
 	 */
 	spin_unlock_irqrestore(&idxd->cmd_lock, flags);
-	wait_for_completion(&done);
-	stat = ioread32(idxd->reg_base + IDXD_CMDSTS_OFFSET);
+	left = wait_for_completion_timeout(&done,
+				msecs_to_jiffies(IDXD_CMD_TIMEOUT_MS));
 	spin_lock(&idxd->cmd_lock);
+	/*
+	 * A reset, or the recovery from a halt, forgot this command
+	 * meanwhile, and another may be running by now. Forgetting the
+	 * command completes the wait, but it can also happen between the
+	 * interrupt's completion and this lock, or after the wait ran out,
+	 * so ownership is checked whichever way the wait ended. The device
+	 * is not stuck on this command, and the command state belongs to
+	 * whatever runs now. Mark nothing and leave that state alone, even
+	 * if this command completed just before the reset or the halt: its
+	 * status can no longer be trusted.
+	 */
+	if (idxd->cmd_done != &done) {
+		spin_unlock(&idxd->cmd_lock);
+		dev_err(&idxd->pdev->dev,
+			"device command %#x was ended by a reset\n",
+			cmd_code);
+		if (status)
+			*status = IDXD_CMDSTS_HW_ERR;
+		return;
+	}
+	/* A timeout, unless the interrupt beat the lock. */
+	if (!left && !completion_done(&done)) {
+		/*
+		 * The device did not complete the command. Detach the
+		 * on-stack completion so a late interrupt cannot touch it,
+		 * and leave IDXD_FLAG_CMD_RUNNING set: the device may still
+		 * be executing, so no further commands may be issued.
+		 * IDXD_FLAG_CMD_TIMEDOUT makes waiters and future callers
+		 * fail fast; a late completion interrupt or a device reset
+		 * clears both flags.
+		 */
+		idxd->cmd_done = NULL;
+		set_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags);
+		wake_up(&idxd->cmd_waitq);
+		spin_unlock(&idxd->cmd_lock);
+		dev_err(&idxd->pdev->dev,
+			"device command %#x timed out, device needs a reset\n",
+			cmd_code);
+		if (status)
+			*status = IDXD_CMDSTS_HW_ERR;
+		return;
+	}
+	/*
+	 * Read the status while this command still owns the register: no
+	 * other command is written before RUNNING is cleared below.
+	 */
+	stat = ioread32(idxd->reg_base + IDXD_CMDSTS_OFFSET);
+	idxd->cmd_done = NULL;
 	if (status)
 		*status = stat;
 	idxd->cmd_status = stat & GENMASK(7, 0);
@@ -543,6 +716,77 @@ static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,
 	spin_unlock(&idxd->cmd_lock);
 }
 
+/*
+ * Forget the running command, whether its owner still waits for it or
+ * has given up on it. Called when the device has been reset or has
+ * halted, so the command can no longer be executing. A waiting owner is
+ * woken instead of sleeping out its timeout. It finds that it no longer
+ * owns the command and returns without touching the command state,
+ * which belongs to whatever command runs next.
+ */
+void idxd_cmd_reset_state(struct idxd_device *idxd)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&idxd->cmd_lock, flags);
+	/*
+	 * The completion is on the owner's stack. It is valid while
+	 * cmd_done points to it, since the owner clears cmd_done, or sees
+	 * that it points elsewhere, under cmd_lock before it returns.
+	 */
+	if (idxd->cmd_done)
+		complete(idxd->cmd_done);
+	idxd->cmd_done = NULL;
+	__clear_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags);
+	clear_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags);
+	wake_up(&idxd->cmd_waitq);
+	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;
@@ -578,9 +822,16 @@ int idxd_device_disable(struct idxd_device *idxd)
 
 	idxd_cmd_exec(idxd, IDXD_CMD_DISABLE_DEVICE, 0, &status);
 
-	/* If the command is successful or if the device was disabled */
+	/*
+	 * The command succeeded, or the device was already disabled. The
+	 * error code is a value, not a bit mask, so compare it whole. A
+	 * refused command reports IDXD_CMDSTS_HW_ERR, which shares a bit
+	 * with the already-disabled code but leaves the device enabled,
+	 * and clearing the software state of an enabled device lets a
+	 * later teardown free memory the device still writes.
+	 */
 	if (status != IDXD_CMDSTS_SUCCESS &&
-	    !(status & IDXD_CMDSTS_ERR_DIS_DEV_EN)) {
+	    (status & IDXD_CMDSTS_ERR_MASK) != IDXD_CMDSTS_ERR_DIS_DEV_EN) {
 		dev_dbg(dev, "%s: err_code: %#x\n", __func__, status);
 		return -ENXIO;
 	}
@@ -589,24 +840,41 @@ int idxd_device_disable(struct idxd_device *idxd)
 	return 0;
 }
 
-void idxd_device_reset(struct idxd_device *idxd)
+/*
+ * Returns -ENXIO when the device refused or never ran the reset. The
+ * software state is cleared only after a reset that ran, since clearing
+ * it for an enabled device lets a later teardown free memory the device
+ * still writes.
+ */
+int idxd_device_reset(struct idxd_device *idxd)
 {
-	idxd_cmd_exec(idxd, IDXD_CMD_RESET_DEVICE, 0, NULL);
+	u32 status;
+
+	idxd_cmd_exec(idxd, IDXD_CMD_RESET_DEVICE, 0, &status);
+	if (status != IDXD_CMDSTS_SUCCESS) {
+		dev_dbg(&idxd->pdev->dev, "%s: err_code: %#x\n", __func__, status);
+		return -ENXIO;
+	}
 	idxd_device_clear_state(idxd);
 	spin_lock(&idxd->dev_lock);
 	idxd_unmask_error_interrupts(idxd);
 	spin_unlock(&idxd->dev_lock);
+	return 0;
 }
 
-void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid)
+/* Returns -ETIMEDOUT when the drain was never run or never completed. */
+int idxd_device_drain_pasid(struct idxd_device *idxd, int pasid)
 {
 	struct device *dev = &idxd->pdev->dev;
-	u32 operand;
+	u32 operand, status;
 
 	operand = pasid;
 	dev_dbg(dev, "cmd: %u operand: %#x\n", IDXD_CMD_DRAIN_PASID, operand);
-	idxd_cmd_exec(idxd, IDXD_CMD_DRAIN_PASID, operand, NULL);
+	idxd_cmd_exec(idxd, IDXD_CMD_DRAIN_PASID, operand, &status);
+	if (idxd_cmd_drain_result(idxd, status))
+		return -ETIMEDOUT;
 	dev_dbg(dev, "pasid %d drained\n", pasid);
+	return 0;
 }
 
 int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,
@@ -644,31 +912,20 @@ int idxd_device_release_int_handle(struct idxd_device *idxd, int handle,
 {
 	struct device *dev = &idxd->pdev->dev;
 	u32 operand, status;
-	union idxd_command_reg cmd;
 
 	if (!(idxd->hw.cmd_cap & BIT(IDXD_CMD_RELEASE_INT_HANDLE)))
 		return -EOPNOTSUPP;
 
 	dev_dbg(dev, "release int handle, handle %d\n", handle);
 
-	memset(&cmd, 0, sizeof(cmd));
 	operand = handle & GENMASK(15, 0);
 
 	if (irq_type == IDXD_IRQ_IMS)
 		operand |= CMD_INT_HANDLE_IMS;
 
-	cmd.cmd = IDXD_CMD_RELEASE_INT_HANDLE;
-	cmd.operand = operand;
-
 	dev_dbg(dev, "cmd: %u operand: %#x\n", IDXD_CMD_RELEASE_INT_HANDLE, operand);
 
-	spin_lock(&idxd->cmd_lock);
-	iowrite32(cmd.bits, idxd->reg_base + IDXD_CMD_OFFSET);
-
-	while (ioread32(idxd->reg_base + IDXD_CMDSTS_OFFSET) & IDXD_CMDSTS_ACTIVE)
-		cpu_relax();
-	status = ioread32(idxd->reg_base + IDXD_CMDSTS_OFFSET);
-	spin_unlock(&idxd->cmd_lock);
+	idxd_cmd_exec(idxd, IDXD_CMD_RELEASE_INT_HANDLE, operand, &status);
 
 	if ((status & IDXD_CMDSTS_ERR_MASK) != IDXD_CMDSTS_SUCCESS) {
 		dev_dbg(dev, "release int handle failed: %#x\n", status);
@@ -1269,11 +1526,14 @@ int idxd_device_load_config(struct idxd_device *idxd)
 	return 0;
 }
 
-static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)
+static void idxd_flush_pending_descs(struct idxd_irq_entry *ie,
+				     bool keep_callbacks, bool quarantine)
 {
+	struct idxd_wq *wq = ie_to_wq(ie);
 	struct idxd_desc *desc, *itr;
 	struct llist_node *head;
 	LIST_HEAD(flist);
+	LIST_HEAD(qlist);
 	enum idxd_complete_type ctype;
 
 	spin_lock(&ie->list_lock);
@@ -1283,6 +1543,28 @@ static void idxd_flush_pending_descs(struct idxd_irq_entry *ie)
 			list_add_tail(&desc->list, &ie->work_list);
 	}
 
+	/*
+	 * A halt flush that delivers the callbacks of a dmaengine queue
+	 * leaves its descriptors to the interrupt thread, which runs them
+	 * without wq_lock, as it runs every completion. A callback may
+	 * terminate the channel, which takes that lock, and the halt flush
+	 * holds it. The halted device writes no record any more, so one it
+	 * never finished is marked aborted for the thread to complete.
+	 */
+	if (keep_callbacks && idxd_wq_has_txd(wq)) {
+		bool wake = false;
+
+		list_for_each_entry(desc, &ie->work_list, list) {
+			if (!desc->completion->status)
+				desc->completion->status = IDXD_COMP_DESC_ABORT;
+			wake = true;
+		}
+		spin_unlock(&ie->list_lock);
+		if (wake)
+			irq_wake_thread(ie->vector, ie);
+		return;
+	}
+
 	list_for_each_entry_safe(desc, itr, &ie->work_list, list)
 		list_move_tail(&desc->list, &flist);
 	spin_unlock(&ie->list_lock);
@@ -1293,16 +1575,123 @@ 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.
+		 * Another driver's descriptor carries that driver's request
+		 * in place of a txd, and a client may still wait for it, so it
+		 * goes back through that driver's completion. The completion
+		 * reads the outcome from the record, which the device never
+		 * wrote for an unfinished descriptor. Only a dmaengine channel
+		 * terminates, so nothing of such a queue is quarantined.
+		 */
+		if (!idxd_wq_has_txd(wq)) {
+			if (ctype == IDXD_COMPLETE_ABORT)
+				desc->completion->status = IDXD_COMP_DESC_ABORT;
+			idxd_desc_complete(desc, ctype, true);
+			continue;
+		}
+		/*
+		 * wq is being disabled or terminated. Any remaining
+		 * descriptors are likely to be stuck and can be dropped.
+		 * With no client left the callback could point to code that
+		 * is no longer accessible (dmatest unloaded), and a client's
+		 * own terminate must not get it, so it is stripped. A halt
+		 * that delivers the callbacks left them to the thread above.
 		 */
 		tx = &desc->txd;
 		tx->callback = NULL;
 		tx->callback_result = NULL;
-		idxd_dma_complete_txd(desc, ctype, true, NULL, NULL);
+		/*
+		 * A descriptor the device has not finished still has its
+		 * completion record to write. A flush that leaves the
+		 * device running keeps its slot out of use, or the record
+		 * would land on the slot's next owner and complete it with
+		 * this descriptor's status. Its unmap data stays with the
+		 * slot as well, since the device may still access what it
+		 * maps, and an address released now could be mapped again
+		 * for someone else before the late access.
+		 */
+		if (quarantine && ctype == IDXD_COMPLETE_ABORT) {
+			struct dmaengine_unmap_data *unmap = tx->unmap;
+
+			tx->unmap = NULL;
+			idxd_dma_complete_txd(desc, ctype, false, NULL, NULL);
+			tx->unmap = unmap;
+			list_add_tail(&desc->list, &qlist);
+			continue;
+		}
+		/*
+		 * The abort type keeps a record that reports a revoked
+		 * interrupt handle from being resubmitted. The device is done
+		 * with it, and with the handle kept across a terminate the
+		 * copy would run once the client may have freed its memory.
+		 */
+		idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT, true, NULL,
+				      NULL);
 	}
+
+	if (list_empty(&qlist))
+		return;
+	spin_lock(&ie->list_lock);
+	list_splice_tail(&qlist, &wq->quarantine);
+	spin_unlock(&ie->list_lock);
+}
+
+/*
+ * Take what terminate_all has quarantined so far. A drain covers only
+ * what the device held when it was issued, so a synchronize takes the
+ * quarantine before it drains and frees it if the drain completed. A
+ * descriptor terminated meanwhile waits for the next one. The list lock
+ * serialises this with the flush that adds to the quarantine and with a
+ * halt or a teardown that frees it all.
+ */
+void idxd_wq_quarantine_take(struct idxd_wq *wq, struct list_head *list)
+{
+	spin_lock(&wq->ie.list_lock);
+	list_splice_init(&wq->quarantine, list);
+	spin_unlock(&wq->ie.list_lock);
+}
+
+/* The drain did not complete: the device may still run them. */
+void idxd_wq_quarantine_put_back(struct idxd_wq *wq, struct list_head *list)
+{
+	spin_lock(&wq->ie.list_lock);
+	list_splice(list, &wq->quarantine);
+	spin_unlock(&wq->ie.list_lock);
+}
+
+/*
+ * Nothing the device holds can write their completion records, or reach
+ * the memory their unmap data maps, any more. The unmap data goes before
+ * the slot, which a new owner may take at once.
+ */
+void idxd_wq_quarantine_free(struct idxd_wq *wq, struct list_head *list)
+{
+	struct idxd_desc *desc, *itr;
+
+	list_for_each_entry_safe(desc, itr, list, list) {
+		list_del(&desc->list);
+		dma_descriptor_unmap(&desc->txd);
+		idxd_free_desc(wq, desc);
+	}
+}
+
+/*
+ * A halt killed every descriptor the device held: the quarantined slots
+ * are free, and the fence a failed drain raised can be lifted. The halt
+ * flush calls this under wq_lock, since an unbind racing the halt may
+ * free the pool.
+ */
+void idxd_wq_halt_release(struct idxd_wq *wq)
+{
+	LIST_HEAD(dead_descs);
+
+	lockdep_assert_held(&wq->wq_lock);
+
+	if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL)
+		return;
+
+	idxd_wq_quarantine_take(wq, &dead_descs);
+	idxd_wq_quarantine_free(wq, &dead_descs);
+	WRITE_ONCE(wq->stuck, false);
 }
 
 static void idxd_device_set_perm_entry(struct idxd_device *idxd,
@@ -1334,12 +1723,18 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
 		return;
 
 	free_irq(ie->vector, ie);
-	idxd_flush_pending_descs(ie);
+	idxd_flush_pending_descs(ie, false, false);
 
-	/* The interrupt might have been already released by FLR */
+	/* FLR revokes every handle; the halt path marks them invalid. */
 	if (ie->int_handle == INVALID_INT_HANDLE)
 		return;
 
+	/*
+	 * The release waits for a running command like any other command.
+	 * It is not sent, or does not complete, only on a halted device or
+	 * after a command timed out, and the reset such a device needs
+	 * revokes the handle. The handle is forgotten in any case.
+	 */
 	if (idxd->request_int_handles)
 		idxd_device_release_int_handle(idxd, ie->int_handle, IDXD_IRQ_MSIX);
 	idxd_device_clear_perm_entry(idxd, ie);
@@ -1348,21 +1743,49 @@ void idxd_wq_free_irq(struct idxd_wq *wq)
 	ie->pasid = IOMMU_PASID_INVALID;
 }
 
-void idxd_wq_flush_descs(struct idxd_wq *wq)
+/*
+ * @keep_callbacks: deliver the flushed descriptors' completions to the
+ * client, aborted, or with their hardware status where the device had
+ * already finished them. A client's own terminate_all must not get them
+ * (the dmaengine contract); a device halt with a client still holding the
+ * channel must, or the client waits for them forever. The interrupt
+ * thread delivers them, outside wq_lock.
+ * @quarantine: the device keeps running, so the slots of the descriptors
+ * it has not finished stay out of use until a drain covers them. A halt
+ * has killed them and frees their slots at once.
+ * The caller holds wq_lock.
+ */
+void __idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,
+			   bool quarantine)
 {
 	struct idxd_irq_entry *ie = &wq->ie;
-	struct idxd_device *idxd = wq->idxd;
+	bool killed = false;
 
-	guard(mutex)(&wq->wq_lock);
+	lockdep_assert_held(&wq->wq_lock);
 
 	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;
+	/*
+	 * A submitter between its list add and its portal write holds
+	 * wq_active. Waiting for the reference to die puts every listed
+	 * descriptor in the device, where the drain that frees the
+	 * quarantine covers it. A halt flush has done this itself.
+	 */
+	if (quarantine)
+		killed = idxd_wq_kill(wq);
+	idxd_flush_pending_descs(ie, keep_callbacks, quarantine);
+	if (killed) {
+		percpu_ref_reinit(&wq->wq_active);
+		complete_all(&wq->wq_resurrect);
+	}
+}
+
+void idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,
+			 bool quarantine)
+{
+	guard(mutex)(&wq->wq_lock);
+	__idxd_wq_flush_descs(wq, keep_callbacks, quarantine);
 }
 
 int idxd_wq_request_irq(struct idxd_wq *wq)
@@ -1415,6 +1838,16 @@ int idxd_drv_enable_wq(struct idxd_wq *wq)
 
 	lockdep_assert_held(&wq->wq_lock);
 
+	/*
+	 * The device remove releases the queues' drivers before it disables
+	 * the device, so the device still reads enabled meanwhile.
+	 */
+	if (test_bit(IDXD_FLAG_REMOVING, &idxd->flags)) {
+		idxd->cmd_status = IDXD_SCMD_DEV_NOT_ENABLED;
+		rc = -ENODEV;
+		goto err;
+	}
+
 	if (idxd->state != IDXD_DEV_ENABLED) {
 		idxd->cmd_status = IDXD_SCMD_DEV_NOT_ENABLED;
 		goto err;
@@ -1541,6 +1974,7 @@ void idxd_drv_disable_wq(struct idxd_wq *wq)
 {
 	struct idxd_device *idxd = wq->idxd;
 	struct device *dev = &idxd->pdev->dev;
+	int rc;
 
 	lockdep_assert_held(&wq->wq_lock);
 
@@ -1549,10 +1983,19 @@ void idxd_drv_disable_wq(struct idxd_wq *wq)
 			 wq->id, idxd_wq_refcount(wq));
 
 	idxd_wq_unmap_portal(wq);
-	idxd_wq_drain(wq);
+	rc = idxd_wq_drain(wq);
 	idxd_wq_free_irq(wq);
-	idxd_wq_reset(wq);
-	idxd_wq_free_resources(wq);
+	rc |= idxd_wq_reset(wq);
+	/*
+	 * A drain or reset that never completed leaves descriptors in the
+	 * device, and their completion records live in the memory freed
+	 * here. Leak it; the device writing into freed memory is worse.
+	 */
+	if (rc)
+		dev_err(dev, "wq %d: drain or reset timed out, leaking its descriptor memory\n",
+			wq->id);
+	else
+		idxd_wq_free_resources(wq);
 	percpu_ref_exit(&wq->wq_active);
 	wq->client_count = 0;
 }
@@ -1563,6 +2006,9 @@ int idxd_device_drv_probe(struct idxd_dev *idxd_dev)
 	struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
 	int rc = 0;
 
+	if (test_bit(IDXD_FLAG_REMOVING, &idxd->flags))
+		return -ENODEV;
+
 	/*
 	 * Device should be in disabled state for the idxd_drv to load. If it's in
 	 * enabled state, then the device was altered outside of driver's control.
@@ -1617,23 +2063,41 @@ void idxd_device_drv_remove(struct idxd_dev *idxd_dev)
 {
 	struct device *dev = &idxd_dev->conf_dev;
 	struct idxd_device *idxd = idxd_dev_to_idxd(idxd_dev);
+	bool stopped;
 	int i;
 
 	for (i = 0; i < idxd->max_wqs; i++) {
 		struct idxd_wq *wq = idxd->wqs[i];
 		struct device *wq_dev = wq_confdev(wq);
 
-		if (wq->state == IDXD_WQ_DISABLED)
-			continue;
-		dev_warn(dev, "Active wq %d on disable %s.\n", i, dev_name(wq_dev));
+		/*
+		 * A halt's clear_state leaves a bound queue DISABLED while
+		 * its driver still holds the queue's channel and resources.
+		 * Release every bound driver, not only the enabled queues',
+		 * before the dma_device below frees their channels. For a
+		 * queue without a driver the release is a no-op.
+		 */
+		if (wq->state != IDXD_WQ_DISABLED)
+			dev_warn(dev, "Active wq %d on disable %s.\n", i,
+				 dev_name(wq_dev));
 		device_release_driver(wq_dev);
 	}
 
 	idxd_unregister_dma_device(idxd);
-	idxd_device_disable(idxd);
-	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags))
-		idxd_device_reset(idxd);
-	idxd_device_evl_free(idxd);
+	/*
+	 * A disable or a reset that ran, or found the device disabled or
+	 * halted, leaves nothing in flight. Both are refused after a device
+	 * command timed out, and the device then stays enabled with whatever
+	 * it holds, so what it may still write is kept.
+	 */
+	stopped = !idxd_device_disable(idxd);
+	if (test_bit(IDXD_FLAG_CONFIGURABLE, &idxd->flags) &&
+	    !idxd_device_reset(idxd))
+		stopped = true;
+	if (stopped)
+		idxd_device_evl_free(idxd);
+	else
+		dev_err(dev, "device still enabled after a command timeout, leaking the event log\n");
 }
 
 static enum idxd_dev_type dev_types[] = {
diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
index 9937b671f6376..0a7517cb51f29 100644
--- a/drivers/dma/idxd/dma.c
+++ b/drivers/dma/idxd/dma.c
@@ -115,7 +115,8 @@ idxd_dma_submit_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
 	if (wq->state != IDXD_WQ_ENABLED)
 		return NULL;
 
-	if (len > idxd->max_xfer_bytes)
+	/* The work queue's configured limit is what the hardware enforces. */
+	if (len > idxd->max_xfer_bytes || len > wq->max_xfer_bytes)
 		return NULL;
 
 	op_flag_setup(flags, &desc_flags);
@@ -198,7 +199,18 @@ static int idxd_dma_terminate_all(struct dma_chan *c)
 {
 	struct idxd_wq *wq = to_idxd_wq(c);
 
-	idxd_wq_flush_descs(wq);
+	guard(mutex)(&wq->wq_lock);
+	/*
+	 * A descriptor that completed with a revoked interrupt handle is
+	 * resubmitted by a work item. One submitted before this terminate
+	 * may reach that work after the flush, from the interrupt thread or
+	 * from a work item queued earlier, and is cancelled there rather
+	 * than run with its callback once the client may have freed its
+	 * memory.
+	 */
+	WRITE_ONCE(wq->terminate_gen, wq->terminate_gen + 1);
+	/* The device keeps running what the lists held. See synchronize. */
+	__idxd_wq_flush_descs(wq, false, true);
 
 	return 0;
 }
@@ -206,8 +218,38 @@ static int idxd_dma_terminate_all(struct dma_chan *c)
 static void idxd_dma_synchronize(struct dma_chan *c)
 {
 	struct idxd_wq *wq = to_idxd_wq(c);
+	LIST_HEAD(quarantined);
 
-	idxd_wq_drain(wq);
+	/*
+	 * dmaengine_synchronize() promises the client that its memory may
+	 * be freed afterwards. A drain that completed keeps that promise,
+	 * and nothing the device held before it is left to write a
+	 * completion record, so the slots terminate_all quarantined are
+	 * free again. A drain that never completed, or that was refused
+	 * because an earlier command never did, leaves the client's
+	 * descriptors in a device that may still run them. The channel
+	 * release path runs this under dma_list_mutex, and a device that
+	 * refused the drain offers nothing to wait for, so waiting longer
+	 * here would hold up every dmaengine user for nothing. The driver
+	 * cannot keep the promise for the client's memory then and says so.
+	 * It keeps its own memory safe: the quarantined slots stay out of
+	 * use and the queue takes no new descriptor until a later drain
+	 * completes or a halt kills what the device holds, so a late
+	 * completion record lands in a slot nobody reuses, and
+	 * idxd_drv_disable_wq() leaks what the device may still write.
+	 * Only a device reset ends the exposure of the client's memory.
+	 */
+	idxd_wq_quarantine_take(wq, &quarantined);
+	if (!idxd_wq_drain(wq)) {
+		idxd_wq_quarantine_free(wq, &quarantined);
+		WRITE_ONCE(wq->stuck, false);
+		return;
+	}
+	idxd_wq_quarantine_put_back(wq, &quarantined);
+	WRITE_ONCE(wq->stuck, true);
+	dev_err_ratelimited(&wq->idxd->pdev->dev,
+			    "wq %d: drain failed. Its descriptors may still complete and it takes no new work until a drain completes or the device is reset\n",
+			    wq->id);
 }
 
 int idxd_register_dma_device(struct idxd_device *idxd)
@@ -278,7 +320,7 @@ static int idxd_register_dma_channel(struct idxd_wq *wq)
 
 	chan = &idxd_chan->chan;
 	chan->device = dma;
-	list_add_tail(&chan->device_node, &dma->channels);
+	idxd_chan->wq = wq;
 
 	for (i = 0; i < wq->num_descs; i++) {
 		struct idxd_desc *desc = wq->descs[i];
@@ -287,14 +329,20 @@ static int idxd_register_dma_channel(struct idxd_wq *wq)
 		desc->txd.tx_submit = idxd_dma_tx_submit;
 	}
 
-	rc = dma_async_device_channel_register(dma, chan, NULL);
+	/*
+	 * The dma_device is registered already, so a channel request may
+	 * take the channel as soon as it is on the device's list. The core
+	 * links it only once it is registered, and everything a client
+	 * reaches through it is set up by then. What follows serves the
+	 * unbind, which cannot run before this probe returns.
+	 */
+	rc = dma_async_device_channel_add(dma, chan, NULL);
 	if (rc < 0) {
 		kfree(idxd_chan);
 		return rc;
 	}
 
 	wq->idxd_chan = idxd_chan;
-	idxd_chan->wq = wq;
 	get_device(wq_confdev(wq));
 
 	return 0;
diff --git a/drivers/dma/idxd/idxd.h b/drivers/dma/idxd/idxd.h
index ce78b9a7c641c..b0cfd71011742 100644
--- a/drivers/dma/idxd/idxd.h
+++ b/drivers/dma/idxd/idxd.h
@@ -224,6 +224,21 @@ struct idxd_wq {
 	struct idxd_desc **descs;
 	struct sbitmap_queue sbq;
 	struct idxd_dma_chan *idxd_chan;
+	bool stuck;		/* a drain failed with the device enabled: the
+				 * outstanding descriptors may complete at any
+				 * time, so no slot is reused until a later
+				 * drain completes or a halt kills them
+				 */
+	u16 terminate_gen;	/* bumps on every terminate_all, under
+				 * wq_lock before its kill
+				 */
+	struct list_head quarantine;	/* descriptors a terminate_all took
+					 * off the lists while the device
+					 * still held them. Their slots, with
+					 * their unmap data, are freed once a
+					 * drain that covers them completes or
+					 * the device stops. Under ie.list_lock.
+					 */
 	char name[WQ_NAME_SIZE + 1];
 	u64 max_xfer_bytes;
 	u32 max_batch_size;
@@ -267,8 +282,10 @@ enum idxd_device_state {
 enum idxd_device_flag {
 	IDXD_FLAG_CONFIGURABLE = 0,
 	IDXD_FLAG_CMD_RUNNING,
+	IDXD_FLAG_CMD_TIMEDOUT,
 	IDXD_FLAG_PASID_ENABLED,
 	IDXD_FLAG_USER_PASID_ENABLED,
+	IDXD_FLAG_REMOVING,	/* PCI remove under way, refuse binds */
 };
 
 struct idxd_dma_dev {
@@ -331,6 +348,7 @@ struct idxd_device {
 	spinlock_t dev_lock;	/* spinlock for device */
 	spinlock_t cmd_lock;	/* spinlock for device commands */
 	struct completion *cmd_done;
+	u32 cmd_seq;		/* bumps when a command starts running */
 	struct idxd_group **groups;
 	struct idxd_wq **wqs;
 	struct idxd_engine **engines;
@@ -429,6 +447,9 @@ struct idxd_desc {
 	struct list_head list;
 	int id;
 	int cpu;
+	u16 terminate_gen;	/* the queue's terminate_gen at an
+				 * interrupt-armed submit
+				 */
 	struct idxd_wq *wq;
 };
 
@@ -740,6 +761,16 @@ void idxd_dma_complete_txd(struct idxd_desc *desc,
 			   enum idxd_complete_type comp_type,
 			   bool free_desc, void *ctx, u32 *status);
 
+/*
+ * Whether the queue's descriptors are dmaengine transactions. Another
+ * driver, such as iaa_crypto, keeps its own context where they keep
+ * their txd.
+ */
+static inline bool idxd_wq_has_txd(struct idxd_wq *wq)
+{
+	return wq_to_idxd_drv(wq)->desc_complete == idxd_dma_complete_txd;
+}
+
 static inline void idxd_desc_complete(struct idxd_desc *desc,
 				      enum idxd_complete_type comp_type,
 				      bool free_desc)
@@ -776,10 +807,13 @@ void idxd_drv_disable_wq(struct idxd_wq *wq);
 int idxd_device_init_reset(struct idxd_device *idxd);
 int idxd_device_enable(struct idxd_device *idxd);
 int idxd_device_disable(struct idxd_device *idxd);
-void idxd_device_reset(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);
-void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
+int idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
 int idxd_device_load_config(struct idxd_device *idxd);
 int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,
 				   enum idxd_interrupt_type irq_type);
@@ -792,21 +826,30 @@ int idxd_wq_alloc_resources(struct idxd_wq *wq);
 void idxd_wq_free_resources(struct idxd_wq *wq);
 int idxd_wq_enable(struct idxd_wq *wq);
 int idxd_wq_disable(struct idxd_wq *wq, bool reset_config);
-void idxd_wq_drain(struct idxd_wq *wq);
-void idxd_wq_reset(struct idxd_wq *wq);
+int idxd_wq_drain(struct idxd_wq *wq);
+int idxd_wq_reset(struct idxd_wq *wq);
 int idxd_wq_map_portal(struct idxd_wq *wq);
 void idxd_wq_unmap_portal(struct idxd_wq *wq);
 int idxd_wq_set_pasid(struct idxd_wq *wq, int pasid);
 int idxd_wq_disable_pasid(struct idxd_wq *wq);
+bool idxd_wq_kill(struct idxd_wq *wq);
 void __idxd_wq_quiesce(struct idxd_wq *wq);
 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);
+void __idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,
+			   bool quarantine);
+void idxd_wq_flush_descs(struct idxd_wq *wq, bool keep_callbacks,
+			 bool quarantine);
+void idxd_wq_quarantine_take(struct idxd_wq *wq, struct list_head *list);
+void idxd_wq_quarantine_put_back(struct idxd_wq *wq, struct list_head *list);
+void idxd_wq_quarantine_free(struct idxd_wq *wq, struct list_head *list);
+void idxd_wq_halt_release(struct idxd_wq *wq);
 
 /* submission */
 int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
+int idxd_resubmit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
 struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype);
 int idxd_enqcmds(struct idxd_wq *wq, void __iomem *portal, const void *desc);
 
diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c
index 4b827a3297564..312b4670b3e82 100644
--- a/drivers/dma/idxd/init.c
+++ b/drivers/dma/idxd/init.c
@@ -213,6 +213,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
 		init_waitqueue_head(&wq->err_queue);
 		init_completion(&wq->wq_dead);
 		init_completion(&wq->wq_resurrect);
+		INIT_LIST_HEAD(&wq->quarantine);
 		wq->max_xfer_bytes = WQ_DEFAULT_MAX_XFER;
 		idxd_wq_set_max_batch_size(idxd->data->type, wq, WQ_DEFAULT_MAX_BATCH);
 		idxd_wq_set_init_max_sgl_size(idxd, wq);
@@ -1057,6 +1058,15 @@ static void idxd_reset_done(struct pci_dev *pdev)
 	struct device *dev;
 	int rc, i;
 
+	/*
+	 * A reset ends any command, including one that had timed out. The
+	 * PCI core resets the device even when the preparation failed and
+	 * the device is not rebound, and it calls this after a reset that
+	 * failed as well, which cannot be told apart here. Like the rebind
+	 * below, this assumes that the reset ran.
+	 */
+	idxd_cmd_reset_state(idxd);
+
 	if (!idxd->idxd_saved)
 		return;
 
@@ -1202,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);
 
@@ -1209,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",
@@ -1267,25 +1287,55 @@ static void idxd_remove(struct pci_dev *pdev)
 {
 	struct idxd_device *idxd = pci_get_drvdata(pdev);
 
+	/*
+	 * The devices on the dsa bus stay registered, and so open to a
+	 * sysfs bind, until the unregisters below. A bind during the
+	 * removal would re-probe the device or enable one of its queues
+	 * while they are torn down, and the PCI device lock held here does
+	 * not exclude it, so the probes test this first. The command path
+	 * changes IDXD_FLAG_CMD_RUNNING in the same word with non-atomic
+	 * bit operations under cmd_lock, which would lose a bit set
+	 * concurrently, so the flag is set under that lock too.
+	 */
+	spin_lock_irq(&idxd->cmd_lock);
+	set_bit(IDXD_FLAG_REMOVING, &idxd->flags);
+	spin_unlock_irq(&idxd->cmd_lock);
+	/*
+	 * The idxd sub-driver's remove walks idxd->wqs to disable the
+	 * active queues, and each wq is freed with its conf_dev. Unbind
+	 * that driver while the queues still exist.
+	 */
+	device_release_driver(idxd_confdev(idxd));
+	/*
+	 * Disable the device while the queues still exist too. The
+	 * sub-driver's remove leaves the device enabled when a command has
+	 * timed out, a late completion can clear that state at any time,
+	 * and the disable below then clears the queues' software state.
+	 */
+	idxd_shutdown(pdev);
 	idxd_unregister_devices(idxd);
 	/*
-	 * When ->release() is called for the idxd->conf_dev, it frees all the memory related
-	 * to the idxd context. The driver still needs those bits in order to do the rest of
-	 * the cleanup. However, we do need to unbound the idxd sub-driver. So take a ref
-	 * on the device here to hold off the freeing while allowing the idxd sub-driver
-	 * to unbind.
+	 * When ->release() is called for the idxd->conf_dev, it frees all
+	 * the memory related to the idxd context. The driver still needs
+	 * those bits in order to do the rest of the cleanup, so take a ref
+	 * on the device here to hold off the freeing until that is done.
 	 */
 	get_device(idxd_confdev(idxd));
 	device_unregister(idxd_confdev(idxd));
-	idxd_shutdown(pdev);
 	idxd_device_remove_debugfs(idxd);
 	perfmon_pmu_remove(idxd);
 	idxd_cleanup_interrupts(idxd);
 	if (device_pasid_enabled(idxd))
 		idxd_disable_system_pasid(idxd);
 	pci_iounmap(pdev, idxd->reg_base);
-	put_device(idxd_confdev(idxd));
 	pci_disable_device(pdev);
+	/*
+	 * Bus mastering is off, so nothing the device holds can complete.
+	 * The store comes before the reference taken above is dropped:
+	 * that reference is the last one, and its release frees the device.
+	 */
+	idxd->state = IDXD_DEV_DISABLED;
+	put_device(idxd_confdev(idxd));
 }
 
 static struct pci_driver idxd_pci_driver = {
diff --git a/drivers/dma/idxd/irq.c b/drivers/dma/idxd/irq.c
index 6a25e1fd0e62c..8217698056bb4 100644
--- a/drivers/dma/idxd/irq.c
+++ b/drivers/dma/idxd/irq.c
@@ -35,7 +35,14 @@ static void idxd_device_reinit(struct work_struct *work)
 	struct device *dev = &idxd->pdev->dev;
 	int rc, i;
 
-	idxd_device_reset(idxd);
+	/*
+	 * The halt ended whatever command was running, and a command that
+	 * timed out before the halt would otherwise refuse the reset.
+	 */
+	idxd_cmd_reset_state(idxd);
+	rc = idxd_device_reset(idxd);
+	if (rc < 0)
+		goto out;
 	rc = idxd_device_config(idxd);
 	if (rc < 0)
 		goto out;
@@ -108,6 +115,11 @@ static void idxd_abort_invalid_int_handle_descs(struct idxd_irq_entry *ie)
 	struct idxd_desc *d, *t;
 	struct llist_node *head;
 
+	/*
+	 * An unbind frees the descriptors and the allocator under
+	 * wq_lock, so they are completed under it as well.
+	 */
+	lockdep_assert_held(&ie_to_wq(ie)->wq_lock);
 	spin_lock(&ie->list_lock);
 	head = llist_del_all(&ie->pending_llist);
 	if (head) {
@@ -135,6 +147,7 @@ static void idxd_int_handle_revoke(struct work_struct *work)
 	struct pci_dev *pdev = idxd->pdev;
 	struct device *dev = &pdev->dev;
 	int i, new_handle, rc;
+	bool killed;
 
 	if (!idxd->request_int_handles) {
 		kfree(revoke);
@@ -159,15 +172,31 @@ static void idxd_int_handle_revoke(struct work_struct *work)
 			continue;
 
 		rc = idxd_device_request_int_handle(idxd, i, &new_handle, IDXD_IRQ_MSIX);
-		if (rc < 0) {
+		if (rc < 0)
 			dev_warn(dev, "get int handle %d failed: %d\n", i, rc);
+
+		/*
+		 * The request runs without wq_lock, so that a reset can end
+		 * it, and the queue may have been unbound meanwhile. An
+		 * unbind invalidates the handle in the same wq_lock hold
+		 * that unmaps the portal and frees the descriptors, so a
+		 * handle still valid under the lock means that the queue
+		 * still has its portal, its descriptors and its completion
+		 * handler. Everything below, the drain included, stays in
+		 * this hold.
+		 */
+		guard(mutex)(&wq->wq_lock);
+		if (ie->int_handle == INVALID_INT_HANDLE)
+			continue;
+
+		if (rc < 0) {
 			/*
 			 * Failed to acquire new interrupt handle. Kill the WQ
 			 * and release all the pending submitters. The submitters will
 			 * get error return code and handle appropriately.
 			 */
 			ie->int_handle = INVALID_INT_HANDLE;
-			idxd_wq_quiesce(wq);
+			__idxd_wq_quiesce(wq);
 			idxd_abort_invalid_int_handle_descs(ie);
 			continue;
 		}
@@ -186,21 +215,20 @@ static void idxd_int_handle_revoke(struct work_struct *work)
 			continue;
 		}
 
-		mutex_lock(&wq->wq_lock);
-		reinit_completion(&wq->wq_resurrect);
-
-		/* Kill percpu_ref to pause additional descriptor submissions */
-		percpu_ref_kill(&wq->wq_active);
-
-		/* Wait for all submitters quiesce before we change interrupt handle */
-		wait_for_completion(&wq->wq_dead);
+		/*
+		 * Kill percpu_ref to pause additional descriptor submissions
+		 * and wait for all submitters to quiesce before we change
+		 * the interrupt handle. A queue a halt already killed and did
+		 * not revive is left dead.
+		 */
+		killed = idxd_wq_kill(wq);
 
 		ie->int_handle = new_handle;
 
 		/* Revive percpu ref and wake up all the waiting submitters */
-		percpu_ref_reinit(&wq->wq_active);
+		if (killed)
+			percpu_ref_reinit(&wq->wq_active);
 		complete_all(&wq->wq_resurrect);
-		mutex_unlock(&wq->wq_lock);
 
 		/*
 		 * The delay here is to wait for all possible MOVDIR64B that
@@ -331,10 +359,28 @@ static void process_evl_entry(struct idxd_device *idxd,
 			if (!entry_head->rcr && status == DSA_COMP_DRAIN_EVL)
 				return;
 
+			struct idxd_wq *wq = idxd->wqs[entry_head->wq_idx];
+
+			/*
+			 * The fault worker only does user-context work,
+			 * copying the completion record through the wq's
+			 * PASID xarray, which is populated by cdev opens
+			 * alone. A kernel WQ has no cdev workqueue and no
+			 * user contexts, so queueing could only warn and
+			 * drop the record. Note it and move on. The user
+			 * driver detaches the workqueue under evl->lock,
+			 * which this walk holds, so the one tested here is
+			 * the one queued on.
+			 */
+			if (!is_idxd_wq_user(wq) || !wq->wq) {
+				dev_warn_ratelimited(dev,
+					"EVL fault on kernel wq %d, status %#x\n",
+					wq->id, status);
+				return;
+			}
+
 			fault = kmem_cache_alloc(idxd->evl_cache, GFP_ATOMIC);
 			if (fault) {
-				struct idxd_wq *wq = idxd->wqs[entry_head->wq_idx];
-
 				fault->wq = wq;
 				fault->status = status;
 				memcpy(&fault->entry, entry_head, ent_size);
@@ -397,14 +443,61 @@ 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)
+/*
+ * Complete what the halted engines will never finish, or a client waiting
+ * on one of those descriptors waits forever. The flush hands descriptors
+ * back, so no submitter may still own one: a submitter that passed the
+ * state check before the halt can hold a descriptor on the pending list
+ * while its ENQCMDS retries, and it aborts and frees that descriptor
+ * itself when the submit fails. Killing wq_active and waiting for the
+ * last submitter to drop its reference orders the flush after that.
+ * Each queue is handled in one hold of wq_lock, from the state check
+ * through the revive. A driver remove that quiesces the queue in one
+ * hold and disables it in another, as iaa_crypto's does, would otherwise
+ * find the reference dying between the kill and the revive, skip its
+ * own kill, and have the revive undo its quiesce before its disable
+ * frees the queue.
+ * @resurrect: revive the queues afterwards for a reset that keeps them.
+ */
+static void idxd_wqs_halt_flush(struct idxd_device *idxd, bool resurrect)
 {
+	bool killed;
 	int i;
 
 	for (i = 0; i < idxd->max_wqs; i++) {
 		struct idxd_wq *wq = idxd->wqs[i];
 
-		idxd_wq_flush_descs(wq);
+		mutex_lock(&wq->wq_lock);
+		if (wq->state != IDXD_WQ_ENABLED || wq->type != IDXD_WQT_KERNEL) {
+			mutex_unlock(&wq->wq_lock);
+			continue;
+		}
+		killed = idxd_wq_kill(wq);
+		__idxd_wq_flush_descs(wq, idxd_wq_refcount(wq) > 0, false);
+		idxd_wq_halt_release(wq);
+
+		if (resurrect) {
+			/*
+			 * Revive only what this flush killed, and only if no
+			 * failed interrupt handle revoke killed it for good,
+			 * which leaves the handle invalid. The state changes
+			 * without the lock only to enabled, in the reinit of
+			 * an earlier halt, or on a queue that an FLR recovery
+			 * has unbound, whose reference reads as dying, so this
+			 * flush did not kill it. A reference an earlier halt
+			 * left dead stays dead, since that halt's recovery
+			 * unbinds the queue. The revive has to stay in this
+			 * hold: moved to the reinit, it would reopen the
+			 * window described above.
+			 */
+			if (killed && wq->ie.int_handle != INVALID_INT_HANDLE)
+				percpu_ref_reinit(&wq->wq_active);
+			complete_all(&wq->wq_resurrect);
+		} else {
+			/* Let blocked submitters retry and fail on the state. */
+			complete_all(&wq->wq_resurrect);
+		}
+		mutex_unlock(&wq->wq_lock);
 	}
 }
 
@@ -416,6 +509,8 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
 	if (gensts.state == IDXD_DEVICE_STATE_HALT) {
 		idxd->state = IDXD_DEV_HALTED;
 		if (gensts.reset_type == IDXD_DEVICE_RESET_SOFTWARE) {
+			/* The reinit below re-enables the queues, so revive them. */
+			idxd_wqs_halt_flush(idxd, true);
 			/*
 			 * If we need a software reset, we will throw the work
 			 * on a system workqueue in order to allow interrupts
@@ -424,13 +519,23 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
 			INIT_WORK(&idxd->work, idxd_device_reinit);
 			queue_work(idxd->wq, &idxd->work);
 		} else if (gensts.reset_type == IDXD_DEVICE_RESET_FLR) {
+			int i;
+
 			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.
+			/*
+			 * Flush all pending descriptors. The FLR revokes every
+			 * interrupt handle, so mark them invalid here without a
+			 * device command; they are requested again when a work
+			 * queue is re-enabled after the reset.
 			 */
-			idxd_wqs_flush_descs(idxd);
+			idxd_wqs_halt_flush(idxd, false);
+			for (i = 0; i < idxd->max_wqs; i++) {
+				struct idxd_wq *wq = idxd->wqs[i];
+
+				if (wq->type == IDXD_WQT_KERNEL)
+					WRITE_ONCE(wq->ie.int_handle, INVALID_INT_HANDLE);
+			}
 			dev_dbg(&idxd->pdev->dev,
 				"idxd halted, doing FLR. After FLR, configs are restored\n");
 			INIT_WORK(&idxd->work, idxd_device_flr);
@@ -438,7 +543,8 @@ static irqreturn_t idxd_halt(struct idxd_device *idxd)
 
 		} else {
 			idxd->state = IDXD_DEV_HALTED;
-			idxd_wqs_quiesce(idxd);
+			/* Same as above: nothing in flight will ever complete. */
+			idxd_wqs_halt_flush(idxd, false);
 			idxd_wqs_unmap_portal(idxd);
 			idxd_device_clear_state(idxd);
 			dev_err(&idxd->pdev->dev,
@@ -522,7 +628,25 @@ irqreturn_t idxd_misc_thread(int vec, void *data)
 
 	if (cause & IDXD_INTC_CMD) {
 		val |= IDXD_INTC_CMD;
-		complete(idxd->cmd_done);
+		/*
+		 * cmd_done is cleared under cmd_lock when idxd_cmd_exec()
+		 * gives up on a command: the completion lives on its stack,
+		 * so a late interrupt must not touch it.
+		 */
+		spin_lock(&idxd->cmd_lock);
+		if (idxd->cmd_done) {
+			complete(idxd->cmd_done);
+		} else if (test_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags)) {
+			/*
+			 * The command its owner gave up on has finished after
+			 * all. The device is usable again, so let the queue go.
+			 */
+			__clear_bit(IDXD_FLAG_CMD_RUNNING, &idxd->flags);
+			clear_bit(IDXD_FLAG_CMD_TIMEDOUT, &idxd->flags);
+			wake_up(&idxd->cmd_waitq);
+			dev_warn(dev, "a timed-out device command completed late\n");
+		}
+		spin_unlock(&idxd->cmd_lock);
 	}
 
 	if (cause & IDXD_INTC_OCCUPY) {
@@ -556,22 +680,27 @@ static void idxd_int_handle_resubmit_work(struct work_struct *work)
 	int rc;
 
 	desc->completion->status = 0;
-	rc = idxd_submit_desc(wq, desc);
+	rc = idxd_resubmit_desc(wq, desc);
 	if (rc < 0) {
 		dev_dbg(&wq->idxd->pdev->dev, "Failed to resubmit desc %d to wq %d.\n",
 			desc->id, wq->id);
 		/*
-		 * If the error is not -EAGAIN, it means the submission failed due to wq
-		 * has been killed instead of ENQCMDS failure. Here the driver needs to
-		 * notify the submitter of the failure by reporting abort status.
-		 *
-		 * -EAGAIN comes from ENQCMDS failure. idxd_submit_desc() will handle the
-		 * abort.
+		 * The submission failed because the device is not enabled,
+		 * because the wq has been killed or because ENQCMDS failed,
+		 * and in each case the descriptor is on no list. Here the
+		 * driver needs to notify the submitter of the failure by
+		 * reporting abort status. The submit has dropped its
+		 * wq_active reference by now, so a callback that submits or
+		 * terminates does not wait for it. A descriptor submitted
+		 * before a terminate_all, which cancels its resubmission,
+		 * gets no callback, since its client terminated it.
 		 */
-		if (rc != -EAGAIN) {
-			desc->completion->status = IDXD_COMP_DESC_ABORT;
-			idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, false);
+		if (desc->terminate_gen != READ_ONCE(wq->terminate_gen)) {
+			desc->txd.callback = NULL;
+			desc->txd.callback_result = NULL;
 		}
+		desc->completion->status = IDXD_COMP_DESC_ABORT;
+		idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, false);
 		idxd_free_desc(wq, desc);
 	}
 	kfree(irw);
@@ -597,31 +726,39 @@ static void irq_process_pending_llist(struct idxd_irq_entry *irq_entry)
 {
 	struct idxd_desc *desc, *t;
 	struct llist_node *head;
+	LIST_HEAD(flist);
 
-	head = llist_del_all(&irq_entry->pending_llist);
-	if (!head)
+	if (llist_empty(&irq_entry->pending_llist))
 		return;
 
+	/*
+	 * Sort under the list lock, as the submit abort does. A descriptor
+	 * still waiting on the hardware reaches the work list within the
+	 * same hold, so the abort of a failed submission, which searches
+	 * both lists under the lock, always finds its own descriptor.
+	 */
+	spin_lock(&irq_entry->list_lock);
+	head = llist_del_all(&irq_entry->pending_llist);
 	llist_for_each_entry_safe(desc, t, head, llnode) {
 		u8 status = desc->completion->status & DSA_COMP_STATUS_MASK;
 
-		if (status) {
-			/*
-			 * Check against the original status as ABORT is software defined
-			 * and 0xff, which DSA_COMP_STATUS_MASK can mask out.
-			 */
-			if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT)) {
-				idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true);
-				continue;
-			}
+		if (status)
+			list_add_tail(&desc->list, &flist);
+		else
+			list_add_tail(&desc->list, &irq_entry->work_list);
+	}
+	spin_unlock(&irq_entry->list_lock);
 
+	list_for_each_entry_safe(desc, t, &flist, list) {
+		list_del(&desc->list);
+		/*
+		 * Check against the original status as ABORT is software
+		 * defined and 0xff, which DSA_COMP_STATUS_MASK can mask out.
+		 */
+		if (unlikely(desc->completion->status == IDXD_COMP_DESC_ABORT))
+			idxd_desc_complete(desc, IDXD_COMPLETE_ABORT, true);
+		else
 			idxd_desc_complete(desc, IDXD_COMPLETE_NORMAL, true);
-		} else {
-			spin_lock(&irq_entry->list_lock);
-			list_add_tail(&desc->list,
-				      &irq_entry->work_list);
-			spin_unlock(&irq_entry->list_lock);
-		}
 	}
 }
 
@@ -673,18 +810,19 @@ irqreturn_t idxd_wq_thread(int irq, void *data)
 	 * submmiter adds all the submitted descriptor after sending it to
 	 * the workqueue. It's a lockless singly linked list. The work_list
 	 * is the common linux double linked list. We are in a scenario of
-	 * multiple producers and a single consumer. The producers are all
-	 * the kernel submitters of descriptors, and the consumer is the
-	 * kernel irq handler thread for the msix vector when using threaded
-	 * irq. To work with the restrictions of llist to remain lockless,
-	 * we are doing the following steps:
+	 * multiple producers and several consumers. The producers are all
+	 * the kernel submitters of descriptors, and they add to the llist
+	 * without a lock. The consumers are the kernel irq handler thread
+	 * for the msix vector when using threaded irq, the abort of a
+	 * failed submission, the interrupt handle abort and the flushes,
+	 * and each empties the llist under the list lock. The thread does
+	 * so in these steps:
 	 * 1. Iterate through the work_list and process any completed
 	 *    descriptor. Delete the completed entries during iteration.
-	 * 2. llist_del_all() from the pending list.
-	 * 3. Iterate through the llist that was deleted from the pending list
-	 *    and process the completed entries.
-	 * 4. If the entry is still waiting on hardware, list_add_tail() to
-	 *    the work_list.
+	 * 2. Under the list lock, llist_del_all() from the pending list and
+	 *    move each entry still waiting on hardware to the work_list and
+	 *    each completed one to a private list.
+	 * 3. Process the entries of the private list outside the lock.
 	 */
 	irq_process_work_list(irq_entry);
 	irq_process_pending_llist(irq_entry);
diff --git a/drivers/dma/idxd/submit.c b/drivers/dma/idxd/submit.c
index 03217041b8b3e..469a0cadb984d 100644
--- a/drivers/dma/idxd/submit.c
+++ b/drivers/dma/idxd/submit.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
 #include <linux/init.h>
+#include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -34,6 +35,13 @@ struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)
 
 	if (idxd->state != IDXD_DEV_ENABLED)
 		return ERR_PTR(-EIO);
+	/*
+	 * A failed drain left descriptors the device may still complete.
+	 * No slot is reused until a later drain completes or a halt kills
+	 * them.
+	 */
+	if (READ_ONCE(wq->stuck))
+		return ERR_PTR(-ENXIO);
 
 	sbq = &wq->sbq;
 	idx = sbitmap_queue_get(sbq, &cpu);
@@ -44,6 +52,21 @@ struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype)
 		return __get_desc(wq, idx, cpu);
 	}
 
+	/*
+	 * A dying reference whose resurrect has completed belongs to a
+	 * queue quiesced for good: no kill in progress will revive it, and
+	 * every submission fails. Waiting for a slot there gains nothing
+	 * and may never end. The teardown flush and the interrupt thread
+	 * free the slot of each descriptor they complete only when its
+	 * completion returns, and iaa_crypto's verify of a compression
+	 * allocates from inside one. The two reads are not atomic, so an
+	 * allocation that races a revive can fail like a request the kill
+	 * caught.
+	 */
+	if (data_race(percpu_ref_is_dying(&wq->wq_active)) &&
+	    completion_done(&wq->wq_resurrect))
+		return ERR_PTR(-ENXIO);
+
 	ws = &sbq->ws[0];
 	for (;;) {
 		sbitmap_prepare_to_wait(sbq, ws, &wait, TASK_INTERRUPTIBLE);
@@ -85,23 +108,16 @@ static struct idxd_desc *list_abort_desc(struct idxd_wq *wq, struct idxd_irq_ent
 		}
 	}
 
-	/*
-	 * At this point, the desc needs to be aborted is held by the completion
-	 * handler where it has taken it off the pending list but has not added to the
-	 * work list. It will be cleaned up by the interrupt handler when it sees the
-	 * IDXD_COMP_DESC_ABORT for completion status.
-	 */
 	return NULL;
 }
 
 static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,
-			     struct idxd_desc *desc)
+			     struct idxd_desc *desc, bool submitter_cleans)
 {
 	struct idxd_desc *d, *t, *found = NULL;
 	struct llist_node *head;
-	LIST_HEAD(flist);
+	bool wake = false;
 
-	desc->completion->status = IDXD_COMP_DESC_ABORT;
 	/*
 	 * Grab the list lock so it will block the irq thread handler. This allows the
 	 * abort code to locate the descriptor need to be aborted.
@@ -115,10 +131,19 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,
 				continue;
 			}
 
+			/*
+			 * A completion runs a client's callback or another
+			 * driver's handler, and either may submit or terminate
+			 * and so wait for a killer, which waits for this
+			 * submitter's wq_active reference. iaa_crypto's verify
+			 * of a compression may also wait for a free descriptor
+			 * while this submitter holds one. A finished
+			 * descriptor therefore goes on the work list for the
+			 * interrupt thread, as one still in flight does.
+			 */
 			if (d->completion->status)
-				list_add_tail(&d->list, &flist);
-			else
-				list_add_tail(&d->list, &ie->work_list);
+				wake = true;
+			list_add_tail(&d->list, &ie->work_list);
 		}
 	}
 
@@ -126,19 +151,45 @@ static void llist_abort_desc(struct idxd_wq *wq, struct idxd_irq_entry *ie,
 		found = list_abort_desc(wq, ie, desc);
 	spin_unlock(&ie->list_lock);
 
-	if (found)
-		idxd_dma_complete_txd(found, IDXD_COMPLETE_ABORT, false,
-				      NULL, NULL);
+	/*
+	 * Their interrupts may have run the thread before they reached the
+	 * work list, so it is woken again.
+	 */
+	if (wake)
+		irq_wake_thread(ie->vector, ie);
 
 	/*
-	 * completing the descriptor will return desc to allocator and
-	 * the desc can be acquired by a different process and the
-	 * desc->list can be modified.  Delete desc from list so the
-	 * list traversing does not get corrupted by the other process.
+	 * The device never took the descriptor, so its record is still
+	 * clear. While this submitter holds wq_active, only the interrupt
+	 * thread and another submitter's abort may take descriptors off
+	 * the lists, and both sort them under the list lock and leave one
+	 * with a clear record on a list. A flush takes them all, so every
+	 * flusher must kill wq_active and wait for this reference before
+	 * it takes the lists, and nothing may revive the reference before
+	 * the flush runs. The error path of iaa_crypto_probe() breaks the
+	 * rule: it disables a queue it has already published without a
+	 * quiesce. Otherwise the search finds the descriptor, and once off
+	 * the lists it is the submitter's alone. Marking it aborted before
+	 * that would let another context that saw the mark on a list
+	 * complete and free it, and the caller frees it as well.
+	 */
+	WARN_ON_ONCE(!found);
+	/*
+	 * When the failing submission is a client's tx_submit(), the
+	 * client learns of it from the return value and owns the cleanup,
+	 * and a callback on top of that would complete the descriptor
+	 * twice. A dmaengine descriptor then only has its cookie completed
+	 * and its unmap data released here, with the callbacks stripped.
+	 * Nothing reads its record before the caller frees it, so it is
+	 * not marked. An internal resubmission reports the abort through
+	 * the callback, which its worker runs once the submit has dropped
+	 * its reference. Another driver's submitter cleans up all of its
+	 * own, and only dmaengine descriptors are resubmitted.
 	 */
-	list_for_each_entry_safe(d, t, &flist, list) {
-		list_del_init(&d->list);
-		idxd_dma_complete_txd(d, IDXD_COMPLETE_ABORT, true,
+	if (found && submitter_cleans && idxd_wq_has_txd(wq)) {
+		desc->txd.callback = NULL;
+		desc->txd.callback_result = NULL;
+		idxd_dma_complete_txd(desc, IDXD_COMPLETE_ABORT, false,
 				      NULL, NULL);
 	}
 }
@@ -167,7 +218,8 @@ int idxd_enqcmds(struct idxd_wq *wq, void __iomem *portal, const void *desc)
 	return rc;
 }
 
-int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
+static int __idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc,
+			      bool submitter_cleans)
 {
 	struct idxd_device *idxd = wq->idxd;
 	struct idxd_irq_entry *ie = NULL;
@@ -184,6 +236,35 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
 			return -ENXIO;
 	}
 
+	/*
+	 * A software-reset halt revives wq_active before its reinit enables
+	 * the device again. A submitter that passed the check above before
+	 * the halt and got its reference after the revive would post to the
+	 * halted device, which drops the descriptor, and nothing would
+	 * complete an interrupt-armed one. The halt stores the state before
+	 * its kill and revives the reference after the wait. The barrier
+	 * pairs with the release in percpu_ref_reinit() and orders this
+	 * read after the tryget that saw the revive.
+	 */
+	smp_rmb();
+	if (idxd->state != IDXD_DEV_ENABLED) {
+		percpu_ref_put(&wq->wq_active);
+		return -EIO;
+	}
+	/*
+	 * A resubmission of a descriptor first submitted before a
+	 * terminate_all is cancelled. The terminate bumps the generation
+	 * before its kill, so the barrier above orders this read too. A
+	 * resubmission that read the old one is on the pending list when
+	 * the terminate's flush runs, since the kill waits for it, or has
+	 * failed with its stamp unchanged.
+	 */
+	if (!submitter_cleans &&
+	    desc->terminate_gen != READ_ONCE(wq->terminate_gen)) {
+		percpu_ref_put(&wq->wq_active);
+		return -ECANCELED;
+	}
+
 	portal = idxd_wq_portal_addr(wq);
 
 	/*
@@ -193,6 +274,12 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
 	if (desc_flags & IDXD_OP_FLAG_RCI) {
 		ie = &wq->ie;
 		desc->hw->int_handle = ie->int_handle;
+		/*
+		 * A resubmission keeps the stamp of the client's submit, so
+		 * the resubmit work sees every terminate since then.
+		 */
+		if (submitter_cleans)
+			desc->terminate_gen = READ_ONCE(wq->terminate_gen);
 		llist_add(&desc->llnode, &ie->pending_llist);
 	}
 
@@ -208,10 +295,18 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
 	} else {
 		rc = idxd_enqcmds(wq, portal, desc->hw);
 		if (rc < 0) {
-			percpu_ref_put(&wq->wq_active);
-			/* abort operation frees the descriptor */
+			/*
+			 * Abort before dropping the reference: a halt flush
+			 * waits for wq_active to die before it takes the
+			 * pending descriptors, and this one must not still be
+			 * listed when it does. The abort takes the descriptor
+			 * off the lists and runs no callback, which could wait
+			 * for this reference to die. The caller completes or
+			 * frees the descriptor.
+			 */
 			if (ie)
-				llist_abort_desc(wq, ie, desc);
+				llist_abort_desc(wq, ie, desc, submitter_cleans);
+			percpu_ref_put(&wq->wq_active);
 			return rc;
 		}
 	}
@@ -219,4 +314,15 @@ int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
 	percpu_ref_put(&wq->wq_active);
 	return 0;
 }
+/* A client submission: on failure the return value is the notification. */
+int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
+{
+	return __idxd_submit_desc(wq, desc, true);
+}
 EXPORT_SYMBOL_NS_GPL(idxd_submit_desc, "IDXD");
+
+/* The driver's own resubmission: a failure must still call the client back. */
+int idxd_resubmit_desc(struct idxd_wq *wq, struct idxd_desc *desc)
+{
+	return __idxd_submit_desc(wq, desc, false);
+}
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index fe33a20abc614..4178248611d9d 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1751,6 +1751,8 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
 int dma_async_device_register(struct dma_device *device);
 int dmaenginem_async_device_register(struct dma_device *device);
 void dma_async_device_unregister(struct dma_device *device);
+int dma_async_device_channel_add(struct dma_device *device,
+				 struct dma_chan *chan, const char *name);
 int dma_async_device_channel_register(struct dma_device *device,
 				      struct dma_chan *chan,
 				      const char *name);

3/2 2026/10/20 19:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30843
							output: 24
							thoughts: 658
						

Thoughts:
**Analyzing the Kernel Patch for Fuzzing Suitability**

Okay, so I need to assess this Linux kernel patch series. My initial thought is to dive right in and understand the scope. First, let's see where the changes are being made. It looks like this touches `drivers/dma/dmaengine.c`, `include/linux/dmaengine.h`, and, significantly, the `drivers/dma/idxd/*` directory. Hmm, `idxd`... that rings a bell. It's the Intel Data Accelerator Driver, related to Intel's DSA/IAA hardware, right?

The specific addition of `dma_async_device_channel_add` is the key. It looks like it adds a `dma_async_device_channel_add` function. Looks like `WARN_ON_ONCE` is being called. It also appears to add a device channel using a mutex and `list_add_tail`.

Now, the crucial question: is `idxd` hardware-specific? Does QEMU even emulate this thing? Can it be reached in a virtual environment, through software emulation, or, at the very least, a mock? My understanding of fuzzing is that it only works on code that *can* actually be reached in standard virtualization. We need to know if we can hit it in GCE or QEMU using emulated devices. I need to make sure this code is not structurally unreachable, given the prompt's explicit warnings about vendor-specific PCIe devices and the like. We need to keep in mind the explicit warning about vendor-specific PCIe switches, SmartNICs, or GPU drivers. Things like `mlxsw`, `pds_core`, `qed`, `ionic`, or `amdgpu` are examples. The prompt seems to say that these drivers will require physical cards, and are not to be fuzzed.

So, digging deeper, specifically `dma_async_device_channel_add` is the important bit. A quick look in the code reveals it's being called in `drivers/dma/idxd/dma.c`. But is it used elsewhere? Let's check with `grepper`. I need to be 100% sure we can reach the call path. If this is truly hardware-dependent and not emulatable, this whole thing's a no-go for fuzzing.



4/2 2026/10/20 19:04 tool grepper
0m Args:
{
  "Expression": "dma_async_device_channel_add"
}

Results:
{
  "Output": "drivers/dma/dmaengine.c=1156=EXPORT_SYMBOL_GPL(dma_async_device_channel_register);\n--\ndrivers/dma/dmaengine.c-1158-/**\ndrivers/dma/dmaengine.c:1159: * dma_async_device_channel_add - register a channel and make it available\ndrivers/dma/dmaengine.c-1160- * @device: the dmaengine device, DMA_PRIVATE and registered already\n--\ndrivers/dma/dmaengine.c-1178- */\ndrivers/dma/dmaengine.c:1179:int dma_async_device_channel_add(struct dma_device *device,\ndrivers/dma/dmaengine.c-1180-\t\t\t\t struct dma_chan *chan, const char *name)\n--\ndrivers/dma/dmaengine.c-1196-}\ndrivers/dma/dmaengine.c:1197:EXPORT_SYMBOL_GPL(dma_async_device_channel_add);\ndrivers/dma/dmaengine.c-1198-\n--\ndrivers/dma/idxd/dma.c=308=static int idxd_register_dma_channel(struct idxd_wq *wq)\n--\ndrivers/dma/idxd/dma.c-338-\t */\ndrivers/dma/idxd/dma.c:339:\trc = dma_async_device_channel_add(dma, chan, NULL);\ndrivers/dma/idxd/dma.c-340-\tif (rc \u003c 0) {\n--\ninclude/linux/dmaengine.h=1753=void dma_async_device_unregister(struct dma_device *device);\ninclude/linux/dmaengine.h:1754:int dma_async_device_channel_add(struct dma_device *device,\ninclude/linux/dmaengine.h-1755-\t\t\t\t struct dma_chan *chan, const char *name);\n"
}

5/2 2026/10/20 19:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32558
							output: 21
							thoughts: 107
						

Thoughts:
**Investigating the `dma_async_device_channel_add` Function and its Context**

Okay, so where are we? I've got `dma_async_device_channel_add` on the radar. The important thing here is that it looks like it's only called by `idxd_register_dma_channel`, and that's found in `drivers/dma/idxd/dma.c`. Hmm, right. This points directly to the Intel DMA device, so the next step is pretty clear: I need to dig deeper into what `idxd` actually *is*. What's the underlying hardware it expects? Is this something that can be emulated, or is there a software representation or even a test driver floating around somewhere? I can't just dive in without understanding the hardware dependencies. I need to be efficient and work out if I'm even going to be able to test this. Time to get familiar with `idxd` and work out what's going on! The tree search will start now. Let's see if this is something I can quickly find within the kernel sources or in QEMU.



6/2 2026/10/20 19:04 tool grepper
0m Args:
{
  "Expression": "CONFIG_INTEL_IDXD"
}

Results:
{
  "Output": "Documentation/driver-api/crypto/iaa/iaa-crypto.rst=63=The following config options should also be enabled::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-70-  CONFIG_PCI_PASID=y\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:71:  CONFIG_INTEL_IDXD=m\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:72:  CONFIG_INTEL_IDXD_SVM=y\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-73-\n--\ndrivers/dma/idxd/Makefile=1=ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE='\"IDXD\"'\ndrivers/dma/idxd/Makefile-2-\ndrivers/dma/idxd/Makefile:3:obj-$(CONFIG_INTEL_IDXD_BUS) += idxd_bus.o\ndrivers/dma/idxd/Makefile-4-idxd_bus-y := bus.o\ndrivers/dma/idxd/Makefile-5-\ndrivers/dma/idxd/Makefile:6:obj-$(CONFIG_INTEL_IDXD) += idxd.o\ndrivers/dma/idxd/Makefile-7-idxd-y := init.o irq.o device.o sysfs.o submit.o dma.o cdev.o debugfs.o defaults.o\ndrivers/dma/idxd/Makefile-8-\ndrivers/dma/idxd/Makefile:9:idxd-$(CONFIG_INTEL_IDXD_PERFMON) += perfmon.o\ndrivers/dma/idxd/Makefile-10-\ndrivers/dma/idxd/Makefile:11:obj-$(CONFIG_INTEL_IDXD_COMPAT) += idxd_compat.o\ndrivers/dma/idxd/Makefile-12-idxd_compat-y := compat.o\n--\ndrivers/dma/idxd/idxd.h=868=void idxd_user_counter_increment(struct idxd_wq *wq, u32 pasid, int index);\n--\ndrivers/dma/idxd/idxd.h-870-/* perfmon */\ndrivers/dma/idxd/idxd.h:871:#if IS_ENABLED(CONFIG_INTEL_IDXD_PERFMON)\ndrivers/dma/idxd/idxd.h-872-int perfmon_pmu_init(struct idxd_device *idxd);\n--\ndrivers/dma/idxd/init.c=694=static int idxd_probe(struct idxd_device *idxd)\n--\ndrivers/dma/idxd/init.c-706-\ndrivers/dma/idxd/init.c:707:\tif (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) \u0026\u0026 sva) {\ndrivers/dma/idxd/init.c-708-\t\tset_bit(IDXD_FLAG_USER_PASID_ENABLED, \u0026idxd-\u003eflags);\n"
}

7/2 2026/10/20 19:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33682
							output: 36
							thoughts: 16
						

Thoughts:
Here's my take on those thoughts, tailored for an expert audience:

**Diving into the IDXD Kconfig**

Alright, let's get down to brass tacks. I'm thinking, "Okay, where are we with this IDXD integration?" My immediate instinct is to jump into `drivers/dma/idxd/Kconfig`. That's where all the fundamental configuration options for the IDXD driver should reside. I need to understand what's exposed to the user, what dependencies are in play, and how the various features are enabled or disabled. This Kconfig file will be the Rosetta Stone, mapping the high-level needs to the low-level implementation. I need to quickly grasp the configurable aspects to assess the current state and potential gaps or issues that need attention. This is where the core building blocks are defined. This is my starting point, before going deeper.



8/2 2026/10/20 19:04 tool read-file
0m Error:
the file does not exist

Args:
{
  "File": "drivers/dma/idxd/Kconfig",
  "FirstLine": 1,
  "LineCount": 60
}

Results:
{
  "error": "the file does not exist"
}

9/2 2026/10/20 19:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33938
							output: 20
							thoughts: 13
						

Thoughts:
Here's a summary of my thought process, as requested:

**Locating the INTEL_IDXD Definition**

Okay, so I need to track down exactly where `INTEL_IDXD` is defined. This is a common first step, especially when dealing with low-level hardware or driver code.  My initial instinct is to use the standard tools; `grep` and a targeted search across relevant source files will be the first approach. I'll need to remember any potential variations on the name (e.g., case sensitivity issues or alternative naming conventions that might be used). I'll also consider if it's likely to be in a header file, a configuration file, or perhaps defined as a macro in the build system. This tells me about how the IDXD hardware is exposed by the OS. Then if it is indeed in the OS, I will look to understand the OS version and kernel. If the OS version is very old I will attempt to determine if the definition is in older hardware configuration files. This level of detail in the OS/Hardware configuration may be important to know the exact features available to the processor.



10/2 2026/10/20 19:04 tool grepper
0m Args:
{
  "Expression": "config INTEL_IDXD"
}

Results:
{
  "Output": "drivers/dma/Kconfig=289=config INTEL_IDMA64\n--\ndrivers/dma/Kconfig-297-\ndrivers/dma/Kconfig:298:config INTEL_IDXD_BUS\ndrivers/dma/Kconfig-299-\ttristate\n--\ndrivers/dma/Kconfig-301-\ndrivers/dma/Kconfig:302:config INTEL_IDXD\ndrivers/dma/Kconfig-303-\ttristate \"Intel Data Accelerators support\"\n--\ndrivers/dma/Kconfig-316-\ndrivers/dma/Kconfig:317:config INTEL_IDXD_COMPAT\ndrivers/dma/Kconfig-318-\tbool \"Legacy behavior for idxd driver\"\n--\ndrivers/dma/Kconfig-335-# support shared virtual memory for the devices supported by idxd.\ndrivers/dma/Kconfig:336:config INTEL_IDXD_SVM\ndrivers/dma/Kconfig-337-\tbool \"Accelerator Shared Virtual Memory Support\"\n--\ndrivers/dma/Kconfig-343-\ndrivers/dma/Kconfig:344:config INTEL_IDXD_PERFMON\ndrivers/dma/Kconfig-345-\tbool \"Intel Data Accelerators performance monitor support\"\n"
}

11/2 2026/10/20 19:04 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34542
							output: 35
							thoughts: 20
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Analyzing the DMA Kconfig File**

Alright, time to dive into the kernel source. Based on what I've been working on, my gut feeling is that something related to DMA configuration might be at play. Let's start by zeroing in on the `drivers/dma/Kconfig` file around line 298. My assumption is that within that section, there's likely to be a relevant configuration option, perhaps related to a specific DMA controller, a feature flag, or some dependency that's currently causing an issue or giving me grief. It’s the usual process when tracking down kernel configuration bugs, right? Identify the likely area, then zoom in on the relevant Kconfig options and their dependencies. This is where the magic happens.



12/2 2026/10/20 19:05 tool read-file
0m Args:
{
  "File": "drivers/dma/Kconfig",
  "FirstLine": 298,
  "LineCount": 55
}

Results:
{
  "Contents": " 298:\tconfig INTEL_IDXD_BUS\n 299:\t\ttristate\n 300:\t\tdefault INTEL_IDXD\n 301:\t\n 302:\tconfig INTEL_IDXD\n 303:\t\ttristate \"Intel Data Accelerators support\"\n 304:\t\tdepends on PCI \u0026\u0026 X86_64 \u0026\u0026 !UML\n 305:\t\tdepends on PCI_MSI\n 306:\t\tdepends on PCI_PASID\n 307:\t\tdepends on SBITMAP\n 308:\t\tselect DMA_ENGINE\n 309:\t\thelp\n 310:\t\t  Enable support for the Intel(R) data accelerators present\n 311:\t\t  in Intel Xeon CPU.\n 312:\t\n 313:\t\t  Say Y if you have such a platform.\n 314:\t\n 315:\t\t  If unsure, say N.\n 316:\t\n 317:\tconfig INTEL_IDXD_COMPAT\n 318:\t\tbool \"Legacy behavior for idxd driver\"\n 319:\t\tdepends on PCI \u0026\u0026 X86_64\n 320:\t\tselect INTEL_IDXD_BUS\n 321:\t\thelp\n 322:\t\t  Compatible driver to support old /sys/bus/dsa/drivers/dsa behavior.\n 323:\t\t  The old behavior performed driver bind/unbind for device and wq\n 324:\t\t  devices all under the dsa driver. The compat driver will emulate\n 325:\t\t  the legacy behavior in order to allow existing support apps (i.e.\n 326:\t\t  accel-config) to continue function. It is expected that accel-config\n 327:\t\t  v3.2 and earlier will need the compat mode. A distro with later\n 328:\t\t  accel-config version can disable this compat config.\n 329:\t\n 330:\t\t  Say Y if you have old applications that require such behavior.\n 331:\t\n 332:\t\t  If unsure, say N.\n 333:\t\n 334:\t# Config symbol that collects all the dependencies that's necessary to\n 335:\t# support shared virtual memory for the devices supported by idxd.\n 336:\tconfig INTEL_IDXD_SVM\n 337:\t\tbool \"Accelerator Shared Virtual Memory Support\"\n 338:\t\tdepends on INTEL_IDXD\n 339:\t\tdepends on INTEL_IOMMU_SVM\n 340:\t\tdepends on PCI_PRI\n 341:\t\tdepends on PCI_PASID\n 342:\t\tdepends on PCI_IOV\n 343:\t\n 344:\tconfig INTEL_IDXD_PERFMON\n 345:\t\tbool \"Intel Data Accelerators performance monitor support\"\n 346:\t\tdepends on INTEL_IDXD\n 347:\t\thelp\n 348:\t\t  Enable performance monitor (pmu) support for the Intel(R)\n 349:\t\t  data accelerators present in Intel Xeon CPU.  With this\n 350:\t\t  enabled, perf can be used to monitor the DSA (Intel Data\n 351:\t\t  Streaming Accelerator) events described in the Intel DSA\n 352:\t\t  spec.\n"
}

13/2 2026/10/20 19:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35607
							output: 36
							thoughts: 38
						

Thoughts:
Okay, let's dive into this. Here's my thought process on the matter:

**Analyzing INTEL_IDXD Device Probe Behavior**

Right, so I need to figure out what devices the `INTEL_IDXD` driver is actually probing. Where would that information be defined? The logical place to start is the driver's initialization code. I need to look for that `pci_device_id` structure. That's usually where you find the PCI ID table used to match devices. So, let's head over to `drivers/dma/idxd/init.c`. That should contain the relevant information. I expect to find a list of PCI device IDs that the driver recognizes and binds to. This is where the magic happens; this is where the driver knows which hardware it's supposed to handle. Let's see what's in there.



14/2 2026/10/20 19:05 tool grepper
0m Args:
{
  "Expression": "idxd_pci_tbl",
  "PathPrefixes": [
    "drivers/dma/idxd/"
  ]
}

Results:
{
  "Output": "drivers/dma/idxd/init.c=43=static struct idxd_driver_data idxd_driver_data[] = {\n--\ndrivers/dma/idxd/init.c-68-\ndrivers/dma/idxd/init.c:69:static struct pci_device_id idxd_pci_tbl[] = {\ndrivers/dma/idxd/init.c-70-\t/* DSA ver 1.0 platforms */\n--\ndrivers/dma/idxd/init.c-86-};\ndrivers/dma/idxd/init.c:87:MODULE_DEVICE_TABLE(pci, idxd_pci_tbl);\ndrivers/dma/idxd/init.c-88-\n--\ndrivers/dma/idxd/init.c=1341=static struct pci_driver idxd_pci_driver = {\ndrivers/dma/idxd/init.c-1342-\t.name\t\t= DRV_NAME,\ndrivers/dma/idxd/init.c:1343:\t.id_table\t= idxd_pci_tbl,\ndrivers/dma/idxd/init.c-1344-\t.probe\t\t= idxd_pci_probe,\n"
}

15/2 2026/10/20 19:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36185
							output: 38
							thoughts: 16
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of some PCI driver work:

**Investigating the `idxd_pci_tbl`**

Alright, time to get my hands dirty. I need to take a look at the `idxd_pci_tbl`. It's likely a critical data structure, probably a table of some kind, that holds the specifics of how the driver is interacting with the PCI devices associated with the Intel Data Accelerator devices. This table is where the magic (or the problems!) are usually found. I need to understand its contents to figure out how the driver is handling device enumeration, resource allocation, interrupt routing, and ultimately, how it's talking to the hardware. I’m thinking there will be entries relating to the PCI bus, device, and function numbers, vendor and device IDs, perhaps BAR assignments, and potentially some pointers to device-specific data. Knowing this table's layout is essential to debugging, optimization, or even just understanding the flow of the code. This is the jumping-off point for digging deeper. Let's see what's in there.



16/2 2026/10/20 19:05 tool read-file
0m Args:
{
  "File": "drivers/dma/idxd/init.c",
  "FirstLine": 69,
  "LineCount": 20
}

Results:
{
  "Contents": "  69:\tstatic struct pci_device_id idxd_pci_tbl[] = {\n  70:\t\t/* DSA ver 1.0 platforms */\n  71:\t\t{ PCI_DEVICE_DATA(INTEL, DSA_SPR0, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\n  72:\t\t/* DSA on GNR-D platforms */\n  73:\t\t{ PCI_DEVICE_DATA(INTEL, DSA_GNRD, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\n  74:\t\t/* DSA on DMR platforms */\n  75:\t\t{ PCI_DEVICE_DATA(INTEL, DSA_DMR, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\n  76:\t\n  77:\t\t/* IAX ver 1.0 platforms */\n  78:\t\t{ PCI_DEVICE_DATA(INTEL, IAX_SPR0, \u0026idxd_driver_data[IDXD_TYPE_IAX]) },\n  79:\t\t/* IAA on DMR platforms */\n  80:\t\t{ PCI_DEVICE_DATA(INTEL, IAA_DMR, \u0026idxd_driver_data[IDXD_TYPE_IAX]) },\n  81:\t\t/* IAA PTL platforms */\n  82:\t\t{ PCI_DEVICE_DATA(INTEL, IAA_PTL, \u0026idxd_driver_data[IDXD_TYPE_IAX]) },\n  83:\t\t/* IAA WCL platforms */\n  84:\t\t{ PCI_DEVICE_DATA(INTEL, IAA_WCL, \u0026idxd_driver_data[IDXD_TYPE_IAX]) },\n  85:\t\t{ 0, }\n  86:\t};\n  87:\tMODULE_DEVICE_TABLE(pci, idxd_pci_tbl);\n  88:\t\n"
}

17/2 2026/10/20 19:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36928
							output: 20
							thoughts: 96
						

Thoughts:
**Investigating Intel DSA/IAA Emulation**

Okay, so `idxd`... that's the Intel DSA/IAA PCIe driver. It's specifically for those Xeon and Core platforms, like Sapphire Rapids (DSA_SPR0) and Granite Rapids (GNR-D). Hmm, interesting. Now, the question that pops into my head is: Does QEMU actually *emulate* these Intel DSA/IAA devices? Or is it just a pass-through situation? I need to clarify this before I go any further.

Right, so before I get too deep, I should check whether there's any emulation support at all. Are there any dummy drivers, mock drivers, or even virtual hardware available for DSA/IAA in the first place? To get a clear answer, I'll need to dig into the kernel source tree, and look for any clues. I'll search for things like "DSA test," "IDXD mock," or "IAA emulation." That should give me a good starting point.



18/2 2026/10/20 19:05 tool grepper
0m Args:
{
  "Expression": "IDXD_TYPE_DSA"
}

Results:
{
  "Output": "drivers/dma/idxd/device.c=113=int idxd_wq_alloc_resources(struct idxd_wq *wq)\n--\ndrivers/dma/idxd/device.c-151-\t\tdesc-\u003ehw = wq-\u003ehw_descs[i];\ndrivers/dma/idxd/device.c:152:\t\tif (idxd-\u003edata-\u003etype == IDXD_TYPE_DSA)\ndrivers/dma/idxd/device.c-153-\t\t\tdesc-\u003ecompletion = \u0026wq-\u003ecompls[i];\n--\ndrivers/dma/idxd/idxd.h=47=enum idxd_type {\ndrivers/dma/idxd/idxd.h-48-\tIDXD_TYPE_UNKNOWN = -1,\ndrivers/dma/idxd/idxd.h:49:\tIDXD_TYPE_DSA = 0,\ndrivers/dma/idxd/idxd.h-50-\tIDXD_TYPE_IAX,\n--\ndrivers/dma/idxd/idxd.h=718=static bool idxd_sgl_supported(struct idxd_device *idxd)\ndrivers/dma/idxd/idxd.h-719-{\ndrivers/dma/idxd/idxd.h:720:\treturn idxd-\u003edata-\u003etype == IDXD_TYPE_DSA \u0026\u0026\ndrivers/dma/idxd/idxd.h-721-\t       idxd-\u003ehw.version \u003e= DEVICE_VERSION_3 \u0026\u0026\n--\ndrivers/dma/idxd/init.c=43=static struct idxd_driver_data idxd_driver_data[] = {\ndrivers/dma/idxd/init.c:44:\t[IDXD_TYPE_DSA] = {\ndrivers/dma/idxd/init.c-45-\t\t.name_prefix = \"dsa\",\ndrivers/dma/idxd/init.c:46:\t\t.type = IDXD_TYPE_DSA,\ndrivers/dma/idxd/init.c-47-\t\t.compl_size = sizeof(struct dsa_completion_record),\n--\ndrivers/dma/idxd/init.c=69=static struct pci_device_id idxd_pci_tbl[] = {\ndrivers/dma/idxd/init.c-70-\t/* DSA ver 1.0 platforms */\ndrivers/dma/idxd/init.c:71:\t{ PCI_DEVICE_DATA(INTEL, DSA_SPR0, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\ndrivers/dma/idxd/init.c-72-\t/* DSA on GNR-D platforms */\ndrivers/dma/idxd/init.c:73:\t{ PCI_DEVICE_DATA(INTEL, DSA_GNRD, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\ndrivers/dma/idxd/init.c-74-\t/* DSA on DMR platforms */\ndrivers/dma/idxd/init.c:75:\t{ PCI_DEVICE_DATA(INTEL, DSA_DMR, \u0026idxd_driver_data[IDXD_TYPE_DSA]) },\ndrivers/dma/idxd/init.c-76-\n--\ndrivers/dma/idxd/perfmon.c=474=int perfmon_pmu_init(struct idxd_device *idxd)\n--\ndrivers/dma/idxd/perfmon.c-493-\ndrivers/dma/idxd/perfmon.c:494:\tif (idxd-\u003edata-\u003etype == IDXD_TYPE_DSA) {\ndrivers/dma/idxd/perfmon.c-495-\t\trc = sprintf(idxd_pmu-\u003ename, \"dsa%d\", idxd-\u003eid);\n--\ndrivers/dma/idxd/sysfs.c=1765=static bool idxd_device_attr_dsacaps_invisible(struct attribute *attr,\n--\ndrivers/dma/idxd/sysfs.c-1768-\treturn attr == \u0026dev_attr_dsacaps.attr \u0026\u0026\ndrivers/dma/idxd/sysfs.c:1769:\t\t(idxd-\u003edata-\u003etype != IDXD_TYPE_DSA ||\ndrivers/dma/idxd/sysfs.c-1770-\t\tidxd-\u003ehw.version \u003c DEVICE_VERSION_3);\n"
}

19/2 2026/10/20 19:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38332
							output: 25
							thoughts: 37
						

Thoughts:
Okay, here's my thought process laid out, assuming I'm an expert working with this code:

**Checking IDXD Driver Files**

Alright, before I dive too deep, I need to get a lay of the land. I should first check the `drivers/dma/idxd/` directory. I'm assuming that the `idxd` refers to a specific Direct Memory Access (DMA) controller, so that's where I'd expect to find the relevant driver files. Let me take a quick look to see what's in there. I'll issue a command to list the contents of that directory. This should give me a good starting point for my investigation.



20/2 2026/10/20 19:05 tool codesearch-dir-index
0m Args:
{
  "Dir": "drivers/dma/idxd"
}

Results:
{
  "Files": [
    "bus.c",
    "cdev.c",
    "compat.c",
    "debugfs.c",
    "defaults.c",
    "device.c",
    "dma.c",
    "idxd.h",
    "init.c",
    "irq.c",
    "perfmon.c",
    "perfmon.h",
    "registers.h",
    "submit.c",
    "sysfs.c"
  ],
  "Subdirs": null
}

21/2 2026/10/20 19:05 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38650
							output: 24
							thoughts: 346
						

Thoughts:
**Investigating the DMA Driver Change**

Okay, hold on a second. I need to circle back and really dig into that change in `drivers/dma/dmaengine.c`. Specifically, I'm concerned about the impact of modifications around `dma_async_device_channel_add`. Let's take a closer look at that function, shall we?

```c
int dma_async_device_channel_add(struct dma_device *device,
				 struct dma_chan *chan, const char *name)
{
	int rc;

	if (WARN_ON_ONCE(!dma_has_cap(DMA_PRIVATE, device->cap_mask)))
		return -EINVAL;

	rc = __dma_async_device_channel_register(device, chan, name);
	if (rc < 0)
		return rc;

	mutex_lock(&dma_list_mutex);
	list_add_tail(&chan->device_node, &device->channels);
	dma_channel_rebalance();
	mutex_unlock(&dma_list_mutex);
	return 0;
}
EXPORT_SYMBOL_GPL(dma_async_device_channel_add);
```

Right, the key question is: is this function, `dma_async_device_channel_add`, used *exclusively* by the `idxd` driver, or are there other parts of the kernel that might be calling it?  We know `idxd` calls it, but that doesn't tell the whole story. Let's do a quick search and see if this function is used anywhere else.

Hmm, okay, after a quick check, it looks like ONLY `drivers/dma/idxd/dma.c` calls it. But we should be thorough.

Hang on. Just because we didn't *find* it doesn't mean it's not possible that other drivers might *also* use it, and we might have missed something. Let's trace back. I need to investigate `dma_async_device_channel_register` and how channel registration was handled before the change, just to be sure. I'm going to scan the code for usage of *that* function, and see if there are any subtle or indirect uses that could be relevant. Just need to be sure...



22/2 2026/10/20 19:06 tool grepper
0m Args:
{
  "Expression": "dma_async_device_channel_register"
}

Results:
{
  "Output": "drivers/dma/dmaengine.c=1078=static int get_dma_id(struct dma_device *device)\n--\ndrivers/dma/dmaengine.c-1087-\ndrivers/dma/dmaengine.c:1088:static int __dma_async_device_channel_register(struct dma_device *device,\ndrivers/dma/dmaengine.c-1089-\t\t\t\t\t       struct dma_chan *chan,\n--\ndrivers/dma/dmaengine.c-1142-\ndrivers/dma/dmaengine.c:1143:int dma_async_device_channel_register(struct dma_device *device,\ndrivers/dma/dmaengine.c-1144-\t\t\t\t      struct dma_chan *chan,\n--\ndrivers/dma/dmaengine.c-1148-\ndrivers/dma/dmaengine.c:1149:\trc = __dma_async_device_channel_register(device, chan, name);\ndrivers/dma/dmaengine.c-1150-\tif (rc \u003c 0)\n--\ndrivers/dma/dmaengine.c-1155-}\ndrivers/dma/dmaengine.c:1156:EXPORT_SYMBOL_GPL(dma_async_device_channel_register);\ndrivers/dma/dmaengine.c-1157-\n--\ndrivers/dma/dmaengine.c=1179=int dma_async_device_channel_add(struct dma_device *device,\n--\ndrivers/dma/dmaengine.c-1186-\ndrivers/dma/dmaengine.c:1187:\trc = __dma_async_device_channel_register(device, chan, name);\ndrivers/dma/dmaengine.c-1188-\tif (rc \u003c 0)\n--\ndrivers/dma/dmaengine.c=1233=int dma_async_device_register(struct dma_device *device)\n--\ndrivers/dma/dmaengine.c-1301-\tlist_for_each_entry(chan, \u0026device-\u003echannels, device_node) {\ndrivers/dma/dmaengine.c:1302:\t\trc = __dma_async_device_channel_register(device, chan, NULL);\ndrivers/dma/dmaengine.c-1303-\t\tif (rc \u003c 0)\n--\ndrivers/dma/stm32/stm32-dma3.c=1729=static int stm32_dma3_probe(struct platform_device *pdev)\n--\ndrivers/dma/stm32/stm32-dma3.c-1882-\ndrivers/dma/stm32/stm32-dma3.c:1883:\t\tret = dma_async_device_channel_register(\u0026ddata-\u003edma_dev, \u0026chan-\u003evchan.chan, name);\ndrivers/dma/stm32/stm32-dma3.c-1884-\t\tif (ret) {\n--\ninclude/linux/dmaengine.h=1754=int dma_async_device_channel_add(struct dma_device *device,\ninclude/linux/dmaengine.h-1755-\t\t\t\t struct dma_chan *chan, const char *name);\ninclude/linux/dmaengine.h:1756:int dma_async_device_channel_register(struct dma_device *device,\ninclude/linux/dmaengine.h-1757-\t\t\t\t      struct dma_chan *chan,\n"
}

23/2 2026/10/20 19:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40460
							output: 33
							thoughts: 215
						

Thoughts:
**Investigating IDXD and QEMU Emulation**

Okay, hold on a second. I need to figure out if I can even *probe* or load an `idxd` device within QEMU. My initial hunch is that standard QEMU might not handle Intel DSA or IAA. I should probably clarify: Does the vanilla QEMU I'm working with have any DSA emulation baked in, or is this something that requires real hardware?

Let's dive into some research. I'll hit up online resources, the kernel documentation, and my QEMU knowledge base. Ah, right – DSA (Data Streaming Accelerator) is a PCI device, typically found on Sapphire Rapids platforms, with those device IDs like 0x0b25.

So, the next question: does QEMU, in its standard form, offer any emulation for `intel-dsa`? Based on my previous experience I can say, no, standard QEMU doesn't do DSA emulation. I vaguely recall some experimental patches or perhaps user-space simulators existing, but neither the standard build of QEMU nor Google Compute Engine (GCE) provides DSA or IAA emulation.

Okay, if I can't emulate it directly, can I at least create an `idxd` device somehow? Through `sysfs`, maybe? Or a mock or dummy device? Or perhaps a platform device?

Let's investigate the kernel driver code – specifically, the `drivers/dma/idxd/` directory. I'll search for how devices are created and registered within that driver. I'll grep for things like `idxd_device`, `pci_register_driver`, and any bus creation code in there. That should give me some clues about whether I can inject a virtual `idxd` device into the system.



24/2 2026/10/20 19:06 tool grepper
0m Args:
{
  "Expression": "idxd_device",
  "PathPrefixes": [
    "drivers/dma/idxd/"
  ]
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 1478 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (15 files in total):\ndrivers/dma/idxd/bus.c:8\ndrivers/dma/idxd/cdev.c:11\ndrivers/dma/idxd/compat.c:1\ndrivers/dma/idxd/debugfs.c:4\ndrivers/dma/idxd/defaults.c:1\ndrivers/dma/idxd/device.c:82\ndrivers/dma/idxd/dma.c:7\ndrivers/dma/idxd/idxd.h:69\ndrivers/dma/idxd/init.c:37\ndrivers/dma/idxd/irq.c:22\ndrivers/dma/idxd/perfmon.c:17\ndrivers/dma/idxd/perfmon.h:2\ndrivers/dma/idxd/registers.h:2\ndrivers/dma/idxd/submit.c:3\ndrivers/dma/idxd/sysfs.c:81\n\ndrivers/dma/idxd/bus.c-9-\ndrivers/dma/idxd/bus.c:10:int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,\ndrivers/dma/idxd/bus.c-11-\t\t\t   const char *mod_name)\n--\ndrivers/dma/idxd/bus.c=27=EXPORT_SYMBOL_GPL(__idxd_driver_register);\ndrivers/dma/idxd/bus.c-28-\ndrivers/dma/idxd/bus.c:29:void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)\ndrivers/dma/idxd/bus.c-30-{\n--\ndrivers/dma/idxd/bus.c=35=static int idxd_config_bus_match(struct device *dev,\n--\ndrivers/dma/idxd/bus.c-37-{\ndrivers/dma/idxd/bus.c:38:\tconst struct idxd_device_driver *idxd_drv =\ndrivers/dma/idxd/bus.c:39:\t\tcontainer_of_const(drv, struct idxd_device_driver, drv);\ndrivers/dma/idxd/bus.c-40-\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n--\ndrivers/dma/idxd/bus.c=52=static int idxd_config_bus_probe(struct device *dev)\ndrivers/dma/idxd/bus.c-53-{\ndrivers/dma/idxd/bus.c:54:\tstruct idxd_device_driver *idxd_drv =\ndrivers/dma/idxd/bus.c:55:\t\tcontainer_of(dev-\u003edriver, struct idxd_device_driver, drv);\ndrivers/dma/idxd/bus.c-56-\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n--\ndrivers/dma/idxd/bus.c=61=static void idxd_config_bus_remove(struct device *dev)\ndrivers/dma/idxd/bus.c-62-{\ndrivers/dma/idxd/bus.c:63:\tstruct idxd_device_driver *idxd_drv =\ndrivers/dma/idxd/bus.c:64:\t\tcontainer_of(dev-\u003edriver, struct idxd_device_driver, drv);\ndrivers/dma/idxd/bus.c-65-\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n--\ndrivers/dma/idxd/cdev.c=118=static void idxd_file_dev_release(struct device *dev)\n--\ndrivers/dma/idxd/cdev.c-121-\tstruct idxd_wq *wq = ctx-\u003ewq;\ndrivers/dma/idxd/cdev.c:122:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-123-\tint rc, drained = 0;\n--\ndrivers/dma/idxd/cdev.c-128-\tif (wq_shared(wq)) {\ndrivers/dma/idxd/cdev.c:129:\t\tdrained = idxd_device_drain_pasid(idxd, ctx-\u003epasid);\ndrivers/dma/idxd/cdev.c-130-\t} else {\n--\ndrivers/dma/idxd/cdev.c=237=static int idxd_cdev_open(struct inode *inode, struct file *filp)\n--\ndrivers/dma/idxd/cdev.c-239-\tstruct idxd_user_context *ctx;\ndrivers/dma/idxd/cdev.c:240:\tstruct idxd_device *idxd;\ndrivers/dma/idxd/cdev.c-241-\tstruct idxd_wq *wq;\n--\ndrivers/dma/idxd/cdev.c=349=static void idxd_cdev_evl_drain_pasid(struct idxd_wq *wq, u32 pasid)\ndrivers/dma/idxd/cdev.c-350-{\ndrivers/dma/idxd/cdev.c:351:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-352-\tstruct idxd_evl *evl = idxd-\u003eevl;\n--\ndrivers/dma/idxd/cdev.c=379=static int idxd_cdev_release(struct inode *node, struct file *filep)\n--\ndrivers/dma/idxd/cdev.c-382-\tstruct idxd_wq *wq = ctx-\u003ewq;\ndrivers/dma/idxd/cdev.c:383:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-384-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/cdev.c=410=static int idxd_cdev_mmap(struct file *filp, struct vm_area_struct *vma)\n--\ndrivers/dma/idxd/cdev.c-413-\tstruct idxd_wq *wq = ctx-\u003ewq;\ndrivers/dma/idxd/cdev.c:414:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-415-\tstruct pci_dev *pdev = idxd-\u003epdev;\n--\ndrivers/dma/idxd/cdev.c=519=static __poll_t idxd_cdev_poll(struct file *filp,\n--\ndrivers/dma/idxd/cdev.c-523-\tstruct idxd_wq *wq = ctx-\u003ewq;\ndrivers/dma/idxd/cdev.c:524:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-525-\t__poll_t out = 0;\n--\ndrivers/dma/idxd/cdev.c=539=static const struct file_operations idxd_cdev_fops = {\n--\ndrivers/dma/idxd/cdev.c-547-\ndrivers/dma/idxd/cdev.c:548:int idxd_cdev_get_major(struct idxd_device *idxd)\ndrivers/dma/idxd/cdev.c-549-{\n--\ndrivers/dma/idxd/cdev.c=553=int idxd_wq_add_cdev(struct idxd_wq *wq)\ndrivers/dma/idxd/cdev.c-554-{\ndrivers/dma/idxd/cdev.c:555:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-556-\tstruct idxd_cdev *idxd_cdev;\n--\ndrivers/dma/idxd/cdev.c=638=static int idxd_user_drv_probe(struct idxd_dev *idxd_dev)\n--\ndrivers/dma/idxd/cdev.c-641-\tstruct idxd_wq *wq = idxd_dev_to_wq(idxd_dev);\ndrivers/dma/idxd/cdev.c:642:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/cdev.c-643-\tint rc;\n--\ndrivers/dma/idxd/cdev.c=716=static enum idxd_dev_type dev_types[] = {\n--\ndrivers/dma/idxd/cdev.c-720-\ndrivers/dma/idxd/cdev.c:721:struct idxd_device_driver idxd_user_drv = {\ndrivers/dma/idxd/cdev.c-722-\t.probe = idxd_user_drv_probe,\n--\ndrivers/dma/idxd/compat.c=105=static enum idxd_dev_type dev_types[] = {\n--\ndrivers/dma/idxd/compat.c-108-\ndrivers/dma/idxd/compat.c:109:struct idxd_device_driver dsa_drv = {\ndrivers/dma/idxd/compat.c-110-\t.name = \"dsa\",\n--\ndrivers/dma/idxd/debugfs.c=13=static struct dentry *idxd_debugfs_dir;\ndrivers/dma/idxd/debugfs.c-14-\ndrivers/dma/idxd/debugfs.c:15:static void dump_event_entry(struct idxd_device *idxd, struct seq_file *s,\ndrivers/dma/idxd/debugfs.c-16-\t\t\t     u16 index, int *count, bool processed)\n--\ndrivers/dma/idxd/debugfs.c=57=static int debugfs_evl_show(struct seq_file *s, void *d)\ndrivers/dma/idxd/debugfs.c-58-{\ndrivers/dma/idxd/debugfs.c:59:\tstruct idxd_device *idxd = s-\u003eprivate;\ndrivers/dma/idxd/debugfs.c-60-\tstruct idxd_evl *evl = idxd-\u003eevl;\n--\ndrivers/dma/idxd/debugfs.c=94=DEFINE_SHOW_ATTRIBUTE(debugfs_evl);\ndrivers/dma/idxd/debugfs.c-95-\ndrivers/dma/idxd/debugfs.c:96:int idxd_device_init_debugfs(struct idxd_device *idxd)\ndrivers/dma/idxd/debugfs.c-97-{\n--\ndrivers/dma/idxd/debugfs.c-118-\ndrivers/dma/idxd/debugfs.c:119:void idxd_device_remove_debugfs(struct idxd_device *idxd)\ndrivers/dma/idxd/debugfs.c-120-{\n--\ndrivers/dma/idxd/defaults.c-5-\ndrivers/dma/idxd/defaults.c:6:int idxd_load_iaa_device_defaults(struct idxd_device *idxd)\ndrivers/dma/idxd/defaults.c-7-{\n--\ndrivers/dma/idxd/device.c-17-\ndrivers/dma/idxd/device.c:18:static void idxd_cmd_exec(struct idxd_device *idxd, int cmd_code, u32 operand,\ndrivers/dma/idxd/device.c-19-\t\t\t  u32 *status);\ndrivers/dma/idxd/device.c:20:static void idxd_device_wqs_clear_state(struct idxd_device *idxd);\ndrivers/dma/idxd/device.c-21-static void idxd_wq_disable_cleanup(struct idxd_wq *wq);\ndrivers/dma/idxd/device.c:22:static inline bool idxd_device_is_halted(struct idxd_device *idxd);\ndrivers/dma/idxd/device.c-23-static int idxd_wq_config_write(struct idxd_wq *wq);\n--\ndrivers/dma/idxd/device.c-25-/* Interrupt control bits */\ndrivers/dma/idxd/device.c:26:void idxd_unmask_error_interrupts(struct idxd_device *idxd)\ndrivers/dma/idxd/device.c-27-{\n--\ndrivers/dma/idxd/device.c-35-\ndrivers/dma/idxd/device.c:36:void idxd_mask_error_interrupts(struct idxd_device *idxd)\ndrivers/dma/idxd/device.c-37-{\n--\ndrivers/dma/idxd/device.c=113=int idxd_wq_alloc_resources(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-114-{\ndrivers/dma/idxd/device.c:115:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-116-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/device.c=197=int idxd_wq_enable(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-198-{\ndrivers/dma/idxd/device.c:199:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-200-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/device.c=222=int idxd_wq_disable(struct idxd_wq *wq, bool reset_config)\ndrivers/dma/idxd/device.c-223-{\ndrivers/dma/idxd/device.c:224:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-225-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/device.c-280- */\ndrivers/dma/idxd/device.c:281:static int idxd_cmd_drain_result(struct idxd_device *idxd, u32 status)\ndrivers/dma/idxd/device.c-282-{\ndrivers/dma/idxd/device.c:283:\tif (status != IDXD_CMDSTS_HW_ERR || idxd_device_is_halted(idxd))\ndrivers/dma/idxd/device.c-284-\t\treturn 0;\n--\ndrivers/dma/idxd/device.c=294=int idxd_wq_drain(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-295-{\ndrivers/dma/idxd/device.c:296:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-297-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/device.c=311=int idxd_wq_reset(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-312-{\ndrivers/dma/idxd/device.c:313:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-314-\tstruct device *dev = \u0026idxd-\u003epdev-\u003edev;\n--\ndrivers/dma/idxd/device.c=340=int idxd_wq_map_portal(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-341-{\ndrivers/dma/idxd/device.c:342:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-343-\tstruct pci_dev *pdev = idxd-\u003epdev;\n--\ndrivers/dma/idxd/device.c=357=void idxd_wq_unmap_portal(struct idxd_wq *wq)\n--\ndrivers/dma/idxd/device.c-365-\ndrivers/dma/idxd/device.c:366:void idxd_wqs_unmap_portal(struct idxd_device *idxd)\ndrivers/dma/idxd/device.c-367-{\n--\ndrivers/dma/idxd/device.c=378=static void __idxd_wq_set_pasid_locked(struct idxd_wq *wq, int pasid)\ndrivers/dma/idxd/device.c-379-{\ndrivers/dma/idxd/device.c:380:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-381-\tunion wqcfg wqcfg;\n--\ndrivers/dma/idxd/device.c=411=int idxd_wq_disable_pasid(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-412-{\ndrivers/dma/idxd/device.c:413:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-414-\tint rc;\n--\ndrivers/dma/idxd/device.c=437=static void idxd_wq_disable_cleanup(struct idxd_wq *wq)\ndrivers/dma/idxd/device.c-438-{\ndrivers/dma/idxd/device.c:439:\tstruct idxd_device *idxd = wq-\u003eidxd;\ndrivers/dma/idxd/device.c-440-\n--\ndrivers/dma/idxd/device.c=521=EXPORT_SYMBOL_NS_GPL(idxd_wq_quiesce, \"IDXD\");\n--\ndrivers/dma/idxd/device.c-523-/* Device control bits */\ndrivers/dma/idxd/device.c:524:static inline bool idxd_is_enabled(struct idxd_device *idxd)\ndrivers/dma/idxd/device.c-525-{\n--\ndrivers/dma/idxd/device.c-534-\ndrivers/dma/idxd/device.c:535:static inline bool idxd_device_is_halted(struct idxd_device *idxd)\n\n"
}

25/2 2026/10/20 19:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 45891
							output: 36
							thoughts: 53
						

Thoughts:
Here's my analysis of what I'm seeing:

**Diving into the IDXD PCI Probe**

Okay, so I'm looking at how the `idxd` driver handles PCI devices. The code indicates that it starts with a PCI probe function: `idxd_pci_probe`. Right, that's standard practice. Now, to understand the initialization process, I need to check out the details of that probe function. It's almost certain that the `idxd_pci_probe` function handles device discovery, resource allocation, and initialization specific to the hardware it finds. I'll need to go to `drivers/dma/idxd/init.c` to examine its implementation. From here, I can get a better picture of how `idxd` interacts with PCI devices on system boot, and what hardware parameters need to be satisfied by the devices to function in the correct manner.



26/2 2026/10/20 19:06 tool grepper
0m Args:
{
  "Expression": "idxd_pci_probe",
  "PathPrefixes": [
    "drivers/dma/idxd/"
  ]
}

Results:
{
  "Output": "drivers/dma/idxd/idxd.h=801=int idxd_device_drv_probe(struct idxd_dev *idxd_dev);\ndrivers/dma/idxd/idxd.h:802:int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,\ndrivers/dma/idxd/idxd.h-803-\t\t\t const struct pci_device_id *id);\n--\ndrivers/dma/idxd/init.c=1054=static void idxd_reset_done(struct pci_dev *pdev)\n--\ndrivers/dma/idxd/init.c-1085-\t */\ndrivers/dma/idxd/init.c:1086:\tidxd_pci_probe_alloc(idxd, NULL, NULL);\ndrivers/dma/idxd/init.c-1087-\n--\ndrivers/dma/idxd/init.c=1136=static const struct pci_error_handlers idxd_error_handler = {\n--\ndrivers/dma/idxd/init.c-1148- */\ndrivers/dma/idxd/init.c:1149:int idxd_pci_probe_alloc(struct idxd_device *idxd, struct pci_dev *pdev,\ndrivers/dma/idxd/init.c-1150-\t\t\t const struct pci_device_id *id)\n--\ndrivers/dma/idxd/init.c-1252-\ndrivers/dma/idxd/init.c:1253:static int idxd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)\ndrivers/dma/idxd/init.c-1254-{\ndrivers/dma/idxd/init.c:1255:\treturn idxd_pci_probe_alloc(NULL, pdev, id);\ndrivers/dma/idxd/init.c-1256-}\n--\ndrivers/dma/idxd/init.c=1341=static struct pci_driver idxd_pci_driver = {\n--\ndrivers/dma/idxd/init.c-1343-\t.id_table\t= idxd_pci_tbl,\ndrivers/dma/idxd/init.c:1344:\t.probe\t\t= idxd_pci_probe,\ndrivers/dma/idxd/init.c-1345-\t.remove\t\t= idxd_remove,\n"
}

27/2 2026/10/20 19:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46819
							output: 37
							thoughts: 187
						

Thoughts:
**Analyzing the idxd_pci_driver**

Okay, let's dive into this `idxd_pci_driver`. It's clearly a PCI driver, and the `id_table` is specifically keyed to Intel hardware PCI IDs: DSA_SPR0, DSA_GNRD, DSA_DMR, IAX_SPR0, IAA_DMR, IAA_PTL, and IAA_WCL. That's a strong indicator. These are all Intel's on-CPU accelerator hardware – DSA (Data Streaming Accelerator) and IAA (In-Memory Analytics Accelerator).

The important takeaway is that this hardware isn't emulated in standard QEMU or Google Compute Engine VMs. The fact that the driver is designed this way is worth noting for its implications for virtualization and cloud environments.

But, before jumping to conclusions, I need to confirm whether there's some kind of virtual bus or software device that *could* register `idxd`. I need to rule out alternative scenarios. Let's start with `drivers/dma/idxd/bus.c`. I need to understand if `idxd_bus` is something significant here. Let's read `drivers/dma/idxd/bus.c`.



28/2 2026/10/20 19:07 tool read-file
0m Args:
{
  "File": "drivers/dma/idxd/bus.c",
  "FirstLine": 1,
  "LineCount": 80
}

Results:
{
  "Contents": "   1:\t// SPDX-License-Identifier: GPL-2.0\n   2:\t/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */\n   3:\t#include \u003clinux/init.h\u003e\n   4:\t#include \u003clinux/kernel.h\u003e\n   5:\t#include \u003clinux/module.h\u003e\n   6:\t#include \u003clinux/device.h\u003e\n   7:\t#include \"idxd.h\"\n   8:\t\n   9:\t\n  10:\tint __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,\n  11:\t\t\t\t   const char *mod_name)\n  12:\t{\n  13:\t\tstruct device_driver *drv = \u0026idxd_drv-\u003edrv;\n  14:\t\n  15:\t\tif (!idxd_drv-\u003etype) {\n  16:\t\t\tpr_debug(\"driver type not set (%ps)\\n\", __builtin_return_address(0));\n  17:\t\t\treturn -EINVAL;\n  18:\t\t}\n  19:\t\n  20:\t\tdrv-\u003ename = idxd_drv-\u003ename;\n  21:\t\tdrv-\u003ebus = \u0026dsa_bus_type;\n  22:\t\tdrv-\u003eowner = owner;\n  23:\t\tdrv-\u003emod_name = mod_name;\n  24:\t\n  25:\t\treturn driver_register(drv);\n  26:\t}\n  27:\tEXPORT_SYMBOL_GPL(__idxd_driver_register);\n  28:\t\n  29:\tvoid idxd_driver_unregister(struct idxd_device_driver *idxd_drv)\n  30:\t{\n  31:\t\tdriver_unregister(\u0026idxd_drv-\u003edrv);\n  32:\t}\n  33:\tEXPORT_SYMBOL_GPL(idxd_driver_unregister);\n  34:\t\n  35:\tstatic int idxd_config_bus_match(struct device *dev,\n  36:\t\t\t\t\t const struct device_driver *drv)\n  37:\t{\n  38:\t\tconst struct idxd_device_driver *idxd_drv =\n  39:\t\t\tcontainer_of_const(drv, struct idxd_device_driver, drv);\n  40:\t\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n  41:\t\tint i = 0;\n  42:\t\n  43:\t\twhile (idxd_drv-\u003etype[i] != IDXD_DEV_NONE) {\n  44:\t\t\tif (idxd_dev-\u003etype == idxd_drv-\u003etype[i])\n  45:\t\t\t\treturn 1;\n  46:\t\t\ti++;\n  47:\t\t}\n  48:\t\n  49:\t\treturn 0;\n  50:\t}\n  51:\t\n  52:\tstatic int idxd_config_bus_probe(struct device *dev)\n  53:\t{\n  54:\t\tstruct idxd_device_driver *idxd_drv =\n  55:\t\t\tcontainer_of(dev-\u003edriver, struct idxd_device_driver, drv);\n  56:\t\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n  57:\t\n  58:\t\treturn idxd_drv-\u003eprobe(idxd_dev);\n  59:\t}\n  60:\t\n  61:\tstatic void idxd_config_bus_remove(struct device *dev)\n  62:\t{\n  63:\t\tstruct idxd_device_driver *idxd_drv =\n  64:\t\t\tcontainer_of(dev-\u003edriver, struct idxd_device_driver, drv);\n  65:\t\tstruct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);\n  66:\t\n  67:\t\tidxd_drv-\u003eremove(idxd_dev);\n  68:\t}\n  69:\t\n  70:\tstatic int idxd_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)\n  71:\t{\n  72:\t\treturn add_uevent_var(env, \"MODALIAS=\" IDXD_DEVICES_MODALIAS_FMT, 0);\n  73:\t}\n  74:\t\n  75:\tconst struct bus_type dsa_bus_type = {\n  76:\t\t.name = \"dsa\",\n  77:\t\t.match = idxd_config_bus_match,\n  78:\t\t.probe = idxd_config_bus_probe,\n  79:\t\t.remove = idxd_config_bus_remove,\n  80:\t\t.uevent = idxd_bus_uevent,\n"
}

29/2 2026/10/20 19:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48498
							output: 20
							thoughts: 66
						

Thoughts:
Here's my summary, considering my expertise:

**Diving Deep into the DSA Bus and Device Registration**

Okay, so `dsa_bus_type` is clearly an internal bus structure within the DSA (Data Stream Accelerator) subsystem. My intuition immediately flags this as something managed by the `idxd` PCI driver, specifically during the probing phase of a physical PCI device. The connection to workqueues (wq) and engines points to the fundamental hardware abstraction of the Intel accelerator.

The key question that pops into my head now is: *Where exactly are the crucial device registration steps happening?* Specifically, I need to pinpoint the calls to `device_register` or `device_add` for the `dsa_bus_type`. Understanding *how* these devices are integrated into the system is paramount. Knowing the registration path gives me the context, the ownership models, and helps to figure out potential issues during device initialization or hotplug events. I must verify the exact function calls for these functions. Let's see what the code tells us!



30/2 2026/10/20 19:07 tool grepper
0m Args:
{
  "Expression": "dsa_bus_type"
}

Results:
{
  "Output": "drivers/dma/idxd/bus.c=10=int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,\n--\ndrivers/dma/idxd/bus.c-20-\tdrv-\u003ename = idxd_drv-\u003ename;\ndrivers/dma/idxd/bus.c:21:\tdrv-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/bus.c-22-\tdrv-\u003eowner = owner;\n--\ndrivers/dma/idxd/bus.c=70=static int idxd_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)\n--\ndrivers/dma/idxd/bus.c-74-\ndrivers/dma/idxd/bus.c:75:const struct bus_type dsa_bus_type = {\ndrivers/dma/idxd/bus.c-76-\t.name = \"dsa\",\n--\ndrivers/dma/idxd/bus.c-81-};\ndrivers/dma/idxd/bus.c:82:EXPORT_SYMBOL_GPL(dsa_bus_type);\ndrivers/dma/idxd/bus.c-83-\ndrivers/dma/idxd/bus.c=84=static int __init dsa_bus_init(void)\ndrivers/dma/idxd/bus.c-85-{\ndrivers/dma/idxd/bus.c:86:\treturn bus_register(\u0026dsa_bus_type);\ndrivers/dma/idxd/bus.c-87-}\n--\ndrivers/dma/idxd/bus.c=90=static void __exit dsa_bus_exit(void)\ndrivers/dma/idxd/bus.c-91-{\ndrivers/dma/idxd/bus.c:92:\tbus_unregister(\u0026dsa_bus_type);\ndrivers/dma/idxd/bus.c-93-}\ndrivers/dma/idxd/bus.c=94=module_exit(dsa_bus_exit);\ndrivers/dma/idxd/bus.c-95-\ndrivers/dma/idxd/bus.c:96:MODULE_DESCRIPTION(\"IDXD driver dsa_bus_type driver\");\ndrivers/dma/idxd/bus.c-97-MODULE_LICENSE(\"GPL v2\");\n--\ndrivers/dma/idxd/cdev.c=237=static int idxd_cdev_open(struct inode *inode, struct file *filp)\n--\ndrivers/dma/idxd/cdev.c-311-\tfdev-\u003eparent = cdev_dev(idxd_cdev);\ndrivers/dma/idxd/cdev.c:312:\tfdev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/cdev.c-313-\tfdev-\u003etype = \u0026idxd_cdev_file_type;\n--\ndrivers/dma/idxd/cdev.c=553=int idxd_wq_add_cdev(struct idxd_wq *wq)\n--\ndrivers/dma/idxd/cdev.c-579-\tdev-\u003eparent = wq_confdev(wq);\ndrivers/dma/idxd/cdev.c:580:\tdev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/cdev.c-581-\tdev-\u003etype = \u0026idxd_cdev_device_type;\n--\ndrivers/dma/idxd/idxd.h=544=static inline void idxd_set_user_intr(struct idxd_device *idxd, bool enable)\n--\ndrivers/dma/idxd/idxd.h-552-\ndrivers/dma/idxd/idxd.h:553:extern const struct bus_type dsa_bus_type;\ndrivers/dma/idxd/idxd.h-554-\n--\ndrivers/dma/idxd/init.c=173=static int idxd_setup_wqs(struct idxd_device *idxd)\n--\ndrivers/dma/idxd/init.c-203-\t\tconf_dev-\u003eparent = idxd_confdev(idxd);\ndrivers/dma/idxd/init.c:204:\t\tconf_dev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/init.c-205-\t\tconf_dev-\u003etype = \u0026idxd_wq_device_type;\n--\ndrivers/dma/idxd/init.c=269=static int idxd_setup_engines(struct idxd_device *idxd)\n--\ndrivers/dma/idxd/init.c-293-\t\tconf_dev-\u003eparent = idxd_confdev(idxd);\ndrivers/dma/idxd/init.c:294:\t\tconf_dev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/init.c-295-\t\tconf_dev-\u003etype = \u0026idxd_engine_device_type;\n--\ndrivers/dma/idxd/init.c=327=static int idxd_setup_groups(struct idxd_device *idxd)\n--\ndrivers/dma/idxd/init.c-351-\t\tconf_dev-\u003eparent = idxd_confdev(idxd);\ndrivers/dma/idxd/init.c:352:\t\tconf_dev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/init.c-353-\t\tconf_dev-\u003etype = \u0026idxd_group_device_type;\n--\ndrivers/dma/idxd/init.c=590=static struct idxd_device *idxd_alloc(struct pci_dev *pdev, struct idxd_driver_data *data)\n--\ndrivers/dma/idxd/init.c-614-\tconf_dev-\u003eparent = dev;\ndrivers/dma/idxd/init.c:615:\tconf_dev-\u003ebus = \u0026dsa_bus_type;\ndrivers/dma/idxd/init.c-616-\tconf_dev-\u003etype = idxd-\u003edata-\u003edev_type;\n"
}

31/2 2026/10/20 19:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50354
							output: 18
							thoughts: 1655
						

Thoughts:
**Analysis of DMA Channel Registration and Intel IDXD Hardware Dependency**

Okay, so here's the deal. I'm looking at this patch and, initially, the `conf_dev->bus = &dsa_bus_type` assignment caught my eye.  It's only happening inside functions called during `idxd_pci_probe_alloc`, which itself is tied to the Intel PCI device (`idxd_pci_tbl`).  Without *actual* Intel DSA/IAA PCI hardware, `idxd_pci_driver.probe` is never called, and consequently, none of the `idxd` devices (WQs, groups, engines, cdevs) are ever registered.  Essentially, this is all locked behind physical hardware.

The question then becomes: can anything *else* call `dma_async_device_channel_add`? This is the core of the matter.  I checked, and it's only called in `idxd_register_dma_channel` within `drivers/dma/idxd/dma.c`.  I see the author added `dma_async_device_channel_add`, which suggests an alternative to `dma_async_device_channel_register`.

Digging deeper, I examined the patch itself and found the following comment in the code: "The dma_device is registered already, so a channel request may take the channel as soon as it is on the device's list. The core links it only once it is registered, and everything a client reaches through it is set up by then. What follows serves the unbind, which cannot run before this probe returns."

Now, according to the "WorthFuzzing" criteria, I need to figure out if all the modifications fall into unreachable hardware.

The modified code includes the new `dma_async_device_channel_add` function in `drivers/dma/dmaengine.c`, but it is only used by `drivers/dma/idxd/dma.c`. This means it *is* reachable, but only if the DSA/IAA hardware is present and initialized. I checked if `dma_async_device_channel_add` is called by any other syscall or driver, but grepping the codebase confirms that it is only called in `drivers/dma/idxd/dma.c`. It's exported, but no other driver actually utilizes the symbol.

So, the next thing I did was to verify that it is dependent on hardware. The `drivers/dma/idxd` part is tightly coupled with physical Intel DSA/IAA PCIe hardware.

My concern is that the changes are unreachable without the specific physical hardware. I also double-checked for any kind of emulation. My first thought was about QEMU, but there's no DSA/IAA emulation in the upstream QEMU. Also, I searched the kernel sources for any kind of mock/virtual device like `CONFIG_DMA_VIRTUAL_CHANNELS` or any other kind of idxd emulation, but nothing came up.

Just to be thorough, I grepped for `idxd` across the entire kernel to see if there was any kind of interaction (e.g., in `crypto/iaa`).

Finally, I checked all the other files in the patch. The other files that were touched are all within `drivers/dma/idxd/`.

So, it's pretty clear: This patch is strictly tied to real Intel DSA/IAA hardware.



32/2 2026/10/20 19:07 tool grepper
0m Args:
{
  "Expression": "iaa_crypto"
}

Results:
{
  "Output": "\nFull output is too long, showing 200 out of 452 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (11 files in total):\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:52\ndrivers/crypto/intel/iaa/Kconfig:1\ndrivers/crypto/intel/iaa/Makefile:3\ndrivers/crypto/intel/iaa/iaa_crypto_comp_fixed.c:1\ndrivers/crypto/intel/iaa/iaa_crypto_main.c:39\ndrivers/crypto/intel/iaa/iaa_crypto_stats.c:14\ndrivers/crypto/intel/iaa/iaa_crypto_stats.h:4\ndrivers/dma/idxd/defaults.c:2\ndrivers/dma/idxd/idxd.h:1\ndrivers/dma/idxd/irq.c:1\ndrivers/dma/idxd/submit.c:3\n\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=13=The IAA hardware spec can be found here:\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-16-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:17:The iaa_crypto driver is designed to work as a layer underneath\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-18-higher-level compression devices such as zswap.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=132=accel-config\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-134-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:135:When loaded, the iaa_crypto driver automatically creates a default\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-136-configuration and enables it, and assigns default driver attributes.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=139=configuration, and then re-register the deflate-iaa algorithm with the\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:140:crypto subsystem by removing and reinserting the iaa_crypto module.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-141-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=168=Typical usage\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-170-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:171:In order for the iaa_crypto module to actually do any\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-172-compression/decompression work on behalf of a facility, one or more\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:173:IAA workqueues need to be bound to the iaa_crypto driver.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-174-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=175=For instance, here's an example of configuring an IAA workqueue and\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:176:binding it to the iaa_crypto driver (note that device names are\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-177-specified as 'iax' rather than 'iaa' - this is because upstream still\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=178=has the old 'iax' device naming in place) ::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-181-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:182:  accel-config config-wq --group-id=0 --mode=dedicated --type=kernel --priority=10 --name=\"iaa_crypto\" --driver-name=\"crypto\" iax1/wq1.0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-183-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-193-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:194:Whenever a new workqueue is bound to or unbound from the iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-195-driver, the available workqueues are 'rebalanced' such that work\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=199=least one workqueue configured and bound to any IAA device in the\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:200:system, the iaa_crypto driver will work, albeit most likely not as\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-201-efficiently.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=204=decompression operations are fully enabled following the successful\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:205:binding of the first IAA workqueue to the iaa_crypto driver.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-206-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=208=and decompression operations are disabled following the unbinding of\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:209:the last IAA worqueue to the iaa_crypto driver.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-210-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=211=As a result, the IAA crypto algorithms and thus the IAA hardware are\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:212:only available when one or more workques are bound to the iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-213-driver.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=232=The available attributes are:\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-248-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:249:    The crypto async interface support implemented by iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-250-    provides an implementation that satisfies the interface but does\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-256-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:257:    The iaa_crypto driver does however provide true asynchronous\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-258-    support for callers that can make use of it.  In this mode, it\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-266-    significantly slower than the synchronous mode that does the\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:267:    polling in the iaa_crypto driver previously mentioned.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-268-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-269-    This mode can be enabled by writing 'async_irq' to the sync_mode\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:270:    iaa_crypto driver attribute::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-271-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-278-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:279:    The mode that does the polling in the iaa_crypto driver can be\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-280-    enabled by writing 'sync' to it::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-285-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:286:    Caveat: since the only mechanism that iaa_crypto currently implements\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-287-    for async polling without interrupts is via the 'sync' mode as\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-289-    '/sys/bus/dsa/drivers/crypto/sync_mode' will internally enable the\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:290:    'sync' mode. This is to ensure correct iaa_crypto behavior until true\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:291:    async polling without interrupts is enabled in iaa_crypto.\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-292-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=295=IAA Default Configuration\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-297-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:298:When the iaa_crypto driver is loaded, each IAA device has a single\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-299-work queue configured for it, with the following attributes::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-306-          group             0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:307:          name              \"iaa_crypto\"\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-308-          driver_name       \"crypto\"\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=321=algorithm, it needs to be re-registered by removing and reinserting\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:322:the iaa_crypto module.  The :ref:`iaa_disable_script` in the 'Use\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-323-Cases' section below can be used to disable the default configuration.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=354=in addition to some global stats::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-364-    wqs:\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:365:      name: iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-366-      comp_calls: 0\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-378-    wqs:\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:379:      name: iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-380-      comp_calls: 0\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-392-    wqs:\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:393:      name: iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-394-      comp_calls: 1360\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-406-    wqs:\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:407:      name: iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-408-      comp_calls: 2940\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=449=workqueue driver_name of \"crypto\".\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-450-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:451:The first step is to make sure the iaa_crypto module is loaded::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-452-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:453:  modprobe iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-454-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=469=commands can be used to enable debug output::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-470-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:471:  # echo -n 'module iaa_crypto +p' \u003e /sys/kernel/debug/dynamic_debug/control\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-472-  # echo -n 'module idxd +p' \u003e /sys/kernel/debug/dynamic_debug/control\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=528=The below script automatically does that::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-557-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:558:  echo \"Reload iaa_crypto module\"\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-559-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:560:  rmmod iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:561:  modprobe iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-562-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:563:  echo \"End Reload iaa_crypto module\"\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-564-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-569-  for ((i = 1; i \u003c ${num_iaa} * 2; i += 2)); do\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:570:      accel-config config-wq --group-id=0 --mode=dedicated --wq-size=128 --priority=10 --type=kernel --name=\"iaa_crypto\" --driver-name=\"crypto\" i...\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-571-      accel-config config-engine iax${i}/engine${i}.0 --group-id=0\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-589-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:590:When the workqueues are bound to the iaa_crypto driver, you should\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-591-see something similar to the following in dmesg output if you've\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:592:enabled debug output (echo -n 'module iaa_crypto +p' \u003e\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-593-/sys/kernel/debug/dynamic_debug/control)::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-595-  [   60.752344] idxd 0000:f6:02.0: add_iaa_wq: added wq 000000004068d14d to iaa 00000000c9585ba2, n_wq 1\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:596:  [   60.752346] iaa_crypto: rebalance_wq_table: nr_nodes=2, nr_cpus 160, nr_iaa 8, cpus_per_iaa 20\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:597:  [   60.752347] iaa_crypto: rebalance_wq_table: iaa=0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-598-  [   60.752349] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-599-  [   60.752350] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:600:  [   60.752352] iaa_crypto: rebalance_wq_table: assigned wq for cpu=0, node=0 = wq 00000000c8bb4452\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:601:  [   60.752354] iaa_crypto: rebalance_wq_table: iaa=0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-602-  [   60.752355] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-603-  [   60.752356] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:604:  [   60.752358] iaa_crypto: rebalance_wq_table: assigned wq for cpu=1, node=0 = wq 00000000c8bb4452\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:605:  [   60.752359] iaa_crypto: rebalance_wq_table: iaa=0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-606-  [   60.752360] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-607-  [   60.752361] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:608:  [   60.752362] iaa_crypto: rebalance_wq_table: assigned wq for cpu=2, node=0 = wq 00000000c8bb4452\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:609:  [   60.752364] iaa_crypto: rebalance_wq_table: iaa=0\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-610-  .\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=617=output::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-618-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:619:  [   64.893759] iaa_crypto: iaa_crypto_enable: iaa_crypto now ENABLED\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-620-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=644=You should see something like the following in the dmesg output if\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:645:you've enabled debug output (echo -n 'module iaa_crypto +p' \u003e\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-646-/sys/kernel/debug/dynamic_debug/control)::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=664=compressor and turn off swap (to remove all references to\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:665:iaa_crypto)::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-666-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-673-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:674:Once zswap is disabled and no longer using iaa_crypto, the IAA wqs and\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-675-devices can be disabled.\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=682=The below script automatically does that::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-711-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:712:Finally, at this point the iaa_crypto module can be removed, which\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-713-will unregister the current IAA crypto algorithms::\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-714-\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:715:  rmmod iaa_crypto\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-716-\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst=819=For each device::\n--\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-837-       # echo \"kernel\" \u003e /sys/bus/dsa/devices/iax3/wq3.3/type\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst:838:       # echo \"iaa_crypto\" \u003e /sys/bus/dsa/devices/iax3/wq3.3/name\nDocumentation/driver-api/crypto/iaa/iaa-crypto.rst-839-       # echo \"crypto\" \u003e /sys/bus/dsa/devices/iax3/wq3.3/driver_name\n--\ndrivers/crypto/intel/iaa/Kconfig=1=config CRYPTO_DEV_IAA_CRYPTO\n--\ndrivers/crypto/intel/iaa/Kconfig-9-\t  hardware using the cryptographic API.  If you choose 'M'\ndrivers/crypto/intel/iaa/Kconfig:10:\t  here, the module will be called iaa_crypto.\ndrivers/crypto/intel/iaa/Kconfig-11-\n\n"
}

33/2 2026/10/20 19:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 58834
							output: 132
							thoughts: 3690
						

Thoughts:
**Analysis of Code Modification for Fuzzing Eligibility**

Okay, let's break this down. My initial assessment points directly to the `idxd` driver, specifically its interactions with the `dmaengine` subsystem. The key here is reachability: can fuzzers trigger the new code in standard environments? My reading of the documentation and code reveals that the `iaa_crypto` driver (which I assume is related) binds to IAA workqueues *when* the hardware is present, which clearly points to physical PCI devices like those found in Intel Xeon Sapphire Rapids systems. This immediately sets off alarm bells because I know from experience that these accelerators aren't emulated in the usual QEMU or GCE environments used for fuzzing.

My primary focus then, is `dmaengine.c`. The introduction of `dma_async_device_channel_add` is the change in the core code. However, after careful examination, I confirm that *no* existing `dmaengine.c` code was modified. The new function is *only* called by `idxd_register_dma_channel`, which, in turn, is only triggered when the Intel DSA/IAA PCI device is probed. So, `dma_async_device_channel_add` is *dead* code in any environment without the physical hardware.

The reachability analysis reveals the following:

*   The modifications are confined to the `drivers/dma/idxd/` directory and the addition of `dma_async_device_channel_add` in `dmaengine.c`.
*   The IDXD driver relies on Intel DSA/IAA hardware, which are present on Xeon servers.
*   The function `dma_async_device_channel_add` is only called by the IDXD driver.
*   This specific hardware is *not* emulated in standard QEMU or GCE environments.

This falls squarely under the "Structurally unreachable hardware" category defined in Section 2 of the fuzzing triage philosophy. Even though `dma_async_device_channel_add` has a warning, the philosophy explicitly states that unreachable code *must not* be fuzzed, regardless of assertions. It doesn't matter that the code includes assertion, it's not going to be executed in fuzzed environments.

Therefore, the `WorthFuzzing` flag should be `false`, as the changes are exclusively associated with hardware that cannot be accessed in standard fuzzing environments. There's no need to enable any specific configurations or focus on any symbols. The rationale is straightforward: the modified code is unreachable during fuzzing.



34/2 2026/10/20 19:08 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch series modifies the Intel Data Accelerator (IDXD / DSA / IAA) driver along with adding a helper function, dma_async_device_channel_add(), in dmaengine.c whose sole caller is the IDXD driver. Intel DSA and IAA devices require physical Intel Xeon hardware (Sapphire Rapids and newer) and are not emulated in standard QEMU or GCE virtualized environments. Consequently, all modified and added code paths are structurally unreachable in standard fuzzing environments.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch series modifies the Intel Data Accelerator (IDXD / DSA / IAA) driver along with adding a helper function, dma_async_device_channel_add(), in dmaengine.c whose sole caller is the IDXD driver. Intel DSA and IAA devices require physical Intel Xeon hardware (Sapphire Rapids and newer) and are not emulated in standard QEMU or GCE virtualized environments. Consequently, all modified and added code paths are structurally unreachable in standard fuzzing environments.",
  "WorthFuzzing": false
}

35/1 2026/10/20 19:08 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)