Linux IOMMU Development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Cc: m-karicheri2-l0cyMroinI0@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	arnd-r2nGTMty4D4@public.gmane.org
Subject: Re: [PATCH 1/2] iommu: return dma alias from iommu_group_get_for_pci_dev()
Date: Fri, 16 Jan 2015 10:41:51 -0700	[thread overview]
Message-ID: <1421430111.6130.254.camel@redhat.com> (raw)
In-Reply-To: <1421427514-16579-2-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>

On Fri, 2015-01-16 at 16:58 +0000, Will Deacon wrote:
> Some IOMMU drivers (e.g. the ARM SMMU) require not only the IOMMU group
> for a PCI device, but also the effective alias of the device (as seen by
> the IOMMU) in order to program the translations correctly.
> 
> This patch extends iommu_group_get_for_pci_dev to return the DMA alias
> of the device as well as the group, which can potentially be overridden
> by quirks in the PCI layer. The function is also made visible to drivers
> so that the new functionality can be used.
> 
> Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
> ---
>  drivers/iommu/iommu.c | 14 ++++++++++++--
>  include/linux/iommu.h |  2 ++
>  2 files changed, 14 insertions(+), 2 deletions(-)

This would seem to promote the idea that an IOMMU group for a PCI device
has a single bdf alias, which is not necessarily true.  It also only
returns the alias based on PCI topology, which can easily be discovered
by the caller using pci_for_each_dma_alias() directly.  So I don't
really see the benefit of this versus using iommu_group_for_each_dev()
and/or pci_for_each_dma_alias().

It's also intentional that while we have PCI specific code in iommu.c,
the exposed interfaces are device agnostic.  I'm not seeing enough
reason here to change that.  Thanks,

Alex

> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index f7718d73e984..5300b6507481 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -616,6 +616,7 @@ static struct iommu_group *get_pci_alias_group(struct pci_dev *pdev,
>  struct group_for_pci_data {
>  	struct pci_dev *pdev;
>  	struct iommu_group *group;
> +	u16 alias;
>  };
>  
>  /*
> @@ -628,6 +629,7 @@ static int get_pci_alias_or_group(struct pci_dev *pdev, u16 alias, void *opaque)
>  
>  	data->pdev = pdev;
>  	data->group = iommu_group_get(&pdev->dev);
> +	data->alias = alias;
>  
>  	return data->group != NULL;
>  }
> @@ -636,7 +638,8 @@ static int get_pci_alias_or_group(struct pci_dev *pdev, u16 alias, void *opaque)
>   * Use standard PCI bus topology, isolation features, and DMA alias quirks
>   * to find or create an IOMMU group for a device.
>   */
> -static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev)
> +struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev,
> +						u16 *alias)
>  {
>  	struct group_for_pci_data data;
>  	struct pci_bus *bus;
> @@ -653,6 +656,13 @@ static struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *pdev)
>  		return data.group;
>  
>  	pdev = data.pdev;
> +	if (alias) {
> +		u8 busn = PCI_BUS_NUM(pdev->bus->number);
> +		if (pdev->dev_flags & PCI_DEV_FLAGS_DMA_ALIAS_DEVFN)
> +			*alias = PCI_DEVID(busn, pdev->dma_alias_devfn);
> +		else
> +			*alias = data.alias;
> +	}
>  
>  	/*
>  	 * Continue upstream from the point of minimum IOMMU granularity
> @@ -717,7 +727,7 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
>  	if (!dev_is_pci(dev))
>  		return ERR_PTR(-EINVAL);
>  
> -	group = iommu_group_get_for_pci_dev(to_pci_dev(dev));
> +	group = iommu_group_get_for_pci_dev(to_pci_dev(dev), NULL);
>  
>  	if (IS_ERR(group))
>  		return group;
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index 38daa453f2e5..1fe97d62a286 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -199,6 +199,8 @@ extern int iommu_group_register_notifier(struct iommu_group *group,
>  extern int iommu_group_unregister_notifier(struct iommu_group *group,
>  					   struct notifier_block *nb);
>  extern int iommu_group_id(struct iommu_group *group);
> +extern struct iommu_group *iommu_group_get_for_pci_dev(struct pci_dev *dev,
> +						       u16 *alias);
>  extern struct iommu_group *iommu_group_get_for_dev(struct device *dev);
>  
>  extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr,

  parent reply	other threads:[~2015-01-16 17:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-16 16:58 [PATCH 0/2] Reuse generic PCI DMA alias parsing code for the ARM SMMU Will Deacon
     [not found] ` <1421427514-16579-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2015-01-16 16:58   ` [PATCH 1/2] iommu: return dma alias from iommu_group_get_for_pci_dev() Will Deacon
     [not found]     ` <1421427514-16579-2-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2015-01-16 17:41       ` Alex Williamson [this message]
     [not found]         ` <1421430111.6130.254.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-01-16 20:33           ` Will Deacon
     [not found]             ` <20150116203350.GA21807-5wv7dgnIgG8@public.gmane.org>
2015-01-16 21:11               ` Alex Williamson
     [not found]                 ` <1421442663.6130.281.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-01-19 12:02                   ` Will Deacon
2015-01-16 16:58   ` [PATCH 2/2] iommu/arm-smmu: remove homebrew PCI dma alias parsing Will Deacon
     [not found]     ` <1421427514-16579-3-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2015-01-19 13:43       ` Varun Sethi
     [not found]         ` <BN3PR0301MB121948FC05425680C6C2CA63EA4A0-CEkquS/Gb81uuip9JPHoc5wN6zqB+hSMnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2015-01-19 14:09           ` Will Deacon

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=1421430111.6130.254.camel@redhat.com \
    --to=alex.williamson-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=m-karicheri2-l0cyMroinI0@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.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