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 2/5] iommu/vt-d: debugfs: Support specifying source identifier and PASID
Date: Sun, 25 Jun 2023 23:04:39 +0800 [thread overview]
Message-ID: <20230625150442.42197-3-Jingqi.liu@intel.com> (raw)
In-Reply-To: <20230625150442.42197-1-Jingqi.liu@intel.com>
The original debugfs only dumps IOMMU page tables of all domains.
Usually developers want to dump the specified page table instead of all.
This patch supports users to specify the source identifier and PASID to
dump the specific page table.
For a device that only supports legacy mode, specify the source
identifier to dump its page table. For a device that supports scalable
mode, specify a {source identifier, PASID} pair to dump its page table.
Switch to dump all page tables by specifying "auto".
Examples are as follows:
1) Specify device "00:1f.0" that only supports legacy mode.
$ sudo echo 00:1f.0 >
/sys/kernel/debug/iommu/intel/domain_translation_struct
2) Specify device "00:0a.0" with PASID "1".
$ sudo echo 00:0a.0,1 >
/sys/kernel/debug/iommu/intel/domain_translation_struct
3) Specify all page tables:
$ sudo echo "auto" >
/sys/kernel/debug/iommu/intel/domain_translation_struct
Signed-off-by: Jingqi Liu <Jingqi.liu@intel.com>
---
drivers/iommu/intel/debugfs.c | 86 ++++++++++++++++++++++++++++++++++-
1 file changed, 85 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c
index 072cfef19175..6d02cd91718a 100644
--- a/drivers/iommu/intel/debugfs.c
+++ b/drivers/iommu/intel/debugfs.c
@@ -32,6 +32,13 @@ struct iommu_regset {
const char *regs;
};
+#define BUF_SIZE 64
+
+static struct show_domain_info {
+ struct pci_dev *pdev;
+ ioasid_t pasid;
+} *show_domain_info;
+
#define DEBUG_BUFFER_SIZE 1024
static char debug_buf[DEBUG_BUFFER_SIZE];
@@ -392,6 +399,82 @@ static int domain_translation_struct_show(struct seq_file *m, void *unused)
show_device_domain_translation);
}
+static ssize_t domain_translation_struct_write(struct file *filp,
+ const char __user *ubuf,
+ size_t cnt, loff_t *ppos)
+{
+ char buf[BUF_SIZE], *srcid_ptr = NULL, *pasid_ptr = NULL;
+ unsigned int seg, bus, slot, func;
+ struct pci_dev *pdev = NULL;
+ u32 pasid = INVALID_IOASID;
+ char *key, *pbuf;
+ int i = 0;
+
+ if (cnt >= BUF_SIZE)
+ return -EINVAL;
+
+ if (copy_from_user(buf, ubuf, cnt))
+ return -EFAULT;
+
+ buf[cnt - 1] = 0;
+ if (!strcmp(buf, "auto")) {
+ if (show_domain_info)
+ show_domain_info->pdev = NULL;
+ *ppos += cnt;
+ return cnt;
+ }
+
+ pbuf = buf;
+
+ /* Seperate the input: one {source identifier, PASID} pair */
+ while ((key = strsep(&pbuf, ", ")) != NULL) {
+ if (!*key)
+ continue;
+ if (i >= 2) /* too many fields */
+ return -EINVAL;
+ if (i++ == 0)
+ srcid_ptr = key;
+ else
+ pasid_ptr = key;
+ }
+
+ if (!srcid_ptr) /* no source identifier */
+ return -EINVAL;
+
+ /*
+ * The string of source identifier must be of the form:
+ * [<domain>:]<bus>:<device>.<func>
+ */
+ i = sscanf(srcid_ptr, "%x:%x:%x.%x", &seg, &bus, &slot, &func);
+ if (i != 4) {
+ seg = 0;
+ i = sscanf(srcid_ptr, "%x:%x.%x", &bus, &slot, &func);
+ if (i != 3)
+ return -EINVAL;
+ }
+
+ pdev = pci_get_domain_bus_and_slot(seg, bus, PCI_DEVFN(slot, func));
+ if (!pdev)
+ return -EINVAL;
+
+ if (pasid_ptr &&
+ ((kstrtou32(pasid_ptr, 0, &pasid) < 0) || (pasid >= PASID_MAX)))
+ return -EINVAL;
+
+ if (!show_domain_info) {
+ show_domain_info = kzalloc(sizeof(*show_domain_info),
+ GFP_KERNEL);
+ if (!show_domain_info)
+ return -EINVAL;
+ }
+
+ show_domain_info->pdev = pdev;
+ show_domain_info->pasid = pasid;
+
+ *ppos += cnt;
+ return cnt;
+}
+
static int domain_translation_struct_open(struct inode *inode,
struct file *filp)
{
@@ -406,6 +489,7 @@ static int domain_translation_struct_open(struct inode *inode,
static const struct file_operations domain_translation_struct_fops = {
.open = domain_translation_struct_open,
+ .write = domain_translation_struct_write,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
@@ -691,7 +775,7 @@ void __init intel_iommu_debugfs_init(void)
&iommu_regset_fops);
debugfs_create_file("dmar_translation_struct", 0444, intel_iommu_debug,
NULL, &dmar_translation_struct_fops);
- debugfs_create_file("domain_translation_struct", 0444,
+ debugfs_create_file("domain_translation_struct", 0644,
intel_iommu_debug, NULL,
&domain_translation_struct_fops);
debugfs_create_file("invalidation_queue", 0444, intel_iommu_debug,
--
2.21.3
next prev 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 ` Jingqi Liu [this message]
2023-06-25 15:04 ` [PATCH 3/5] iommu/vt-d: debugfs: Dump the corresponding page table of a pasid Jingqi Liu
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-3-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