aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary R Hook <gary.hook@amd.com>2018-06-12 17:41:21 -0400
committerJoerg Roedel <jroedel@suse.de>2018-07-06 08:06:30 -0400
commitbad614b24293ae463e74d2465685f0e4e229baca (patch)
tree5548eef5b84284b0621f60ffdde93c75e92a6241
parent021c91791a5e7e85c567452f1be3e4c2c6cb6063 (diff)
iommu: Enable debugfs exposure of IOMMU driver internals
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 <gary.hook@amd.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r--drivers/iommu/Kconfig10
-rw-r--r--drivers/iommu/Makefile1
-rw-r--r--drivers/iommu/iommu-debugfs.c66
-rw-r--r--drivers/iommu/iommu.c2
-rw-r--r--include/linux/iommu.h7
5 files changed, 86 insertions, 0 deletions
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index e055d228bfb9..ab9181d8af3b 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -60,6 +60,16 @@ config IOMMU_IO_PGTABLE_ARMV7S_SELFTEST
60 60
61endmenu 61endmenu
62 62
63config IOMMU_DEBUGFS
64 bool "Export IOMMU internals in DebugFS"
65 depends on DEBUG_FS
66 help
67 Allows exposure of IOMMU device internals. This option enables
68 the use of debugfs by IOMMU drivers as required. Devices can,
69 at initialization time, cause the IOMMU code to create a top-level
70 debug/iommu directory, and then populate a subdirectory with
71 entries as required.
72
63config IOMMU_IOVA 73config IOMMU_IOVA
64 tristate 74 tristate
65 75
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 @@
2obj-$(CONFIG_IOMMU_API) += iommu.o 2obj-$(CONFIG_IOMMU_API) += iommu.o
3obj-$(CONFIG_IOMMU_API) += iommu-traces.o 3obj-$(CONFIG_IOMMU_API) += iommu-traces.o
4obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o 4obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o
5obj-$(CONFIG_IOMMU_DEBUGFS) += iommu-debugfs.o
5obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o 6obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o
6obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o 7obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
7obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o 8obj-$(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 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * IOMMU debugfs core infrastructure
4 *
5 * Copyright (C) 2018 Advanced Micro Devices, Inc.
6 *
7 * Author: Gary R Hook <gary.hook@amd.com>
8 */
9
10#include <linux/pci.h>
11#include <linux/iommu.h>
12#include <linux/debugfs.h>
13
14struct dentry *iommu_debugfs_dir;
15
16/**
17 * iommu_debugfs_setup - create the top-level iommu directory in debugfs
18 *
19 * Provide base enablement for using debugfs to expose internal data of an
20 * IOMMU driver. When called, this function creates the
21 * /sys/kernel/debug/iommu directory.
22 *
23 * Emit a strong warning at boot time to indicate that this feature is
24 * enabled.
25 *
26 * This function is called from iommu_init; drivers may then call
27 * iommu_debugfs_new_driver_dir() to instantiate a vendor-specific
28 * directory to be used to expose internal data.
29 */
30void iommu_debugfs_setup(void)
31{
32 if (!iommu_debugfs_dir) {
33 iommu_debugfs_dir = debugfs_create_dir("iommu", NULL);
34 pr_warn("\n");
35 pr_warn("*************************************************************\n");
36 pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
37 pr_warn("** **\n");
38 pr_warn("** IOMMU DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n");
39 pr_warn("** **\n");
40 pr_warn("** This means that this kernel is built to expose internal **\n");
41 pr_warn("** IOMMU data structures, which may compromise security on **\n");
42 pr_warn("** your system. **\n");
43 pr_warn("** **\n");
44 pr_warn("** If you see this message and you are not debugging the **\n");
45 pr_warn("** kernel, report this immediately to your vendor! **\n");
46 pr_warn("** **\n");
47 pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
48 pr_warn("*************************************************************\n");
49 }
50}
51
52/**
53 * iommu_debugfs_new_driver_dir - create a vendor directory under debugfs/iommu
54 * @vendor: name of the vendor-specific subdirectory to create
55 *
56 * This function is called by an IOMMU driver to create the top-level debugfs
57 * directory for that driver.
58 *
59 * Return: upon success, a pointer to the dentry for the new directory.
60 * NULL in case of failure.
61 */
62struct dentry *iommu_debugfs_new_driver_dir(const char *vendor)
63{
64 return debugfs_create_dir(vendor, iommu_debugfs_dir);
65}
66EXPORT_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)
1748 NULL, kernel_kobj); 1748 NULL, kernel_kobj);
1749 BUG_ON(!iommu_group_kset); 1749 BUG_ON(!iommu_group_kset);
1750 1750
1751 iommu_debugfs_setup();
1752
1751 return 0; 1753 return 0;
1752} 1754}
1753core_initcall(iommu_init); 1755core_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)
698 698
699#endif /* CONFIG_IOMMU_API */ 699#endif /* CONFIG_IOMMU_API */
700 700
701#ifdef CONFIG_IOMMU_DEBUGFS
702extern struct dentry *iommu_debugfs_dir;
703void iommu_debugfs_setup(void);
704#else
705static inline void iommu_debugfs_setup(void) {}
706#endif
707
701#endif /* __LINUX_IOMMU_H */ 708#endif /* __LINUX_IOMMU_H */