Re: [PATCH v3 6/7] iommu: Park TDISP T=0 devices in the blocking domain

From: Jason Gunthorpe

Date: Wed Nov 25 2026 - 13:08:32 EST


> [ ... 28 lines skipped ... ]
> @@ -1238,6 +1238,14 @@ static int iommu_create_device_direct_mappings(struct iommu_domain *domain,
> unsigned long pg_size;
> int ret = 0;
>
> + /*
> + * The direct-map reserved regions are still fine because the T=0 stream
> + * always goes to an identity mapping. Skip them: recording the request
> + * would only refuse the device its blocking domain.
> + */
> + if (iommu_using_t0_stream(dev))
> + return 0;
> +

Not sure about this. If we are allocating a paging domain then it
should always have the direct mappings setup in it.

I think this patch is the right idea, but it should probably be
removed from this series for now if we don't need it to make a basic
trusted vIOMMU work.

After Leon's trust level series we should have the flow I mentioned
before where the iommu starts out in BLOCKED naturally and we will
allocate the paging domain right at driver binding.

With that infrastructure you can make a decision to just not alloc the
paging domain if the device is not in T=1 mode.

> pg_size = domain->pgsize_bitmap ? 1UL << __ffs(domain->pgsize_bitmap) : 0;
>
> if (WARN_ON_ONCE(iommu_is_dma_domain(domain) && !pg_size))
> @@ -1790,11 +1798,22 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
> static struct iommu_domain *
> iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
> {
> - const struct iommu_ops *ops = dev_iommu_ops(iommu_group_first_dev(group));
> + struct device *first = iommu_group_first_dev(group);
> + const struct iommu_ops *ops = dev_iommu_ops(first);
> struct iommu_domain *dom;
>
> lockdep_assert_held(&group->mutex);
>
> + /*
> + * When in T=0 mode the T=1 vIOMMU must always be set to BLOCKED to
> + * release control of ATS.
> + */
> + if (iommu_using_t0_stream(first)) {
> + if (!ops->blocked_domain)
> + return ERR_PTR(-EINVAL);
> + return ops->blocked_domain;
> + }

I think the general invariant we will eventually have is the TDISP
state can't be changed without the trust level being disabled and then
this logic will just be 'if the trust level is disabled then set blocking'

> +
> /*
> * Allow legacy drivers to specify the domain that will be the default
> * domain. This should always be either an IDENTITY/BLOCKED/PLATFORM
> @@ -2399,6 +2418,10 @@ static int __iommu_attach_group(struct iommu_domain *domain,
> !domain_iommu_ops_compatible(dev_iommu_ops(dev), domain))
> return -EINVAL;
>
> + /* A domain cannot be attached while using the T=0 stream. */
> + if (iommu_using_t0_stream(dev))
> + return -EINVAL;

We do need some way to block vfio though..

> [ ... 17 lines skipped ... ]
> @@ -3690,6 +3719,12 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
> goto out_unlock;
> }
>
> + /* PASID cannot be used on the T=0 stream. */
> + if (iommu_using_t0_stream(dev)) {
> + ret = -EINVAL;
> + goto out_unlock;
> + }

And this PASID related makes sense at this point, again with clearer
function naming

> [ ... 30 lines skipped ... ]
> @@ -4294,8 +4341,9 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
> return ret;
>
> mutex_lock(&group->mutex);
> - /* An IDENTITY domain must pass through */
> - if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY) {
> + /* An IDENTITY domain or a T=0 device must pass through */
> + if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY &&
> + !iommu_using_t0_stream(dev)) {
> switch (group->domain->cookie_type) {
> case IOMMU_COOKIE_DMA_MSI:
> case IOMMU_COOKIE_DMA_IOVA:

Hmm. At the moment we expect that MSI is always using T=0, so this
would be more like '!iommu->confidential' I guess since T=0 will
always use bypass. It doesn't matter at all though since existing VMMs
ignore the address selected here :\

--
Jason