iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu/arm-smmu-v3: Set TTL invalidation hint better
@ 2023-06-01 16:43 Robin Murphy
  2023-06-08 21:36 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Robin Murphy @ 2023-06-01 16:43 UTC (permalink / raw)
  To: will; +Cc: joro, jean-philippe, iommu, linux-arm-kernel

When io-pgtable unmaps a whole table, rather than waste time walking it
to find the leaf entries to invalidate exactly, it simply expects
.tlb_flush_walk with nominal last-level granularity to invalidate any
leaf entries at higher intermediate levels as well. This works fine with
page-based invalidation, but with range commands we need to be careful
with the TTL hint - unconditionally setting it based on the given level
3 granule means that an invalidation for a level 1 table would strictly
not be required to affect level 2 block entries. It's easy to comply
with the expected behaviour by simply not setting the TTL hint for
non-leaf invalidations, so let's do that.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 3fd83fb75722..4763e68cc1ab 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1892,8 +1892,13 @@ static void __arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd,
 		/* Convert page size of 12,14,16 (log2) to 1,2,3 */
 		cmd->tlbi.tg = (tg - 10) / 2;
 
-		/* Determine what level the granule is at */
-		cmd->tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3));
+		/*
+		 * Determine what level the granule is at. For non-leaf, io-pgtable
+		 * assumes .tlb_flush_walk can invalidate multiple levels at once,
+		 * so ignore the nominal last-level granule and leave TTL=0.
+		 */
+		if (cmd->tlbi.leaf)
+			cmd->tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3));
 
 		num_pages = size >> tg;
 	}
-- 
2.39.2.101.g768bb238c484.dirty


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

* Re: [PATCH] iommu/arm-smmu-v3: Set TTL invalidation hint better
  2023-06-01 16:43 [PATCH] iommu/arm-smmu-v3: Set TTL invalidation hint better Robin Murphy
@ 2023-06-08 21:36 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2023-06-08 21:36 UTC (permalink / raw)
  To: Robin Murphy
  Cc: catalin.marinas, kernel-team, Will Deacon, jean-philippe,
	linux-arm-kernel, joro, iommu

On Thu, 1 Jun 2023 17:43:33 +0100, Robin Murphy wrote:
> When io-pgtable unmaps a whole table, rather than waste time walking it
> to find the leaf entries to invalidate exactly, it simply expects
> .tlb_flush_walk with nominal last-level granularity to invalidate any
> leaf entries at higher intermediate levels as well. This works fine with
> page-based invalidation, but with range commands we need to be careful
> with the TTL hint - unconditionally setting it based on the given level
> 3 granule means that an invalidation for a level 1 table would strictly
> not be required to affect level 2 block entries. It's easy to comply
> with the expected behaviour by simply not setting the TTL hint for
> non-leaf invalidations, so let's do that.
> 
> [...]

Applied to will (for-joerg/arm-smmu/updates), thanks!

[1/1] iommu/arm-smmu-v3: Set TTL invalidation hint better
      https://git.kernel.org/will/c/6833b8f2e199

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

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

end of thread, other threads:[~2023-06-08 21:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 16:43 [PATCH] iommu/arm-smmu-v3: Set TTL invalidation hint better Robin Murphy
2023-06-08 21:36 ` Will Deacon

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