Re: [PATCH v3 1/5] iommu: Add static iommu_ops->release_domain

From: Jason Gunthorpe
Date: Thu Apr 11 2024 - 09:47:26 EST


On Wed, Apr 10, 2024 at 05:37:06PM +0100, Robin Murphy wrote:
> > We should probably be sensitive to the
> > dev->iommu->require_direct flag - generally drivers should prefer the
> > blocked for the release domain, but in case the FW ias asking for
> > require_direct we need to switch to identity.
>
> At this point do we even need release_domain?

Ultimately ideally not, but I feel better going through the exercise
driver-by-driver before we just make the core code do it
automatically. Maybe I'm being overly pessimistic about the drivers..

Have all the drivers setting identity/blocked domain set release
domain before we switch to this unconditional method.

Anyhow, I just noticed it went into -rc1 already, so may as well keep
going.

> static void iommu_set_release_domain(struct device *dev)
> {
> const struct iommu_ops *ops = dev_iommu_ops(dev);
> struct iommu_domain *rd;
>
> /*
> * Static domains are expected not to track any device state,
> * and thus be tolerant of devices disappearing once "attached"
> */
> if (ops->blocked_domain && !(dev->iommu->require_direct ||
> other_arch_or_platform_reason))
> rd = ops->blocked_domain;
> else if (ops->identity_domain)
> rd = ops->identity_domain;
> else /* Hope release_device does the right thing! */
> return;
>
> if (!dev->iommu->attach_deferred && rd != dev->iommu_group->domain)
> __iommu_attach_device(rd, dev);
> }

Yeah, this is a good end goal.

Jason