From: Yi Liu Date: Wed, 4 Dec 2024 12:29:24 +0000 (-0800) Subject: iommu: Detaching pasid by attaching to the blocked_domain X-Git-Tag: v6.14-rc1~116^2^7~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b18301b9156a0d8a0094fcd16a1b98816539eab0;p=thirdparty%2Fkernel%2Flinux.git iommu: Detaching pasid by attaching to the blocked_domain The iommu drivers are on the way to detach pasid by attaching to the blocked domain. However, this cannot be done in one shot. During the transition, iommu core would select between the remove_dev_pasid op and the blocked domain. Suggested-by: Kevin Tian Suggested-by: Jason Gunthorpe Reviewed-by: Kevin Tian Reviewed-by: Vasant Hegde Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu Signed-off-by: Yi Liu Link: https://lore.kernel.org/r/20241204122928.11987-4-yi.l.liu@intel.com Signed-off-by: Joerg Roedel --- diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2ff4fa60a86a7..2064dc8bb8b53 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -3316,8 +3316,18 @@ static void iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid, struct iommu_domain *domain) { const struct iommu_ops *ops = dev_iommu_ops(dev); + struct iommu_domain *blocked_domain = ops->blocked_domain; + int ret = 1; - ops->remove_dev_pasid(dev, pasid, domain); + if (blocked_domain && blocked_domain->ops->set_dev_pasid) { + ret = blocked_domain->ops->set_dev_pasid(blocked_domain, + dev, pasid, domain); + } else { + ops->remove_dev_pasid(dev, pasid, domain); + ret = 0; + } + + WARN_ON(ret); } static int __iommu_set_group_pasid(struct iommu_domain *domain, @@ -3380,7 +3390,9 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, ops = dev_iommu_ops(dev); if (!domain->ops->set_dev_pasid || - !ops->remove_dev_pasid) + (!ops->remove_dev_pasid && + (!ops->blocked_domain || + !ops->blocked_domain->ops->set_dev_pasid))) return -EOPNOTSUPP; if (ops != domain->owner || pasid == IOMMU_NO_PASID)