From patchwork Tue May 22 05:05:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 160546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DEF76B6EEB for ; Tue, 22 May 2012 16:34:19 +1000 (EST) Received: from localhost ([::1]:44953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWifh-0005Im-K9 for incoming@patchwork.ozlabs.org; Tue, 22 May 2012 02:34:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWhHl-0006PY-T2 for qemu-devel@nongnu.org; Tue, 22 May 2012 01:05:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWhHk-0007Nw-2f for qemu-devel@nongnu.org; Tue, 22 May 2012 01:05:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39032) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWhHj-0007Ns-RC for qemu-devel@nongnu.org; Tue, 22 May 2012 01:05:28 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4M55H2D029489 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 May 2012 01:05:17 -0400 Received: from bling.home (ovpn-113-40.phx2.redhat.com [10.3.113.40]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4M55F63028298; Tue, 22 May 2012 01:05:15 -0400 From: Alex Williamson To: benh@kernel.crashing.org, aik@ozlabs.ru, david@gibson.dropbear.id.au, joerg.roedel@amd.com, dwmw2@infradead.org Date: Mon, 21 May 2012 23:05:15 -0600 Message-ID: <20120522050515.5871.92344.stgit@bling.home> In-Reply-To: <20120522043607.5871.11340.stgit@bling.home> References: <20120522043607.5871.11340.stgit@bling.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Tue, 22 May 2012 02:33:15 -0400 Cc: aafabbri@cisco.com, alex.williamson@redhat.com, kvm@vger.kernel.org, B07421@freescale.com, linux-pci@vger.kernel.org, konrad.wilk@oracle.com, agraf@suse.de, qemu-devel@nongnu.org, chrisw@sous-sol.org, B08248@freescale.com, iommu@lists.linux-foundation.org, ddutile@redhat.com, avi@redhat.com, gregkh@linuxfoundation.org, bhelgaas@google.com, linux-kernel@vger.kernel.org, benve@cisco.com Subject: [Qemu-devel] [PATCH v2 06/13] iommu: Make use of DMA quirking and ACS enabled check for groups X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Incorporate DMA quirking and ACS checking into amd_iommu and intel-iommu. Note that IOMMU groups are not yet used for streaming DMA, so this doesn't immediately solve the problems with broken Ricoh devices. This a very strict implementation of ACS checking, which will often result in multifunction devices being grouped together. This is actually a good thing as we generally have no reason to trust isolation between functions, but I won't be surprised if we later add a boot option to relax this if a user wants to opt-in to a less secure grouping. Signed-off-by: Alex Williamson --- drivers/iommu/amd_iommu.c | 18 ++++++++++++++++++ drivers/iommu/intel-iommu.c | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index b7e5ddf..be72d6d 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -254,6 +254,8 @@ static bool check_device(struct device *dev) return true; } +#define PCI_ACS_ENABLED (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF) + static int iommu_init_device(struct device *dev) { struct pci_dev *dma_pdev, *pdev = to_pci_dev(dev); @@ -291,6 +293,22 @@ static int iommu_init_device(struct device *dev) dma_pdev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); + dma_pdev = pci_dma_source(dma_pdev); + + if (dma_pdev->multifunction && + !pci_acs_enabled(dma_pdev, PCI_ACS_ENABLED)) + dma_pdev = pci_get_slot(dma_pdev->bus, + PCI_DEVFN(PCI_SLOT(dma_pdev->devfn), + 0)); + + while (!pci_is_root_bus(dma_pdev->bus)) { + if (pci_acs_path_enabled(dma_pdev->bus->self, + NULL, PCI_ACS_ENABLED)) + break; + + dma_pdev = dma_pdev->bus->self; + } + group = iommu_group_get(&dma_pdev->dev); if (!group) { group = iommu_group_alloc(); diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index e63b33b..cf2a650 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -4087,6 +4087,8 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain, return 0; } +#define PCI_ACS_ENABLED (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF) + static int intel_iommu_add_device(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); @@ -4113,6 +4115,22 @@ static int intel_iommu_add_device(struct device *dev) dma_pdev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); + dma_pdev = pci_dma_source(dma_pdev); + + if (dma_pdev->multifunction && + !pci_acs_enabled(dma_pdev, PCI_ACS_ENABLED)) + dma_pdev = pci_get_slot(dma_pdev->bus, + PCI_DEVFN(PCI_SLOT(dma_pdev->devfn), + 0)); + + while (!pci_is_root_bus(dma_pdev->bus)) { + if (pci_acs_path_enabled(dma_pdev->bus->self, + NULL, PCI_ACS_ENABLED)) + break; + + dma_pdev = dma_pdev->bus->self; + } + group = iommu_group_get(&dma_pdev->dev); if (!group) { group = iommu_group_alloc();