Received: by 10.223.185.116 with SMTP id b49csp252816wrg; Thu, 8 Mar 2018 16:53:09 -0800 (PST) X-Google-Smtp-Source: AG47ELswbDNyb0hxhJhqgHGbzeMOtyEn4qYlX+VSMh5VDCl94/TLmJv6WSXTGhWzJtIPUnNjo6q4 X-Received: by 10.99.126.14 with SMTP id z14mr23175131pgc.429.1520556789034; Thu, 08 Mar 2018 16:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520556788; cv=none; d=google.com; s=arc-20160816; b=ypidGY69y/ifDsTRVmydVT1djc3hPxVbojGAE2hZJnBKzqtCXGgSL63fUY1pvha+WG 7gqRCrIViGRCrmPGG/0ky3TUx/NZongGZPno5MtuNOhuOCbv9SSyIH5DMCott1vrpfAR qS1oIpn9Jys32VqVr8oN6NnZrow2TXHhBu+aHGIqYfrgzMowC6x5dZ5ixPaVGWzGIcom F4w//FBeJtfnputrzRGPGaMkw8rHLR1w8sVh2pzSwmS/UfDQwU/uoebMggErpIG/1eRU wPRRMOVi9u0mqFUn/dJYAcQPIkBWNtALw8m+LFW/tHA9ljB+87lptT3nQnfjT1rd88iC dR2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature:arc-authentication-results; bh=pjnzZC2WjMyFvimYOlUh+rt/1QAH0ftsnVkraL79hRY=; b=zUMJ76thABujvpplSqsMZFtg9XlCffgh9IRbP/YzUE5ElffHUF706ESZWT2vc/7MSR ClC/0QOw4zDcgnTIv89Ghat5Z/+4IqQbY5uh6SV6zWpRkKrMLgyZC3SblgxiVPm1kRK6 +2Fnv1rKhjljdF9dqMxudigNIr+iJBg88MGis7sKKn74oghxO5fKU8U5GEaR/0Yhyr1k huOoV6FdTzsZRCN5bIOMFQ68Tw5H85MK074jJLdwNNoaTZNd8vbVqIZz8LOWxwEd8mCF KVuM04cw5urTkGehDDTOC1ZSscIsP+xsEHT//BiXDt2HpFKHUD+AgR5APA3ygaHYP3aU LSsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=I0OG7sks; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si13775534pgq.796.2018.03.08.16.52.54; Thu, 08 Mar 2018 16:53:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=I0OG7sks; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752005AbeCIAvl (ORCPT + 99 others); Thu, 8 Mar 2018 19:51:41 -0500 Received: from mail-co1nam03on0084.outbound.protection.outlook.com ([104.47.40.84]:59608 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751146AbeCIAvj (ORCPT ); Thu, 8 Mar 2018 19:51:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pjnzZC2WjMyFvimYOlUh+rt/1QAH0ftsnVkraL79hRY=; b=I0OG7sks5IqLZhbK7qpRU+bPKnD83GizxBhMsiSKZxpg5+z2fppPhM+zIqzrAcrsZZGv4r2EMoRDfGKUowcTQUAiIO4b28tlVI/sAWO9VZ35b8IPkmPAqOGLO/xFtWKV/Myg+S6qLJIx23eklS9s5fwCcJx5dt4II0BDwV9/wFQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from sosxen2.amd.com (165.204.78.1) by BLUPR12MB0689.namprd12.prod.outlook.com (2a01:111:e400:5950::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.12; Fri, 9 Mar 2018 00:51:35 +0000 Subject: [PATCH v2 5/5] iommu/amd - Add a debugfs entry to specify a IOMMU device table entry From: Gary R Hook To: iommu@lists.linux-foundation.org Cc: joro@8bytes.org, linux-kernel@vger.kernel.org Date: Thu, 08 Mar 2018 18:51:31 -0600 Message-ID: <152055669123.63229.1692099069085978884.stgit@sosxen2.amd.com> In-Reply-To: <152055660594.63229.5131049527614494130.stgit@sosxen2.amd.com> References: <152055660594.63229.5131049527614494130.stgit@sosxen2.amd.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: BN6PR17CA0020.namprd17.prod.outlook.com (2603:10b6:404:65::30) To BLUPR12MB0689.namprd12.prod.outlook.com (2a01:111:e400:5950::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8f9b53ac-5e7d-49ad-f93f-08d58557e8c6 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:BLUPR12MB0689; X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0689;3:RFt8ZVkDzC1q/DEFAYLhKJilAZ+uThpkEKXGabrj3c4H0ybA6SIKSqPrmcRrekxZVx4h+eYhLqT1USt5W9Wyyv3WIry7OsuR2rL7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jxVeW/up1rVjUkCLlpenrxraUMdkQtghkeectZ8vZbnDLJwzJ8cUikLMvx2eOTP59cXi7fn7xPaHXBqp8sQYmkbW7+KbGE0RGNVuCDEJLuCuS+ACHj4xWWu+Ls20h4foQHAtHyyWUAd9FIATc+olrzQmvQvzoNLFIzAVJ9iIXg/6tnWbAGjU+GSKL1nE7fwMc63M+ANDpeJ4echWiS2jwQ/q8L2gk++XmLsscnQhA9CLmETbo;4:o2nvcbtu2OWD1joakdjxNXXFxOEkjKV7ToOhLe4Wv8r1IbMwT8+Hj7F+MEQE7/WcONu9MC8srj5/YEbdg2XZKTm5+MgkKIAhzvGSOIDqV/pQrj76Kp8fWFb3QwD2znBEYSccz3Kj8j05zy54N4wZqL1/PlIPXv8wmo6Zl9Ig9bovkoSmlFxc17DmFWXcoGwu0/HdwcebLHrsFx+hzUtGeXwgjHmkYIejW8gcUFJ1Vve0Fs+Ej4s1vfTNk96+sE/5NMZ1yugNVJTND8gWcOvdlC87rWYWBbxFOcnPHdakz9ZK471R05xYm9fIfvOLJTXc X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040521)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(3002001)(10201501046)(6055026)(6041309)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:BLUPR12MB0689;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0689; X-Forefront-PRVS: 0606BBEB39 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(979002)(39380400002)(366004)(396003)(39860400002)(346002)(376002)(189003)(199004)(97736004)(2950100002)(6916009)(6666003)(316002)(2351001)(58126008)(53936002)(81156014)(8676002)(386003)(86362001)(26005)(59450400001)(16526019)(8936002)(186003)(81166006)(55016002)(52116002)(230700001)(72206003)(4326008)(478600001)(2906002)(2486003)(7696005)(50466002)(23676004)(76176011)(3846002)(25786009)(5660300001)(68736007)(103116003)(305945005)(105586002)(2361001)(66066001)(7736002)(106356001)(53416004)(6116002)(47776003)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR12MB0689;H:sosxen2.amd.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjEyTUIwNjg5OzIzOnF5UjFqK0s4OUtGV1pMQVlMY2tneWhQZjZj?= =?utf-8?B?VGNwU1hHRmpHTzFKT1lmZFFKM2d1a200Mmp2dFgwUFJWZ2d6c2FhcVhJTmMr?= =?utf-8?B?ZHkwQlhlNGJ2NnRBVEJ5dDVrYm51bSswdllMcEgvOGhoN3hwNFB1a3dESllD?= =?utf-8?B?eUNsNE9MN2lxeDlnRkZuS29uY2RxaEYwOExnNWdudElSNjArNTZMMUhPQmRN?= =?utf-8?B?bUtPSldnVkEwWXk3bTQwSUtndk50eXplbWc4ekxTV21IOFBYdUg3Lzd1ZTFU?= =?utf-8?B?ZVhnQjArUmRsRzM1UW5zQnlHZFMyZ05mcDQrU0VTd3ZwdUhrb2NSNDJ3ZHN4?= =?utf-8?B?MzZSbHFaSVVWSG1XbWNEU1lYY0dZaThiNi84WVN4eHMwcDBKbHJGVjczYjFa?= =?utf-8?B?aEh4V1FJV29LZm01RUpXaXhTbmhVNm84bG4wYTNvczVGaWNLaHRvSzdKMHV6?= =?utf-8?B?bnJocTBUUkY3N3NGcm9QTDNWb2ZoTG1PUzJ6OFVEWVNsMkNDVm4xbW1nVUdu?= =?utf-8?B?aUY1b2dQK245Y1B0TTlLRWpoemZHTGxkQlhMa090bVlpMkV3bjI0NGl5dnJi?= =?utf-8?B?TXBTTGh4TVY5M1VXREIrK0FHTHYyamVQc3RWaE02Sks3V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TJsMufJ9F0=;24:oY9bZBVn7A6iMmvpPMaWWZYV3qtl40Mtfh/bZa9KbAy2gLiZybDflg/Zn0to9x+RvTaD5XBSdhVAKlm6rlx4vgJIXYNRk5jfySaj5t9o6xk=;7:SS7G+cqNSfcblyHHJ5ENc27R4NVSvGSoPjJxDeSAugLliQkzfDUJi06oN3vx0WPG+/jYA0znvrtpLPT+I6aQ6yTr3CrcYD6jD8Q5jz58sTJj1ajEL51KUzTUv+wQd5A5ISDtdn2y+gojGrGa/Aj5576XomIQC+r8sxdhupvsbEkB1Nci6aduiY0yVDM2hjbLaSEhMSMOgJRBFOFPn0cgLqtFtbwzg4imcP0+nnrl738NjNqq2OGCTWxdOwSzcp6c SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR12MB0689;20:uyGgeIZBKUolc6A8ZNI0WmvQUqq/6A75VKbwFjsOjxuwG3LpWhQDa9fm4XC5vs0KDJBVjPdMYa6J+zCthQlf5Em4NlbB08+3kGgnb9rXfS/6WcZG44rpEMYaSyvUvEEZml8m3fMYfRbBRffURLzWBsY7npjoirViAeOBJ5y7VHfWsXQTugZxunBSepCMZAQmP9XuBvvGa4lzAJPMiAFft4AD8Z4PwQeRRIxlpmmG4g8c8qfeer8fEYNX4lTdJyvL X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2018 00:51:35.3373 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f9b53ac-5e7d-49ad-f93f-08d58557e8c6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0689 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initially (at boot) the device table values dumped are all of the active devices. Add a devid debugfs file to allow the user to select a single device table entry to dump (active or not). Let any devid value greater than the maximum allowable PCI ID (0xFFFF) restore the behavior to that effective at boot. Signed-off-by: Gary R Hook --- drivers/iommu/amd_iommu_debugfs.c | 109 ++++++++++++++++++++++++++++++++++--- 1 file changed, 100 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/amd_iommu_debugfs.c b/drivers/iommu/amd_iommu_debugfs.c index c4e071f7a5b9..aa6935340163 100644 --- a/drivers/iommu/amd_iommu_debugfs.c +++ b/drivers/iommu/amd_iommu_debugfs.c @@ -28,6 +28,7 @@ static DEFINE_RWLOCK(iommu_debugfs_lock); #define MAX_NAME_LEN 20 static unsigned int amd_iommu_verbose = 0; +static unsigned int amd_iommu_devid = ~0; static unsigned int amd_iommu_count_valid_dtes(int start, int end) { @@ -81,6 +82,76 @@ static const struct file_operations amd_iommu_debugfs_dtecount_ops = { .write = NULL, }; +static ssize_t amd_iommu_debugfs_devid_read(struct file *filp, + char __user *ubuf, + size_t count, loff_t *offp) +{ + struct amd_iommu *iommu = filp->private_data; + unsigned int obuflen = 512; + unsigned int oboff = 0; + ssize_t ret; + char *obuf; + + if (!iommu) + return 0; + + obuf = kmalloc(OBUFLEN, GFP_KERNEL); + if (!obuf) + return -ENOMEM; + + if (amd_iommu_verbose) + oboff += OSCNPRINTF("%02x:%02x:%x (%u / %04x)\n", + PCI_BUS_NUM(amd_iommu_devid), + PCI_SLOT(amd_iommu_devid), + PCI_FUNC(amd_iommu_devid), + amd_iommu_devid, amd_iommu_devid); + else + oboff += OSCNPRINTF("%u\n", amd_iommu_devid); + + ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff); + kfree(obuf); + + return ret; +} + +static ssize_t amd_iommu_debugfs_devid_write(struct file *filp, + const char __user *ubuf, + size_t count, loff_t *offp) +{ + unsigned int pci_id, pci_slot, pci_func; + unsigned int obuflen = 80; + ssize_t ret; + char *obuf; + int n; + + obuf = kmalloc(OBUFLEN, GFP_KERNEL); + if (!obuf) + return -ENOMEM; + + ret = simple_write_to_buffer(obuf, OBUFLEN, offp, ubuf, count); + + if (strnchr(obuf, OBUFLEN, ':')) + { + n = sscanf(obuf, "%x:%x.%x", &pci_id, &pci_slot, &pci_func); + if (n == 3) + amd_iommu_devid = PCI_DEVID(pci_id, PCI_DEVFN(pci_slot, pci_func)); + } else if (obuf[0] == '0' && obuf[1] == 'x') { + n = sscanf(obuf, "%x", &amd_iommu_devid); + } else { + n = sscanf(obuf, "%d", &amd_iommu_devid); + } + kfree(obuf); + + return ret; +} + +static const struct file_operations amd_iommu_debugfs_devid_ops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = amd_iommu_debugfs_devid_read, + .write = amd_iommu_debugfs_devid_write, +}; + #define MAX_PCI_ID 0xFFFF #define PRINTDTE(i) OSCNPRINTF("%02x:%02x:%x - %016llx %016llx %016llx %016llx\n", \ @@ -106,19 +177,28 @@ static ssize_t amd_iommu_debugfs_dte_read(struct file *filp, return 0; /* Count the number of valid entries in the device table */ - istart = 0; - iend = MAX_PCI_ID; - n = amd_iommu_count_valid_dtes(istart, iend); + if (amd_iommu_devid > MAX_PCI_ID) { + istart = 0; + iend = MAX_PCI_ID; + n = amd_iommu_count_valid_dtes(istart, iend); + } else { + n = 1; + } obuflen = n * 80; obuf = kmalloc(OBUFLEN, GFP_KERNEL); if (!obuf) return -ENOMEM; - for (i = istart ; i <= iend ; i++) - if ((amd_iommu_dev_table[i].data[0] ^ 0x3) - || amd_iommu_dev_table[i].data[1]) - oboff += PRINTDTE(i); + if (amd_iommu_devid > MAX_PCI_ID) { + for (i = istart ; i <= iend ; i++) + if ((amd_iommu_dev_table[i].data[0] ^ 0x3) + || amd_iommu_dev_table[i].data[1]) + oboff += PRINTDTE(i); + } else { + i = amd_iommu_devid; + oboff += PRINTDTE(i); + } ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff); kfree(obuf); @@ -135,12 +215,17 @@ static const struct file_operations amd_iommu_debugfs_dte_ops = { static char readmetext[] = "devicetable Print active entries in the device table\n" +"devid Controls which device IDs are printed\n" "count Count of active devices\n" "verbose Provide additional descriptive text\n" "\n" " Dumping the Device Table\n" -"The device table is scanned for entries that appear to be active. The\n" -"default range is from 0 to 0xFFFF, and only active entries will be reported\n" +"The device table is scanned for entries that appear to be active.\n" +"The default (initial) range is from 0 to 0xFFFF, represented by a devid\n" +"value greater than 0xFFFF, and only active entries will be reported.\n" +"If devid is set to a specific value, only that device entry will be\n" +"displayed (active or not). devid may be specified as ##:##:#, a decimal\n" +"value, or a hex value.\n" "\n"; static ssize_t amd_iommu_debugfs_readme_read(struct file *filp, @@ -204,6 +289,12 @@ void amd_iommu_debugfs_setup(struct amd_iommu *iommu) if (!d_dte) goto err; + d_dte = debugfs_create_file("devid", 0400, + iommu->debugfs_instance, iommu, + &amd_iommu_debugfs_devid_ops); + if (!d_dte) + goto err; + d_dte = debugfs_create_file("README", 0400, iommu->debugfs_instance, iommu, &amd_iommu_debugfs_readme_ops);