Skip to content

Commit ad48b1d

Browse files
dhsrivaswilldeacon
authored andcommitted
iommu/amd: Refactor AMD IOMMU debugfs initial setup
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>
1 parent c694bc8 commit ad48b1d

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

drivers/iommu/amd/amd_iommu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu,
2828
gfp_t gfp, size_t size);
2929

3030
#ifdef CONFIG_AMD_IOMMU_DEBUGFS
31-
void amd_iommu_debugfs_setup(struct amd_iommu *iommu);
31+
void amd_iommu_debugfs_setup(void);
3232
#else
33-
static inline void amd_iommu_debugfs_setup(struct amd_iommu *iommu) {}
33+
static inline void amd_iommu_debugfs_setup(void) {}
3434
#endif
3535

3636
/* Needed for interrupt remapping */

drivers/iommu/amd/debugfs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@
1313
#include "amd_iommu.h"
1414

1515
static struct dentry *amd_iommu_debugfs;
16-
static DEFINE_MUTEX(amd_iommu_debugfs_lock);
1716

1817
#define MAX_NAME_LEN 20
1918

20-
void amd_iommu_debugfs_setup(struct amd_iommu *iommu)
19+
void amd_iommu_debugfs_setup(void)
2120
{
21+
struct amd_iommu *iommu;
2222
char name[MAX_NAME_LEN + 1];
2323

24-
mutex_lock(&amd_iommu_debugfs_lock);
25-
if (!amd_iommu_debugfs)
26-
amd_iommu_debugfs = debugfs_create_dir("amd",
27-
iommu_debugfs_dir);
28-
mutex_unlock(&amd_iommu_debugfs_lock);
24+
amd_iommu_debugfs = debugfs_create_dir("amd", iommu_debugfs_dir);
2925

30-
snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
31-
iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
26+
for_each_iommu(iommu) {
27+
snprintf(name, MAX_NAME_LEN, "iommu%02d", iommu->index);
28+
iommu->debugfs = debugfs_create_dir(name, amd_iommu_debugfs);
29+
}
3230
}

drivers/iommu/amd/init.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,6 @@ int amd_iommu_enable_faulting(unsigned int cpu)
34193419
*/
34203420
static int __init amd_iommu_init(void)
34213421
{
3422-
struct amd_iommu *iommu;
34233422
int ret;
34243423

34253424
ret = iommu_go_to_state(IOMMU_INITIALIZED);
@@ -3433,8 +3432,8 @@ static int __init amd_iommu_init(void)
34333432
}
34343433
#endif
34353434

3436-
for_each_iommu(iommu)
3437-
amd_iommu_debugfs_setup(iommu);
3435+
if (!ret)
3436+
amd_iommu_debugfs_setup();
34383437

34393438
return ret;
34403439
}

0 commit comments

Comments
 (0)