Skip to contentSkip to conversation

iova: Some misc changes

PATCH Superseded John Garry 2 participants 5 messages Sep 7, 2022

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

John Garry

author
#0 lore raw

v3 cover iova: Some misc changes

This series removes some checks in the code which are not required or don't fulfil their purpose.

Differences to v2:
- Add more words in 1/3 commit log
- Add Jerry's tags (thanks)
- Add patch to drop iovad->rcaches check

Differences to v1:
- Drop re-org
- Add RB/AB tags

Based on v6.0-rc4

John Garry (3):
iova: Remove some magazine pointer NULL checks
iova: Remove magazine BUG_ON() checks
iova: Remove iovad->rcaches check in iova_rcache_get()

 drivers/iommu/iova.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/3 iova: Remove some magazine pointer NULL checks

Since commit 32e92d9f6f87 ("iommu/iova: Separate out rcache init") it has not been possible to have NULL CPU rcache "loaded" or "prev" magazine pointers once the IOVA domain has been properly initialized. Previously it was only possible to have NULL pointers from failure to allocate the magazines in the IOVA domain initialization. The only other two functions to modify these pointers - __iova_rcache_{get, insert}() - would already ensure that these pointers were non-NULL if initially non-NULL.

As such, the mag NULL pointer checks in iova_magazine_full(), iova_magazine_empty(), and iova_magazine_free_pfns() may be dropped.

---
 drivers/iommu/iova.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/iommu/iova.c +2 -5
index 47d1983dfa2a..580fdf669922 100644
@@ -661,9 +661,6 @@ iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
 	unsigned long flags;
 	int i;
 
-	if (!mag)
-		return;
-
 	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
 
 	for (i = 0 ; i < mag->size; ++i) {
@@ -683,12 +680,12 @@ iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
 
 static bool iova_magazine_full(struct iova_magazine *mag)
 {
-	return (mag && mag->size == IOVA_MAG_SIZE);
+	return mag->size == IOVA_MAG_SIZE;
 }
 
 static bool iova_magazine_empty(struct iova_magazine *mag)
 {
-	return (!mag || mag->size == 0);
+	return mag->size == 0;
 }
 
 static unsigned long iova_magazine_pop(struct iova_magazine *mag,
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v3 2/3 iova: Remove magazine BUG_ON() checks

In reply to John Garry

Two of the magazine helpers have BUG_ON() checks, as follows:
- iova_magazine_pop() - here we ensure that the mag is not empty. However we already ensure that in the only caller, __iova_rcache_get().
- iova_magazine_push() - here we ensure that the mag is not full. However we already ensure that in the only caller, __iova_rcache_insert().

As described, the two bug checks are pointless so drop them.

---
 drivers/iommu/iova.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/iommu/iova.c +0 -4
index 580fdf669922..8aece052ce72 100644
@@ -694,8 +694,6 @@ static unsigned long iova_magazine_pop(struct iova_magazine *mag,
 	int i;
 	unsigned long pfn;
 
-	BUG_ON(iova_magazine_empty(mag));
-
 	/* Only fall back to the rbtree if we have no suitable pfns at all */
 	for (i = mag->size - 1; mag->pfns[i] > limit_pfn; i--)
 		if (i == 0)
@@ -710,8 +708,6 @@ static unsigned long iova_magazine_pop(struct iova_magazine *mag,
 
 static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn)
 {
-	BUG_ON(iova_magazine_full(mag));
-
 	mag->pfns[mag->size++] = pfn;
 }
 
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v3 3/3 iova: Remove iovad->rcaches check in iova_rcache_get()

In reply to John Garry

The iovad->rcaches check in iova_rcache_get() is pretty much useless without the same check in iova_rcache_insert().

Instead of adding this symmetric check to fathpath iova_rcache_insert(), drop the check in iova_rcache_get() in favour of making the IOVA domain rcache init more robust to failure in future.

---
 drivers/iommu/iova.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iova.c +1 -1
index 8aece052ce72..a44ad92fc5eb 100644
@@ -875,7 +875,7 @@ static unsigned long iova_rcache_get(struct iova_domain *iovad,
 {
 	unsigned int log_size = order_base_2(size);
 
-	if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE || !iovad->rcaches)
+	if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE)
 		return 0;
 
 	return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 3/3
#4 lore raw

Re: [PATCH v3 3/3] iova: Remove iovad->rcaches check in iova_rcache_get()

Quoted 4 lines · John Garry

The iovad->rcaches check in iova_rcache_get() is pretty much useless without the same check in iova_rcache_insert().

Instead of adding this symmetric check to fathpath iova_rcache_insert(),

Nit: "fastpath"

Quoted 2 lines

drop the check in iova_rcache_get() in favour of making the IOVA domain rcache init more robust to failure in future.

Quoted 18 lines
---
  drivers/iommu/iova.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iova.c +1 -1
index 8aece052ce72..a44ad92fc5eb 100644
@@ -875,7 +875,7 @@ static unsigned long iova_rcache_get(struct iova_domain *iovad,
  {
  	unsigned int log_size = order_base_2(size);
 
-	if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE || !iovad->rcaches)
+	if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE)
  		return 0;
 
  	return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size);