Hi Joerg,

On 2016-11-29 17:48, Joerg Roedel wrote:
On Thu, Nov 24, 2016 at 12:20:19PM +0100, Marek Szyprowski wrote:
This patch adds default_domain check before calling
exynos_iommu_detach_device. This path was intended only to cope with
default domains, which are automatically attached by the iommu core, so
return error if user tries to attach device, which is already attached
to other (non-default) domain.

Signed-off-by: Marek Szyprowski <m.szyprow...@samsung.com>
---
  drivers/iommu/exynos-iommu.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index 426b1534d4d3..63d9358a6d9c 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -859,8 +859,17 @@ static int exynos_iommu_attach_device(struct iommu_domain 
*iommu_domain,
        if (!has_sysmmu(dev))
                return -ENODEV;
- if (owner->domain)
+       if (owner->domain) {
+               struct iommu_group *group = iommu_group_get(dev);
+
+               if (!group ||
+                   owner->domain != iommu_group_default_domain(group)) {
+                       iommu_group_put(group);
+                       return -EINVAL;
+               }
+               iommu_group_put(group);
                exynos_iommu_detach_device(owner->domain, dev);
+       }
Does this fix any actual bug? The iommu core should take care that the
above never happens. See __iommu_attach_group() function for details.

I've made this patch, when I was adding default domain handling in
exynos_iommu_remove_device(), but as it has been already pointed by Robin,
there is no point for the above check in exynos_iommu_attach_device(),
because it is handled in the iommu core. Please ignore this patch.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to