[PATCH v8 8/9] iommu/arm-smmu-v3: Change how the tlbi describes the invalidation
Will Deacon
will at kernel.org
Sun Oct 4 06:43:33 PDT 2026
On Fri, Oct 02, 2026 at 10:23:27PM -0300, Jason Gunthorpe wrote:
> /*
> - * Generate up to two range TLBI command payloads covering [iova, iova+size).
> - * Sets use_full_inv if the range is too large to represent.
> + * Compute the TTL hint from leaf/table level bitmaps. 0 ttl means no hint
> + * invalidate all levels.
> + */
> +static unsigned int arm_smmu_compute_ttl(u8 leaf_bitmap, u8 table_bitmap,
> + u8 tgsz_lg2)
> +{
> + int ttl;
> +
> + if (leaf_bitmap) {
> + /* If TTL is used then only leaves at the TTL are invalidated */
> + if (!is_power_of_2(leaf_bitmap))
> + return 0;
> +
> + ttl = arm_smmu_bitmap_to_level(leaf_bitmap);
> + if (table_bitmap) {
> + int table_ttl =
> + arm_smmu_bitmap_to_level(table_bitmap) + 1;
> +
> + /*
> + * A range invalidation with !leaf_only clears out all
> + * table levels above the leaf level ttl only.
> + */
> + if (table_ttl > ttl)
> + return 0;
> + }
> + } else if (table_bitmap) {
> + /*
> + * Table-only invalidation. Spec says:
> + * For operations with Leaf=0, invalidation of cached Table
> + * descriptors for the address and scope additionally occurs at
> + * levels between the start of the walk and the level before
> + * the last level given by TTL.
> + * Choose a TTL hint that covers the only target table
> + * descriptor levels.
> + */
> + ttl = arm_smmu_bitmap_to_level(table_bitmap) + 1;
> +
> + /*
> + * 16K granule, ARM TTL=1 is reserved (SMMUv3 H.a Section
> + * 4.4.1.1) if DS=0, avoid it always for table invalidations
> + * since we don't know what instance this will be applied to
> + * yet.
> + */
> + if (tgsz_lg2 == 14 && ttl == 1)
> + return 0;
> + } else {
> + /* Both bitmaps zero is not allowed */
> + WARN_ON(true);
> + return 0;
> + }
> +
> + /*
> + * Assumes the page table is formed properly and does not trigger the
> + * 16k TTL=1 condition for leaf-only unless DS is enabled.
> + *
> + * ARM level -1 never has a leaf so something has gone wrong. ARM Level
> + * 0 cannot be hinted because ttl=0 means no-hint.
> + */
nit: This isn't strictly true for the non-range invalidation operations, so
I think it would be handy to have a big note saying that this function only
works for range invalidation or even stick "range" in the function name
somewhere.
> @@ -2917,12 +2998,17 @@ static void arm_smmu_tlb_inv_walk(unsigned long iova, size_t size,
> size_t granule, void *cookie)
> {
> struct arm_smmu_domain *smmu_domain = cookie;
> + u8 tgsz_lg2 = smmu_domain->tgsz_lg2;
> struct arm_smmu_tlbi tlbi = {
> .tgsz_lg2 = smmu_domain->tgsz_lg2,
> - .iova = iova,
> - .size = size,
> - .iopte_size = 1 << smmu_domain->tgsz_lg2,
> + .start = iova,
> + .last = iova + size - 1,
> };
> + u8 table_levels =
> + BIT(arm_smmu_pt_lg2sz_to_level(tgsz_lg2, ilog2(size)));
> +
> + tlbi.table_levels_bitmap = table_levels;
> + tlbi.leaf_levels_bitmap = table_levels - 1;
I'm having a tough time understanding this part. Specifically, I'm trying
to work out what happens if we end up doing a non-leaf invalidation at the
PGD (1GiB) level with leaves at the PTE (4KiB) level. In that case, don't
we need to have table_levels describing both PGD and PMD levels so that
the TTL describes the 4k leaf entries?
Will
More information about the linux-arm-kernel
mailing list