Linux IOMMU Development
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
	iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
	llvm@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>, Tom Rix <trix@redhat.com>,
	Will Deacon <will@kernel.org>
Cc: baolu.lu@linux.intel.com, Kevin Tian <kevin.tian@intel.com>,
	Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: [PATCH v2 07/14] iommu: Make iommu_group_do_dma_first_attach() simpler
Date: Thu, 30 Mar 2023 14:42:20 +0800	[thread overview]
Message-ID: <5a249f94-7742-a2c8-2eff-88821783a6f2@linux.intel.com> (raw)
In-Reply-To: <7-v2-cd32667d2ba6+70bd1-iommu_err_unwind_jgg@nvidia.com>

On 3/30/23 7:40 AM, Jason Gunthorpe wrote:
> It should always attach to the current group->domain, so don't take in a
> domain parameter. Use the __iommu_device_set_domain() common code to
> handle the attach.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/iommu.c | 22 +++++++++-------------
>   1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index af3af752c255e4..c68cf551d05dc4 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -105,6 +105,10 @@ enum {
>   	IOMMU_SET_DOMAIN_WITH_DEFERRED = 1 << 1,
>   };
>   
> +static int __iommu_device_set_domain(struct iommu_group *group,
> +				     struct device *dev,
> +				     struct iommu_domain *new_domain,
> +				     unsigned int flags);
>   static int __iommu_group_set_domain_internal(struct iommu_group *group,
>   					     struct iommu_domain *new_domain,
>   					     unsigned int flags);
> @@ -405,18 +409,10 @@ static bool iommu_is_attach_deferred(struct device *dev)
>   	return false;
>   }
>   
> -static int iommu_group_do_dma_first_attach(struct device *dev, void *data)
> +static int iommu_group_do_dma_first_attach(struct iommu_group *group, struct device *dev)
>   {
> -	struct iommu_domain *domain = data;
> -
> -	lockdep_assert_held(&dev->iommu_group->mutex);
> -
> -	if (iommu_is_attach_deferred(dev)) {
> -		dev->iommu->attach_deferred = 1;
> -		return 0;
> -	}
> -
> -	return __iommu_attach_device(domain, dev);
> +	return __iommu_device_set_domain(group, dev, group->domain,
> +					 IOMMU_SET_DOMAIN_WITH_DEFERRED);

Just out of curiosity, why is this group->domain instead of
group->default_domain?

>   }
>   
>   int iommu_probe_device(struct device *dev)
> @@ -449,7 +445,7 @@ int iommu_probe_device(struct device *dev)
>   	 * attach the default domain.
>   	 */
>   	if (group->default_domain && !group->owner) {
> -		ret = iommu_group_do_dma_first_attach(dev, group->default_domain);
> +		ret = iommu_group_do_dma_first_attach(group, dev);
>   		if (ret) {
>   			mutex_unlock(&group->mutex);
>   			iommu_group_put(group);
> @@ -1117,7 +1113,7 @@ 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)
> -		ret = iommu_group_do_dma_first_attach(dev, group->domain);
> +		ret = iommu_group_do_dma_first_attach(group, dev);

I am wondering whether we need to do dma first attach here.

iommu_group_add_device() is called from

1) drivers/vfio/group.c
    The deferred attachment is only used for kdump. In the kdump capture
    kernel, vfio should not be used. Or not?

2) arch/powerpc/kernel/iommu.c
    Is powerpc iommu implementation compatible with the generic IOMMU
    framework and provide a is_attach_deferred op? If not, no need for
    dma first attach either.

If above are true, perhaps we could simply call
__iommu_group_set_domain() here?

>   	mutex_unlock(&group->mutex);
>   	if (ret)
>   		goto err_put_group;

Best regards,
baolu

  reply	other threads:[~2023-03-30  6:42 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 23:40 [PATCH v2 00/14] Consolidate the error handling around device attachment Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 01/14] iommu: Replace iommu_group_device_count() with list_count_nodes() Jason Gunthorpe
2023-03-30  6:22   ` Baolu Lu
2023-04-04  9:15   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 02/14] iommu: Add for_each_group_device() Jason Gunthorpe
2023-03-29 23:52   ` Miguel Ojeda
2023-03-30 14:28     ` Jason Gunthorpe
2023-05-09 13:12       ` Miguel Ojeda
2023-05-10  1:01         ` Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-04-04  9:16   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 03/14] iommu: Make __iommu_group_set_domain() handle error unwind Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 04/14] iommu: Use __iommu_group_set_domain() for __iommu_attach_group() Jason Gunthorpe
2023-03-30  6:23   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 05/14] iommu: Use __iommu_group_set_domain() in iommu_change_dev_def_domain() Jason Gunthorpe
2023-03-30  6:24   ` Baolu Lu
2023-04-04  9:16   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 06/14] iommu: Replace __iommu_group_dma_first_attach() with set_domain Jason Gunthorpe
2023-03-30  6:24   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 07/14] iommu: Make iommu_group_do_dma_first_attach() simpler Jason Gunthorpe
2023-03-30  6:42   ` Baolu Lu [this message]
2023-03-30 14:41     ` Jason Gunthorpe
2023-03-31  2:21       ` Baolu Lu
2023-04-04  9:17   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 08/14] iommu: Make iommu_group_do_dma_first_attach() work with owned groups Jason Gunthorpe
2023-03-30  6:45   ` Baolu Lu
2023-03-30 15:54   ` Robin Murphy
2023-03-30 16:49     ` Jason Gunthorpe
2023-04-04  9:21   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 09/14] iommu: Fix iommu_probe_device() to attach the right domain Jason Gunthorpe
2023-03-30  7:33   ` Baolu Lu
2023-04-04  9:25   ` Tian, Kevin
2023-03-29 23:40 ` [PATCH v2 10/14] iommu: Remove the assignment of group->domain during default domain alloc Jason Gunthorpe
2023-03-30  7:33   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 11/14] iommu: Consolidate the code to calculate the target default domain type Jason Gunthorpe
2023-03-30 11:51   ` Baolu Lu
2023-04-04  9:39   ` Tian, Kevin
2023-04-04 18:51     ` Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 12/14] iommu: Consolidate the default_domain setup to one function Jason Gunthorpe
2023-03-30 12:37   ` Baolu Lu
2023-03-30 14:29     ` Robin Murphy
2023-03-30 14:45       ` Jason Gunthorpe
2023-03-30 15:42         ` Jason Gunthorpe
2023-04-04 11:29           ` Robin Murphy
2023-03-30 15:36     ` Jason Gunthorpe
2023-03-30 18:23       ` Robin Murphy
2023-03-30 19:01         ` Jason Gunthorpe
2023-03-29 23:40 ` [PATCH v2 13/14] iommu: Remove __iommu_group_for_each_dev() Jason Gunthorpe
2023-03-30 12:40   ` Baolu Lu
2023-03-29 23:40 ` [PATCH v2 14/14] iommu: Tidy the control flow in iommu_group_store_type() Jason Gunthorpe
2023-03-30 12:45   ` Baolu Lu

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=5a249f94-7742-a2c8-2eff-88821783a6f2@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolinc@nvidia.com \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=trix@redhat.com \
    --cc=will@kernel.org \
    /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