Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3677575imm; Tue, 29 May 2018 11:25:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZos3MzJxf4sx/JNIloihFNd05fuJ+l3UfHpfPa2oH9f5PjPMJ4Q/WW5O4H0x6t6EXVn/SXg X-Received: by 2002:a62:b03:: with SMTP id t3-v6mr18449069pfi.32.1527618306757; Tue, 29 May 2018 11:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527618306; cv=none; d=google.com; s=arc-20160816; b=q9pG23w4qE/Wn2/QuDOhTNJFNHQ/MB3Avhpk8uiC5TzwCFrZFyI/ld0rBbI6C1sX0k C47Nat8s3KEnADn7CMvWBvtmZ8/9RwKF+fnfc47QnQ1y6vFvX0Hql5CAZti6ebSZRRpz OstQ+cMCisPmYkltrlOP2F9vu/ZBSM0ByTA8lkoY2NRhyXuhxJH0YaY/a2sRcbsUWxJx P968PKI7kP4JF9dswvSENnYrhTXe5txzfa512v7WUG9WoqIpQSAhD+woW6mVWHbdXS9q 7+MVv2P4kXOq6s9P9S1NhlPRt1ZT8XRxGgfmWewc2jXEEhpUeqpr6GuOZR49Fo1kfNSV Mm0A== 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=oD6jANPuX9yxUniccHZEDmjZmlj6WJlW6X43JIuod4Y=; b=NPsri1KKVxYi4hOAKhInvzQEjDyl9vPjT9rk940ZxyPfF1myGisDPIrapZXt6K8U2X yOwSeqRngN+qiERhYMaom7AhqM8ppE5byk/z/t8ljzmJTAqaFW711tNBtNVQR7qPfWJC Vq4M5dqnf0dyTBq7lLmhrqKMXdnZu8s/CuZ8wZWIoLLHV7lThhJlTCma2p1ooUyIBnxm 25D0f7yPXqnIlLSaUp/kgJitrk7WKimiDHtgc9EIlcQ/7Tipz749Ij5iVKQYe91T5u6J 0H2oltVizr2XtPryMcIyn2zPTvNqDoP4/517YKeKxVcY1SqVIhCCjC5x1Wnh8mjXzqbm yfVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=VmFLGx++; 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 f38-v6si11264426plb.117.2018.05.29.11.24.52; Tue, 29 May 2018 11:25:06 -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=VmFLGx++; 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 S966156AbeE2SX1 (ORCPT + 99 others); Tue, 29 May 2018 14:23:27 -0400 Received: from mail-dm3nam03on0083.outbound.protection.outlook.com ([104.47.41.83]:40208 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965954AbeE2SXU (ORCPT ); Tue, 29 May 2018 14:23:20 -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:X-MS-Exchange-SenderADCheck; bh=oD6jANPuX9yxUniccHZEDmjZmlj6WJlW6X43JIuod4Y=; b=VmFLGx++WiWR73qxvV0Wlrg23xLVDNrWixpUJH9ltM5fesU259mpup0oGajtGs12eEStZcwJX5YOy68wMo/Ku1a/xWj96WaSpBTJyG0dpN41OvK4ak5/TCfz8NrY/E4lbcBGssDwCKH7FBAltQwBN284MGK3hpg0SeS3ihdindk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from sosgrh1.amd.com (165.204.78.1) by DM5PR12MB1450.namprd12.prod.outlook.com (2603:10b6:4:d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Tue, 29 May 2018 18:23:18 +0000 Subject: [PATCH v8 1/2] iommu - Enable debugfs exposure of IOMMU driver internals From: Gary R Hook To: iommu@lists.linux-foundation.org Cc: joro@8bytes.org, linux-kernel@vger.kernel.org Date: Tue, 29 May 2018 13:23:14 -0500 Message-ID: <152761819480.2654.5371070582955429468.stgit@sosgrh1.amd.com> In-Reply-To: <152761784341.2654.8609366076331539902.stgit@sosgrh1.amd.com> References: <152761784341.2654.8609366076331539902.stgit@sosgrh1.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: SN4PR0601CA0011.namprd06.prod.outlook.com (2603:10b6:803:2f::21) To DM5PR12MB1450.namprd12.prod.outlook.com (2603:10b6:4:d::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:DM5PR12MB1450; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1450;3:X8n79YCAg6SorqacExifWydAPzstDblbb6NMDmD6FfmpEwAmHUW0+msz4YPYIXM2DRcn9PUPQDm6NMslSPIa0M5gKNHzCccDCVHTtmv2vVsiY3CRtU6Yr9oaeK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0R+uU99KsXB+e0wQxA1LNILHlPkQpRVjouBvm6zApjhE6zYHPmON4LC/xDHKUi7NsFmFYUs+3QVWOKEBVGpFocCg5eWrHZ4VfbS9im+QKOpnSZtebTHdGfiSQbpiNc76d8K8KzZr3Gx90iDfTUalii0sNw+Mv7Kp6jOQp+cD849FwRtopowrf9XDNitvs/Yyud3wLK3CMDLmph2v+Ywbobi47r7vbfcwBhtb;4:L8NRsPS2a6H5dH7HrCLVxBjCgist+l4Oh8NwiQJAIgkZ4NG4MRYtvFfTkC6DVtRfjWLv1ptrkIvNFiWEiZruVsRugh7dxzD5ZWbgGRphkNNXMvVLXrs+OLMBnle5Smohon7dkFHOc2Hb0wMQtl5SdaTRxNzTK+phJWRjtsTtNNmVT3YpQb7yK9ksnsaTJEMSCRQC1/jLHrNXY9NHp9zYr+61WryxBMN9g0OXTw7j8isDc75rVFJN49gouKIkqPNgpdmV0FiYYw8QTTePAF6Cp90b0nPCK6vh0HHUadhhH5oKo2zo5nmQhGFsFl5Osy+OGhRv0BuRooj9qH7COlDOEq+aaihMTdWxKJsICvjl1rE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705)(767451399110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:DM5PR12MB1450;BCL:0;PCL:0;RULEID:;SRVR:DM5PR12MB1450; X-Forefront-PRVS: 0687389FB0 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(376002)(39380400002)(346002)(39860400002)(396003)(366004)(189003)(199004)(106356001)(956004)(476003)(4326008)(50466002)(81156014)(81166006)(316002)(8676002)(53936002)(446003)(26005)(11346002)(16526019)(186003)(2361001)(2906002)(25786009)(68736007)(103116003)(8936002)(2351001)(230700001)(486006)(3846002)(6116002)(66066001)(386003)(575784001)(72206003)(86362001)(97736004)(5660300001)(6666003)(6916009)(47776003)(55016002)(59450400001)(105586002)(53416004)(7696005)(52116002)(76176011)(23676004)(305945005)(58126008)(7736002)(2486003)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1450;H:sosgrh1.amd.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxNDUwOzIzOnJvNmRldkk4Q0Y0RWt1VFh2TU5CUk9GdTlV?= =?utf-8?B?a3g5MS9VUVlOQ3RYbkZpSCtXNVNiOUdOYm0wY1pzRktIMFdpKzVaVUcrdzkw?= =?utf-8?B?RzAvcWN1TWJtZG9QaEswZUNnNEd0RDVlOXZnTWlHaHlmVmRkWWtha0pZOVBD?= =?utf-8?B?N2M4U21RUlBYMDZmYU04c21GeGQ0SDR4anpIcDRMOWJaQ1BxVzN1OE83WDJn?= =?utf-8?B?ekZ3SW5CNEZyOUV4S2tRZ1pPcGxpb2oxd2tISWxYVks5aW5BZThBWk10N2JK?= =?utf-8?B?MU45VWljODlqc05reGV4SlRQQmZtdFBISEJSZnh0OTVqdXFyUURLTGtNZEtl?= =?utf-8?B?Q3Q5clBveEZMQzhmTjJGTTc1U0RLMG52clpKWXVra0NoZXhZTndtNS9adC9E?= =?utf-8?B?YWxVeE5JdS9xS3Y2TVNGYUtxMjJDYnVvN0oyZHJ3c2I0ODkwY0hFczNLVWE5?= =?utf-8?B?dDFhRE9jblpmeWZraS85SEY3UXBQcW53M3R1M0NYUkJRZVd0bDIyaENvckpV?= =?utf-8?B?T3IxQzhLM09nbCtWZWhOd3R4ek5hMFZnaUNVOTZmV0h1cEVBT29UUXk2Tkhw?= =?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qmALJRoM1GQ9y/EJ2TQP6WKr5L6WsXinUfqDmsKjWBgPjdWSAV/Valq0Yf05RzT1gmpB0H71RP77R3uim+pVLQlCawzS4/ZCeOagnirQwsfAIPd8=;24:LU64EGjw5sPFQ7jLYSDB8FizOiNRChviiifT5D7oN+nm6AgIsdxWr8fYXW9+8qPp1SivF2kW/RdLZL75DXF/n09Bx7iRjqpBRlbHcRjTmRE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1450;7:kFD14mni5a6Z8uJbLiztrj7IYnx2cGZ2w2v16Zv48IRUCRdYUK9NcEbjzryhW/BSOplzHbg030Ym7vUPx4pIMVm1RA0JmEKJn5jT99ZKDuhAbutXVgdOgBXrEJUg9niMvgXtfga0kraidiOwYIjXPNLU2+RiBvyb5cypGQr6hb4sxIUTs4IjiP8gI5t/ZP9SkvV1Fgsm5m5p0cHsdAhqcceMBGaB4x9k5qi69ohMvUhlqhvHjH1WTyJNbyBTPZy6;20:+s5l/Q4YejBfRqgRX3rPgOpZ5m1ZYSbtYiDMQrpST42n67sscFBEdbMk280aY22dr6xbvpWv79NrX8pGMMaHR1vDU6A8NqaCplGkaRuUBZ50KQQ/T5TdD3EKXJbaC8CsHHLZq9hGozPa8bQNXtT2yDKLGaY+MZ2Mc+Vuxe4AOLjdDwoLHkMqTJAGsrFzxjrGfDbT5g98ShYHIsLI/1qSJ2O+lkjZ4IUXeosyBEwg3/BRuXZQzIBjwj5Iwbd/RBCs X-MS-Office365-Filtering-Correlation-Id: 597b4143-f135-4a4d-a205-08d5c5914060 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2018 18:23:18.0828 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 597b4143-f135-4a4d-a205-08d5c5914060 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1450 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide base enablement for using debugfs to expose internal data of an IOMMU driver. When called, create the /sys/kernel/debug/iommu directory. Emit a strong warning at boot time to indicate that this feature is enabled. This function is called from iommu_init, and creates the initial DebugFS directory. Drivers may then call iommu_debugfs_new_driver_dir() to instantiate a device-specific directory to expose internal data. It will return a pointer to the new dentry structure created in /sys/kernel/debug/iommu, or NULL in the event of a failure. Since the IOMMU driver can not be removed from the running system, there is no need for an "off" function. Signed-off-by: Gary R Hook --- drivers/iommu/Kconfig | 10 ++++++ drivers/iommu/Makefile | 1 + drivers/iommu/iommu-debugfs.c | 72 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 2 + include/linux/iommu.h | 11 ++++++ 5 files changed, 96 insertions(+) create mode 100644 drivers/iommu/iommu-debugfs.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index c76157e57f6b..f9af25ac409f 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -60,6 +60,16 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST endmenu +config IOMMU_DEBUGFS + bool "Export IOMMU internals in DebugFS" + depends on DEBUG_FS + help + Allows exposure of IOMMU device internals. This option enables + the use of debugfs by IOMMU drivers as required. Devices can, + at initialization time, cause the IOMMU code to create a top-level + debug/iommu directory, and then populate a subdirectory with + entries as required. + config IOMMU_IOVA tristate diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile index 1fb695854809..74cfbc392862 100644 --- a/drivers/iommu/Makefile +++ b/drivers/iommu/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_IOMMU_API) += iommu.o obj-$(CONFIG_IOMMU_API) += iommu-traces.o obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o +obj-$(CONFIG_IOMMU_DEBUGFS) += iommu-debugfs.o obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o diff --git a/drivers/iommu/iommu-debugfs.c b/drivers/iommu/iommu-debugfs.c new file mode 100644 index 000000000000..bb1bf2d0ac51 --- /dev/null +++ b/drivers/iommu/iommu-debugfs.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * IOMMU debugfs core infrastructure + * + * Copyright (C) 2018 Advanced Micro Devices, Inc. + * + * Author: Gary R Hook + */ + +#include +#include +#include + +static struct dentry *iommu_debugfs_dir; + +/** + * iommu_debugfs_setup - create the top-level iommu directory in debugfs + * + * Provide base enablement for using debugfs to expose internal data of an + * IOMMU driver. When called, this function creates the + * /sys/kernel/debug/iommu directory. + * + * Emit a strong warning at boot time to indicate that this feature is + * enabled. + * + * This function is called from iommu_init; drivers may then call + * iommu_debugfs_new_driver_dir() to instantiate a vendor-specific + * directory to be used to expose internal data. + */ +void iommu_debugfs_setup(void) +{ + if (!iommu_debugfs_dir) { + iommu_debugfs_dir = debugfs_create_dir("iommu", NULL); + if (iommu_debugfs_dir) { + pr_warn("\n"); + pr_warn("*************************************************************\n"); + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); + pr_warn("** **\n"); + pr_warn("** IOMMU DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n"); + pr_warn("** **\n"); + pr_warn("** This means that this kernel is built to expose internal **\n"); + pr_warn("** IOMMU data structures, which may compromise security on **\n"); + pr_warn("** your system. **\n"); + pr_warn("** **\n"); + pr_warn("** If you see this message and you are not debugging the **\n"); + pr_warn("** kernel, report this immediately to your vendor! **\n"); + pr_warn("** **\n"); + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); + pr_warn("*************************************************************\n"); + } + } +} + +/** + * iommu_debugfs_new_driver_dir - create a vendor directory under debugfs/iommu + * @vendor: name of the vendor-specific subdirectory to create + * + * This function is called by an IOMMU driver to create the top-level debugfs + * directory for that driver. + * + * Return: upon success, a pointer to the dentry for the new directory. + * NULL in case of failure. + */ +struct dentry *iommu_debugfs_new_driver_dir(const char *vendor) +{ + struct dentry *d_new; + + d_new = debugfs_create_dir(vendor, iommu_debugfs_dir); + + return d_new; +} +EXPORT_SYMBOL_GPL(iommu_debugfs_new_driver_dir); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d2aa23202bb9..350819f1c5e1 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1747,6 +1747,8 @@ static int __init iommu_init(void) NULL, kernel_kobj); BUG_ON(!iommu_group_kset); + iommu_debugfs_setup(); + return 0; } core_initcall(iommu_init); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 19938ee6eb31..0933db261b9d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -698,4 +698,15 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) #endif /* CONFIG_IOMMU_API */ +#ifdef CONFIG_IOMMU_DEBUGFS +void iommu_debugfs_setup(void); +struct dentry *iommu_debugfs_new_driver_dir(const char *vendor); +#else +static inline void iommu_debugfs_setup(void) {} +static inline struct dentry *iommu_debugfs_new_driver_dir(const char *vendor) +{ + return NULL; +} +#endif + #endif /* __LINUX_IOMMU_H */