Skip to contentSkip to conversation

iommu/amd: Enhance "Completion-wait Time-out" error message

PATCH Applied Dheeraj Kumar Srivastava 3 participants 3 messages Nov 12, 2025 – Nov 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 iommu/amd: Enhance "Completion-wait Time-out" error message

Current IOMMU driver prints "Completion-wait Time-out" error message with insufficient information to further debug the issue.

Enhancing the error message as following:
1. Log IOMMU PCI device ID in the error message.
2. With "amd_iommu_dump=1" kernel command line option, dump entire command buffer entries including Head and Tail offset.

Dump the entire command buffer only on the first 'Completion-wait Time-out' to avoid dmesg spam.

---
Changes since v4:
-> Changed head and tail variables from int to u32 in dump_command_buffer()
to match readl() return type and updated pr_err() format specifiers from %d to %u accordingly for head and tail. (Ankit)

Changes since v3:
-> Dump the entire command buffer only on the first 'Completion-wait Time-out'
when amd_iommu_dump=1, instead of dumping it on every occurrence.

 drivers/iommu/amd/amd_iommu_types.h |  4 ++++
 drivers/iommu/amd/iommu.c           | 28 +++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
drivers/iommu/amd/amd_iommu_types.h +4 -0
index 95f63c5f6159..c20798fc644d 100644
@@ -247,6 +247,10 @@
 #define CMD_BUFFER_ENTRIES 512
 #define MMIO_CMD_SIZE_SHIFT 56
 #define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT)
+#define MMIO_CMD_HEAD_MASK	GENMASK_ULL(18, 4)	/* Command buffer head ptr field [18:4] */
+#define MMIO_CMD_BUFFER_HEAD(x) FIELD_GET(MMIO_CMD_HEAD_MASK, (x))
+#define MMIO_CMD_TAIL_MASK	GENMASK_ULL(18, 4)	/* Command buffer tail ptr field [18:4] */
+#define MMIO_CMD_BUFFER_TAIL(x) FIELD_GET(MMIO_CMD_TAIL_MASK, (x))
 
 /* constants for event buffer handling */
 #define EVT_BUFFER_SIZE		8192 /* 512 entries */
drivers/iommu/amd/iommu.c +27 -1
index eb348c63a8d0..c68b0fdc5433 100644
@@ -1156,6 +1156,25 @@ irqreturn_t amd_iommu_int_handler(int irq, void *data)
  *
  ****************************************************************************/
 
+static void dump_command_buffer(struct amd_iommu *iommu)
+{
+	struct iommu_cmd *cmd;
+	u32 head, tail;
+	int i;
+
+	head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET);
+	tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
+
+	pr_err("CMD Buffer head=%llu tail=%llu\n", MMIO_CMD_BUFFER_HEAD(head),
+	       MMIO_CMD_BUFFER_TAIL(tail));
+
+	for (i = 0; i < CMD_BUFFER_ENTRIES; i++) {
+		cmd = (struct iommu_cmd *)(iommu->cmd_buf + i * sizeof(*cmd));
+		pr_err("%3d: %08x %08x %08x %08x\n", i, cmd->data[0], cmd->data[1], cmd->data[2],
+		       cmd->data[3]);
+	}
+}
+
 static int wait_on_sem(struct amd_iommu *iommu, u64 data)
 {
 	int i = 0;
@@ -1166,7 +1185,14 @@ static int wait_on_sem(struct amd_iommu *iommu, u64 data)
 	}
 
 	if (i == LOOP_TIMEOUT) {
-		pr_alert("Completion-Wait loop timed out\n");
+
+		pr_alert("IOMMU %04x:%02x:%02x.%01x: Completion-Wait loop timed out\n",
+			 iommu->pci_seg->id, PCI_BUS_NUM(iommu->devid),
+			 PCI_SLOT(iommu->devid), PCI_FUNC(iommu->devid));
+
+		if (amd_iommu_dump)
+			DO_ONCE_LITE(dump_command_buffer, iommu);
+
 		return -EIO;
 	}
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v5 1/1
#1 lore raw
Quoted 8 lines · Dheeraj Kumar Srivastava

Current IOMMU driver prints "Completion-wait Time-out" error message with insufficient information to further debug the issue.

Enhancing the error message as following:
1. Log IOMMU PCI device ID in the error message.
2. With "amd_iommu_dump=1" kernel command line option, dump entire command buffer entries including Head and Tail offset.

Quoted 5 lines

Dump the entire command buffer only on the first 'Completion-wait Time-out' to avoid dmesg spam.

-Vasant

maintainer Applied
#2 lore raw
In reply to Dheeraj Kumar Srivastava
Quoted 8 lines · Dheeraj Kumar Srivastava

Current IOMMU driver prints "Completion-wait Time-out" error message with insufficient information to further debug the issue.

Enhancing the error message as following:
1. Log IOMMU PCI device ID in the error message.
2. With "amd_iommu_dump=1" kernel command line option, dump entire command buffer entries including Head and Tail offset.

Quoted 5 lines

Dump the entire command buffer only on the first 'Completion-wait Time-out' to avoid dmesg spam.

Applied, thanks.