linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/3] iova: Some misc changes
@ 2022-09-07 13:34 John Garry
  2022-09-07 13:34 ` [PATCH v4 1/3] iova: Remove some magazine pointer NULL checks John Garry
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: John Garry @ 2022-09-07 13:34 UTC (permalink / raw)
  To: robin.murphy, joro, will
  Cc: iommu, linux-kernel, linuxarm, jsnitsel, haifeng.zhao, John Garry

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

Differences to v3:
- fix typo
- Add Robin's tag to 3/3 (thanks)

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/3] iova: Remove some magazine pointer NULL checks
  2022-09-07 13:34 [PATCH v4 0/3] iova: Some misc changes John Garry
@ 2022-09-07 13:34 ` John Garry
  2022-09-07 13:34 ` [PATCH v4 2/3] iova: Remove magazine BUG_ON() checks John Garry
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: John Garry @ 2022-09-07 13:34 UTC (permalink / raw)
  To: robin.murphy, joro, will
  Cc: iommu, linux-kernel, linuxarm, jsnitsel, haifeng.zhao, John Garry

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.

Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
---
 drivers/iommu/iova.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 47d1983dfa2a..580fdf669922 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -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,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 2/3] iova: Remove magazine BUG_ON() checks
  2022-09-07 13:34 [PATCH v4 0/3] iova: Some misc changes John Garry
  2022-09-07 13:34 ` [PATCH v4 1/3] iova: Remove some magazine pointer NULL checks John Garry
@ 2022-09-07 13:34 ` John Garry
  2022-09-07 13:34 ` [PATCH v4 3/3] iova: Remove iovad->rcaches check in iova_rcache_get() John Garry
  2022-09-07 14:01 ` [PATCH v4 0/3] iova: Some misc changes Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: John Garry @ 2022-09-07 13:34 UTC (permalink / raw)
  To: robin.murphy, joro, will
  Cc: iommu, linux-kernel, linuxarm, jsnitsel, haifeng.zhao, 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.

Signed-off-by: John Garry <john.garry@huawei.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>
---
 drivers/iommu/iova.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 580fdf669922..8aece052ce72 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4 3/3] iova: Remove iovad->rcaches check in iova_rcache_get()
  2022-09-07 13:34 [PATCH v4 0/3] iova: Some misc changes John Garry
  2022-09-07 13:34 ` [PATCH v4 1/3] iova: Remove some magazine pointer NULL checks John Garry
  2022-09-07 13:34 ` [PATCH v4 2/3] iova: Remove magazine BUG_ON() checks John Garry
@ 2022-09-07 13:34 ` John Garry
  2022-09-07 14:01 ` [PATCH v4 0/3] iova: Some misc changes Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: John Garry @ 2022-09-07 13:34 UTC (permalink / raw)
  To: robin.murphy, joro, will
  Cc: iommu, linux-kernel, linuxarm, jsnitsel, haifeng.zhao, 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 fastpath 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.

Signed-off-by: John Garry <john.garry@huawei.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/iommu/iova.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
index 8aece052ce72..a44ad92fc5eb 100644
--- a/drivers/iommu/iova.c
+++ b/drivers/iommu/iova.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 0/3] iova: Some misc changes
  2022-09-07 13:34 [PATCH v4 0/3] iova: Some misc changes John Garry
                   ` (2 preceding siblings ...)
  2022-09-07 13:34 ` [PATCH v4 3/3] iova: Remove iovad->rcaches check in iova_rcache_get() John Garry
@ 2022-09-07 14:01 ` Joerg Roedel
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2022-09-07 14:01 UTC (permalink / raw)
  To: John Garry
  Cc: robin.murphy, will, iommu, linux-kernel, linuxarm, jsnitsel,
	haifeng.zhao

On Wed, Sep 07, 2022 at 09:34:38PM +0800, John Garry wrote:
> 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(-)

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-07 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 13:34 [PATCH v4 0/3] iova: Some misc changes John Garry
2022-09-07 13:34 ` [PATCH v4 1/3] iova: Remove some magazine pointer NULL checks John Garry
2022-09-07 13:34 ` [PATCH v4 2/3] iova: Remove magazine BUG_ON() checks John Garry
2022-09-07 13:34 ` [PATCH v4 3/3] iova: Remove iovad->rcaches check in iova_rcache_get() John Garry
2022-09-07 14:01 ` [PATCH v4 0/3] iova: Some misc changes Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).