From patchwork Tue Jan 7 09:00:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 3446671 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F240B9F1C4 for ; Tue, 7 Jan 2014 09:06:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68A1620117 for ; Tue, 7 Jan 2014 09:06:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3476B20114 for ; Tue, 7 Jan 2014 09:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756411AbaAGJAb (ORCPT ); Tue, 7 Jan 2014 04:00:31 -0500 Received: from mga09.intel.com ([134.134.136.24]:20795 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755760AbaAGJA1 (ORCPT ); Tue, 7 Jan 2014 04:00:27 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 07 Jan 2014 00:56:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.95,617,1384329600"; d="scan'208";a="454739863" Received: from gerry-dev.bj.intel.com ([10.238.158.74]) by fmsmga001.fm.intel.com with ESMTP; 07 Jan 2014 01:00:09 -0800 From: Jiang Liu To: Joerg Roedel , David Woodhouse , Yinghai Lu , Bjorn Helgaas , Dan Williams , Vinod Koul Cc: Jiang Liu , Ashok Raj , Yijing Wang , Tony Luck , iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Alex Williamson Subject: [Patch Part2 V1 05/14] iommu/vt-d: create device_domain_info structure for intermediate P2P bridges Date: Tue, 7 Jan 2014 17:00:25 +0800 Message-Id: <1389085234-22296-6-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1389085234-22296-1-git-send-email-jiang.liu@linux.intel.com> References: <1389085234-22296-1-git-send-email-jiang.liu@linux.intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When creating DMAR domain for a PCI device, we will only associate the PCI device and upstream (PCIe) bridge with the domain and skip all intermediate P2P bridges. Function domain_context_mapping() will attach the created domain to the PCI device, the upstream (PCIe) bridge and all intermediate P2P bridge. Later when domain_remove_dev_info() is called, it only detaches the domain from the PCI device and its upstream (PCIe) bridge and leaves the domain still attached to all intermediate P2P bridges. This stale state may cause troubles when we assign the affected PCI hierarchy to a virtual machine later. So also create device_domain_info for intermediate P2P bridges when creating domain for PCI device. Signed-off-by: Jiang Liu Cc: Alex Williamson --- drivers/iommu/intel-iommu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 2bbb877..d5ad21d 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2018,7 +2018,7 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) struct dmar_domain *domain; struct intel_iommu *iommu; struct dmar_drhd_unit *drhd; - struct pci_dev *bridge; + struct pci_dev *bridge, *parent; unsigned long flags; int segment, bus, devfn; @@ -2072,6 +2072,13 @@ static struct dmar_domain *get_domain_for_dev(struct pci_dev *pdev, int gaw) domain_exit(domain); goto error; } + /* also register intermediate P2P bridges */ + for (parent = pdev->bus->self; parent != bridge; + parent = parent->bus->self) { + if (dmar_insert_dev_info(segment, parent->bus->number, + parent->devfn, NULL, &domain)) + goto error; + } } found_domain: