xen/arm: smmu: Set/clear IOMMU domain for device
authorOleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Wed, 18 Aug 2021 05:22:02 +0000 (08:22 +0300)
committerJulien Grall <jgrall@amazon.com>
Tue, 24 Aug 2021 10:08:25 +0000 (10:08 +0000)
When a device is assigned/de-assigned it is required to properly set
IOMMU domain used to protect the device. This assignment was missing,
thus it was not possible to de-assign the device:

(XEN) Deassigning device 0000:03:00.0 from dom2
(XEN) smmu: 0000:03:00.0:  not attached to domain 2
(XEN) d2: deassign (0000:03:00.0) failed (-3)

Fix this by assigning IOMMU domain on arm_smmu_assign_dev and reset it
to NULL on arm_smmu_deassign_dev.

Fixes: 06d1f7a278dd ("xen/arm: smmuv1: Keep track of S2CR state")
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
xen/drivers/passthrough/arm/smmu.c

index c234ad9c7f1e4bf740a3fd8287be73b66ce5f734..c9dfc4caa0d6f28b76447e0371d9c719c742cc11 100644 (file)
@@ -2768,6 +2768,7 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
                        arm_smmu_destroy_iommu_domain(domain);
        } else {
                atomic_inc(&domain->ref);
+               dev_iommu_domain(dev) = domain;
        }
 
 out:
@@ -2791,6 +2792,7 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
        spin_lock(&xen_domain->lock);
 
        arm_smmu_detach_dev(domain, dev);
+       dev_iommu_domain(dev) = NULL;
        atomic_dec(&domain->ref);
 
        if (domain->ref.counter == 0)