From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZxzK-0008TS-0q for qemu-devel@nongnu.org; Thu, 10 Sep 2015 05:17:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZxzI-0004Uo-QX for qemu-devel@nongnu.org; Thu, 10 Sep 2015 05:17:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZxzI-0004Ug-Ke for qemu-devel@nongnu.org; Thu, 10 Sep 2015 05:17:48 -0400 Date: Thu, 10 Sep 2015 12:17:43 +0300 From: "Michael S. Tsirkin" Message-ID: <1441876643-7467-2-git-send-email-mst@redhat.com> References: <1441876643-7467-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1441876643-7467-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 1/7] pci: Fix pci_device_iommu_address_space() bus propagation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell From: Benjamin Herrenschmidt 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 Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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