Skip to contentSkip to conversation

iommu/amd: Enhance "Command buffer timeout" error message

PATCH New Dheeraj Kumar Srivastava 1 participant 1 message Oct 18

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

PATCH 1/1 iommu/amd: Enhance "Command buffer timeout" error message

Current IOMMU driver prints "Command buffer timeout" error message with insufficient information to further debug the issue.

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

Consolidate the timeout logging and the command buffer dump into a single helper and use DO_ONCE_LITE() to dump the command buffer only once to avoid dmesg spam. While at it, apply the same reporting to the completion-wait timeout path as well.

---
 drivers/iommu/amd/iommu.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/iommu/amd/iommu.c +12 -9
index 893cd2be11a2..e75b3f6123e6 100644
@@ -1228,6 +1228,16 @@ static void dump_command_buffer(struct amd_iommu *iommu)
 	}
 }
 
+static void report_command_buffer_timeout(struct amd_iommu *iommu, const char *reason)
+{
+	pr_err_ratelimited("IOMMU %04x:%02x:%02x.%01x: %s\n",
+			   iommu->pci_seg->id, PCI_BUS_NUM(iommu->devid),
+			   PCI_SLOT(iommu->devid), PCI_FUNC(iommu->devid), reason);
+
+	if (amd_iommu_dump)
+		DO_ONCE_LITE(dump_command_buffer, iommu);
+}
+
 static int wait_on_sem(struct amd_iommu *iommu, u64 data)
 {
 	int i = 0;
@@ -1243,14 +1253,7 @@ static int wait_on_sem(struct amd_iommu *iommu, u64 data)
 	}
 
 	if (i == LOOP_TIMEOUT) {
-
-		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);
-
+		report_command_buffer_timeout(iommu, "Completion-Wait loop timed out");
 		return -EIO;
 	}
 
@@ -1422,7 +1425,7 @@ static int __iommu_queue_command_sync(struct amd_iommu *iommu,
 		/* Skip udelay() the first time around */
 		if (count++) {
 			if (count == LOOP_TIMEOUT) {
-				pr_err("Command buffer timeout\n");
+				report_command_buffer_timeout(iommu, "Command buffer timeout");
 				return -EIO;
 			}
 
Signature · 1 line
2.25.1