Skip to contentSkip to conversation

iova: Move fast alloc size roundup into alloc_iova_fast()

PATCH Applied John Garry via iommu 3 participants 3 messages Dec 7, 2021 – Dec 17, 2021

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

PATCH v2 1/1 iova: Move fast alloc size roundup into alloc_iova_fast()

It really is a property of the IOVA rcache code that we need to alloc a power-of-2 size, so relocate the functionality to resize into alloc_iova_fast(), rather than the callsites.

---
Differences to v1:
- Separate out from original series which conflicts with Robin's IOVA FQ work:
https://lore.kernel.org/linux-iommu/[email protected]/
- Add tags - thanks!

drivers/iommu/dma-iommu.c +0 -8
index b42e38a0dbe2..84dee53fe892 100644
@@ -442,14 +442,6 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain,
 
 	shift = iova_shift(iovad);
 	iova_len = size >> shift;
-	/*
-	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
-	 * will come back to bite us badly, so we have to waste a bit of space
-	 * rounding up anything cacheable to make sure that can't happen. The
-	 * order of the unadjusted size will still match upon freeing.
-	 */
-	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
-		iova_len = roundup_pow_of_two(iova_len);
 
 	dma_limit = min_not_zero(dma_limit, dev->bus_dma_limit);
 
drivers/iommu/iova.c +9 -0
index 9e8bc802ac05..ff567cbc42f7 100644
@@ -497,6 +497,15 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size,
 	unsigned long iova_pfn;
 	struct iova *new_iova;
 
+	/*
+	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
+	 * will come back to bite us badly, so we have to waste a bit of space
+	 * rounding up anything cacheable to make sure that can't happen. The
+	 * order of the unadjusted size will still match upon freeing.
+	 */
+	if (size < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
+		size = roundup_pow_of_two(size);
+
 	iova_pfn = iova_rcache_get(iovad, size, limit_pfn + 1);
 	if (iova_pfn)
 		return iova_pfn;
drivers/vdpa/vdpa_user/iova_domain.c +0 -8
index 1daae2608860..2b1143f11d8f 100644
@@ -292,14 +292,6 @@ vduse_domain_alloc_iova(struct iova_domain *iovad,
 	unsigned long iova_len = iova_align(iovad, size) >> shift;
 	unsigned long iova_pfn;
 
-	/*
-	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
-	 * will come back to bite us badly, so we have to waste a bit of space
-	 * rounding up anything cacheable to make sure that can't happen. The
-	 * order of the unadjusted size will still match upon freeing.
-	 */
-	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
-		iova_len = roundup_pow_of_two(iova_len);
 	iova_pfn = alloc_iova_fast(iovad, iova_len, limit >> shift, true);
 
 	return iova_pfn << shift;
Signature · 6 lines
2.26.2

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 3 lines · John Garry

It really is a property of the IOVA rcache code that we need to alloc a power-of-2 size, so relocate the functionality to resize into alloc_iova_fast(), rather than the callsites.

I'd still much prefer to resolve the issue that there shouldn't *be* more than one caller in the first place, but hey.

Quoted 60 lines

---
Differences to v1:
- Separate out from original series which conflicts with Robin's IOVA FQ work:

   https://lore.kernel.org/linux-iommu/[email protected]/

- Add tags - thanks!

drivers/iommu/dma-iommu.c +0 -8
index b42e38a0dbe2..84dee53fe892 100644
@@ -442,14 +442,6 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain,
 
  	shift = iova_shift(iovad);
  	iova_len = size >> shift;
-	/*
-	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
-	 * will come back to bite us badly, so we have to waste a bit of space
-	 * rounding up anything cacheable to make sure that can't happen. The
-	 * order of the unadjusted size will still match upon freeing.
-	 */
-	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
-		iova_len = roundup_pow_of_two(iova_len);
 
  	dma_limit = min_not_zero(dma_limit, dev->bus_dma_limit);
 
drivers/iommu/iova.c +9 -0
index 9e8bc802ac05..ff567cbc42f7 100644
@@ -497,6 +497,15 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size,
  	unsigned long iova_pfn;
  	struct iova *new_iova;
 
+	/*
+	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
+	 * will come back to bite us badly, so we have to waste a bit of space
+	 * rounding up anything cacheable to make sure that can't happen. The
+	 * order of the unadjusted size will still match upon freeing.
+	 */
+	if (size < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
+		size = roundup_pow_of_two(size);
+
  	iova_pfn = iova_rcache_get(iovad, size, limit_pfn + 1);
  	if (iova_pfn)
  		return iova_pfn;
drivers/vdpa/vdpa_user/iova_domain.c +0 -1
index 1daae2608860..2b1143f11d8f 100644
@@ -292,14 +292,6 @@ vduse_domain_alloc_iova(struct iova_domain *iovad,
  	unsigned long iova_len = iova_align(iovad, size) >> shift;
  	unsigned long iova_pfn;
 
-	/*

drivers/vdpa/vdpa_user/iova_domain.c vduse_domain_alloc_iova(struct iova_domain *iovad, · line 297

Quoted 10 lines
drivers/vdpa/vdpa_user/iova_domain.c +0 -7
-	 * Freeing non-power-of-two-sized allocations back into the IOVA caches
-	 * will come back to bite us badly, so we have to waste a bit of space
-	 * rounding up anything cacheable to make sure that can't happen. The
-	 * order of the unadjusted size will still match upon freeing.
-	 */
-	if (iova_len < (1 << (IOVA_RANGE_CACHE_MAX_SIZE - 1)))
-		iova_len = roundup_pow_of_two(iova_len);
  	iova_pfn = alloc_iova_fast(iovad, iova_len, limit >> shift, true);
 
  	return iova_pfn << shift;

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

maintainer Applied
#2 lore raw
In reply to John Garry via iommu
Quoted 9 lines · John Garry

It really is a property of the IOVA rcache code that we need to alloc a power-of-2 size, so relocate the functionality to resize into alloc_iova_fast(), rather than the callsites.

Quoted 5 lines

---
Differences to v1:
- Separate out from original series which conflicts with Robin's IOVA FQ work:
https://lore.kernel.org/linux-iommu/[email protected]/
- Add tags - thanks!

Applied, thanks.

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization