From patchwork Wed May 27 16:56:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Derrick X-Patchwork-Id: 11573579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 588D514F6 for ; Wed, 27 May 2020 16:56:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 407CB2088E for ; Wed, 27 May 2020 16:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726748AbgE0Q4X (ORCPT ); Wed, 27 May 2020 12:56:23 -0400 Received: from mga12.intel.com ([192.55.52.136]:24078 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgE0Q4X (ORCPT ); Wed, 27 May 2020 12:56:23 -0400 IronPort-SDR: tAcCzAGIpsnkk9NM4FHtMZvRNvb6Oaz9rn9nOLHgR8OG0aOfJl5ltbUoPCy77bY4vXdP1EB7va 14zd7Xhc4pJw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 09:56:22 -0700 IronPort-SDR: ljnwbifSi6tpzAZRS3tJCSTDtQX25lWKO+sp42EQ+RzMLhQIPq+xmCqfGncYN7KLMv6U+22KyH DxL7UDXCiPgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,442,1583222400"; d="scan'208";a="302522293" Received: from jderrick-mobl.amr.corp.intel.com ([10.209.128.69]) by orsmga008.jf.intel.com with ESMTP; 27 May 2020 09:56:21 -0700 From: Jon Derrick To: Cc: , Joerg Roedel , Lu Baolu , Jacob Pan , Sai Praneeth Prakhya , Ashok Raj , Jon Derrick Subject: [PATCH v1 1/3] iommu/vt-d: Only clear real DMA device's context entries Date: Wed, 27 May 2020 10:56:15 -0600 Message-Id: <20200527165617.297470-2-jonathan.derrick@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200527165617.297470-1-jonathan.derrick@intel.com> References: <20200527165617.297470-1-jonathan.derrick@intel.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Domain context mapping can encounter issues with sub-devices of a real DMA device. A sub-device cannot have a valid context entry due to it potentially aliasing another device's 16-bit ID. It's expected that sub-devices of the real DMA device uses the real DMA device's requester when context mapping. This is an issue when a sub-device is removed where the context entry is cleared for all aliases. Other sub-devices are still valid, resulting in those sub-devices being stranded without valid context entries. The correct approach is to use the real DMA device when programming the context entries. The insertion path is correct because device_to_iommu() will return the bus and devfn of the real DMA device. The removal path needs to only operate on the real DMA device, otherwise the entire context entry would be cleared for all sub-devices of the real DMA device. This patch also adds a helper to determine if a struct device is a sub-device of a real DMA device. Signed-off-by: Jon Derrick Acked-by: Lu Baolu --- 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 ff5a30a..1ff45b2 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2500,6 +2500,12 @@ static int domain_setup_first_level(struct intel_iommu *iommu, flags); } +static bool dev_is_real_dma_subdevice(struct device *dev) +{ + return dev && dev_is_pci(dev) && + pci_real_dma_dev(to_pci_dev(dev)) != to_pci_dev(dev); +} + static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, int bus, int devfn, struct device *dev, @@ -4975,7 +4981,8 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info) PASID_RID2PASID, false); iommu_disable_dev_iotlb(info); - domain_context_clear(iommu, info->dev); + if (!dev_is_real_dma_subdevice(info->dev)) + domain_context_clear(iommu, info->dev); intel_pasid_free_table(info->dev); } From patchwork Wed May 27 16:56:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Derrick X-Patchwork-Id: 11573581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0DBF1744 for ; Wed, 27 May 2020 16:56:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2D5A20C09 for ; Wed, 27 May 2020 16:56:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbgE0Q4Y (ORCPT ); Wed, 27 May 2020 12:56:24 -0400 Received: from mga12.intel.com ([192.55.52.136]:24076 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbgE0Q4X (ORCPT ); Wed, 27 May 2020 12:56:23 -0400 IronPort-SDR: ep3o264UgtZuiAHDDBTxPb9tfB70vkW6/riUeX7/be7DWoTbzotuUQoM/+GXNf/lxOZ8ffHJZY sWdejBjiUBRA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 09:56:22 -0700 IronPort-SDR: RqmHfxYy8/LbxXwmLvdQBUf3l+FxLpr7XnwFVqArBcCm2GmEJ7S1hV1rS8DTLVRtwbYdckTLWa SPB6jkPEwAAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,442,1583222400"; d="scan'208";a="302522300" Received: from jderrick-mobl.amr.corp.intel.com ([10.209.128.69]) by orsmga008.jf.intel.com with ESMTP; 27 May 2020 09:56:22 -0700 From: Jon Derrick To: Cc: , Joerg Roedel , Lu Baolu , Jacob Pan , Sai Praneeth Prakhya , Ashok Raj , Jon Derrick Subject: [PATCH v1 2/3] iommu/vt-d: Allocate domain info for real DMA sub-devices Date: Wed, 27 May 2020 10:56:16 -0600 Message-Id: <20200527165617.297470-3-jonathan.derrick@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200527165617.297470-1-jonathan.derrick@intel.com> References: <20200527165617.297470-1-jonathan.derrick@intel.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Sub-devices of a real DMA device might exist on a separate segment than the real DMA device and its IOMMU. These devices should still have a valid device_domain_info, but the current dma alias model won't allocate info for the subdevice. This patch adds a segment member to struct device_domain_info and uses the sub-device's BDF so that these sub-devices won't alias to other devices. Signed-off-by: Jon Derrick Acked-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 19 +++++++++++++++---- include/linux/intel-iommu.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 1ff45b2..6d39b9b 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2463,7 +2463,7 @@ static void do_deferred_attach(struct device *dev) struct device_domain_info *info; list_for_each_entry(info, &device_domain_list, global) - if (info->iommu->segment == segment && info->bus == bus && + if (info->segment == segment && info->bus == bus && info->devfn == devfn) return info; @@ -2520,8 +2520,18 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, if (!info) return NULL; - info->bus = bus; - info->devfn = devfn; + if (!dev_is_real_dma_subdevice(dev)) { + info->bus = bus; + info->devfn = devfn; + info->segment = iommu->segment; + } else { + struct pci_dev *pdev = to_pci_dev(dev); + + info->bus = pdev->bus->number; + info->devfn = pdev->devfn; + info->segment = pci_domain_nr(pdev->bus); + } + info->ats_supported = info->pasid_supported = info->pri_supported = 0; info->ats_enabled = info->pasid_enabled = info->pri_enabled = 0; info->ats_qdep = 0; @@ -2561,7 +2571,8 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, if (!found) { struct device_domain_info *info2; - info2 = dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); + info2 = dmar_search_domain_by_dev_info(info->segment, info->bus, + info->devfn); if (info2) { found = info2->domain; info2->dev = dev; diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 21633ce..4100bd2 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -609,6 +609,7 @@ struct device_domain_info { struct list_head auxiliary_domains; /* auxiliary domains * attached to this device */ + u32 segment; /* PCI segment number */ u8 bus; /* PCI bus number */ u8 devfn; /* PCI devfn number */ u16 pfsid; /* SRIOV physical function source ID */ From patchwork Wed May 27 16:56:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Derrick X-Patchwork-Id: 11573583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D40614B7 for ; Wed, 27 May 2020 16:56:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7649F2088E for ; Wed, 27 May 2020 16:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731071AbgE0Q4Y (ORCPT ); Wed, 27 May 2020 12:56:24 -0400 Received: from mga12.intel.com ([192.55.52.136]:24081 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbgE0Q4Y (ORCPT ); Wed, 27 May 2020 12:56:24 -0400 IronPort-SDR: zEet3UX0ylBGBhmhZF+sV/6A6bP3+AFWFHi3q67YbS/C3cPrPud8ifQDBwlozbIw1wgSJ+0H+Y yGkXapcXy1vQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 09:56:23 -0700 IronPort-SDR: +fxzajnotclfoyaC6dDc/CwJPCUD8o/zmAlac5GDz+x+/VtC6DOnvJo1lK77l1hxjuI1oWM8oz iLWPPAlA2Aew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,442,1583222400"; d="scan'208";a="302522306" Received: from jderrick-mobl.amr.corp.intel.com ([10.209.128.69]) by orsmga008.jf.intel.com with ESMTP; 27 May 2020 09:56:23 -0700 From: Jon Derrick To: Cc: , Joerg Roedel , Lu Baolu , Jacob Pan , Sai Praneeth Prakhya , Ashok Raj , Jon Derrick Subject: [PATCH v1 3/3] iommu/vt-d: Remove real DMA lookup in find_domain Date: Wed, 27 May 2020 10:56:17 -0600 Message-Id: <20200527165617.297470-4-jonathan.derrick@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200527165617.297470-1-jonathan.derrick@intel.com> References: <20200527165617.297470-1-jonathan.derrick@intel.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org By removing the real DMA indirection in find_domain(), we can allow sub-devices of a real DMA device to have their own valid device_domain_info. The dmar lookup and context entry removal paths have been fixed to account for sub-devices. Fixes: 2b0140c69637 ("iommu/vt-d: Use pci_real_dma_dev() for mapping") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207575 Signed-off-by: Jon Derrick Acked-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 6d39b9b..5767882 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2436,9 +2436,6 @@ struct dmar_domain *find_domain(struct device *dev) if (unlikely(attach_deferred(dev) || iommu_dummy(dev))) return NULL; - if (dev_is_pci(dev)) - dev = &pci_real_dma_dev(to_pci_dev(dev))->dev; - /* No lock here, assumes no domain exit in normal case */ info = get_domain_info(dev); if (likely(info))