Skip to contentSkip to conversation

xen/arm: smmu: Set/clear IOMMU domain for device

PATCH In review Oleksandr Andrushchenko 2 participants 3 messages Aug 18, 2021 – Aug 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/arm: smmu: Set/clear IOMMU domain for device

From: Oleksandr Andrushchenko <[email protected]>

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")

---
v2:
Fixed NULL assignment out of refcount == 0 check for domain Added "Fixes" tag

---
 xen/drivers/passthrough/arm/smmu.c | 2 ++
 1 file changed, 2 insertions(+)
xen/drivers/passthrough/arm/smmu.c +2 -0
index c234ad9c7f1e..c9dfc4caa0d6 100644
@@ -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)
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

Hi Oleksandr,

Quoted 10 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

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)

Quoted 7 lines

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")

Cheers,

Signature · 1 line
Julien Grall
#2 lore raw
Quoted 14 lines · Julien Grall
Quoted 13 lines · Oleksandr Andrushchenko

From: Oleksandr Andrushchenko <[email protected]>

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.

Quoted 6 lines
Quoted 4 lines
Fixes 06d1f7a278dd ("xen/arm: smmuv1: Keep track of S2CR state")

I have just committed it.

Cheers,

Signature · 1 line
Julien Grall