From nobody Sun Feb 8 23:04:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E6DAC0015E for ; Sun, 25 Jun 2023 15:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbjFYPSR (ORCPT ); Sun, 25 Jun 2023 11:18:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjFYPSG (ORCPT ); Sun, 25 Jun 2023 11:18:06 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F20441B7 for ; Sun, 25 Jun 2023 08:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687706285; x=1719242285; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GBzP0QOzSLMJvNAZUflo7PPRyVHgUMz92AyAiFJMx5k=; b=P0eNZqAqEvl8Wejz0ZK7AS6ZMpMpaB4JoMHlyKeIfW1+kBpv7H9BjrlU kbRggPqXdmQf1pVwmtNAwzC/gglsZi1AhjW47a6SJI5RTK9pnzRjBOzJ+ 20RqNM5NZbWDR8BIkS8iJdA2piQ8csLlO9Gu+8yOrcIjvijcp2oGgSl5I qiyXxGGtR9a8QUWFDFsz7u4yiKjWN8wCbfmCEXykwfFm7vmVLfeQHoOg3 Us9oSHD4R+JDyYmQHw8gSs9QpCqCC0MCHWzWe2mpdRsOTR2cL76NR7/Nt Nv+mqWqWSaKp8kUXnWCVAA/yAdu6ky45vfNjSs/L3h7iTiA+59yv1jHB7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391255066" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="391255066" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 08:18:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="840004527" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="840004527" Received: from cascade.sh.intel.com ([10.239.48.162]) by orsmga004.jf.intel.com with ESMTP; 25 Jun 2023 08:18:03 -0700 From: Jingqi Liu To: iommu@lists.linux.dev, Lu Baolu , Tian Kevin , Joerg Roedel , Will Deacon , Robin Murphy Cc: linux-kernel@vger.kernel.org, Jingqi Liu Subject: [PATCH 2/5] iommu/vt-d: debugfs: Support specifying source identifier and PASID Date: Sun, 25 Jun 2023 23:04:39 +0800 Message-Id: <20230625150442.42197-3-Jingqi.liu@intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20230625150442.42197-1-Jingqi.liu@intel.com> References: <20230625150442.42197-1-Jingqi.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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; }; =20 +#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]; =20 @@ -392,6 +399,82 @@ static int domain_translation_struct_show(struct seq_f= ile *m, void *unused) show_device_domain_translation); } =20 +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 =3D NULL, *pasid_ptr =3D NULL; + unsigned int seg, bus, slot, func; + struct pci_dev *pdev =3D NULL; + u32 pasid =3D INVALID_IOASID; + char *key, *pbuf; + int i =3D 0; + + if (cnt >=3D BUF_SIZE) + return -EINVAL; + + if (copy_from_user(buf, ubuf, cnt)) + return -EFAULT; + + buf[cnt - 1] =3D 0; + if (!strcmp(buf, "auto")) { + if (show_domain_info) + show_domain_info->pdev =3D NULL; + *ppos +=3D cnt; + return cnt; + } + + pbuf =3D buf; + + /* Seperate the input: one {source identifier, PASID} pair */ + while ((key =3D strsep(&pbuf, ", ")) !=3D NULL) { + if (!*key) + continue; + if (i >=3D 2) /* too many fields */ + return -EINVAL; + if (i++ =3D=3D 0) + srcid_ptr =3D key; + else + pasid_ptr =3D key; + } + + if (!srcid_ptr) /* no source identifier */ + return -EINVAL; + + /* + * The string of source identifier must be of the form: + * [:]:. + */ + i =3D sscanf(srcid_ptr, "%x:%x:%x.%x", &seg, &bus, &slot, &func); + if (i !=3D 4) { + seg =3D 0; + i =3D sscanf(srcid_ptr, "%x:%x.%x", &bus, &slot, &func); + if (i !=3D 3) + return -EINVAL; + } + + pdev =3D 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 >=3D PASID_MAX))) + return -EINVAL; + + if (!show_domain_info) { + show_domain_info =3D kzalloc(sizeof(*show_domain_info), + GFP_KERNEL); + if (!show_domain_info) + return -EINVAL; + } + + show_domain_info->pdev =3D pdev; + show_domain_info->pasid =3D pasid; + + *ppos +=3D 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, =20 static const struct file_operations domain_translation_struct_fops =3D { .open =3D domain_translation_struct_open, + .write =3D domain_translation_struct_write, .read =3D seq_read, .llseek =3D seq_lseek, .release =3D 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, --=20 2.21.3