linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sohil Mehta <sohil.mehta@intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: Ashok Raj <ashok.raj@intel.com>,
	David Woodhouse <dwmw2@infradead.org>,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Jacob Pan <jacob.jun.pan@linux.intel.com>,
	Gayatri Kammela <gayatri.kammela@intel.com>,
	Sohil Mehta <sohil.mehta@intel.com>,
	Ravi V Shankar <ravi.v.shankar@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Fenghua Yu <fenghua.yu@intel.com>
Subject: [PATCH v8 6/6] iommu/vt-d: Add debugfs support to show context internals
Date: Tue, 11 Sep 2018 17:11:41 -0700	[thread overview]
Message-ID: <20180912001141.64025-7-sohil.mehta@intel.com> (raw)
In-Reply-To: <20180912001141.64025-1-sohil.mehta@intel.com>

Export Intel IOMMU DMA remapping internal states, such as root and
context table entries in debugfs.

Example of such dump in Kabylake:
/sys/kernel/debug/iommu/intel/dmar_translation_struct

IOMMU dmar0: Root Table Address:45699c000
Root Table Entries:
 Bus: 0 H: 0 L: 45699f001
 Context Table Entries for Bus: 0
  Entry B:D.F   High    Low
  16    00:02.0 102     45699e005

IOMMU dmar1: Root Table Address:45699d000
Root Table Entries:
 Bus: 0 H: 0 L: 45644f001
 Context Table Entries for Bus: 0
  Entry B:D.F   High    Low
  160   00:14.0 102     45644e001
  184   00:17.0 302     456310001
  248   00:1f.0 202     4564bf001

Cc: Lu Baolu <baolu.lu@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Co-Developed-by: Gayatri Kammela <gayatri.kammela@intel.com>
Signed-off-by: Gayatri Kammela <gayatri.kammela@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
    
v8: Remove extended context support since it is deprecated in the new spec
    Use iommu lock to protect context table access
    Simplify and split the patches differently

v7: Split patch 1/5 and 2/5 differently
    Update commit message and copyright year
    Fix typo in a comment
    Simplify code

v6: Change the order of includes to an alphabetical order
    Change seq_printf formatting

v5: Change to a SPDX license tag
    Fix seq_printf formatting

v4: Remove the unused function parameter
    Fix checkpatch.pl warnings
    Remove error reporting for debugfs_create_file function
    Fix unnecessary reprogramming of the context entries
    Simplify and merge the show context and extended context patch into one
    Remove redundant IOMMU null check under for_each_active_iommu

v3: Add a macro for seq file operations 
    Change the intel_iommu_ctx file name to dmar_translation_struct

v2: No change

 drivers/iommu/intel-iommu-debugfs.c | 65 +++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/drivers/iommu/intel-iommu-debugfs.c b/drivers/iommu/intel-iommu-debugfs.c
index 2becbd78620f..7fabf9b1c2dc 100644
--- a/drivers/iommu/intel-iommu-debugfs.c
+++ b/drivers/iommu/intel-iommu-debugfs.c
@@ -131,6 +131,69 @@ static int iommu_regset_show(struct seq_file *m, void *unused)
 }
 DEFINE_SHOW_ATTRIBUTE(iommu_regset);
 
+static void ctx_tbl_entry_show(struct seq_file *m, struct intel_iommu *iommu,
+			       int bus)
+{
+	struct context_entry *context;
+	int devfn;
+
+	seq_printf(m, " Context Table Entries for Bus: %d\n", bus);
+	seq_puts(m, "  Entry\tB:D.F\tHigh\tLow\n");
+
+	for (devfn = 0; devfn < 256; devfn++) {
+		context = iommu_context_addr(iommu, bus, devfn, 0);
+		if (!context)
+			return;
+
+		if (!context_present(context))
+			continue;
+
+		seq_printf(m, "  %-5d\t%02x:%02x.%x\t%-6llx\t%llx\n", devfn,
+			   bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
+			   context[0].hi, context[0].lo);
+	}
+}
+
+static void root_tbl_entry_show(struct seq_file *m, struct intel_iommu *iommu)
+{
+	unsigned long flags;
+	int bus;
+
+	spin_lock_irqsave(&iommu->lock, flags);
+	seq_printf(m, "IOMMU %s: Root Table Address:%llx\n", iommu->name,
+		   (u64)virt_to_phys(iommu->root_entry));
+	seq_puts(m, "Root Table Entries:\n");
+
+	for (bus = 0; bus < 256; bus++) {
+		if (!(iommu->root_entry[bus].lo & 1))
+			continue;
+
+		seq_printf(m, " Bus: %d H: %llx L: %llx\n", bus,
+			   iommu->root_entry[bus].hi,
+			   iommu->root_entry[bus].lo);
+
+		ctx_tbl_entry_show(m, iommu, bus);
+		seq_putc(m, '\n');
+	}
+	spin_unlock_irqrestore(&iommu->lock, flags);
+}
+
+static int dmar_translation_struct_show(struct seq_file *m, void *unused)
+{
+	struct dmar_drhd_unit *drhd;
+	struct intel_iommu *iommu;
+
+	rcu_read_lock();
+	for_each_active_iommu(iommu, drhd) {
+		root_tbl_entry_show(m, iommu);
+		seq_putc(m, '\n');
+	}
+	rcu_read_unlock();
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(dmar_translation_struct);
+
 #ifdef CONFIG_IRQ_REMAP
 static void ir_tbl_remap_entry_show(struct seq_file *m,
 				    struct intel_iommu *iommu)
@@ -242,6 +305,8 @@ void __init intel_iommu_debugfs_init(void)
 
 	debugfs_create_file("iommu_regset", 0444, intel_iommu_debug, NULL,
 			    &iommu_regset_fops);
+	debugfs_create_file("dmar_translation_struct", 0444, intel_iommu_debug,
+			    NULL, &dmar_translation_struct_fops);
 #ifdef CONFIG_IRQ_REMAP
 	debugfs_create_file("ir_translation_struct", 0444, intel_iommu_debug,
 			    NULL, &ir_translation_struct_fops);
-- 
2.18.0


  parent reply	other threads:[~2018-09-12  0:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12  0:11 [PATCH v8 0/6] Add Intel IOMMU debugfs support Sohil Mehta
2018-09-12  0:11 ` [PATCH v8 1/6] iommu/vt-d: Relocate struct/function declarations to its header files Sohil Mehta
2018-09-12  0:11 ` [PATCH v8 2/6] iommu/vt-d: Update register definitions to VT-d 3.0 specification Sohil Mehta
2018-09-12  0:11 ` [PATCH v8 3/6] iommu/vt-d: Enable base Intel IOMMU debugfs support Sohil Mehta
2018-09-12  0:11 ` [PATCH v8 4/6] iommu/vt-d: Add debugfs support to show register contents Sohil Mehta
2018-09-12  0:11 ` [PATCH v8 5/6] iommu/vt-d: Add debugfs support for Interrupt remapping Sohil Mehta
2018-09-12  0:11 ` Sohil Mehta [this message]
2018-09-25 12:34 ` [PATCH v8 0/6] Add Intel IOMMU debugfs support Joerg Roedel

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=20180912001141.64025-7-sohil.mehta@intel.com \
    --to=sohil.mehta@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ashok.raj@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=fenghua.yu@intel.com \
    --cc=gayatri.kammela@intel.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ravi.v.shankar@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).