Skip to content

Commit bf8aff2

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu: Introduce iommu_group_mutex_assert()
Add function to check iommu group mutex lock. So that device drivers can rely on group mutex lock instead of adding another driver level lock before modifying driver specific device data structure. Suggested-by: Jason Gunthorpe <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent b2e8a7f commit bf8aff2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,25 @@ void iommu_group_remove_device(struct device *dev)
12481248
}
12491249
EXPORT_SYMBOL_GPL(iommu_group_remove_device);
12501250

1251+
#if IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_IOMMU_API)
1252+
/**
1253+
* iommu_group_mutex_assert - Check device group mutex lock
1254+
* @dev: the device that has group param set
1255+
*
1256+
* This function is called by an iommu driver to check whether it holds
1257+
* group mutex lock for the given device or not.
1258+
*
1259+
* Note that this function must be called after device group param is set.
1260+
*/
1261+
void iommu_group_mutex_assert(struct device *dev)
1262+
{
1263+
struct iommu_group *group = dev->iommu_group;
1264+
1265+
lockdep_assert_held(&group->mutex);
1266+
}
1267+
EXPORT_SYMBOL_GPL(iommu_group_mutex_assert);
1268+
#endif
1269+
12511270
static struct device *iommu_group_first_dev(struct iommu_group *group)
12521271
{
12531272
lockdep_assert_held(&group->mutex);

include/linux/iommu.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,14 @@ static inline ioasid_t iommu_alloc_global_pasid(struct device *dev)
13561356
static inline void iommu_free_global_pasid(ioasid_t pasid) {}
13571357
#endif /* CONFIG_IOMMU_API */
13581358

1359+
#if IS_ENABLED(CONFIG_LOCKDEP) && IS_ENABLED(CONFIG_IOMMU_API)
1360+
void iommu_group_mutex_assert(struct device *dev);
1361+
#else
1362+
static inline void iommu_group_mutex_assert(struct device *dev)
1363+
{
1364+
}
1365+
#endif
1366+
13591367
/**
13601368
* iommu_map_sgtable - Map the given buffer to the IOMMU domain
13611369
* @domain: The IOMMU domain to perform the mapping

0 commit comments

Comments
 (0)