On Tue, Aug 20, 2019 at 07:42:25PM -0700, Sai Praneeth Prakhya wrote:
> +     /*
> +      * iommu_domain_alloc() takes "struct bus_type" as an argument which is
> +      * a member in "struct device". Changing a group's default domain type
> +      * deals at iommu_group level rather than device level and hence there
> +      * is no straight forward way to get "bus_type" of an iommu_group that
> +      * could be passed to iommu_domain_alloc(). So, instead of directly
> +      * calling iommu_domain_alloc(), use iommu_ops from previous default
> +      * domain.
> +      */
> +     if (!prev_domain || !prev_domain->ops ||
> +         !prev_domain->ops->domain_alloc || !type)
> +             return -EINVAL;

Hmm, this isn't really nice and clean, but I understand why you need it.
I will think about a better way to get iommu_ops here.

> +free_prev_domain:
> +     /*
> +      * Free the existing default domain and replace it with the newly
> +      * created default domain. No need to set group->domain because
> +      * __iommu_attach_group() already does it on success.
> +      */
> +     iommu_domain_free(prev_domain);
> +     group->default_domain = new_domain;
> +     return 0;

It isn't obvious to me from this patch, how to are the dma_ops updated
when the default domain changes between identity and dma?

> +     /* Check if any device in the group still has a driver binded to it */
> +     if (iommu_group_for_each_dev(group, NULL, is_driver_binded)) {
> +             pr_err("Active drivers exist for devices in the group\n");
> +             return -EBUSY;
> +     }

This is racy with device driver probing code. Unfortunatly there is no
clean way out of that either, locking all devices in the group and then
do the re-attach will introduce a lock-inversion with group->mutex. But
please put a comment here saying that this might race with device driver
probing.


Regards,

        Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to