Received: by 10.213.65.68 with SMTP id h4csp1299310imn; Wed, 14 Mar 2018 16:10:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELuiLsW6X3m7ucwEOXe5hiZjQVlglDUOE/xrOke6KLjry69wpllHGkLgXjvCdqjJVh9Up248 X-Received: by 10.101.97.139 with SMTP id c11mr5037056pgv.435.1521069039971; Wed, 14 Mar 2018 16:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521069039; cv=none; d=google.com; s=arc-20160816; b=Dn9RIrO5N7c0MlHtEtoDBQtsSWdaq2vuUQloJ0pDk31TOJ5nVh+1/oc6nxONGYt9n6 MHBj74soSzqNni6ViIEi1H8z7+8rTKkVsCWy3GFjS4fObDy/JWtE56pSI0+l2+m7LYxb Y9Eaje82vARrWHA3BYy6S6hqbYj0LZyfT+vln1CmuoJffvnsawvdUqtXFQRtDU/MO3hu nLvqz4NyT8P+ZNypbjVD0OM9+2YS/RC4NEIXDbObZMHYP58bHwirDVgKjs06++mZ2bZE NOFJh2cYN1ueZ0cUNkroIQC5DfcD7f5asbt+WyyozT5OnXJDlle3Le1gqn43lCT7VBs4 0mDQ== 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=R3soHPrREWfrJog4unye5o7RVOr3mQw2C6rgXxBrXHg=; b=qxnCChMH6rCmX309eGD7dmZzzMcFCPxnekY2lG8SrZbov7+sPosOXIH+3r24ilsg6H e13S+YaSC1RBUusXc1VffE7SIH0yipPTd1j2iysZ7vy/nByyhIWghTPRfiVfES/rKVs1 g6pQ2rAn7SjkDHBbKMKYvju/zHliI1QJIuSVyxzeoqvItxLBE4S/dr/T9cA4NQo79lk6 A97Ry/HBrqElhrcjRuFn0YASCve81Ak9qMMrDB3cnHmXmCXdnI73YWXN1sSKpX1j9GDK GWb8wqBy7JCBWtWo/7039SUcy/8OUhnEfH7TqZIHOrV9LhTnmrKCPWShcYnRNFkqQHT1 eUxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=E2xrYDcC; 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 l5-v6si2055829pls.740.2018.03.14.16.10.25; Wed, 14 Mar 2018 16:10:39 -0700 (PDT) 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=E2xrYDcC; 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 S1752025AbeCNXFq (ORCPT + 99 others); Wed, 14 Mar 2018 19:05:46 -0400 Received: from mail-cys01nam02on0062.outbound.protection.outlook.com ([104.47.37.62]:14368 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751289AbeCNXFm (ORCPT ); Wed, 14 Mar 2018 19:05:42 -0400 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=R3soHPrREWfrJog4unye5o7RVOr3mQw2C6rgXxBrXHg=; b=E2xrYDcCc/o9K6JBGWOfHnU1faio/urKaIS2eo9a07uDJFdJEhEX9DFjTdx4RfFFQ0MLEpddKA0g9pDUUqogM/hloVSFD/74pnYbDPdJc7f2v9LBjbKxVMqW6/0/MZmr2Tj/b61EC297zI/AHHpYP1WEEPTQ1GidjNSJyEisBt4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from sosxen2.amd.com (165.204.78.1) by BY2PR12MB0696.namprd12.prod.outlook.com (10.163.113.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Wed, 14 Mar 2018 23:05:38 +0000 Subject: [PATCH v3 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: Wed, 14 Mar 2018 18:05:34 -0500 Message-ID: <152106873475.67212.6697709546085749566.stgit@sosxen2.amd.com> In-Reply-To: <152106836233.67212.15861879210675477690.stgit@sosxen2.amd.com> References: <152106836233.67212.15861879210675477690.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: MWHPR15CA0035.namprd15.prod.outlook.com (10.173.226.149) To BY2PR12MB0696.namprd12.prod.outlook.com (10.163.113.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4b5f0eb7-a8c3-4bd4-e044-08d58a001abe X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:BY2PR12MB0696; X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0696;3:7tWNEi9Tv4wa3PtTK9/ccrUT3ZQP+wSRyi4CD1QEeHr3bumbMBrgaFmI8K43V0qSGtB8OwbGHDNQZH7ntJCTvRo4VVNvOfSoKKs7pAV0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hYDs3D2WGy4Udi5sOqDkFZcecBebv/btrTznIGTj/QI45g0TeYTRQgxHE/q/JUdEvFmTQ+GfsGDfh6Worm/A478VYIjdtaaTSOkfQrUf3aKxv63CZPqG8P4pnrGw8FcbL7vN+zaacVmJDtGijLNj36cchL60Il+RRXKkDTuChlvD5Ta3+TMnY2pN9ePc4QfxciOaQvVI0irS1XudShy4GmRJCtkNEMl9OuPJNiMUDqvlT9FsF8QGyuh/mmEQXqIc/yNcqdiiDPOTgv;4:aBsRmF+lZxCcCklVplN5u2mU26aRMfF+As7agpus36sVzoGocV5E0EXbgUV0CzZsNInLvKy0cqEh3AHubwDykxswqTihsP7mjJ1Tt9M1iODASVPwj/0zUVPgPOz4Ol/jiCCQjngbHuhjOjYM/cgmiTLZpRK0OJYYcP+1kHxU8cWzl/w7eCHXqQr55fu8R9KZlwx/mXqJnJnDKTd2klb0wj97Q/LmfeoFhtkDp72j/aBnaFKfGbaqEqDIokwKX4wh3p9ereUaCNcNwZoOaH521K50YDwkIIGFsGfGrqgrcrTHBVidZqYk7fmf2jXK4pIh X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501244)(52105095)(3002001)(10201501046)(6055026)(6041310)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(6072148)(201708071742011);SRVR:BY2PR12MB0696;BCL:0;PCL:0;RULEID:;SRVR:BY2PR12MB0696; X-Forefront-PRVS: 0611A21987 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(346002)(376002)(39380400002)(396003)(189003)(199004)(68736007)(316002)(66066001)(5660300001)(2486003)(3846002)(7736002)(186003)(305945005)(16526019)(7696005)(52116002)(59450400001)(6116002)(478600001)(50466002)(26005)(53416004)(8936002)(23676004)(8676002)(81166006)(105586002)(386003)(81156014)(72206003)(97736004)(4326008)(55016002)(103116003)(230700001)(6916009)(106356001)(2351001)(2906002)(2361001)(6666003)(2950100002)(86362001)(25786009)(47776003)(58126008)(53936002)(76176011);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR12MB0696;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?MTtCWTJQUjEyTUIwNjk2OzIzOk1SbGNnOXpvU09IczYvMDBiWVZUWnZLd0No?= =?utf-8?B?NVEvMk9wU3pIamFqTk9ZSUVCaVZtck9kNEVJZGVHT1k1cXRPcVp1ZnpXNmgw?= =?utf-8?B?QUhJYjNoMlFiR2h6S25ReEV2aTNFUVAvSmROWW9BaWdpNjUzZmQ0aWJFcHdQ?= =?utf-8?B?aDMzMmozdTd6Tk9sQXlFUGw0SW9DeFlrNW1pZVNuVlB4UnRrTU1BS1puNnpO?= =?utf-8?B?ZU8rditvU0NUTldxQU5QZlpWcDZROWtVYStNcDJzWFNmZFNvWllla3dITWJk?= =?utf-8?B?WWJwSmJ6SDRPbFgyQlZxdmxQSVhJWjdxTW1UTCsyU3ovekk4YkEyS1BjWEc4?= =?utf-8?B?akJZZ0lnZ1VKNFV5eTZsMVIva2lNRTRpQ09TOERkQWN6ZHRxRElWZmRNQ09K?= =?utf-8?B?Q3c3MGs3ZDlmMERSRmx2QlIyQXREZG9HdngzSEpWL3NKMklEY3BwOXJmWlVF?= =?utf-8?B?Ti8zQmM4dzQwc3NjZDdrV1BBcjhGZ3g1ZUtpejVXZ2lhYWlrN09YWkRJcU0v?= =?utf-8?B?aGQvd3g3UXZFd3ltcXBjaUJMbUxMYW1acDY0TXVlcUxaUStRMGhZWlFub2hU?= =?utf-8?B?Q0taUWpsdWpLcXZIU2pyVmorbGc1dE5wOWZXYm1YVTcySjhhRm9pRnFNY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SJZKK28PVTiQTn1f6K6gXCCxQfzp8M5FwzgCYW25Zhk48b7r5TIhAxPZ6BCLoGO3bse/6Lcy2XL4ar0DlazFHO6MeY2Fh22Mwx1XHshTX1yJLzNd9aefGafvz7dhw+8ACUeOs/b9KdrL1vnA44Xa2Qgzm8QbQWidPHD9ng14UxzMww4 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY2PR12MB0696;20:w2tCbBsS04xImxPBYTN8c5xtb1KrlOQTryChpzKVCA7daOZLj3NiM07dVBNHvy0i71LaNzUTwR3VNN5Io8F+8pev2ixXf2REXz6gKYC74F61iU7mv8OScA84AWEbsRztZk0bKFlTBrOthlopkLFltHiFR632vQ8hHVfY9F0/qk3SCh6yCnKXxxbn0X9uFUAISFnpkRZJqE4kxELWVuI8z+/63CHOjQRSZfGRuq2XCRH+96PG+aVpRDIK4vvzbb9s X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2018 23:05:38.9579 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b5f0eb7-a8c3-4bd4-e044-08d58a001abe X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR12MB0696 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 | 121 ++++++++++++++++++++++++++++++++----- 1 file changed, 106 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/amd_iommu_debugfs.c b/drivers/iommu/amd_iommu_debugfs.c index 1d941c5329be..47bf718f6178 100644 --- a/drivers/iommu/amd_iommu_debugfs.c +++ b/drivers/iommu/amd_iommu_debugfs.c @@ -42,6 +42,7 @@ static DEFINE_MUTEX(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) { @@ -92,14 +93,84 @@ 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) +{ + unsigned int obuflen = 64; + unsigned int oboff = 0; + ssize_t ret; + char *obuf; + + 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; + + obuf = kmalloc(OBUFLEN, GFP_KERNEL); + if (!obuf) + return -ENOMEM; + + ret = simple_write_to_buffer(obuf, OBUFLEN, offp, ubuf, count); + + if (strnchr(obuf, OBUFLEN, ':')) { + int n; + 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 { + kstrtoint(obuf, 0, &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", \ - PCI_BUS_NUM(i), PCI_SLOT(i), PCI_FUNC(i), \ - amd_iommu_dev_table[i].data[0], \ - amd_iommu_dev_table[i].data[1], \ - amd_iommu_dev_table[i].data[2], \ - amd_iommu_dev_table[i].data[3]); +static inline int amd_iommu_debugfs_printdte(int i, char *obuf, unsigned int obuflen, unsigned int oboff) +{ + int rc; + + rc = OSCNPRINTF("%02x:%02x:%x - %016llx %016llx %016llx %016llx\n", + PCI_BUS_NUM(i), PCI_SLOT(i), PCI_FUNC(i), + amd_iommu_dev_table[i].data[0], + amd_iommu_dev_table[i].data[1], + amd_iommu_dev_table[i].data[2], + amd_iommu_dev_table[i].data[3]); + return rc; +} static ssize_t amd_iommu_debugfs_dte_read(struct file *filp, char __user *ubuf, @@ -113,19 +184,28 @@ static ssize_t amd_iommu_debugfs_dte_read(struct file *filp, char *obuf; /* 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 += amd_iommu_debugfs_printdte(i, obuf, obuflen, oboff); + } else { + i = amd_iommu_devid; + oboff += amd_iommu_debugfs_printdte(i, obuf, obuflen, oboff); + } ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff); kfree(obuf); @@ -142,12 +222,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, @@ -210,6 +295,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);