From: Rahul Singh <rahul.si...@arm.com>

In current implementation io_domain is allocated once for each xen
domain as Stage2 translation is common for all devices in same xen
domain.

Nested stage supports S1 and S2 configuration at the same time. Stage1
translation will be different for each device as linux kernel will
allocate page-table for each device.

Alloc io_domain for each device so that each device can have different
Stage-1 and Stage-2 configuration structure.

Signed-off-by: Rahul Singh <rahul.si...@arm.com>
Signed-off-by: Milan Djokic <milan_djo...@epam.com>
---
 xen/drivers/passthrough/arm/smmu-v3.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index 5c96e8ec7c..15ff703458 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -2790,11 +2790,13 @@ static struct arm_smmu_device 
*arm_smmu_get_by_dev(const struct device *dev)
 static struct iommu_domain *arm_smmu_get_domain(struct domain *d,
                                struct device *dev)
 {
+       unsigned long flags;
        struct iommu_domain *io_domain;
        struct arm_smmu_domain *smmu_domain;
        struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
        struct arm_smmu_xen_domain *xen_domain = dom_iommu(d)->arch.priv;
        struct arm_smmu_device *smmu = arm_smmu_get_by_dev(fwspec->iommu_dev);
+       struct arm_smmu_master *master;
 
        if (!smmu)
                return NULL;
@@ -2805,8 +2807,15 @@ static struct iommu_domain *arm_smmu_get_domain(struct 
domain *d,
         */
        list_for_each_entry(io_domain, &xen_domain->contexts, list) {
                smmu_domain = to_smmu_domain(io_domain);
-               if (smmu_domain->smmu == smmu)
-                       return io_domain;
+
+               spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+               list_for_each_entry(master, &smmu_domain->devices, domain_head) 
{
+                       if (master->dev == dev) {
+                               
spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
+                               return io_domain;
+                       }
+               }
+               spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
        }
        return NULL;
 }
-- 
2.43.0

Reply via email to