Skip to contentSkip to conversation

iommu/vt-d: Don't cast parameter in for_each_set_bit()

PATCH In review Andy Shevchenko 2 participants 2 messages Feb 9, 2022 – Feb 10, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/vt-d: Don't cast parameter in for_each_set_bit()

While in this particular case it would not be a (critical) issue, the pattern itself is bad and error prone in case the location of the parameter is changed.

Don't cast parameter to unsigned long pointer in for_each_set_bit(). Instead copy to a local variable on stack of a proper type and use.

Fixes 6ee1b77ba3ac ("iommu/vt-d: Add svm/sva invalidate function")
---
 drivers/iommu/intel/iommu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +3 -3
index 92fea3fbbb11..777e81b8f4f5 100644
@@ -4973,6 +4973,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev,
 	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
 	struct device_domain_info *info;
 	struct intel_iommu *iommu;
+	unsigned long cache_bits;
 	unsigned long flags;
 	int cache_type;
 	u8 bus, devfn;
@@ -5008,9 +5009,8 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev,
 		size = to_vtd_size(inv_info->granu.addr_info.granule_size,
 				   inv_info->granu.addr_info.nb_granules);
 
-	for_each_set_bit(cache_type,
-			 (unsigned long *)&inv_info->cache,
-			 IOMMU_CACHE_INV_TYPE_NR) {
+	cache_bits = inv_info->cache;
+	for_each_set_bit(cache_type, &cache_bits, IOMMU_CACHE_INV_TYPE_NR) {
 		int granu = 0;
 		u64 pasid = 0;
 		u64 addr = 0;
Signature · 6 lines
2.34.1

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer
#1 lore raw

Hi Andy,

Quoted 27 lines · Andy Shevchenko

While in this particular case it would not be a (critical) issue, the pattern itself is bad and error prone in case the location of the parameter is changed.

Don't cast parameter to unsigned long pointer in for_each_set_bit(). Instead copy to a local variable on stack of a proper type and use.

Fixes 6ee1b77ba3ac ("iommu/vt-d: Add svm/sva invalidate function")
---
  drivers/iommu/intel/iommu.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iommu/intel/iommu.c +1 -0
index 92fea3fbbb11..777e81b8f4f5 100644
@@ -4973,6 +4973,7 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev,
  	struct dmar_domain *dmar_domain = to_dmar_domain(domain);
  	struct device_domain_info *info;
  	struct intel_iommu *iommu;
+	unsigned long cache_bits;
  	unsigned long flags;
  	int cache_type;
  	u8 bus, devfn;
@@ -5008,9 +5009,8 @@ intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev,
  		size = to_vtd_size(inv_info->granu.addr_info.granule_size,

drivers/iommu/intel/iommu.c intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, · line 5016

Quoted 10 lines
drivers/iommu/intel/iommu.c +2 -3
  				   inv_info->granu.addr_info.nb_granules);
 
-	for_each_set_bit(cache_type,
-			 (unsigned long *)&inv_info->cache,
-			 IOMMU_CACHE_INV_TYPE_NR) {
+	cache_bits = inv_info->cache;
+	for_each_set_bit(cache_type, &cache_bits, IOMMU_CACHE_INV_TYPE_NR) {
  		int granu = 0;
  		u64 pasid = 0;
  		u64 addr = 0;

Thanks for your patch. The function that you are changing becomes dead code (nobody uses it and there's no plan to use it anymore) now. I already have a patch to remove this function.

Best regards,
baolu
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu