Received: by 10.213.65.68 with SMTP id h4csp1297565imn; Wed, 14 Mar 2018 16:06:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELvTlismHPYWt79OLZisyJbIloj7tp2ZG+UMh6fAq5YIfuCjM8os56KVdmPBnIh7RRiSHQfF X-Received: by 10.98.133.86 with SMTP id u83mr5840622pfd.172.1521068780459; Wed, 14 Mar 2018 16:06:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521068780; cv=none; d=google.com; s=arc-20160816; b=ul51d8KPEqM5pnnN2enuu/0BMrEGqOMXf/zEBnYEtwpCur6G0QJTARvOXjtaZKZcMz uWsVPveE9Bn6s7ytT2c7ctFm5opNiQHIA8xKRKjPhXob+h1btGKtzov469eF7h1g/Ggz zrLBW5W+uLrix8aDqOBCq1Qt/ciTHjOcq63pEznKNGT4LcWpkAukUj4HIAbc2hFvNwde qsKS6Cqcu1f6FClNhqY0cQ/uoF0+PJmZEVCg0hGpnfzof6Um1rcFkwMU/Yd//fc3pApC KeEH0FfDFe/WeEBTNB6B6QN0xWOp2VC56S9Y2USKliYkaPcEF9pDyKm3MN2P0SAvddFX 9PKQ== 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=dYTM/OSkDU6jVHfDbyrGIC6DchPLpOpzsAsmadaZ8Dg=; b=EKY1CjvEp6uWwnne6LJMIKR7zQEXWWVbFs2uKxlyU6+nZJJbipeoGIbg6qbxNoLu3J Y4VGFGEMwMvO7Q65a6k2EvtSEUHZ86aMLtNxZ58YRl7VjRy5uTVO7WzESYqPpf8XpCxP 1FwZWcvQBE0mWTEHk8i2fAzNRZHR8/I9RWVp7wmTOKz9+muvx+eWNgsln/ouLA+cDrfd H/xQPM7a3a2GSftsiYY5tmIWm6ZoWCbOt9jpRCjpyNjSNXdw2r37PEgvUHfzCFqdvWkS 8HtibsVgUWC2LjekLKaCk6hw7q3/arpb2vrZ704XHmsH/rGvSNAYz2SiLACm9ws11QAH knDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=BmOynqpR; 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 n12si2548947pgc.316.2018.03.14.16.06.04; Wed, 14 Mar 2018 16:06:20 -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=BmOynqpR; 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 S1751700AbeCNXFF (ORCPT + 99 others); Wed, 14 Mar 2018 19:05:05 -0400 Received: from mail-by2nam01on0045.outbound.protection.outlook.com ([104.47.34.45]:55981 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751549AbeCNXFB (ORCPT ); Wed, 14 Mar 2018 19:05:01 -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=dYTM/OSkDU6jVHfDbyrGIC6DchPLpOpzsAsmadaZ8Dg=; b=BmOynqpRlbAhVhCEpMqVSMDTlviIH0dfwfilwdku5yOEYxQ04QIcQdgy2ONQ/ajKexmhZXher2fFxg9euEMs/FR1vdS1XHW/WaPkujEzBnx/nf5SPS8A01tta8t3b2PvtammfSiceiXhmjUza40jgL5g5tN8TRZzlvb4pZXUxB0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from sosxen2.amd.com (165.204.78.1) by CY1PR12MB0697.namprd12.prod.outlook.com (10.163.238.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Wed, 14 Mar 2018 23:04:58 +0000 Subject: [PATCH v3 1/5] iommu/amd - Add debugfs support 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:04:55 -0500 Message-ID: <152106869537.67212.11927240111825397411.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: BN6PR1201CA0009.namprd12.prod.outlook.com (10.174.238.19) To CY1PR12MB0697.namprd12.prod.outlook.com (10.163.238.158) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 72f90a7e-24d4-498b-05ee-08d58a0002db X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:CY1PR12MB0697; X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0697;3:oiZbG8jydY+Gjh4/uwecZ5rQjw7X+x5fCJ9RdF9b+bjC96tz9GcWYPqOe4E9ZGJg3pqfa3DSjeFStcp9rAc2YWAYvy6g+IKydtH6BZ5M/FXKk+PL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qd88mD0ZBTFVlKZ95JTJ55Skjn+l/Xu5hM7NR8VGFIK5TBJmn+Imp0CSMTaPBe3mq365nXIo41lcBnsfnxFWp8DER6AsyojRGbiwLvqhW+61iKHPaS7oZRRzpYQXY9mxwAEG/GQAeR80eXJDJMNfhIL7D5OGpQgHVbOjwOrxJpEpB46VnFJbTT+jq8defh/5XfO5pmSs4wfFJcc5FjYsRAkp0x20XqX;4:HFOcs+/UeqKNNDztnphV3EaM4Y60ssZQSy6/Dk1+1RNA5VgVCS/lPm2cVEJ/h3A+nmTY5KQvst/AL+IjRwJamM4R21IGcpG0iilPVilEszyO4NuvycYx01uMLb+dLvXxOJ9kgkHTihnbr89DVx/3YQAskuNZPvfA4agV6eLs2RzuFQeBu49/styMo27iuikGShfF3VYre6Rsb2+HxGft7zw9RE55esPAr3cQ6e/8vp0p2TUWufUfo6AfGXQtY7/lgpOmIFeOa4+Y6ohagu+4bdHUy7ydTO7bj4w14GO/WUEbEZnDefNK7jo9/MlZITbq 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)(3231221)(944501244)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:CY1PR12MB0697;BCL:0;PCL:0;RULEID:;SRVR:CY1PR12MB0697; X-Forefront-PRVS: 0611A21987 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(376002)(39380400002)(39860400002)(346002)(366004)(396003)(189003)(199004)(53416004)(26005)(23676004)(103116003)(16526019)(81156014)(2950100002)(8676002)(230700001)(305945005)(105586002)(2361001)(386003)(6916009)(68736007)(52116002)(7736002)(59450400001)(50466002)(2906002)(6116002)(186003)(2486003)(7696005)(3846002)(72206003)(81166006)(8936002)(478600001)(66066001)(25786009)(2351001)(6666003)(53936002)(4326008)(55016002)(5660300001)(58126008)(76176011)(97736004)(86362001)(106356001)(316002)(47776003)(575784001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR12MB0697;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?MTtDWTFQUjEyTUIwNjk3OzIzOmlhUGJtU1pGSjNwTi81MXEvNFhRT0ZLd2lo?= =?utf-8?B?U3lTSHozYjVCR2pvUml1QUhhTHRIelZEVXVpek9seldPcDJjK0JBSk1QaVRi?= =?utf-8?B?cVhOak5UUlFybnEyclZyd1ZZSjZxb2hNWU1iemxOOEZmK3NvNkVoWm1CNnk5?= =?utf-8?B?K29hQTZBakdLUkVZTDFNcVYyQTJzRmV6Yi8vWGtkWkY1R29qQWozZ3NYUE1z?= =?utf-8?B?aDVDejZTZVBGWnN2VlNIaUYvdW1SOXlVb2FMTTEzNTFZYnhjK3RaWTRuY29H?= =?utf-8?B?aXlHeldNdVZBYkVUWXlZb0x5ZXh3MVF0a0xqTHNpcXpBRTdkdVcxeG1vRitC?= =?utf-8?B?ZVpkbWdndytMUFJBWUtRczNJSHBzYlRlK3ZRVjRRYmJDeWx1TU11VWZIem9U?= =?utf-8?B?YURubHA5UTlqTEFGL091VHpGSmczYTlYOGVWUXJpTDd5TU9LUHV1Qmp4VjVX?= =?utf-8?B?Qkw4bnVuM0loK3U5VFZLWTBKMUNQQ3FQTnAwckZ3cWg3UXhuQi9PMXg2SlY5?= =?utf-8?B?SEJGRHdpUFgrZWJ6VjBkQ1Rid0wrdWZabnBTNGs0Z01ONjN6V1pGQm0vaVlz?= =?utf-8?B?eGIwc0xnU2FadFVBSWpKclRYZ3FDRW5NQkphU2pLdjJIbTBzT3lTVWJxMjFR?= =?utf-8?B?aDNabWdJSkZ2SzhHQkxqZHN6YT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ePcdMnfEUvqCoP3ksEMpZ3lWdaPDJORcMReHfWCgMthES8MCvfWbT/aVG+AWCaykrNVI1kknpG80mTkoU713zyM3q0K5isJbpEIHY9+ZAQPYubuwsteHaBRsMgAPHMZRUqWG1/Invqg2EHOVPenGpFkN/kWOXXebqN9sKDN1XraS/FWiA9y5 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR12MB0697;20:k1VwY5OppNQ8TO5pqtHmLDQpg3rPC6H9sNafXb8TJnCC1+JO6+4IwODp54zxu2p0p89pF9EQni/XIorEaWYb+Ghg9e2KlCn3EzWMCOheR/0XuqTgn7UkJV0RbLTBD/JuxLgf063al7z5QEqz1SyaZPBpfKoEPIVzCGwrGsrHAEbp0MOVWXVR3QVBHbnehdBtDOUGj4tY5QLcOpIyWF3wkyRQYoqfs0IdJBTX0kN87WcyATlB0LgdX0yqMKAU4BBP X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2018 23:04:58.8615 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72f90a7e-24d4-498b-05ee-08d58a0002db X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB0697 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expose the IOMMU MMIO registers and device table Signed-off-by: Gary R Hook --- drivers/iommu/Kconfig | 7 ++ drivers/iommu/Makefile | 1 drivers/iommu/amd_iommu_debugfs.c | 122 +++++++++++++++++++++++++++++++++++++ drivers/iommu/amd_iommu_init.c | 6 +- drivers/iommu/amd_iommu_proto.h | 7 ++ drivers/iommu/amd_iommu_types.h | 3 + 6 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 drivers/iommu/amd_iommu_debugfs.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index f3a21343e636..8b2a5b8707c6 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -135,6 +135,13 @@ config AMD_IOMMU_V2 hardware. Select this option if you want to use devices that support the PCI PRI and PASID interface. +config AMD_IOMMU_DEBUG + bool "Expose AMD IOMMU internals in DebugFS" + depends on AMD_IOMMU && DEBUG_FS + help + Provides debugfs access to IOMMU data such as registers and device + table entries. + # Intel IOMMU support config DMAR_TABLE bool diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 1fb695854809..64fba8b1ca4f 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_IOMMU_IOVA) += iova.o obj-$(CONFIG_OF_IOMMU) += of_iommu.o obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o +obj-$(CONFIG_AMD_IOMMU_DEBUG) += amd_iommu_debugfs.o obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_ARM_SMMU) += arm-smmu.o obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o diff --git a/drivers/iommu/amd_iommu_debugfs.c b/drivers/iommu/amd_iommu_debugfs.c new file mode 100644 index 000000000000..4f0f05a89a41 --- /dev/null +++ b/drivers/iommu/amd_iommu_debugfs.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD IOMMU driver + * + * Copyright (C) 2018 Advanced Micro Devices, Inc. + * + * Author: Gary R Hook + */ + +#ifdef CONFIG_DEBUG_FS + +#include +#include +#include + +#include "amd_iommu_proto.h" +#include "amd_iommu_types.h" + +/* DebugFS helpers + * + * This is intended to shrink the scnprintf statements used to produce + * debugfs output. Each function that uses OSCNPRINTF will need to declare + * local variables: + * + * unsigned int obuflen = ; + * unsigned int oboff = 0; + * char *obuf; + * + * wherein obuflen is the expected buffer length needed for the output text. + * Every statement then reduces to + * oboff += OSCNPRINTF([, [, ...]]); + */ +#define OBUFP (obuf + oboff) +#define OBUFLEN obuflen +#define OBUFSPC (OBUFLEN - oboff) +#define OSCNPRINTF(fmt, ...) \ + scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__) + +static struct dentry *iommu_debugfs_dir; +static DEFINE_MUTEX(iommu_debugfs_lock); + +#define MAX_NAME_LEN 20 + +static unsigned int amd_iommu_count_valid_dtes(int start, int end) +{ + unsigned int n = 0; + int i; + + /* Scan the DTE table from entry 'start' through entry 'end' for + * active entries + */ + for (i = start ; i <= end ; i++) { + if ((amd_iommu_dev_table[i].data[0] ^ 0x3) + || amd_iommu_dev_table[i].data[1]) + n++; + } + return n; +} + +static ssize_t amd_iommu_debugfs_dtecount_read(struct file *filp, + char __user *ubuf, + size_t count, loff_t *offp) +{ + unsigned int obuflen = 64; + unsigned int oboff = 0; + unsigned int n; + ssize_t ret; + char *obuf; + + obuf = kmalloc(OBUFLEN, GFP_KERNEL); + if (!obuf) + return -ENOMEM; + + n = amd_iommu_count_valid_dtes(0, 0xFFFF); + oboff += OSCNPRINTF("%d\n", n); + + ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff); + kfree(obuf); + + return ret; +} + +static const struct file_operations amd_iommu_debugfs_dtecount_ops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = amd_iommu_debugfs_dtecount_read, + .write = NULL, +}; + +void amd_iommu_debugfs_setup(struct amd_iommu *iommu) +{ + char name[MAX_NAME_LEN + 1]; + struct dentry *d_dte; + + if (!debugfs_initialized()) + return; + + mutex_lock(&iommu_debugfs_lock); + if (!iommu_debugfs_dir) + iommu_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); + mutex_unlock(&iommu_debugfs_lock); + if (!iommu_debugfs_dir) + goto err; + + snprintf(name, MAX_NAME_LEN, "iommu%02x", iommu->index); + iommu->debugfs_instance = debugfs_create_dir(name, iommu_debugfs_dir); + if (!iommu->debugfs_instance) + goto err; + + d_dte = debugfs_create_file("count", 0400, + iommu->debugfs_instance, iommu, + &amd_iommu_debugfs_dtecount_ops); + if (!d_dte) + goto err; + + return; + +err: + debugfs_remove_recursive(iommu->debugfs_instance); +} + +#endif diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 4e4a615bf13f..a03142fd6179 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2721,6 +2721,7 @@ int __init amd_iommu_enable_faulting(void) */ static int __init amd_iommu_init(void) { + struct amd_iommu *iommu; int ret; ret = iommu_go_to_state(IOMMU_INITIALIZED); @@ -2730,14 +2731,15 @@ static int __init amd_iommu_init(void) disable_iommus(); free_iommu_resources(); } else { - struct amd_iommu *iommu; - uninit_device_table_dma(); for_each_iommu(iommu) iommu_flush_all_caches(iommu); } } + for_each_iommu(iommu) + amd_iommu_debugfs_setup(iommu); + return ret; } diff --git a/drivers/iommu/amd_iommu_proto.h b/drivers/iommu/amd_iommu_proto.h index 640c286a0ab9..db5872d3d40f 100644 --- a/drivers/iommu/amd_iommu_proto.h +++ b/drivers/iommu/amd_iommu_proto.h @@ -33,6 +33,13 @@ extern void amd_iommu_uninit_devices(void); extern void amd_iommu_init_notifier(void); extern int amd_iommu_init_api(void); +#ifdef CONFIG_AMD_IOMMU_DEBUG +extern void amd_iommu_debugfs_setup(struct amd_iommu *iommu); +#else +static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {} +#endif + + /* Needed for interrupt remapping */ extern int amd_iommu_prepare(void); extern int amd_iommu_enable(void); diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 6a877ebd058b..43c008dc7ade 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -593,6 +593,9 @@ struct amd_iommu { u32 flags; volatile u64 __aligned(8) cmd_sem; + + /* DebugFS Info */ + struct dentry *debugfs_instance; }; static inline struct amd_iommu *dev_to_amd_iommu(struct device *dev)