iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: Ashok Raj <ashok.raj@intel.com>,
	Will Deacon <will.deacon@arm.com>,
	iommu@lists.linux-foundation.org,
	Robin Murphy <robin.murphy@arm.com>,
	Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 3/4] iommu: Add support to change default domain of an iommu_group
Date: Tue, 3 Sep 2019 14:50:46 +0200	[thread overview]
Message-ID: <20190903125046.GA11530@8bytes.org> (raw)
In-Reply-To: <03cbec8c95b13d417dd1c44f545241d01e7b9654.1566353521.git.sai.praneeth.prakhya@intel.com>

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
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2019-09-03 12:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21  2:42 [PATCH 0/4] iommu: Add support to change default domain of a group Sai Praneeth Prakhya
2019-08-21  2:42 ` [PATCH 1/4] iommu/vt-d: Modify device_def_domain_type() to use at runtime Sai Praneeth Prakhya
2019-08-21  2:42 ` [PATCH 2/4] iommu: Add device_def_domain_type() call back function to iommu_ops Sai Praneeth Prakhya
2019-08-21  2:42 ` [PATCH 3/4] iommu: Add support to change default domain of an iommu_group Sai Praneeth Prakhya
2019-09-03 12:50   ` Joerg Roedel [this message]
2019-09-04  3:09     ` Prakhya, Sai Praneeth
2019-09-04  3:17       ` Lu Baolu
2019-09-04 16:18         ` Prakhya, Sai Praneeth
2019-08-21  2:42 ` [PATCH 4/4] iommu: Document usage of "/sys/kernel/iommu_groups/<grp_id>/type" file Sai Praneeth Prakhya
2019-08-21 14:52   ` John Garry
2019-08-21 17:08     ` Sai Praneeth Prakhya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903125046.GA11530@8bytes.org \
    --to=joro@8bytes.org \
    --cc=ashok.raj@intel.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=robin.murphy@arm.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).