lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230625150442.42197-4-Jingqi.liu@intel.com>
Date:   Sun, 25 Jun 2023 23:04:40 +0800
From:   Jingqi Liu <Jingqi.liu@...el.com>
To:     iommu@...ts.linux.dev, Lu Baolu <baolu.lu@...ux.intel.com>,
        Tian Kevin <kevin.tian@...el.com>,
        Joerg Roedel <joro@...tes.org>, Will Deacon <will@...nel.org>,
        Robin Murphy <robin.murphy@....com>
Cc:     linux-kernel@...r.kernel.org, Jingqi Liu <Jingqi.liu@...el.com>
Subject: [PATCH 3/5] iommu/vt-d: debugfs: Dump the corresponding page table of a pasid

Add a generic helper to dump the page table contained in a pasid table entry.

For implementations supporting Scalable Mode Translation, the PASID-table
entries contain pointers to both first-stage and second-stage translation
structures, along with the PASID Granular Translation Type (PGTT) field that
specifies which translation process the request undergoes.

The original debugfs only dumps the contents of pasid table entry when
traversing the pasid table. Add a check to decide whether to dump the page
table contained by a pasid table entry.

Signed-off-by: Jingqi Liu <Jingqi.liu@...el.com>
---
 drivers/iommu/intel/debugfs.c | 59 ++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c
index 6d02cd91718a..212d33598de9 100644
--- a/drivers/iommu/intel/debugfs.c
+++ b/drivers/iommu/intel/debugfs.c
@@ -19,9 +19,11 @@
 #include "perf.h"
 
 struct tbl_walk {
+	u16 segment;     /* PCI segment# */
 	u16 bus;
 	u16 devfn;
 	u32 pasid;
+	bool dump_page_table;
 	struct root_entry *rt_entry;
 	struct context_entry *ctx_entry;
 	struct pasid_entry *pasid_tbl_entry;
@@ -118,6 +120,8 @@ static const struct iommu_regset iommu_regs_64[] = {
 	IOMMU_REGSET_ENTRY(VCRSP),
 };
 
+static void dump_translation_page_table(struct seq_file *m);
+
 static int iommu_regset_show(struct seq_file *m, void *unused)
 {
 	struct dmar_drhd_unit *drhd;
@@ -199,7 +203,11 @@ static void pasid_tbl_walk(struct seq_file *m, struct pasid_entry *tbl_entry,
 		if (pasid_pte_is_present(tbl_entry)) {
 			tbl_wlk->pasid_tbl_entry = tbl_entry;
 			tbl_wlk->pasid = (dir_idx << PASID_PDE_SHIFT) + tbl_idx;
-			print_tbl_walk(m);
+
+			if (tbl_wlk->dump_page_table)
+				dump_translation_page_table(m);
+			else
+				print_tbl_walk(m);
 		}
 
 		tbl_entry++;
@@ -347,6 +355,55 @@ static void pgtable_walk_level(struct seq_file *m, struct dma_pte *pde,
 	}
 }
 
+/*
+ * Dump the page table that contained in a pasid table entry.
+ * There're two consumers of this helper, as follows:
+ * 1) When traversing the pasid table, dump the page table
+ *    contained in the pasid table entry.
+ * 2) Find the pasid table entry with a specified pasid,
+ *    and dump the page table it contains.
+ */
+static void dump_translation_page_table(struct seq_file *m)
+{
+	struct tbl_walk *tbl_wlk = m->private;
+	u64 pgd, path[6] = { 0 };
+	u16 pgtt;
+	u8 agaw;
+
+	if (!tbl_wlk->pasid_tbl_entry)
+		return;
+
+	/*
+	 * According to PASID Granular Translation Type(PGTT),
+	 * get the page table pointer.
+	 */
+	pgtt = (u16)(tbl_wlk->pasid_tbl_entry->val[0] & GENMASK_ULL(8, 6)) >> 6;
+	agaw = (u8)(tbl_wlk->pasid_tbl_entry->val[0] & GENMASK_ULL(4, 2)) >> 2;
+
+	switch (pgtt) {
+	case PASID_ENTRY_PGTT_FL_ONLY:
+		pgd = tbl_wlk->pasid_tbl_entry->val[2];
+		break;
+	case PASID_ENTRY_PGTT_SL_ONLY:
+	case PASID_ENTRY_PGTT_NESTED:
+		pgd = tbl_wlk->pasid_tbl_entry->val[0];
+		break;
+	default:
+		return;
+	}
+
+	pgd &= VTD_PAGE_MASK;
+	seq_printf(m, "Device %04x:%02x:%02x.%x with pasid %x @0x%llx\n",
+		   tbl_wlk->segment, tbl_wlk->bus, PCI_SLOT(tbl_wlk->devfn),
+		   PCI_FUNC(tbl_wlk->devfn), tbl_wlk->pasid, pgd);
+	seq_printf(m, "%-17s\t%-18s\t%-18s\t%-18s\t%-18s\t%-s\n",
+		   "IOVA_PFN", "PML5E", "PML4E", "PDPE", "PDE", "PTE");
+	pgtable_walk_level(m, phys_to_virt(pgd), agaw + 2, 0, path);
+	seq_putc(m, '\n');
+
+	return;
+}
+
 static int __show_device_domain_translation(struct device *dev, void *data)
 {
 	struct dmar_domain *domain;
-- 
2.21.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ