lkml.org 
[lkml]   [2020]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] iommu: Implement deferred domain attachment
On Mon May 18 20, Joerg Roedel wrote:
>On Fri, May 15, 2020 at 08:23:13PM +0100, Robin Murphy wrote:
>> But that's not what this is; this is (supposed to be) the exact same "don't
>> actually perform the attach yet" logic as before, just restricting it to
>> default domains in the one place that it actually needs to be, so as not to
>> fundamentally bugger up iommu_attach_device() in a way that prevents it from
>> working as expected at the correct point later.
>
>You are right, that is better. I tested it and it seems to work. Updated
>diff attached, with a minor cleanup included. Mind sending it as a
>proper patch I can send upstream?
>
>Thanks,
>
> Joerg
>
>diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>index 7b375421afba..a9d02bc3ab5b 100644
>--- a/drivers/iommu/iommu.c
>+++ b/drivers/iommu/iommu.c
>@@ -693,6 +693,15 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group,
> return ret;
> }
>
>+static bool iommu_is_attach_deferred(struct iommu_domain *domain,
>+ struct device *dev)
>+{
>+ if (domain->ops->is_attach_deferred)
>+ return domain->ops->is_attach_deferred(domain, dev);
>+
>+ return false;
>+}
>+
> /**
> * iommu_group_add_device - add a device to an iommu group
> * @group: the group into which to add the device (reference should be held)
>@@ -705,6 +714,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)
> {
> int ret, i = 0;
> struct group_device *device;
>+ struct iommu_domain *domain;
>
> device = kzalloc(sizeof(*device), GFP_KERNEL);
> if (!device)
>@@ -747,7 +757,8 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)
>
> mutex_lock(&group->mutex);
> list_add_tail(&device->list, &group->devices);
>- if (group->domain)
>+ domain = group->domain;
>+ if (domain && !iommu_is_attach_deferred(domain, dev))
> ret = __iommu_attach_device(group->domain, dev);
> mutex_unlock(&group->mutex);
> if (ret)
>@@ -1653,9 +1664,6 @@ static int __iommu_attach_device(struct iommu_domain *domain,
> struct device *dev)
> {
> int ret;
>- if ((domain->ops->is_attach_deferred != NULL) &&
>- domain->ops->is_attach_deferred(domain, dev))
>- return 0;
>
> if (unlikely(domain->ops->attach_dev == NULL))
> return -ENODEV;
>@@ -1727,8 +1735,7 @@ EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid);
> static void __iommu_detach_device(struct iommu_domain *domain,
> struct device *dev)
> {
>- if ((domain->ops->is_attach_deferred != NULL) &&
>- domain->ops->is_attach_deferred(domain, dev))
>+ if (iommu_is_attach_deferred(domain, dev))
> return;
>
> if (unlikely(domain->ops->detach_dev == NULL))
>_______________________________________________
>iommu mailing list
>iommu@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/iommu
>

This worked for me as well.

\
 
 \ /
  Last update: 2020-05-19 09:11    [W:0.486 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site