From patchwork Wed Jul 8 11:32:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 11651425 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 496B613B4 for ; Wed, 8 Jul 2020 11:34:16 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F96C204EC for ; Wed, 8 Jul 2020 11:34:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ULGqiDaa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F96C204EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=CRQx7+VllxsEYkHbA4LTl9PpzClUQUodAHLca6LRXrA=; b=ULGqiDaa6uLfVlevu+BTSy3Z7x 4Bl7pbXr88CFAWsy7+IVoU6iz30aJBTGfJbnIKrk32krELUxW62Z+E/Wi4heJi1dPY+6Qk3owKj8u qJ1zhkZuBK12KJkr20+shpKrmOlcuw8MKnArPqcblYjR8XMvdQntplIupAw2HaXU6FCDNzYmtzFA2 4HjNnw8TvIG0XHTYtv/Wv7WbFIzACOvNROsRO3Bkug2wDso0IgSnv56S4IV/FvrPlWPrBapHx//Tx U2ioyKw7yS7cu3cOfbru/YcgOgsza0gSZUluA4xwEA4ANOhyPf4q7zuBlDSeLHMGGNSq+qlA1xVcn 7CRk45FA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jt8Ju-0000wP-HE; Wed, 08 Jul 2020 11:32:58 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jt8Js-0000vz-UA for linux-arm-kernel@lists.infradead.org; Wed, 08 Jul 2020 11:32:57 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8752B31B; Wed, 8 Jul 2020 04:32:52 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2FD373F68F; Wed, 8 Jul 2020 04:32:51 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org Subject: [PATCH 1/2] iommu/intel: Avoid SAC address trick for PCIe devices Date: Wed, 8 Jul 2020 12:32:41 +0100 Message-Id: X-Mailer: git-send-email 2.23.0.dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200708_073257_048131_64E58E4E X-CRM114-Status: GOOD ( 15.09 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, jonathan.lemon@gmail.com, dwmw2@infradead.org, hch@lst.de, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For devices stuck behind a conventional PCI bus, saving extra cycles at 33MHz is probably fairly significant. However since native PCI Express is now the norm for high-performance devices, the optimisation to always prefer 32-bit addresses for the sake of avoiding DAC is starting to look rather anachronistic. Technically 32-bit addresses do have shorter TLPs on PCIe, but unless the device is saturating its link bandwidth with small transfers it seems unlikely that the difference is appreciable. What definitely is appreciable, however, is that the IOVA allocator doesn't behave all that well once the 32-bit space starts getting full. As DMA working sets get bigger, this optimisation increasingly backfires and adds considerable overhead to the dma_map path for use-cases like high-bandwidth networking. As such, let's simply take it out of consideration for PCIe devices. Technically this might work out suboptimal for a PCIe device stuck behind a conventional PCI bridge, or for PCI-X devices that also have native 64-bit addressing, but neither of those are likely to be found in performance-critical parts of modern systems. Signed-off-by: Robin Murphy --- drivers/iommu/intel/iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9129663a7406..21b11de23a53 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3348,7 +3348,8 @@ static unsigned long intel_alloc_iova(struct device *dev, /* Ensure we reserve the whole size-aligned region */ nrpages = __roundup_pow_of_two(nrpages); - if (!dmar_forcedac && dma_mask > DMA_BIT_MASK(32)) { + if (!dmar_forcedac && dma_mask > DMA_BIT_MASK(32) && + dev_is_pci(dev) && !pci_is_pcie(to_pci_dev(dev))) { /* * First try to allocate an io virtual address in * DMA_BIT_MASK(32) and if that fails then try allocating From patchwork Wed Jul 8 11:32:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 11651423 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 25A2913B4 for ; Wed, 8 Jul 2020 11:34:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF5C3204EC for ; Wed, 8 Jul 2020 11:34:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Drrzg/Y8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF5C3204EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=k3LOyRlgORecKeYWokjxyfvyko0pPWX3P71mcLn36TU=; b=Drrzg/Y87/0TNxxaf/QHHAllw TffCNjy6ISGkt3LXX7dw+AqX1BtIudxA6MiEs6XE0nhSiZ9bZoW0Zt+ApisyPaiq9r1LMqY78sQEx 0FHv6AoFMJY59cu3H5YAICJMYiIF0ma3fjQNHgj0og/jkCYXkBl0lhvAW1ZcATCz3DOzvw2yzaoWB C2vgqhg54Zv13u5K4UeOKWfaCPO9qQv0l/q5c9kL1lgX0HGco5Ml03+4jLUQxMHeNCQdSkL/FDjGD K4kwCphEfzbB6JNhS88PIyMAaJ0Qi83h9I1fX4nDpWDhPdvoHQX2hugsZIsEDH3LEBjrDNoPHlLu8 B+guruIKw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jt8Jy-0000xj-Te; Wed, 08 Jul 2020 11:33:02 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jt8Jw-0000wv-1p for linux-arm-kernel@lists.infradead.org; Wed, 08 Jul 2020 11:33:00 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1B3831045; Wed, 8 Jul 2020 04:32:54 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C29C63F68F; Wed, 8 Jul 2020 04:32:52 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org Subject: [PATCH 2/2] iommu/dma: Avoid SAC address trick for PCIe devices Date: Wed, 8 Jul 2020 12:32:42 +0100 Message-Id: X-Mailer: git-send-email 2.23.0.dirty In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200708_073300_180558_88E3E04C X-CRM114-Status: GOOD ( 12.71 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [217.140.110.172 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, jonathan.lemon@gmail.com, dwmw2@infradead.org, hch@lst.de, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org As for the intel-iommu implementation, relegate the opportunistic attempt to allocate a SAC address to the domain of conventional PCI devices only, to avoid it increasingly causing far more performance issues than possible benefits on modern PCI Express systems. Signed-off-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 4959f5df21bd..0ff124f16ad4 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -426,7 +426,8 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain, dma_limit = min(dma_limit, (u64)domain->geometry.aperture_end); /* Try to get PCI devices a SAC address */ - if (dma_limit > DMA_BIT_MASK(32) && dev_is_pci(dev)) + if (dma_limit > DMA_BIT_MASK(32) && + dev_is_pci(dev) && !pci_is_pcie(to_pci_dev(dev))) iova = alloc_iova_fast(iovad, iova_len, DMA_BIT_MASK(32) >> shift, false);