From: Jason Gunthorpe <jgg@nvidia.com>
To: Mostafa Saleh <smostafa@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Jonathan Corbet <corbet@lwn.net>,
iommu@lists.linux.dev, "Joerg Roedel (AMD)" <joro@8bytes.org>,
Jean-Philippe Brucker <jpb@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org,
Mark Rutland <mark.rutland@arm.com>,
Randy Dunlap <rdunlap@infradead.org>,
Robin Murphy <robin.murphy@arm.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Will Deacon <will@kernel.org>,
David Matlack <dmatlack@google.com>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Nicolin Chen <nicolinc@nvidia.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
patches@lists.linux.dev, Pranjal Shrivastava <praan@google.com>,
Samiullah Khawaja <skhawaja@google.com>,
stable@vger.kernel.org,
Vijayanand Jitta <vijayanand.jitta@oss.qualcomm.com>
Subject: Re: [PATCH v5 8/9] iommu/arm-smmu-v3: Change how the tlbi describes the invalidation
Date: Mon, 7 Sep 2026 12:34:29 -0300 [thread overview]
Message-ID: <20260907153429.GB4157646@nvidia.com> (raw)
In-Reply-To: <ap7NcebXzWC38VVo@google.com>
On Mon, Sep 07, 2026 at 02:42:57PM +0000, Mostafa Saleh wrote:
> On Tue, Sep 01, 2026 at 02:49:57PM -0300, Jason Gunthorpe wrote:
> > The RIL logic has long had a FIXME that there is not enough
> > information to properly compute the RIL. There is also subtly not
> > enough information to properly compute the single stride either.
> >
> > Change tlbi to use the information format that iommupt is going to
> > use for ARM. This prepares the invalidation code to support iommupt
> > and fixes two small limitations with the current code.
> >
> > iommupt is designed to accumulate all invalidation into a single
> > gather, then the iommu driver should issue a small number of commands
> > to execute the gather to control invalidation latency. This is in
> > contrast to io-pgtable-arm.c which generates many gather flushes and
> > direct walk cache flushes as it progresses.
> >
> > To accommodate this the gather will accumulate "damage" in bitmaps,
> > one for leaf changes and one for table changes. This is enough
> > information for SMMUv3 to compute the proper stride for single
> > invalidation and to generate ideal hints for range invalidation.
>
> I am not sure I understand that, in what situation the leaf_bitmap
> would be used instead of a single page size?=
> Would iommupt combine different page sizes in a single invalidation?
Yes
> And then I see in this patch it has:
> if (!is_power_of_2(leaf_bitmap))
> return 0;
Right, ARM doesn't support mixed leaves in a RIL so we can't use TTL
if iommupt has constructed something like that.
> Would that actually be better for performance than using 2 sets of
> RILs, one for each page size?
> As I'd imagine the HW will spend more effort on the TTL=0 case
> otherwise it wouldn't require it.
I have no idea, it is a hint. Since SW has no knowledge I think it
should just issue as few commands as possible. There is no way to know
what will work better on any particular HW.
> > @@ -140,17 +140,34 @@ static void arm_smmu_mm_arch_invalidate_secondary_tlbs(struct mmu_notifier *mn,
> > {
> > struct arm_smmu_domain *smmu_domain =
> > container_of(mn, struct arm_smmu_domain, mmu_notifier);
> > + u8 tgsz_lg2 = smmu_domain->tgsz_lg2;
> > struct arm_smmu_tlbi tlbi = {
> > .tgsz_lg2 = smmu_domain->tgsz_lg2,
> > - .iova = start,
> > + .start = start,
> > + .last = end - 1,
> > /*
> > - * The mm_types defines vm_end as the first byte after the end
> > - * address, different from IOMMU subsystem using the last
> > - * address of an address range.
> > + * No information comes from the mm, assume the worst case that
> > + * it changed every table level. The way this is hooked into the
> > + * mm is tricky, the range won't be expanded to include an
> > + * entire table level if one was removed like the iommu gather
> > + * does. Thus even if this is a 4k invalidation it may be
> > + * including any table level too.
> > */
> > - .size = end - start,
> > - .iopte_size = PAGE_SIZE,
> > + .table_levels_bitmap = 0xfe,
>
> What does that mean, won't arm have a max of 4 levels?
It is really ~1, the extra leading 1s don't matter. Just can't have
the leaf bit set.
> > + /*
> > + * If the size is small then we can infer the invalidation is PTE only
> > + * and set the PTE level only. Otherwise it could be some other
> > + * combination so just set them all. This allows RIL to use TTL=3 in
> > + * cases of PTE only changes. The mm must not try to partially
> > + * invalidate pmd/etc.
> > + */
>
> How does that work with splitting blocks? I imagine that might be
> ossible with userspace.
If mm splits anything then the invalidation will not be PAGE_SIZE
big. A split requires invalidating the original larger size.
> > +static u8 arm_smmu_tlbi_calc_stride(struct arm_smmu_tlbi *tlbi)
> > +{
> > + u8 combined = tlbi->table_levels_bitmap | tlbi->leaf_levels_bitmap;
> > + u8 tg_szlg2 = tlbi->tgsz_lg2;
> > +
> > + if (WARN_ON(!combined))
> > + return U8_MAX;
>
> When can that happen?
It can't, thats why it is a WARN_ON :)
> > @@ -4152,21 +4237,28 @@ static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain)
> > arm_smmu_tlb_inv_context(smmu_domain);
> > }
> >
> > +/*
> > + * Called by io-pgtable-arm.c for each run of same pgsize leaf only
>
> I believe that it is called from dma-iommu.c, io-pgtable-arm.c will
> call the tlb_add_page which builds the gather though.
Sort of, for the purposes of this comment the important flush is
initiated by io-pgtable-arm.c under tlb_add_page() when it calls
arm_smmu_tlb_inv_page_nosync(), which calls
iommu_iotlb_gather_add_page(), which calls iommu_iotlb_sync()
That's done in a way that guarentees the same-pgsize property:
if ((gather->pgsize && gather->pgsize != size) ||
Yes it is also called from dma-iommu.c, but only for the "trailing"
gather and that doesn't do anything to change what is in the gather..
I'll add a few more words here
> > + * invalidation. If it has to change to a different leaf level then it flushes
> > + * the gather and starts a fresh one. Thus this always targets only a single
> > + * leaf level.
> > + */
> > static void arm_smmu_iotlb_sync(struct iommu_domain *domain,
> > struct iommu_iotlb_gather *gather)
> > {
> > struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
> > + unsigned int tg = smmu_domain->tgsz_lg2;
> > struct arm_smmu_tlbi tlbi = {
> > .tgsz_lg2 = smmu_domain->tgsz_lg2,
> > - .iova = gather->start,
> > - .size = gather->end - gather->start + 1,
> > - .iopte_size = gather->pgsize,
> > - .leaf_only = true,
> > + .start = gather->start,
> > + .last = gather->end,
> > };
> >
> > - if (!gather->pgsize)
> > + if (WARN_ON(gather->pgsize < BIT(tg)))
> > return;
> >
> > + tlbi.leaf_levels_bitmap = BIT((ilog2(gather->pgsize) - tg) / (tg - 3));
>
> Having some page table macros would be helpful (and in other places in
> this patch)
At least this one gets deleted in the next series, so I left it like
this deliberately. Was there something else you saw that had
duplication?
Thanks,
Jason
next prev parent reply other threads:[~2026-09-07 15:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 17:49 [PATCH v5 0/9] Organize the SMMUv3 invalidation flow so iommupt can use it Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 1/9] iommu/arm-smmu-v3: Handle ARM erratum for CONT under invalidation with SVA Jason Gunthorpe
2026-09-07 14:21 ` Mostafa Saleh
2026-09-07 15:11 ` Jason Gunthorpe
2026-09-07 15:17 ` Mostafa Saleh
2026-09-07 15:18 ` Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 2/9] iommu/arm-smmu-v3: Pass the parameters for the invalidation in a struct Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 3/9] iommu/arm-smmu-v3: Move pgsize out of arm_smmu_inv Jason Gunthorpe
2026-09-07 14:22 ` Mostafa Saleh
2026-09-01 17:49 ` [PATCH v5 4/9] iommu/arm-smmu-v3: Optimize range invalidation for latency Jason Gunthorpe
2026-09-07 14:26 ` Mostafa Saleh
2026-09-07 15:23 ` Jason Gunthorpe
2026-09-07 19:34 ` Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 5/9] iommu/arm-smmu-v3: Keep track in the arm_smmu_invs if RIL is used Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 6/9] iommu/arm-smmu-v3: Precompute the invalidation commands Jason Gunthorpe
2026-09-07 14:27 ` Mostafa Saleh
2026-09-07 15:19 ` Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 7/9] iommu/arm-smmu-v3: Populate the tlbi at the top of the call chain Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 8/9] iommu/arm-smmu-v3: Change how the tlbi describes the invalidation Jason Gunthorpe
2026-09-07 14:42 ` Mostafa Saleh
2026-09-07 15:34 ` Jason Gunthorpe [this message]
2026-09-09 15:57 ` Jason Gunthorpe
2026-09-01 17:49 ` [PATCH v5 9/9] iommu/arm-smmu-v3: Support the DS expansion of RIL's SCALE Jason Gunthorpe
2026-09-07 14:44 ` Mostafa Saleh
2026-09-07 19:39 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260907153429.GB4157646@nvidia.com \
--to=jgg@nvidia.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=dmatlack@google.com \
--cc=iommu@lists.linux.dev \
--cc=jean-philippe@linaro.org \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=nicolinc@nvidia.com \
--cc=pasha.tatashin@soleen.com \
--cc=patches@lists.linux.dev \
--cc=praan@google.com \
--cc=rdunlap@infradead.org \
--cc=robin.murphy@arm.com \
--cc=skhan@linuxfoundation.org \
--cc=skhawaja@google.com \
--cc=smostafa@google.com \
--cc=stable@vger.kernel.org \
--cc=vijayanand.jitta@oss.qualcomm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox