From patchwork Wed Apr 25 10:10:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 904100 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="ouVv28rB"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40WGDc0SVbz9ryk for ; Wed, 25 Apr 2018 20:10:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751496AbeDYKKy (ORCPT ); Wed, 25 Apr 2018 06:10:54 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51071 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751487AbeDYKKy (ORCPT ); Wed, 25 Apr 2018 06:10:54 -0400 Received: by mail-wm0-f66.google.com with SMTP id t67so6159679wmt.0 for ; Wed, 25 Apr 2018 03:10:53 -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=ouVv28rBW4isvMZPuNkpZokxBxTu49q6gj50BBrW1gt7tfgiym8sqyMYvX/tpLC+BQ PNF5uSN8MmKWFFVG22KunOxZR/C3hKfMZO4+X3+nKnW+sgRorM7skjINeVKQHMr+MeEo S2NJOgDg1SKrOEMXISmUIMFAzt5frlzwmC0/vNrdQeBEbdd7yWOPKIPRvb+0uabHGgj5 AZTguC/kqFhP6V1SYFUKhq8IUwn0rc73v1CgjelqOQT3wdNqSVne19P9rxEUwrDhUjU/ 14t0JJ509YYjGIrIY9UTMuGvH3JEHkdXFUPoM0Yf/sTo+T+oLKLpZChd4jUV772sO4tJ 7Aog== 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=INDc3HfR5udxHTkICenorL1l4EyquPPnzJ9orxSQjbPGGXAEI+wPnVFqFrXmXXCWK3 9l8dSBaSgIiCEwkOeZPNx6xhtqaKA68DwYO+515Hjf7iKwlo9CgRzEhk8IFqUbsMzkfQ libmm25x6mTIxOZjgPvQzrQ0MdlksL/mFKICxMja316eHy6jHHp/m0HQVHzmI+PIN/nM s5MUdEdzZZIExU1ZGqcdxVbTfKIgMijJ4GQRHanFuzvIQV7klaTg5Yd8MuLs8Fr8xh7h SQmrG54P6rmfOoYqOZK2B6psKYTPzFbJSs8IFN09McmrHELe9YI/oECevjktgzLcYL7L EgXA== X-Gm-Message-State: ALQs6tCvylwbAwulfjlawHCbK29ovV9llbMxEQ9CKqqcSaOEaIkN8YyW BuKMSQV50fqVHEVWPwTHA2w= X-Google-Smtp-Source: AIpwx4+x5X4IJu1HfpzgBtyWmObR0ep36ccwRZbMx2Ft9yX+wrwMQbYBKSvd/dHbJwcbTyuSjot4WQ== X-Received: by 10.28.19.193 with SMTP id 184mr13872948wmt.158.1524651052828; Wed, 25 Apr 2018 03:10:52 -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 z5-v6sm2758081wrm.61.2018.04.25.03.10.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Apr 2018 03:10:52 -0700 (PDT) From: Thierry Reding To: Christoph Hellwig , Joerg Roedel Cc: Daniel Vetter , Russell King , 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 v2 1/5] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping Date: Wed, 25 Apr 2018 12:10:47 +0200 Message-Id: <20180425101051.15349-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;