Received: by 10.192.165.148 with SMTP id m20csp3480203imm; Mon, 7 May 2018 13:03:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqS5OSoVrFXvtt3ynfpgCRcd8KPBzvVuXetNgBpiGPu6aAuJZ+ba8xCTQnWIM0avzbg6jj3 X-Received: by 2002:a6b:b513:: with SMTP id e19-v6mr38012956iof.267.1525723432981; Mon, 07 May 2018 13:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525723432; cv=none; d=google.com; s=arc-20160816; b=bC3V/PgdMmaMouk8Oq9ieMG+xIF0azFhvLq6xkMS1YouoVpEhZR01JFkzT6eq5ka2q 5i5sJVyicArmpAtnrj0oHiiW6D9zw0okEPowBAYRO+nGwwJMcfcn5gn9a7OtFMp8EDPY WS5O/yTd7nATNkD1YWRvup2HMScvXZxChPkUFhaXqR3ThNd1iesrDWPkvkmt+5XD0U2H 8kUGoeWgEtmHU61X4OXqecJrXqghM/UGTfm0PuLRYhbyO6Lpjqcclv+n9D7iPEWbpwd/ Axr5Zk0mf62W8L6kWtcV06zugCfLvbY6P08fRC+CTXcl7G7RMcEMMlBG+/aKMoOEEDRA dToA== 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=hk7Ftqu9rdjGcw99xo1zOkZUK/R7mQb4OMs/UEf7gNs=; b=zoJtIKiRFto4hj4RGb4t3XgVBg6dyc3hnFaDtiEAsc/ObwnvADlLFUwOMKiWdfxk19 /bh8YignVb3Fv9EEn07xhFJXwgzv8MIEVo5h3J5rmweKg8i++KKVaLJtrqqd1BpbCmBf kYHy0tu6+18UaVFV9y09H8HTI+75kSMwaKWBzstma7FR/7RUCY5svdCCAJ9LzHabAfs7 5LNyaURv2SBra6mvtr1amf7GfoJn+HaOGKuVxUTW3oJFhhCIvbi9xg4XX5NOj/MXrDJ+ j5td90/RjJ814hxvL6P/a/Lv5CrlT7UIgccpjSSivm6341cwNZ8szr1g+yUZNPQAaUsF uR1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=gm4Qz+dl; 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 e92-v6si21109148iod.186.2018.05.07.13.03.39; Mon, 07 May 2018 13:03:52 -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=gm4Qz+dl; 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 S1752798AbeEGUCM (ORCPT + 99 others); Mon, 7 May 2018 16:02:12 -0400 Received: from mail-sn1nam01on0056.outbound.protection.outlook.com ([104.47.32.56]:14628 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752389AbeEGUCK (ORCPT ); Mon, 7 May 2018 16:02:10 -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=hk7Ftqu9rdjGcw99xo1zOkZUK/R7mQb4OMs/UEf7gNs=; b=gm4Qz+dlO2tBJ4tWSpjvJkiTnmTmhhBG8izwEXovT7hhTamuQ5b/WO20iFxKuszivI/6gdyZ8zgf/mhbUtHmRBFg4kztefxj2xdChcDfs8M5TeQGsG4koNfolPu7xpu3fd0i1zMur5Yz0LG/sPvIJDmeYIJxVVvbu40NpTib2Ks= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Gary.Hook@amd.com; Received: from sosxen2.amd.com (165.204.78.1) by BN6PR12MB1443.namprd12.prod.outlook.com (2603:10b6:405:10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.735.16; Mon, 7 May 2018 20:02:07 +0000 Subject: [PATCH v5 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: Mon, 07 May 2018 15:02:03 -0500 Message-ID: <152572332370.3235.16541462864315443906.stgit@sosxen2.amd.com> In-Reply-To: <152572281179.3235.11484188869064303333.stgit@sosxen2.amd.com> References: <152572281179.3235.11484188869064303333.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: SN4PR0501CA0094.namprd05.prod.outlook.com (2603:10b6:803:22::32) To BN6PR12MB1443.namprd12.prod.outlook.com (2603:10b6:405:10::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020);SRVR:BN6PR12MB1443; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1443;3:pCLlALJJTLsvym9Pc82ee1xPuGngLVvYlTJENJOh625mOYdatJGbXLF6W1HhnKEDs19Sw15xAZaDllCOF7u6zKagZMNWiCPhCvWV916vRlt6IYmCtf2ZKrEQQWwmJOepsDkTAuOBaphBKkczNiVm3vlYBD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z+95S2fforrwVaxNfe+apAV1pkFHhg5CssVS7D8nOcVA/KMCvjc/q6VST5Qt1QylMPEXv5i3bMhfXWIC2GnJ7ZCUkrQt4GHJGD7eHMwxGOA1/e338/LmlJuXMr3Htk71h8Y7AWjnjOk69p4umYAgmHoczj3jZn8I+C4LbVBDtEgCm6JEw5BVvD9U/;4:ibAtrf7tf6FFmbtgdonYBxLqAj2XWxyi9WItnvQX8o49kPJn4Bn11pvmUhcATeGo2Z53Ea9vcTA09/bPZ7kyEHX79ge+p/wou/LKbK5oNnpdvSHA+xsNSP8dtTFBwnmpXCCgBfLML94zPE8vSiwA5xMPzcxg1w0aWv/evBcy5od9IZkoW9rZhaxBYzSQY1b2hLHSJrriSa6l6TvJY5/z85PF4D7XHXxn7fDhJ/mO5grFj1J3Esp29zjYJZTh9Yr0vBL7KPXqEs4coBEMQufGDZE7UC902aoayy17oS7Aure62canvqyvZafsRa4Qn0dWLjhVutLUfeSGIMAdWO4sEw== 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)(10201501046)(3002001)(3231254)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011);SRVR:BN6PR12MB1443;BCL:0;PCL:0;RULEID:;SRVR:BN6PR12MB1443; X-Forefront-PRVS: 066517B35B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(396003)(346002)(39380400002)(39860400002)(376002)(189003)(199004)(6116002)(8936002)(81156014)(81166006)(8676002)(2906002)(66066001)(50466002)(106356001)(2486003)(52116002)(2361001)(2351001)(53936002)(3846002)(23676004)(7696005)(305945005)(59450400001)(956004)(55016002)(97736004)(68736007)(230700001)(486006)(386003)(478600001)(316002)(72206003)(7736002)(47776003)(86362001)(105586002)(4326008)(5660300001)(76176011)(103116003)(6916009)(6666003)(53416004)(26005)(11346002)(16526019)(58126008)(446003)(25786009)(186003)(476003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1443;H:sosxen2.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?MTtCTjZQUjEyTUIxNDQzOzIzOkhQL2paTFl1L3YyaEk1cXpjcndoUUp2dldk?= =?utf-8?B?MDVDNFhPQisvaGV6cXlkR2ZHblpGWkhxL0M4Y21oMjExdjlzZTR1QWROcTRo?= =?utf-8?B?QnQvb1RqVC91U1lnL25qMC9TdzhsdHRKcTlKbnZNZWkrQWk1ZjNyQWwvV2NB?= =?utf-8?B?V0NRSnVoQWp5bFI5dHBFR0FIUFhuODBoY2RkWTk3N3UvOEpYQ2xPbU1kUjdl?= =?utf-8?B?SWlid3pHc1c1NDNNVVNBNnR0VHcxa1NQRGRWUUVNcVp2bkRqUjl4WndSTTU5?= =?utf-8?B?VnJ1Wkk0WTA1WnNCZFVlbkowQ0dLZ1FtWmR4WHNxODY4SEMxTXJuSHhpdHE0?= =?utf-8?B?RjgvcVgxcWpFQnhMaDVYMjRjaXFjbGNuYkJDTm5tS1RGRzFUWGphNm95aUtx?= =?utf-8?B?TXdKNXFpTnFEWWkwY1NkNFJVM0pudHdCbEd1SHNkWTE5OVNYa3RjL3JFcDAr?= =?utf-8?B?Qk5WdEEwVU53b2hwOU9JZlZmWHB3SU44a3FpSmgyM2l5Q0VIbWtHMklMaWYv?= =?utf-8?B?ZXJFcTlaM1dsZVZ3c2pYNjh2TDllWGFMa244QVk3R2tmaE1PTXhVQkdyZ3NP?= =?utf-8?B?RXl6cWM0TUtiRDBPWUpCN0Vvb0ttbnp0T0lRVSs4cEx3RHh6c3l1Y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ASyJoMGkN0=;24:8ezF3FDyHMKAJKNLJKVEcp9Fm3qVzpRjWtCU5ESPcnaTNzok81bDE0jwymcO6nX+HnV8ffn/13emKW1Up2k+d7KOwVk8GWXd+vOGMUGf30g= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1443;7:GQpR9ausbHtcLn/R8gOFEtRg4FK0la7VrsDVqMjl/tpzFZVX74HcIzoG6FmxVvmJmwPN1IFMMGBW6wEzvJWRngdIELGbNf+q/pjC0uf4TJuWhOX83T6t1qVfBdz/x7q5rQW9mIXFryvA8HlaXAq7L8c/536QbDPzfxXWlAhpidMBS5EafF9WOePUBL6LLHQduiCoMXHRKzI0WWUznwzMf4e23j4r8sNJp8H5kjIltfSCiHZ/d3pWij54y1YXNp6G;20:yJQu/JC5mDl92N3CEy228MuxDhB5w8bul/xqAI8VIoktj8eastJijQPaFberhGYGdlwjpUGFmrXA5CDp/DYNgNtmL8QBCIV/M2HniSEMTxoMUrI9ag8eIzWnIOqZKqqa/Ql43+FQ4H8Kicdr4eUdXDeIH6DYzsU89HQsDqoPMWLLQrmYoIZuw4oUL3ooy2RPY6VAWLywnF3T7/7ZUbQdhD3CXcMgXFwFL4iibeTbJQWw8wLs3NzxPGepv1oqWGly X-MS-Office365-Filtering-Correlation-Id: 2ce30de7-b18d-43d4-188c-08d5b4556959 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2018 20:02:07.1836 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ce30de7-b18d-43d4-188c-08d5b4556959 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1443 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 | 11 +++++++ drivers/iommu/Makefile | 1 + drivers/iommu/iommu-debugfs.c | 64 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 2 + include/linux/iommu.h | 8 +++++ 5 files changed, 86 insertions(+) create mode 100644 drivers/iommu/iommu-debugfs.c diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index f3a21343e636..ff511fa8ca7d 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -60,6 +60,17 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST endmenu +config IOMMU_DEBUGFS + bool "Export IOMMU internals in DebugFS" + depends on DEBUG_FS + default n + 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..d82a10b2478b --- /dev/null +++ b/drivers/iommu/iommu-debugfs.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * IOMMU driver + * + * Copyright (C) 2018 Advanced Micro Devices, Inc. + * + * Author: Gary R Hook + */ + +#include +#include +#include + +static struct dentry *iommu_debugfs_dir; + +/* + * 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. + */ +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"); + } + } +} + +struct dentry *iommu_debugfs_new_driver_dir(char *name) +{ + struct dentry *d_new; + + d_new = debugfs_create_dir(name, 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..6bdfe942068b 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -698,4 +698,12 @@ 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(char *); +#else +static inline void iommu_debugfs_setup(void) {} +struct dentry *iommu_debugfs_new_driver_dir(char *) {}; +#endif + #endif /* __LINUX_IOMMU_H */