Commit 3006b15b authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel

iommu: Add for_each_group_device()

Convenience macro to iterate over every struct group_device in the group.

Replace all open coded list_for_each_entry's with this macro.
Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Tested-by: default avatarHeiko Stuebner <heiko@sntech.de>
Tested-by: default avatarNiklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/2-v5-1b99ae392328+44574-iommu_err_unwind_jgg@nvidia.comSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 4db0e5f8
...@@ -254,6 +254,7 @@ ForEachMacros: ...@@ -254,6 +254,7 @@ ForEachMacros:
- 'for_each_free_mem_range' - 'for_each_free_mem_range'
- 'for_each_free_mem_range_reverse' - 'for_each_free_mem_range_reverse'
- 'for_each_func_rsrc' - 'for_each_func_rsrc'
- 'for_each_group_device'
- 'for_each_group_evsel' - 'for_each_group_evsel'
- 'for_each_group_member' - 'for_each_group_member'
- 'for_each_hstate' - 'for_each_hstate'
......
...@@ -68,6 +68,10 @@ struct group_device { ...@@ -68,6 +68,10 @@ struct group_device {
char *name; char *name;
}; };
/* Iterate over each struct group_device in a struct iommu_group */
#define for_each_group_device(group, pos) \
list_for_each_entry(pos, &(group)->devices, list)
struct iommu_group_attribute { struct iommu_group_attribute {
struct attribute attr; struct attribute attr;
ssize_t (*show)(struct iommu_group *group, char *buf); ssize_t (*show)(struct iommu_group *group, char *buf);
...@@ -468,7 +472,7 @@ __iommu_group_remove_device(struct iommu_group *group, struct device *dev) ...@@ -468,7 +472,7 @@ __iommu_group_remove_device(struct iommu_group *group, struct device *dev)
struct group_device *device; struct group_device *device;
lockdep_assert_held(&group->mutex); lockdep_assert_held(&group->mutex);
list_for_each_entry(device, &group->devices, list) { for_each_group_device(group, device) {
if (device->dev == dev) { if (device->dev == dev) {
list_del(&device->list); list_del(&device->list);
return device; return device;
...@@ -707,7 +711,7 @@ int iommu_get_group_resv_regions(struct iommu_group *group, ...@@ -707,7 +711,7 @@ int iommu_get_group_resv_regions(struct iommu_group *group,
int ret = 0; int ret = 0;
mutex_lock(&group->mutex); mutex_lock(&group->mutex);
list_for_each_entry(device, &group->devices, list) { for_each_group_device(group, device) {
struct list_head dev_resv_regions; struct list_head dev_resv_regions;
/* /*
...@@ -1131,7 +1135,7 @@ static int __iommu_group_for_each_dev(struct iommu_group *group, void *data, ...@@ -1131,7 +1135,7 @@ static int __iommu_group_for_each_dev(struct iommu_group *group, void *data,
struct group_device *device; struct group_device *device;
int ret = 0; int ret = 0;
list_for_each_entry(device, &group->devices, list) { for_each_group_device(group, device) {
ret = fn(device->dev, data); ret = fn(device->dev, data);
if (ret) if (ret)
break; break;
...@@ -1935,7 +1939,7 @@ bool iommu_group_has_isolated_msi(struct iommu_group *group) ...@@ -1935,7 +1939,7 @@ bool iommu_group_has_isolated_msi(struct iommu_group *group)
bool ret = true; bool ret = true;
mutex_lock(&group->mutex); mutex_lock(&group->mutex);
list_for_each_entry(group_dev, &group->devices, list) for_each_group_device(group, group_dev)
ret &= msi_device_has_isolated_msi(group_dev->dev); ret &= msi_device_has_isolated_msi(group_dev->dev);
mutex_unlock(&group->mutex); mutex_unlock(&group->mutex);
return ret; return ret;
...@@ -3243,7 +3247,7 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain, ...@@ -3243,7 +3247,7 @@ static int __iommu_set_group_pasid(struct iommu_domain *domain,
struct group_device *device; struct group_device *device;
int ret = 0; int ret = 0;
list_for_each_entry(device, &group->devices, list) { for_each_group_device(group, device) {
ret = domain->ops->set_dev_pasid(domain, device->dev, pasid); ret = domain->ops->set_dev_pasid(domain, device->dev, pasid);
if (ret) if (ret)
break; break;
...@@ -3258,7 +3262,7 @@ static void __iommu_remove_group_pasid(struct iommu_group *group, ...@@ -3258,7 +3262,7 @@ static void __iommu_remove_group_pasid(struct iommu_group *group,
struct group_device *device; struct group_device *device;
const struct iommu_ops *ops; const struct iommu_ops *ops;
list_for_each_entry(device, &group->devices, list) { for_each_group_device(group, device) {
ops = dev_iommu_ops(device->dev); ops = dev_iommu_ops(device->dev);
ops->remove_dev_pasid(device->dev, pasid); ops->remove_dev_pasid(device->dev, pasid);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment