From patchwork Sun Jun 25 15:04:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 112625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6996765vqr; Sun, 25 Jun 2023 09:29:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59mNk481OjGXQOqKK2JUuRXUM4+YjHaIyKVbPETK6Ki/se+qKOLzsIcM/QymSLzVRmyNUV X-Received: by 2002:a17:906:4fc5:b0:973:daa0:2f6 with SMTP id i5-20020a1709064fc500b00973daa002f6mr25802958ejw.3.1687710549471; Sun, 25 Jun 2023 09:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687710549; cv=none; d=google.com; s=arc-20160816; b=tcoJHMLP0urAlwHY45t0VQXWjInEHfgtdR9i8gftGCyLp0SjLQQIUkFFCzdoA/g2Hp LP1reOKuouTxXdB/LD9p85NqsTIeqI5BJbCbg2GOjxSVE43ZjLBIRpDKEXgCxDWuo9e1 MpohZtWrIPQFDkF/3ijmmtqvrWIDjerCB8Cd9m9E9vruutKJKvfv3KkGplKNSPmPTinp dYHkCdMWlVBfvMLESwylR98lc1dLL9Z2ZQ9DDdbiDa3inOtACRM/BFYdMswsNHbHg7Os wJhkVj1xogqZ9hWw32a8/x3cgdlO6UYiZV8Z8VzU1VHYAfA1i5WeJdT/XY+2KBFyjhVQ S+jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4rwVBaXp6T+ncMlAEIOC8J1NmD2703iKLsw4FlIZUng=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=KBwMXL5+T+4gpHY+i5Y+1yLjfCIonwW1jI5RKt1qjBCgiqjd9fp3ZuRF+urJt+O8l5 PDowkqYumfOhUuDs5tt9J5W3nLdUrnHOCgOWblbwhgbwda1zC3htQuWYQzkBeouGrVCx W/i2G56Z3RgkK+N7Hlh2e+0lleH/qTHRfShuo3RwBcTo9Xc6lulwTmOO2TSpPm1VQKDW MEvk0eHtT5aXFAorQhhRAVqHBFgCZOnUMFC1+THfb1HXvGQOmtCJoKSMF3bHJ4VZLLJL 7GD1YkWcR1F+JKKfHMJwM2U7DtU+KsEO+RrL0F0KNNy518RWSDpooR8e2gY5Vj89rr7i 8K8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HMzrtJ+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lw11-20020a170906bccb00b00982b13e065dsi1723008ejb.208.2023.06.25.09.28.45; Sun, 25 Jun 2023 09:29:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HMzrtJ+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbjFYPSG (ORCPT + 99 others); Sun, 25 Jun 2023 11:18:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbjFYPSE (ORCPT ); Sun, 25 Jun 2023 11:18:04 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968211B9 for ; Sun, 25 Jun 2023 08:18:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687706283; x=1719242283; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mN/2WK8J7n2rewlZ5IincQ/OigkXaXVK51epQ2blgdQ=; b=HMzrtJ+NE/XMqkhhKJAxwHNriLzW71B4XhiL10MGRytkgSDV3sIQ9ENl VRK6AX0fUG3X+YuoZEDtmShUlpObQg8PasedvcQ0ByZ9gO2/0hqSDxrW3 fPKJON1D5z1lLxDU9SeZ6vF7Df+jannAmCz8C/InnWOlwCK1LZy16eXL9 by1xDaFUs4wUY+KF3OqfbEPQ6Z0tT3iOZMr8uCLKhepcRJwT1fk+gPZHO /3SXk7dvaw7vmKDqoAt6rq7UAAjU0P0jv5VEo4ReLmYnOZ3NkjYGCEYEc 0WHc+WggR6tifyawVF1SvGBvR4cEiAO+Kk/NnYFw4dt7oDhwMvAy//4mO Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391255057" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="391255057" 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:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="840004517" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="840004517" Received: from cascade.sh.intel.com ([10.239.48.162]) by orsmga004.jf.intel.com with ESMTP; 25 Jun 2023 08:18:01 -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 1/5] iommu/vt-d: debugfs: Define domain_translation_struct file ops Date: Sun, 25 Jun 2023 23:04:38 +0800 Message-Id: <20230625150442.42197-2-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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769692776737804874?= X-GMAIL-MSGID: =?utf-8?q?1769692776737804874?= Define domain_translation_struct file_operations instead of using DEFINE_SHOW_ATTRIBUTE() in order to specify source identifier and pasid to dump the specified page table. Signed-off-by: Jingqi Liu --- drivers/iommu/intel/debugfs.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 1f925285104e..072cfef19175 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -391,7 +391,25 @@ static int domain_translation_struct_show(struct seq_file *m, void *unused) return bus_for_each_dev(&pci_bus_type, NULL, m, show_device_domain_translation); } -DEFINE_SHOW_ATTRIBUTE(domain_translation_struct); + +static int domain_translation_struct_open(struct inode *inode, + struct file *filp) +{ + /* + * Allocate one 1Mbyte buffer to save sequential file output, + * since the default size of input buffer is 1Mbyte when the + * user reads. + */ + return single_open_size(filp, domain_translation_struct_show, + inode->i_private, SZ_1M); +} + +static const struct file_operations domain_translation_struct_fops = { + .open = domain_translation_struct_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; static void invalidation_queue_entry_show(struct seq_file *m, struct intel_iommu *iommu) From patchwork Sun Jun 25 15:04:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 112611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6974099vqr; Sun, 25 Jun 2023 08:36:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7SBEohLzdJ4j2i0G2EJS79/n1sMt11cOsuUIq7kY+e88Y1lswIH8G9OKkmnwPSXkOQDaU0 X-Received: by 2002:a17:907:3e27:b0:978:ab4a:2154 with SMTP id hp39-20020a1709073e2700b00978ab4a2154mr28574051ejc.1.1687707383864; Sun, 25 Jun 2023 08:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687707383; cv=none; d=google.com; s=arc-20160816; b=0T+dgYMbZlOP8lHqBRkUF2xGAyCWidXJT6vCXMJSLP4lKW/PbOjg5fYf5V62AfkAU5 Wv627fEOoJ38hsxOZsa5A7PUU27zkFoCoRrch6wglEkGmhGWD1OTjrq8hfPmzz/3fj6W pTDz/J+HzOWiX6WNQ5TWMp/W/KB9zTXJNVLsQUWQVGaONb2P2DTUTxQdutZuQd90If/H pDi7iUEcfrB9uAY8CH5jewPS+Qed0nG6j3TjpPQyfAD/8Yw5Mj6hLue4FMe3fecjFhnX 95fVbgmbv28pp2gKtuAzmJ/jSNC9b6Mfwdpm+D7Tw/XpKx2tf2LXQgFjiNppkhyUb84M kd9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8rievhekm/5LiuIgf1I5G4XxDvcj9sA2NBsume12eT4=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=ZVZiDDOXcSLIqryUQyu8CzEtoWCNaQEqduhTOb9OQX6nZojCKtohcbT5B5KwqQex+P oOmhPmyP+OjBiRGbUumGfx/LD0Z05MfWfooKqjp8fG9Odxq9Ld2dSzVHuzlnYXsoq6t4 X2bXThsf2s+WTqyNjHhvYMgtsH87RZExlU9VBk+noVMF9Li0B3nGRny6AG17HunSX0gx eS/b0uQYkPp1Df3rAVS26T4kyQ85nBhem9lSRSgX6R5SYXAx6GIvzOpPGtTJkN2sA932 v8ksV6Or5hewQ+4z9D+RISZGOGJ103W8msI8B4yDmMZ1HzzSo98imj4XhUL/dVQdqvbi dt+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0eNZqAq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h24-20020a1709063c1800b0096f523eff33si1814931ejg.962.2023.06.25.08.35.56; Sun, 25 Jun 2023 08:36:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0eNZqAq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbjFYPSN (ORCPT + 99 others); Sun, 25 Jun 2023 11:18:13 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769689458008141001?= X-GMAIL-MSGID: =?utf-8?q?1769689458008141001?= 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; }; +#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: + * [:]:. + */ + 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, From patchwork Sun Jun 25 15:04:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 112618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6986566vqr; Sun, 25 Jun 2023 09:06:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7fZOnWpaVcmwJcBx31Ly6TkakNDJjLOHsyNZXFajR10NA5thhHQbErf16cASa3P1Lt2ZVq X-Received: by 2002:a05:6a20:4410:b0:121:7454:be2a with SMTP id ce16-20020a056a20441000b001217454be2amr20313923pzb.45.1687709204638; Sun, 25 Jun 2023 09:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687709204; cv=none; d=google.com; s=arc-20160816; b=d/9Way74IMhkexT2GH0JCraiCbYT/NnWvumH/2SIB3/l/X27ZfC/CAbWHCIoTwq2jc 8Ix39vVA8QDm19Ai27jLPCLQ3QdQexQVC4LTFRehljmWRlTQCc9J/csuMHygKLNAaCGX M1ho4CAOWGTCCfaocv3j+rm4NPQb3WVbyLICoi9xAQDPUsMbJ2FdICJSXO+GVVwUJJ4K RLNqY4iXqtryNlNdaUxYsMDPVI+pan2YzUg/Nts2tgHuE9I0+RRpcUWCiy4ACHzQ1CyR ijtKV5GB2z/aBRLIhUSkVb5zjL130fLaMC/OKJHrwIXNzEDysJV8GbtmUP4FMdeEcsDm q55g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lcHtAPLQLsjZYOBLj6VdX2Lfe65iwltxQ9cgxg6+ZyQ=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=RGuJGWzMhTDbVFtiuBo3qFedoPDzmCx81YQ+OfDMyu2rXQseUysDyLZ271Z10pIJEV nZJdphLjBi7HteREQY0kNC3MhBrAiiUQh9C22DW2/Pn26UJ4baSPrbXa5XosqZcJG4jP tyEizdWvvyWzZIJNE0Ow+i9b6cgVAydnQzaQYVUKfM4iKCma9zIchJ5Nvh/KYrRU83Zx rqYRn8B9vI6SnQwtRAKJbR5MaQPgoJvhuhKgjTyGS/pFU90/3Z7RqtAmIgVNZLOB5M7x 8Jzy0lIE4QxLtY3sNtfT/RUCYKCm6Bfag90gjs0VCjh23h+5Jb1uzSbWxRdcX5EY/q4T sWyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=frs0jY2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a631258000000b0054f93b261cfsi3459168pgs.88.2023.06.25.09.06.32; Sun, 25 Jun 2023 09:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=frs0jY2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230280AbjFYPSY (ORCPT + 99 others); Sun, 25 Jun 2023 11:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbjFYPSJ (ORCPT ); Sun, 25 Jun 2023 11:18:09 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 784671B7 for ; Sun, 25 Jun 2023 08:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687706288; x=1719242288; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dGog1IvJBB3RYoMtBN+mKPewp6Oixq643V5vrMTp7ao=; b=frs0jY2kOoEDZsJT6mD43TcdgXbbGwopvrepz7WUpJR8Zdr4LPtNSjHq D5r82I80V8UoX2/3B+ztj2W5s0EHHVnIdnlDNul+r/p3uY4CN0GirTQUM LRhjjTxUt7ujZMdhDx98ZWIxIjJl7BT17jG0JTzETwRXV+4P6CEKsZ3bq HlRVH9s2gxcutxa7w4CrCrh5N+7DFRAz4182itNgu5+7xIIyteRun5R3d 4+2cKgizKZuxnvxLDGtKox3W+rEDcaEkxbm6gTXSMf5r8oClPampq8m7Z 5knZREGt9Yng3rzYsw9wNrfIWRocvRKNXeCLSCexXrH3q//mwdNLJujZL w==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391255078" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="391255078" 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:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="840004533" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="840004533" Received: from cascade.sh.intel.com ([10.239.48.162]) by orsmga004.jf.intel.com with ESMTP; 25 Jun 2023 08:18:05 -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 3/5] iommu/vt-d: debugfs: Dump the corresponding page table of a pasid Date: Sun, 25 Jun 2023 23:04:40 +0800 Message-Id: <20230625150442.42197-4-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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769691367250440518?= X-GMAIL-MSGID: =?utf-8?q?1769691367250440518?= 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 --- 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; From patchwork Sun Jun 25 15:04:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 112617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6985007vqr; Sun, 25 Jun 2023 09:04:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6iKpZav0NB+RFN9uJ64MnbLFSyutRL1inMA4IyW2bMutx40MBzR7sstM8kW8zJPTPJ2n5z X-Received: by 2002:adf:efd1:0:b0:313:df08:7b88 with SMTP id i17-20020adfefd1000000b00313df087b88mr3707238wrp.16.1687709048495; Sun, 25 Jun 2023 09:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687709048; cv=none; d=google.com; s=arc-20160816; b=HXJRTjXFOrrrYx6aFT899ywSIg41womaPNO/t97SQgg6fp6BuZbU+qdykC5+clkNcO VIGyrjOHnZf5o6okqTI6T+RC4t4usVHxbsw8sV4fbj793KbJuAH61OisfPs8amkwG6uS nTyz7fcG5UVV5slMxbKg70V/TBr3OdAzC4uG5RlHw2RAtVjZqKxsTiXF9m59X4zUgfkp p6vj+ErkrjVxblyncuSmJ3+Kt86CIIbYspmdo/SCeCiJRCu1QDUpV5/MbmGfbPHI1oIU hAlOjo6lrlkrngryCS7EkbWVBIQYPabzuZXPOGiLFwZb4Ko0qzOPc5YEb9uZgaMyv0TR HVfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3l0KIj70DuK4umy1EfL9zJG2wm/cP/ToP1+S/iP7k3I=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=egbCP+WOgTIpsgfGMDu4KKoyXPHPpaue8r9dec/Kb9Gdjkhj2kKPK7LFncZzq5KGN/ YG6/rdDmY+xkPoHpXtCuqQprcr/cdYpqgNw+07LtKwdUeIgIRHMpNl/78p3eMFddUmw/ NChcMGhYRC0YnJf0yV3wt71OnNziUPs3xigU+KvfJ5yMNAyO+JgPALn3wtjxJm2dDEWU iymQKIijmQRQhyAWAUOEyy/3dpxzg0lmK9GSVJbLNmEi8goHitkOpss9O8u+RzCkBnMw sZF/TpHg34PCOYPgWEAHaYj6y3ROAqm2dfOGof74jzkCjVt4O5Do7IHYqne63Pva/PZY 9zAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="XaR/Kx0r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kf24-20020a17090776d800b0098761436c53si1967852ejc.937.2023.06.25.09.03.43; Sun, 25 Jun 2023 09:04:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="XaR/Kx0r"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbjFYPS3 (ORCPT + 99 others); Sun, 25 Jun 2023 11:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbjFYPSM (ORCPT ); Sun, 25 Jun 2023 11:18:12 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFEF41BE for ; Sun, 25 Jun 2023 08:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687706290; x=1719242290; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MWvly+gTVz1Bc7knQ7hqBn1J0RvVjUjDzsQTS3OHj+c=; b=XaR/Kx0r/Ud++EzlBr2hzv3B9D6Td/FK/jtukZfcYDy4hT52gLqnAfbY xOGUmd+yiPmLAFA50tN+GmXlKWvZlwX8Xf+blAuVutuR83IEo7bnfmM41 zUzS0Z47W3XOakcqAygR/KKkcetcN5WQuprhrEp4Oz9P7Qnkhk8JoNXU7 pQqv3fFhvtiNtzJ34TEmhhBqeKFFSDW7wcw4PZTUhZddUuuZVu77bqTCG U3RZ2WR5qf0bS8r1lVcinikh5I4ovwv5g2BdgzuOSOeN1Wv35wwMe7mvJ NJiPz3b1NaxN51AdFKj+k+73f+wo6B24qbi3wzZ94btEQQty6JAzDHAaA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391255084" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="391255084" 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:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="840004538" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="840004538" Received: from cascade.sh.intel.com ([10.239.48.162]) by orsmga004.jf.intel.com with ESMTP; 25 Jun 2023 08:18:08 -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 4/5] iommu/vt-d: debugfs: Support dumping a specified page table Date: Sun, 25 Jun 2023 23:04:41 +0800 Message-Id: <20230625150442.42197-5-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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769691203565367334?= X-GMAIL-MSGID: =?utf-8?q?1769691203565367334?= The original debugfs only dumps all page tables without pasid. With pasid supported, the page table with pasid also needs to be dumped. This patch supports dumping a specified page table or all page tables in legacy mode or scalable mode. For legacy mode, according to bus number and DEVFN, traverse the root table and context table to get the pointer of page table in the context table entry, then dump the page table. For scalable mode, according to bus number, DEVFN and pasid, traverse the root table, context table, pasid directory and pasid table to get the pointer of page table in the pasid table entry, then dump it. Examples are as follows: 1) Dump the page table of device "00:1f.0" that only supports legacy mode. $ sudo echo 00:1f.0 > /sys/kernel/debug/iommu/intel/domain_translation_struct $ sudo cat /sys/kernel/debug/iommu/intel/domain_translation_struct 2) Dump the page table of device "00:0a.0" with PASID "1". $ sudo echo 00:0a.0,1 > /sys/kernel/debug/iommu/intel/domain_translation_struct $ sudo cat /sys/kernel/debug/iommu/intel/domain_translation_struct 3) Dump all page tables. $ sudo echo "auto" > /sys/kernel/debug/iommu/intel/domain_translation_struct $ sudo cat /sys/kernel/debug/iommu/intel/domain_translation_struct Signed-off-by: Jingqi Liu --- drivers/iommu/intel/debugfs.c | 191 ++++++++++++++++++++++++++++------ 1 file changed, 159 insertions(+), 32 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index 212d33598de9..e4d3b7836076 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -404,56 +404,183 @@ static void dump_translation_page_table(struct seq_file *m) return; } -static int __show_device_domain_translation(struct device *dev, void *data) +/* + * Dump the page table with the specified device and pasid. + * For legacy mode, search root and context tables to find + * the page table. + * For scalable mode, search root, context, pasid directory + * and pasid tables to find the page table. + * If not specify device, it will traverse all devices and + * pasid tables, and then dump all page tables. + */ +static int show_device_domain_translation(struct show_domain_info *sinfo, + void *data) { - struct dmar_domain *domain; + bool walk_tbl = false, found = false; + u16 s_devfn = 0, e_devfn = 255, devfn; + u16 s_bus = 0, e_bus = 255, bus, seg; + struct dmar_drhd_unit *drhd; + struct intel_iommu *iommu; struct seq_file *m = data; - u64 path[6] = { 0 }; + bool scalable; - domain = to_dmar_domain(iommu_get_domain_for_dev(dev)); - if (!domain) - return 0; + if (sinfo && sinfo->pdev) { + s_bus = sinfo->pdev->bus->number; + e_bus = sinfo->pdev->bus->number; + s_devfn = sinfo->pdev->devfn; + e_devfn = sinfo->pdev->devfn; + seg = pci_domain_nr(sinfo->pdev->bus); + } else + walk_tbl = true; - seq_printf(m, "Device %s @0x%llx\n", dev_name(dev), - (u64)virt_to_phys(domain->pgd)); - seq_puts(m, "IOVA_PFN\t\tPML5E\t\t\tPML4E\t\t\tPDPE\t\t\tPDE\t\t\tPTE\n"); - - pgtable_walk_level(m, domain->pgd, domain->agaw + 2, 0, path); - seq_putc(m, '\n'); + rcu_read_lock(); + for_each_active_iommu(iommu, drhd) { + struct context_entry *context; + u64 pgd, path[6] = { 0 }; + u32 sts, agaw; - /* Don't iterate */ - return 1; -} + if (sinfo && sinfo->pdev && (seg != iommu->segment)) + continue; -static int show_device_domain_translation(struct device *dev, void *data) -{ - struct iommu_group *group; + sts = dmar_readl(iommu->reg + DMAR_GSTS_REG); + if (!(sts & DMA_GSTS_TES)) { + seq_printf(m, "DMA Remapping is not enabled on %s\n", + iommu->name); + continue; + } + if (dmar_readq(iommu->reg + DMAR_RTADDR_REG) & DMA_RTADDR_SMT) + scalable = true; + else + scalable = false; - group = iommu_group_get(dev); - if (group) { /* - * The group->mutex is held across the callback, which will - * block calls to iommu_attach/detach_group/device. Hence, + * The iommu->lock is held across the callback, which will + * block calls to domain_attach/domain_detach. Hence, * the domain of the device will not change during traversal. * - * All devices in an iommu group share a single domain, hence - * we only dump the domain of the first device. Even though, - * this code still possibly races with the iommu_unmap() - * interface. This could be solved by RCU-freeing the page - * table pages in the iommu_unmap() path. + * Traversing page table possibly races with the iommu_unmap() + * interface. This could be solved by incrementing the + * reference count of page table page before traversal and + * decrementing the reference count after traversal. */ - iommu_group_for_each_dev(group, data, - __show_device_domain_translation); - iommu_group_put(group); + spin_lock(&iommu->lock); + for (bus = s_bus; bus <= e_bus; bus++) { + for (devfn = s_devfn; devfn <= e_devfn; devfn++) { + context = iommu_context_addr(iommu, bus, devfn, 0); + if (!context || !context_present(context)) + continue; + + if (!scalable) { /* legacy mode */ + pgd = context->lo & VTD_PAGE_MASK; + agaw = context->hi & 7; + + seq_printf(m, "Device %04x:%02x:%02x.%x @0x%llx\n", + iommu->segment, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), 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'); + + found = true; + } else { /* scalable mode */ + struct tbl_walk tbl_wlk = {0}; + struct pasid_dir_entry *dir_tbl, *dir_entry; + struct pasid_entry *pasid_tbl, *pasid_tbl_entry; + u16 pasid_dir_size, dir_idx, tbl_idx; + u64 pasid_dir_ptr; + + tbl_wlk.segment = iommu->segment; + tbl_wlk.bus = bus; + tbl_wlk.devfn = devfn; + tbl_wlk.rt_entry = &iommu->root_entry[bus]; + tbl_wlk.ctx_entry = context; + tbl_wlk.dump_page_table = true; + m->private = &tbl_wlk; + + pasid_dir_ptr = context->lo & VTD_PAGE_MASK; + pasid_dir_size = get_pasid_dir_size(context); + + if (walk_tbl) { + pasid_dir_walk(m, pasid_dir_ptr, pasid_dir_size); + continue; + } + + if (sinfo && sinfo->pasid == INVALID_IOASID) { + spin_unlock(&iommu->lock); + goto unlock_out; + } + + /* Dump specified device domain mappings with PASID. */ + dir_idx = sinfo->pasid >> PASID_PDE_SHIFT; + tbl_idx = sinfo->pasid & PASID_PTE_MASK; + + dir_tbl = phys_to_virt(pasid_dir_ptr); + dir_entry = &dir_tbl[dir_idx]; + + pasid_tbl = get_pasid_table_from_pde(dir_entry); + if (!pasid_tbl) + continue; + + pasid_tbl_entry = &pasid_tbl[tbl_idx]; + if (!pasid_pte_is_present(pasid_tbl_entry)) + continue; + + tbl_wlk.pasid = sinfo->pasid; + tbl_wlk.pasid_tbl_entry = pasid_tbl_entry; + dump_translation_page_table(m); + + found = true; + } + } + } + + spin_unlock(&iommu->lock); + if (!walk_tbl && found) + break; } +unlock_out: + rcu_read_unlock(); + + if (!walk_tbl && !found && (sinfo->pasid != INVALID_IOASID)) + seq_printf(m, "No mappings found on device %s with pasid %x.\n", + dev_name(&sinfo->pdev->dev), sinfo->pasid); return 0; } static int domain_translation_struct_show(struct seq_file *m, void *unused) { - return bus_for_each_dev(&pci_bus_type, NULL, m, - show_device_domain_translation); + int ret; + + if (show_domain_info && show_domain_info->pdev) { + struct device_domain_info *info = + dev_iommu_priv_get(&show_domain_info->pdev->dev); + + if (info) { + /* + * The domain has already exited, and will + * switch to the default domain next. + */ + if (!info->domain) + return 0; + + if (info->pasid_enabled && + (show_domain_info->pasid == INVALID_IOASID)) + show_domain_info->pasid = PASID_RID2PASID; + else if (!info->pasid_enabled && + (show_domain_info->pasid != INVALID_IOASID)) { + seq_printf(m, "Device %s does not support PASID.\n", + dev_name(&show_domain_info->pdev->dev)); + return 0; + } + } else + show_domain_info->pasid = PASID_RID2PASID; + + ret = show_device_domain_translation(show_domain_info, m); + } else + ret = show_device_domain_translation(NULL, m); + + return ret; } static ssize_t domain_translation_struct_write(struct file *filp, From patchwork Sun Jun 25 15:04:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Jingqi" X-Patchwork-Id: 112612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6975312vqr; Sun, 25 Jun 2023 08:39:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79324rybKgbZHjVaBetcvwZUTnQj/6etczy9H62Tkf5rsGUuLY+taOfMN4lXmXq8xX4hUe X-Received: by 2002:a17:907:971a:b0:988:c97b:8961 with SMTP id jg26-20020a170907971a00b00988c97b8961mr18800402ejc.21.1687707590954; Sun, 25 Jun 2023 08:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687707590; cv=none; d=google.com; s=arc-20160816; b=chJGUdjpf2iiFlcJlBJ6Ugq0J1WTHEQNKxz9rfyyumg5sDFhWJMgTbcB1O9VQ9QRby vkxEbM8hYxiYQ0iMPi/ylS+m/9YWslO4n3DFMz1cHNY933rgqQaid/Wca4Ajlxfs3y7X /ycsf1BxPXEsP95E5+pirIfy/P82vLU1Uyp6y75u7sc6nhAbm8reoGXOssSXErNNzAZ2 BsTHZ+fAuw5wEMn+pOyoyq0kXGf9NpKiJGXquet8phJLLDL2Ezk0WI9huYflmE4jtMcN SLwXUOMcF8Lsn9Zw+CPjhDfQ7QwepEf6XdZJ4dh4MCgA+vRYx/GkvoAGu399Jy4Ucm56 PLtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oqU4mjGDsG7X0Y8np4exQFTUONjEqCZwrz1vQcFJl34=; fh=XFDRxS7z/mPiLWcvDFNXxtez86tw5VSUEAZ1VPulNcQ=; b=zQ+0kfzM86yjBfmw7Wv+BYDRsnHv4QIcpLNDadCA6iyC010RfHA6c60t/yyoBGoI7q bUTmxmIL80tjCxPDzkLGWVFOQPcuHiEZ7WfFzxwiV481kO/WADhJ/lr8jQE+ST5qzNjj LxBGQ9y+7JuQKmhXzWZ6hAXQP3SPcii+s1xflwTxUXFYklEyJgpxXK9veC4KcLQK8T58 U77+o/9OhXYuiWwPOjb+z1icP25z25lY0s+vI57e+v7c3r3jRULMS4ohjxNQq7nEh7R0 jYk6IewedOqV0NU3Vuog7iAjqtpOn6ZNXIo84kpwcvDOPhD9npjDhSQTtcq3ysGvtP5U l1KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9m44QiB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a17090616cb00b00988ca1b3f55si1874524ejd.810.2023.06.25.08.39.27; Sun, 25 Jun 2023 08:39:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S9m44QiB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbjFYPSd (ORCPT + 99 others); Sun, 25 Jun 2023 11:18:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbjFYPSN (ORCPT ); Sun, 25 Jun 2023 11:18:13 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 042B51B8 for ; Sun, 25 Jun 2023 08:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687706293; x=1719242293; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NbhV1jUvIvoPeaMjWeaCFCY5V1AWw9RzK0uK6KP563I=; b=S9m44QiBfsasQInK9mKlcQwBofYKrUAYfbXkz07OzxCorx9lKSSc36qR OCdf0guBmUHdEujJDs9GZyhWIcKj2WF469mlEo/nBIfVzOOoW5E3KbJrT dzWpgpEsFU4JAP+NbRS57jQIhda/0mOUweMh4RspgYtODIjpCK4NDbjZ9 hDY8dZaL7u3JQIFBLlbhUtnSTxLiLFjhTeEqZm4HRO9mmw+0303zYFZFb LCt9S94vunDc6mV/gDUMS6jzMFauxT+8xuRBv2lPWgu2kWVC0qHUoTj8X qVtUQcuqvWtQMENbIQMY5AYYUCFzCcqzblxUbLuBW1IJgIPNw2mIjrCKL A==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391255102" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="391255102" 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:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="840004542" X-IronPort-AV: E=Sophos;i="6.01,157,1684825200"; d="scan'208";a="840004542" Received: from cascade.sh.intel.com ([10.239.48.162]) by orsmga004.jf.intel.com with ESMTP; 25 Jun 2023 08:18:10 -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 5/5] iommu/vt-d: debugfs: Dump entry pointing to huge page Date: Sun, 25 Jun 2023 23:04:42 +0800 Message-Id: <20230625150442.42197-6-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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769689674699035068?= X-GMAIL-MSGID: =?utf-8?q?1769689674699035068?= For the page table entry pointing to a huge page, the data below the level of the huge page is meaningless and does not need to be dumped. Signed-off-by: Jingqi Liu --- drivers/iommu/intel/debugfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index e4d3b7836076..f5e26cc21905 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c @@ -326,9 +326,14 @@ static inline unsigned long level_to_directory_size(int level) static inline void dump_page_info(struct seq_file *m, unsigned long iova, u64 *path) { - seq_printf(m, "0x%013lx |\t0x%016llx\t0x%016llx\t0x%016llx\t0x%016llx\t0x%016llx\n", - iova >> VTD_PAGE_SHIFT, path[5], path[4], - path[3], path[2], path[1]); + seq_printf(m, "0x%013lx |\t0x%016llx\t0x%016llx\t0x%016llx", + iova >> VTD_PAGE_SHIFT, path[5], path[4], path[3]); + if (path[2]) { + seq_printf(m, "\t0x%016llx", path[2]); + if (path[1]) + seq_printf(m, "\t0x%016llx", path[1]); + } + seq_putc(m, '\n'); } static void pgtable_walk_level(struct seq_file *m, struct dma_pte *pde,