From patchwork Wed Apr 25 09:18:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 904049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Uvzg04nG"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40WF3y4XNLz9ryk for ; Wed, 25 Apr 2018 19:18:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbeDYJSU (ORCPT ); Wed, 25 Apr 2018 05:18:20 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35084 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbeDYJSS (ORCPT ); Wed, 25 Apr 2018 05:18:18 -0400 Received: by mail-wr0-f196.google.com with SMTP id w3-v6so52571700wrg.2 for ; Wed, 25 Apr 2018 02:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=nTzDbwdo5mKJygYikra3Jz1XRbwl4YCsRGxzw8sgDrM=; b=Uvzg04nGH3nA8ZcyeaGol6LAjUlFRosoGnd+Fx/YKErAr2dawZmtuwrJ76HvAMGghx wm9e0jJKWfunXno2ELUnK12JKPkdBWnotN5BatUjpavlvNxSFnaMqQ0m0sQmVkEpsSYA k/U1wvT4rbETFRwyvxBP9EqHYShEeIp/pSx1sMgvBXlQl3ycMeLLXzfMW4OE0htqHL0f E4quZHUmtZUu42aLxFpRyHpgBcbEjGqnc7lJSWsBf64bLPYEOo+nCLgC/c0n5hdXB6SF 69eArZnNaskJzU2YNCH/b4BbfpsLf2qBsAs61lDYhADclQVnfrlYT1mrNSvTrvjX2N7b tovw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=nTzDbwdo5mKJygYikra3Jz1XRbwl4YCsRGxzw8sgDrM=; b=Iu211aaN4jEnkbWjJu/iDaSdCXwL60/Zf0h0EAToQnKZ4oo6pNe6WvaspUNYFvdA07 lHMWNV2viyhoI9wA53fXMsaZqwu1Z42w9GG0egWmLXrvWG2QbHNPvFXhtkjqI4SeCkGk ye2E1x54akusG1OSLn8igDYyXdTpDZBMqnjZV0ZpfZ1BLrgEAa69wsVHYPfIWOkpgdrA Uyk7yTLOFSvh5ihRcLIu4pi1Snsii2W/+oEo6OKYlGBFGWjcQsW//Y3+EtToObEizcyL 3P4fIbx+cl7O1kDQRv3CT2a3MXWOL2itVrrXXix41g7hMuTG6a6LmxpZOFP+Kq/jpVMv 2lWg== X-Gm-Message-State: ALQs6tCrNIwqT+aDeGR8NaHjpH07y3f0BSWJt0ZGkvjH0Q8/NidssU9j m5Pa3LK14R3om7NbSvnwHeulXA== X-Google-Smtp-Source: AIpwx48tywkvItOJMXBT6VDxmVXWELhAP6jXKTtBz2Kfc8aqGAvQ7P+qD7s3GY28M0IUKhNnzsb3Xg== X-Received: by 2002:adf:b595:: with SMTP id c21-v6mr23497192wre.233.1524647897307; Wed, 25 Apr 2018 02:18:17 -0700 (PDT) Received: from localhost (p200300E41F041C0032947E635CB49D15.dip0.t-ipconnect.de. [2003:e4:1f04:1c00:3294:7e63:5cb4:9d15]) by smtp.gmail.com with ESMTPSA id d7-v6sm14852816wrj.26.2018.04.25.02.18.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Apr 2018 02:18:16 -0700 (PDT) From: Thierry Reding To: Christoph Hellwig , Joerg Roedel Cc: Daniel Vetter , iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 1/4] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping Date: Wed, 25 Apr 2018 11:18:12 +0200 Message-Id: <20180425091815.16264-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Thierry Reding Depending on the kernel configuration, early ARM architecture setup code may have attached the GPU to a DMA/IOMMU mapping that transparently uses the IOMMU to back the DMA API. Tegra requires special handling for IOMMU backed buffers (a special bit in the GPU's MMU page tables indicates the memory path to take: via the SMMU or directly to the memory controller). Transparently backing DMA memory with an IOMMU prevents Nouveau from properly handling such memory accesses and causes memory access faults. As a side-note: buffers other than those allocated in instance memory don't need to be physically contiguous from the GPU's perspective since the GPU can map them into contiguous buffers using its own MMU. Mapping these buffers through the IOMMU is unnecessary and will even lead to performance degradation because of the additional translation. Signed-off-by: Thierry Reding --- I had already sent this out independently to fix a regression that was introduced in v4.16, but then Christoph pointed out that it should've been sent to a wider audience and should use a core API rather than calling into architecture code directly. I've added it to this series for easier reference and to show the need for the new API. .../drm/nouveau/nvkm/engine/device/tegra.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c index 78597da6313a..23428a7056e9 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c @@ -19,6 +19,11 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ + +#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) +#include +#endif + #include #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER #include "priv.h" @@ -105,6 +110,20 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev) unsigned long pgsize_bitmap; int ret; +#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) + if (dev->archdata.mapping) { + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); + + arm_iommu_release_mapping(mapping); + arm_iommu_detach_device(dev); + + if (dev->archdata.dma_coherent) + set_dma_ops(dev, &arm_coherent_dma_ops); + else + set_dma_ops(dev, &arm_dma_ops); + } +#endif + if (!tdev->func->iommu_bit) return;