Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5856365imm; Tue, 12 Jun 2018 14:42:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK4eTgwpID7FyW+FtDzlkawRzHtfgURJ1+9clSU3vI5JqQ9u8oMygrFMLGI7LCo+PVBz08+ X-Received: by 2002:a17:902:bb8d:: with SMTP id m13-v6mr2210630pls.46.1528839742834; Tue, 12 Jun 2018 14:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528839742; cv=none; d=google.com; s=arc-20160816; b=TuPPw3dzZw7pDEmLlipXvOidELc0uBH/aFzIThwFzAhkjFwSWjA9qzXMrFaQ4Yl8Ul j4zCn1Cc0TR2bj+QMmxskUHx0ybnAHpE1Do0a0EaZc89Fop4152s+vT0kCwDJZsYut9a O0FyErGljGLCrFN4a8TH8jhvCRcTWd183okkfWsYAOUJYFZP6R4Cy6gMIuPsS1AjKu4d FSZlI2H1z5Nl9ZzgQmHQFXlcVjAPpndkdnUZ/XmSp6fFLZX6BDEvPtl+JXwv+HEHmCzX 0VIkep1rHgq8Zr+NlfyROaOJlQlQusFr6KFPb1xbLaC2/ydJ6Yxnb83w0j/d/3cLsDwy xZRg== 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=+3Wv/ODDioRi4O0/4eiHxIlhtzljC8h7ioFeSZ/EMMA=; b=vH/GyHVESsNq9bz8bvQGWjE3n9E0z518VomyMaztMkhMm2XLW4UvD9tey6BxGzLE6v 6M5jCu+SUweGlQCec35uNqiK3he000fXQOl0suePMmEKB+J/AAEhVbTCQt7/3arFYudr uHtdrTf9EeZ2fUz6DPkIcyYp3OX7aBAeRi/Ar3jpBQP50A/fHcb1gR6tQix61haOHc24 dNvjo0ETkUlEPtTPl9q4AJesI2Ri3ckhei5zadqczQUNIyDA+d3Xg8tU355aCwV0h9bh VEfuUHUp4DhMrGp0+NuRWJL9Dycs5dpS3zFaiZUlKDuGwYCzXGEfl4m0kn4VOiHiOZDc lc6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=0Xk0cnIg; 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 g7-v6si904484pgu.152.2018.06.12.14.42.07; Tue, 12 Jun 2018 14:42:22 -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=0Xk0cnIg; 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 S934429AbeFLVl3 (ORCPT + 99 others); Tue, 12 Jun 2018 17:41:29 -0400 Received: from mail-eopbgr690076.outbound.protection.outlook.com ([40.107.69.76]:7392 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934354AbeFLVl1 (ORCPT ); Tue, 12 Jun 2018 17:41:27 -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=+3Wv/ODDioRi4O0/4eiHxIlhtzljC8h7ioFeSZ/EMMA=; b=0Xk0cnIg2OLsf3huJeSUWzEkMdZsc799VBEr8xzux+amTNoAy3lcECzMM3NVlAynty0gA3vLyDNd9IPIM+HJt7EIwWn0ufMsMuQlJKzvpaP/7lwLXk+SbywtDw2Qu8RKVduBuWk5ooARnWVPxZhokjbHMoPqnCFiEBakkRwIGEk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from [127.0.1.1] (165.204.78.1) by MWHPR12MB1454.namprd12.prod.outlook.com (2603:10b6:301:f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.14; Tue, 12 Jun 2018 21:41:24 +0000 Subject: [PATCH v9 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, 12 Jun 2018 16:41:21 -0500 Message-ID: <152883968097.1936.10168344980897538230.stgit@taos> In-Reply-To: <152883965482.1936.13657625103232933481.stgit@taos> References: <152883965482.1936.13657625103232933481.stgit@taos> 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: SN1PR12CA0100.namprd12.prod.outlook.com (2603:10b6:802:21::35) To MWHPR12MB1454.namprd12.prod.outlook.com (2603:10b6:301:f::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ccbf6c0-28f0-4fb1-af68-08d5d0ad3f17 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711015)(48565401081)(2017052603328)(7153060)(7193020);SRVR:MWHPR12MB1454; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1454;3:7wwOgUonqK9REWbZRfsiFLe4DJ2h2VcWsz77n2XigEYbo+QoIKeM5ItILubIuo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Rg2RT2GshEvZmEaz6soVH7+mJzfcbO18pSVT3SPMNCaug+DVXlpOPZ0tdr1Ow+QL8OIXehOkWZlrWzqcp84I9ux+KwkGbgcD+OAZVR60WvzpMzLSLYuceE/VgR5QhfseqNop6MPo5N2ErjfScfTC/O+oHMDNJAzhiXlOyX1Y8ScXA6rBXpB3rqPu4Q0O0zhHyCTZooFXPo78aVT/Q0ZkidPpiZnS/n434EgUBDY4koyeGYFBOfAImcj6rFwPi3T7yD0dJ9H49OGJ40cu8GiaeL1S/eOC4SykB873FYm0;4:ENlJutdrqeEV2ptmMLf12wA4lodl5etmYhYyj3bYSPRSWtdSL4U0KYNFgMVbnN8sazXhMvKvbEiAjh8gBDsrtm6P6dsE2QTCNHgOwvlLQiryNf60YbMxViH80enQRSn5tNfIGSSwVRGRjNytPZySCD4pLx3CAIAMCPR84LUsWNv5rsjXYMDwRfVcSTVvH0FLOjR2M+pYqurcnUdPQX7pUvQuR2zpOkfBwCEgWDW5ebMpZ6Nh+ARcy6y+trQxQZfR4JCjj9QmmnOcKeSHJSq6GB0mDJLBEqcHDeBkHD4ZRc+lixOZwuxPDXIPiI/Q3ej5oggEzd8jN/AuLGsQoJFeQkayyj6tRixl3HzuBrwA66Y= 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)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:MWHPR12MB1454;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1454; X-Forefront-PRVS: 07013D7479 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(7916004)(396003)(346002)(366004)(39860400002)(376002)(39380400002)(199004)(189003)(7736002)(8676002)(81156014)(305945005)(8936002)(105586002)(81166006)(106356001)(6486002)(103116003)(97736004)(230700001)(59450400001)(486006)(386003)(52116002)(33896004)(76176011)(23676004)(2486003)(446003)(11346002)(2906002)(2351001)(6116002)(3846002)(476003)(6916009)(2361001)(6666003)(5660300001)(956004)(186003)(50466002)(77096007)(68736007)(478600001)(58126008)(9686003)(72206003)(16526019)(16576012)(316002)(86362001)(575784001)(47776003)(4326008)(25786009)(53936002)(33716001)(66066001)(26005);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1454;H:[127.0.1.1];FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxNDU0OzIzOnJ2MmJFc0Q5dWxFRHgrTDVOUEZET20zVHRu?= =?utf-8?B?QkxZNGFqeUJKNVd2c1RjMnpNTUdNczZwM0Y1U25MQWNSbUVhYUVEVU1kR0Jr?= =?utf-8?B?N2FkUTRobk5xTWFjTnE1SFpzbkxUaHdEeE1Kd08xeUEzK2dXZHl5ZEp3dFRE?= =?utf-8?B?NWNRVXE3QWg3QkZRTDR3MnlyUlF5UG9RVm9OaDZnRUVSNEdmRDRCZG8rdEtV?= =?utf-8?B?MUU3MExQRlFpcDRsWURmbkdqOUVVL2ZqZzVsdXRzSllSNjJCaDljWkh5ZlRB?= =?utf-8?B?MWFJYXUycTFhN1cxNElFRFlVdjVYL0VaOVM3OTBZaElyNkFiMHVZczVKNXNs?= =?utf-8?B?TnlKMlZsQnBRUGxtcVVWRE9FMmliMlpxUUk1WGxXR1ZOak40ZUJheUF0QnMy?= =?utf-8?B?TDNKT1lWeGJ2UHZ5THh0aGRmM0ExZlZ2RnJFVXhPVTZHNTNaa2NIcWFCV2ZJ?= =?utf-8?B?N2lmYzJkdTZnVk55dnphWDFV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93KMFZOESTjnCszgxgzjrp8T X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2018 21:41:24.4505 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0ccbf6c0-28f0-4fb1-af68-08d5d0ad3f17 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1454 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 | 66 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 2 + include/linux/iommu.h | 7 ++++ 5 files changed, 86 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..3b1bf88fd1b0 --- /dev/null +++ b/drivers/iommu/iommu-debugfs.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * IOMMU debugfs core infrastructure + * + * Copyright (C) 2018 Advanced Micro Devices, Inc. + * + * Author: Gary R Hook + */ + +#include +#include +#include + +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); + 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) +{ + return debugfs_create_dir(vendor, iommu_debugfs_dir); +} +EXPORT_SYMBOL_GPL(iommu_debugfs_new_driver_dir); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 63b37563db7e..d227b864a109 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1748,6 +1748,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..7447b0b0579a 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -698,4 +698,11 @@ const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) #endif /* CONFIG_IOMMU_API */ +#ifdef CONFIG_IOMMU_DEBUGFS +extern struct dentry *iommu_debugfs_dir; +void iommu_debugfs_setup(void); +#else +static inline void iommu_debugfs_setup(void) {} +#endif + #endif /* __LINUX_IOMMU_H */