qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 1/7] pci: Fix pci_device_iommu_address_space() bus propagation
Date: Thu, 10 Sep 2015 12:17:43 +0300	[thread overview]
Message-ID: <1441876643-7467-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1441876643-7467-1-git-send-email-mst@redhat.com>

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

he current code walks up the bus tree for an iommu, however it passes
to the iommu_fn() callback the bus/devfn of the immediate child of
the level where the callback was found, rather than the original
bus/devfn where the search started from.

This prevents iommu's like POWER8 (and in fact also Q35) to properly
provide an address space for a subset of devices that aren't immediate
children of the iommu.

PCIe carries the originator bdfn acccross to the iommu on all DMA
transactions, so we must be able to properly identify devices at all
levels.

This changes the function pci_device_iommu_address_space() to pass
the original pointers to the iommu_fn() callback instead.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pci.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 4700e95..eba7ca2 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2383,17 +2383,14 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
 {
     PCIBus *bus = PCI_BUS(dev->bus);
+    PCIBus *iommu_bus = bus;
 
-    if (bus->iommu_fn) {
-        return bus->iommu_fn(bus, bus->iommu_opaque, dev->devfn);
+    while(iommu_bus && !iommu_bus->iommu_fn && iommu_bus->parent_dev) {
+        iommu_bus = PCI_BUS(iommu_bus->parent_dev->bus);
     }
-
-    if (bus->parent_dev) {
-        /** We are ignoring the bus master DMA bit of the bridge
-         *  as it would complicate things such as VFIO for no good reason */
-        return pci_device_iommu_address_space(bus->parent_dev);
+    if (iommu_bus && iommu_bus->iommu_fn) {
+        return iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, dev->devfn);
     }
-
     return &address_space_memory;
 }
 
-- 
MST

  reply	other threads:[~2015-09-10  9:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-10  9:17 [Qemu-devel] [PULL 0/7] virtio,pc,acpi fixes, cleanups Michael S. Tsirkin
2015-09-10  9:17 ` Michael S. Tsirkin [this message]
2015-09-10  9:17 ` [Qemu-devel] [PULL 2/7] pc: Remove redundant arguments from xen_hvm_init() Michael S. Tsirkin
2015-09-10  9:17 ` [Qemu-devel] [PULL 3/7] virtio: avoid leading underscores for helpers Michael S. Tsirkin
2015-09-10  9:17 ` [Qemu-devel] [PULL 4/7] acpi: Remove unused definition Michael S. Tsirkin
2015-09-10  9:17 ` [Qemu-devel] [PULL 5/7] pc: memhotplug: fix incorrectly set reserved-memory-end Michael S. Tsirkin
2015-09-10  9:18 ` [Qemu-devel] [PULL 6/7] pc: memhotplug: keep reserved-memory-end broken on 2.4 and earlier machines Michael S. Tsirkin
2015-09-10  9:18 ` [Qemu-devel] [PULL 7/7] hw/pci: fix pci_update_mappings() trace events Michael S. Tsirkin
2015-09-10  9:45   ` Laszlo Ersek
2015-09-10  9:54     ` Michael S. Tsirkin
2015-09-10 10:29       ` Laszlo Ersek
2015-09-10 12:55 ` [Qemu-devel] [PULL 0/7] virtio,pc,acpi fixes, cleanups Peter Maydell

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=1441876643-7467-2-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).