Skip to contentSkip to conversation

iommu/vt-d: Dump DMAR translation structure

PATCH Superseded Kyung Min Park 2 participants 2 messages May 26, 2021 – Jun 9, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Dump DMAR translation structure

When the dmar translation fault happens, the kernel prints a single line fault reason with corresponding hexadecimal code defined in the Intel VT-d specification.

Currently, when user wants to debug the translation fault in detail, debugfs is used for dumping the dmar_translation_struct, which is not available when the kernel failed to boot.

Dump the DMAR translation structure, pagewalk the IO page table and print the page table entry when the fault happens.

---
 drivers/iommu/intel/dmar.c  |   7 ++-
 drivers/iommu/intel/iommu.c | 108 ++++++++++++++++++++++++++++++++++++
 include/linux/dmar.h        |   3 +
 3 files changed, 116 insertions(+), 2 deletions(-)
drivers/iommu/intel/dmar.c +5 -2
index 11e37d2c2af2..6f4be1be8917 100644
@@ -1915,18 +1915,21 @@ static int dmar_fault_do_one(struct intel_iommu *iommu, int type,
 		       source_id >> 8, PCI_SLOT(source_id & 0xFF),
 		       PCI_FUNC(source_id & 0xFF), addr >> 48,
 		       fault_reason, reason);
-	else if (pasid == INVALID_IOASID)
+	else if (pasid == INVALID_IOASID) {
 		pr_err("[%s w/o PASID] Request device [%02x:%02x.%d] fault addr %llx [fault reason %02xh] %s\n",
 		       type ? "DMA Read" : "DMA Write",
 		       source_id >> 8, PCI_SLOT(source_id & 0xFF),
 		       PCI_FUNC(source_id & 0xFF), addr,
 		       fault_reason, reason);
-	else
+		dmar_fault_dump_ptes(iommu, source_id, addr, pasid);
+	} else {
 		pr_err("[%s w/ PASID %x] Request device [%02x:%02x.%d] fault addr %llx [fault reason %02xh] %s\n",
 		       type ? "DMA Read" : "DMA Write", pasid,
 		       source_id >> 8, PCI_SLOT(source_id & 0xFF),
 		       PCI_FUNC(source_id & 0xFF), addr,
 		       fault_reason, reason);
+		dmar_fault_dump_ptes(iommu, source_id, addr, pasid);
+	}
 	return 0;
 }
 
drivers/iommu/intel/iommu.c +108 -0

120 lines not on this page · raw message

include/linux/dmar.h +3 -0
index e04436a7ff27..7b43741b79ee 100644
@@ -70,6 +70,9 @@ struct dmar_pci_notify_info {
 extern struct rw_semaphore dmar_global_lock;
 extern struct list_head dmar_drhd_units;
 
+void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id,
+			  unsigned long long addr, u32 pasid);
+
 #define for_each_drhd_unit(drhd)					\
 	list_for_each_entry_rcu(drhd, &dmar_drhd_units, list,		\
 				dmar_rcu_check())
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 4 lines · Kyung Min Park

When the dmar translation fault happens, the kernel prints a single line fault reason with corresponding hexadecimal code defined in the Intel VT-d specification.

Quoted 8 lines

Currently, when user wants to debug the translation fault in detail, debugfs is used for dumping the dmar_translation_struct, which is not available when the kernel failed to boot.

Dump the DMAR translation structure, pagewalk the IO page table and print the page table entry when the fault happens.

Please fix below compile error:

ld: drivers/iommu/intel/dmar.o: in function `dmar_fault_do_one':
/home/allen/Workspace/iommu/drivers/iommu/intel/dmar.c:1965: undefined reference to `dmar_fault_dump_ptes'
make: *** [Makefile:1191: vmlinux] Error 1

Best regards,
baolu