iommu-debugfs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include <linux/pci.h>
  10. #include <linux/iommu.h>
  11. #include <linux/debugfs.h>
  12. struct dentry *iommu_debugfs_dir;
  13. /**
  14. * iommu_debugfs_setup - create the top-level iommu directory in debugfs
  15. *
  16. * Provide base enablement for using debugfs to expose internal data of an
  17. * IOMMU driver. When called, this function creates the
  18. * /sys/kernel/debug/iommu directory.
  19. *
  20. * Emit a strong warning at boot time to indicate that this feature is
  21. * enabled.
  22. *
  23. * This function is called from iommu_init; drivers may then call
  24. * iommu_debugfs_new_driver_dir() to instantiate a vendor-specific
  25. * directory to be used to expose internal data.
  26. */
  27. void iommu_debugfs_setup(void)
  28. {
  29. if (!iommu_debugfs_dir) {
  30. iommu_debugfs_dir = debugfs_create_dir("iommu", NULL);
  31. pr_warn("\n");
  32. pr_warn("*************************************************************\n");
  33. pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
  34. pr_warn("** **\n");
  35. pr_warn("** IOMMU DebugFS SUPPORT HAS BEEN ENABLED IN THIS KERNEL **\n");
  36. pr_warn("** **\n");
  37. pr_warn("** This means that this kernel is built to expose internal **\n");
  38. pr_warn("** IOMMU data structures, which may compromise security on **\n");
  39. pr_warn("** your system. **\n");
  40. pr_warn("** **\n");
  41. pr_warn("** If you see this message and you are not debugging the **\n");
  42. pr_warn("** kernel, report this immediately to your vendor! **\n");
  43. pr_warn("** **\n");
  44. pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n");
  45. pr_warn("*************************************************************\n");
  46. }
  47. }
  48. /**
  49. * iommu_debugfs_new_driver_dir - create a vendor directory under debugfs/iommu
  50. * @vendor: name of the vendor-specific subdirectory to create
  51. *
  52. * This function is called by an IOMMU driver to create the top-level debugfs
  53. * directory for that driver.
  54. *
  55. * Return: upon success, a pointer to the dentry for the new directory.
  56. * NULL in case of failure.
  57. */
  58. struct dentry *iommu_debugfs_new_driver_dir(const char *vendor)
  59. {
  60. return debugfs_create_dir(vendor, iommu_debugfs_dir);
  61. }
  62. EXPORT_SYMBOL_GPL(iommu_debugfs_new_driver_dir);