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,