public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jingqi Liu <Jingqi.liu@intel.com>
To: iommu@lists.linux.dev, Lu Baolu <baolu.lu@linux.intel.com>,
	Tian Kevin <kevin.tian@intel.com>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>
Cc: linux-kernel@vger.kernel.org, Jingqi Liu <Jingqi.liu@intel.com>
Subject: [PATCH 3/5] iommu/vt-d: debugfs: Dump the corresponding page table of a pasid
Date: Sun, 25 Jun 2023 23:04:40 +0800	[thread overview]
Message-ID: <20230625150442.42197-4-Jingqi.liu@intel.com> (raw)
In-Reply-To: <20230625150442.42197-1-Jingqi.liu@intel.com>

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@intel.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


  parent reply	other threads:[~2023-06-25 15:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-25 15:04 [PATCH 0/5] iommu/vt-d: debugfs: Enhancements to IOMMU debugfs Jingqi Liu
2023-06-25 15:04 ` [PATCH 1/5] iommu/vt-d: debugfs: Define domain_translation_struct file ops Jingqi Liu
2023-06-25 15:04 ` [PATCH 2/5] iommu/vt-d: debugfs: Support specifying source identifier and PASID Jingqi Liu
2023-06-25 15:04 ` Jingqi Liu [this message]
2023-06-25 15:04 ` [PATCH 4/5] iommu/vt-d: debugfs: Support dumping a specified page table Jingqi Liu
2023-06-25 15:04 ` [PATCH 5/5] iommu/vt-d: debugfs: Dump entry pointing to huge page Jingqi Liu
2023-07-03  7:15 ` [PATCH 0/5] iommu/vt-d: debugfs: Enhancements to IOMMU debugfs Tian, Kevin
2023-07-03 14:37   ` Liu, Jingqi
2023-07-04  7:54     ` Tian, Kevin
2023-07-11  1:40       ` Liu, Jingqi
2023-07-11  2:52         ` Baolu Lu
2023-07-11  6:23           ` Liu, Jingqi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230625150442.42197-4-Jingqi.liu@intel.com \
    --to=jingqi.liu@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox