]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/amd: Refactor AMD IOMMU debugfs initial setup
authorDheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Wed, 2 Jul 2025 09:37:57 +0000 (15:07 +0530)
committerWill Deacon <will@kernel.org>
Tue, 15 Jul 2025 10:41:52 +0000 (11:41 +0100)
Rearrange initial setup of AMD IOMMU debugfs to segregate per IOMMU
setup and setup which is common for all IOMMUs. This ensures that common
debugfs paths (introduced in subsequent patches) are created only once
instead of being created for each IOMMU.

With the change, there is no need to use lock as amd_iommu_debugfs_setup()
will be called only once during AMD IOMMU initialization. So remove lock
acquisition in amd_iommu_debugfs_setup().

Signed-off-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20250702093804.849-2-dheerajkumar.srivastava@amd.com
Signed-off-by: Will Deacon <will@kernel.org>
drivers/iommu/amd/amd_iommu.h
drivers/iommu/amd/debugfs.c
drivers/iommu/amd/init.c

index 0bf3744c7b3a526dff8ce09c82526cddf4fbce60..9b4b589a54b57e6c1ad03a8b6454b73540ca3a3e 100644 (file)
@@ -28,9 +28,9 @@ void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu,
                                  gfp_t gfp, size_t size);
 
 #ifdef CONFIG_AMD_IOMMU_DEBUGFS
-void amd_iommu_debugfs_setup(struct amd_iommu *iommu);
+void amd_iommu_debugfs_setup(void);
 #else
-static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {}
+static inline void amd_iommu_debugfs_setup(void) {}
 #endif
 
 /* Needed for interrupt remapping */
index 545372fcc72f2ad71d4b295dce6b8b2178eecede..ff9520e002be85b953f69207f8d39158801d09f3 100644 (file)
 #include "amd_iommu.h"
 
 static struct dentry *amd_iommu_debugfs;
-static DEFINE_MUTEX(amd_iommu_debugfs_lock);
 
 #define        MAX_NAME_LEN    20
 
-void amd_iommu_debugfs_setup(struct amd_iommu *iommu)
+void amd_iommu_debugfs_setup(void)
 {
+       struct amd_iommu *iommu;
        char name[MAX_NAME_LEN + 1];
 
-       mutex_lock(&amd_iommu_debugfs_lock);
-       if (!amd_iommu_debugfs)
-               amd_iommu_debugfs = debugfs_create_dir("amd",
-                                                      iommu_debugfs_dir);
-       mutex_unlock(&amd_iommu_debugfs_lock);
+       amd_iommu_debugfs = debugfs_create_dir("amd", iommu_debugfs_dir);
 
-       snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
-       iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
+       for_each_iommu(iommu) {
+               snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
+               iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
+       }
 }
index cadb2c735ffcc3627528e68e029f6837fbd732cb..7b5af6176de99074e91e07825fcc55e3310e95f7 100644 (file)
@@ -3419,7 +3419,6 @@ int amd_iommu_enable_faulting(unsigned int cpu)
  */
 static int __init amd_iommu_init(void)
 {
-       struct amd_iommu *iommu;
        int ret;
 
        ret = iommu_go_to_state(IOMMU_INITIALIZED);
@@ -3433,8 +3432,8 @@ static int __init amd_iommu_init(void)
        }
 #endif
 
-       for_each_iommu(iommu)
-               amd_iommu_debugfs_setup(iommu);
+       if (!ret)
+               amd_iommu_debugfs_setup();
 
        return ret;
 }