From: Bjorn Helgaas <helgaas@kernel.org>
To: Jon Derrick <jonathan.derrick@intel.com>
Cc: linux-pci@vger.kernel.org, iommu@lists.linux-foundation.org,
Keith Busch <kbusch@kernel.org>,
David Woodhouse <dwmw2@infradead.org>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH v5 3/7] PCI: Introduce pci_real_dma_dev()
Date: Wed, 22 Jan 2020 15:12:59 -0600 [thread overview]
Message-ID: <20200122211259.GA19172@google.com> (raw)
In-Reply-To: <1579613871-301529-4-git-send-email-jonathan.derrick@intel.com>
On Tue, Jan 21, 2020 at 06:37:47AM -0700, Jon Derrick wrote:
> The current DMA alias implementation requires the aliased device be on
> the same PCI bus as the requester ID. This introduces an arch-specific
> mechanism to point to another PCI device when doing mapping and
> PCI DMA alias search. The default case returns the actual device.
>
> CC: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Looks like a nice cleanup to me.
Lorenzo, let me know if you want me to take this.
> ---
> arch/x86/pci/common.c | 10 ++++++++++
> drivers/pci/pci.c | 19 ++++++++++++++++++-
> drivers/pci/search.c | 6 ++++++
> include/linux/pci.h | 1 +
> 4 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
> index 1e59df0..fe21a5c 100644
> --- a/arch/x86/pci/common.c
> +++ b/arch/x86/pci/common.c
> @@ -736,3 +736,13 @@ int pci_ext_cfg_avail(void)
> else
> return 0;
> }
> +
> +#if IS_ENABLED(CONFIG_VMD)
> +struct pci_dev *pci_real_dma_dev(struct pci_dev *dev)
> +{
> + if (is_vmd(dev->bus))
> + return to_pci_sysdata(dev->bus)->vmd_dev;
> +
> + return dev;
> +}
> +#endif
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 581b177..36d24f2 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6048,7 +6048,9 @@ bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2)
> return (dev1->dma_alias_mask &&
> test_bit(dev2->devfn, dev1->dma_alias_mask)) ||
> (dev2->dma_alias_mask &&
> - test_bit(dev1->devfn, dev2->dma_alias_mask));
> + test_bit(dev1->devfn, dev2->dma_alias_mask)) ||
> + pci_real_dma_dev(dev1) == dev2 ||
> + pci_real_dma_dev(dev2) == dev1;
> }
>
> bool pci_device_is_present(struct pci_dev *pdev)
> @@ -6072,6 +6074,21 @@ void pci_ignore_hotplug(struct pci_dev *dev)
> }
> EXPORT_SYMBOL_GPL(pci_ignore_hotplug);
>
> +/**
> + * pci_real_dma_dev - Get PCI DMA device for PCI device
> + * @dev: the PCI device that may have a PCI DMA alias
> + *
> + * Permits the platform to provide architecture-specific functionality to
> + * devices needing to alias DMA to another PCI device on another PCI bus. If
> + * the PCI device is on the same bus, it is recommended to use
> + * pci_add_dma_alias(). This is the default implementation. Architecture
> + * implementations can override this.
> + */
> +struct pci_dev __weak *pci_real_dma_dev(struct pci_dev *dev)
> +{
> + return dev;
> +}
> +
> resource_size_t __weak pcibios_default_alignment(void)
> {
> return 0;
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index e4dbdef..2061672 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -32,6 +32,12 @@ int pci_for_each_dma_alias(struct pci_dev *pdev,
> struct pci_bus *bus;
> int ret;
>
> + /*
> + * The device may have an explicit alias requester ID for DMA where the
> + * requester is on another PCI bus.
> + */
> + pdev = pci_real_dma_dev(pdev);
> ret = fn(pdev, pci_dev_id(pdev), data);
> if (ret)
> return ret;
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 930fab2..3840a54 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1202,6 +1202,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
> int pci_select_bars(struct pci_dev *dev, unsigned long flags);
> bool pci_device_is_present(struct pci_dev *pdev);
> void pci_ignore_hotplug(struct pci_dev *dev);
> +struct pci_dev *pci_real_dma_dev(struct pci_dev *dev);
>
> int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
> irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,
> --
> 1.8.3.1
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
WARNING: multiple messages have this Message-ID (diff)
From: Bjorn Helgaas <helgaas@kernel.org>
To: Jon Derrick <jonathan.derrick@intel.com>
Cc: linux-pci@vger.kernel.org,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
iommu@lists.linux-foundation.org, Christoph Hellwig <hch@lst.de>,
Keith Busch <kbusch@kernel.org>, Joerg Roedel <joro@8bytes.org>,
David Woodhouse <dwmw2@infradead.org>,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: Re: [PATCH v5 3/7] PCI: Introduce pci_real_dma_dev()
Date: Wed, 22 Jan 2020 15:12:59 -0600 [thread overview]
Message-ID: <20200122211259.GA19172@google.com> (raw)
In-Reply-To: <1579613871-301529-4-git-send-email-jonathan.derrick@intel.com>
On Tue, Jan 21, 2020 at 06:37:47AM -0700, Jon Derrick wrote:
> The current DMA alias implementation requires the aliased device be on
> the same PCI bus as the requester ID. This introduces an arch-specific
> mechanism to point to another PCI device when doing mapping and
> PCI DMA alias search. The default case returns the actual device.
>
> CC: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Looks like a nice cleanup to me.
Lorenzo, let me know if you want me to take this.
> ---
> arch/x86/pci/common.c | 10 ++++++++++
> drivers/pci/pci.c | 19 ++++++++++++++++++-
> drivers/pci/search.c | 6 ++++++
> include/linux/pci.h | 1 +
> 4 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
> index 1e59df0..fe21a5c 100644
> --- a/arch/x86/pci/common.c
> +++ b/arch/x86/pci/common.c
> @@ -736,3 +736,13 @@ int pci_ext_cfg_avail(void)
> else
> return 0;
> }
> +
> +#if IS_ENABLED(CONFIG_VMD)
> +struct pci_dev *pci_real_dma_dev(struct pci_dev *dev)
> +{
> + if (is_vmd(dev->bus))
> + return to_pci_sysdata(dev->bus)->vmd_dev;
> +
> + return dev;
> +}
> +#endif
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 581b177..36d24f2 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6048,7 +6048,9 @@ bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2)
> return (dev1->dma_alias_mask &&
> test_bit(dev2->devfn, dev1->dma_alias_mask)) ||
> (dev2->dma_alias_mask &&
> - test_bit(dev1->devfn, dev2->dma_alias_mask));
> + test_bit(dev1->devfn, dev2->dma_alias_mask)) ||
> + pci_real_dma_dev(dev1) == dev2 ||
> + pci_real_dma_dev(dev2) == dev1;
> }
>
> bool pci_device_is_present(struct pci_dev *pdev)
> @@ -6072,6 +6074,21 @@ void pci_ignore_hotplug(struct pci_dev *dev)
> }
> EXPORT_SYMBOL_GPL(pci_ignore_hotplug);
>
> +/**
> + * pci_real_dma_dev - Get PCI DMA device for PCI device
> + * @dev: the PCI device that may have a PCI DMA alias
> + *
> + * Permits the platform to provide architecture-specific functionality to
> + * devices needing to alias DMA to another PCI device on another PCI bus. If
> + * the PCI device is on the same bus, it is recommended to use
> + * pci_add_dma_alias(). This is the default implementation. Architecture
> + * implementations can override this.
> + */
> +struct pci_dev __weak *pci_real_dma_dev(struct pci_dev *dev)
> +{
> + return dev;
> +}
> +
> resource_size_t __weak pcibios_default_alignment(void)
> {
> return 0;
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index e4dbdef..2061672 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -32,6 +32,12 @@ int pci_for_each_dma_alias(struct pci_dev *pdev,
> struct pci_bus *bus;
> int ret;
>
> + /*
> + * The device may have an explicit alias requester ID for DMA where the
> + * requester is on another PCI bus.
> + */
> + pdev = pci_real_dma_dev(pdev);
> ret = fn(pdev, pci_dev_id(pdev), data);
> if (ret)
> return ret;
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 930fab2..3840a54 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1202,6 +1202,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
> int pci_select_bars(struct pci_dev *dev, unsigned long flags);
> bool pci_device_is_present(struct pci_dev *pdev);
> void pci_ignore_hotplug(struct pci_dev *dev);
> +struct pci_dev *pci_real_dma_dev(struct pci_dev *dev);
>
> int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
> irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2020-01-22 21:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-21 13:37 [PATCH v5 0/7] Clean up VMD DMA Map Ops Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-21 13:37 ` [PATCH v5 1/7] x86/PCI: Add a to_pci_sysdata helper Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-21 13:37 ` [PATCH v5 2/7] x86/PCI: Expose VMD's PCI Device in pci_sysdata Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-21 13:37 ` [PATCH v5 3/7] PCI: Introduce pci_real_dma_dev() Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-22 21:12 ` Bjorn Helgaas [this message]
2020-01-22 21:12 ` Bjorn Helgaas
2020-01-23 16:08 ` Lorenzo Pieralisi
2020-01-23 16:08 ` Lorenzo Pieralisi
2020-01-21 13:37 ` [PATCH v5 4/7] iommu/vt-d: Use pci_real_dma_dev() for mapping Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-22 4:37 ` Lu Baolu
2020-01-22 4:37 ` Lu Baolu
2020-01-21 13:37 ` [PATCH v5 5/7] iommu/vt-d: Remove VMD child device sanity check Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-22 4:37 ` Lu Baolu
2020-01-22 4:37 ` Lu Baolu
2020-01-21 13:37 ` [PATCH v5 6/7] PCI: vmd: Stop overriding dma_map_ops Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-22 16:56 ` Keith Busch
2020-01-22 16:56 ` Keith Busch
2020-01-21 13:37 ` [PATCH v5 7/7] x86/PCI: Remove X86_DEV_DMA_OPS Jon Derrick
2020-01-21 13:37 ` Jon Derrick
2020-01-24 21:02 ` [PATCH v5 0/7] Clean up VMD DMA Map Ops Bjorn Helgaas
2020-01-24 21:02 ` Bjorn Helgaas
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=20200122211259.GA19172@google.com \
--to=helgaas@kernel.org \
--cc=dwmw2@infradead.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=jonathan.derrick@intel.com \
--cc=kbusch@kernel.org \
--cc=linux-pci@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.