From patchwork Wed Nov 12 12:39:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 5289051 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 06BCCC11AC for ; Wed, 12 Nov 2014 12:39:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1088F20176 for ; Wed, 12 Nov 2014 12:39:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 008E02015D for ; Wed, 12 Nov 2014 12:39:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B99536E27E; Wed, 12 Nov 2014 04:39:12 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pd0-f179.google.com (mail-pd0-f179.google.com [209.85.192.179]) by gabe.freedesktop.org (Postfix) with ESMTP id 60FFC6E27E for ; Wed, 12 Nov 2014 04:39:11 -0800 (PST) Received: by mail-pd0-f179.google.com with SMTP id g10so12079555pdj.24 for ; Wed, 12 Nov 2014 04:39:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=RaaOpBhXbPub3JdkSKugHYUJo7Es3m2vqYoMkd1BE/M=; b=fxQlVl8Z2WqpMUgFAxDiIIyeuSq3NE4cCDt6T0Mttm6PhisbUKwlJ4EsJHHDEEppLH 6qqhmyTKWfEWOGt5hdGFZdyY9EpaQSkaeA3tFpergdotYRiqWyZMrSHjpQvfxndXSiRY TdDnAO+N8G+17DDkBU5OeAMwlyP0bBT7nEj2crJEd78FjkklPHKvfWeYLBTVCyedAsvL brGwETBKHCTIpMGu+9taujsTNaFBJqmkY5+ORdscbaTc4anM2rlKf7xv09dcAFn/pYxG e8DeSyP7cTYFjGjP1W/NiietcC3LgUM1OFU6QvszqEBzIDLxW+5pSH7wenVqb80lHOc3 SsyQ== X-Received: by 10.68.110.69 with SMTP id hy5mr46397444pbb.121.1415795951120; Wed, 12 Nov 2014 04:39:11 -0800 (PST) Received: from localhost ([216.228.120.20]) by mx.google.com with ESMTPSA id o13sm22088028pby.54.2014.11.12.04.39.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Nov 2014 04:39:09 -0800 (PST) From: Thierry Reding To: dri-devel@lists.freedesktop.org Subject: [RFC] drm/ttm: dma: Fixes for 32-bit and 64-bit ARM Date: Wed, 12 Nov 2014 13:39:05 +0100 Message-Id: <1415795945-17575-1-git-send-email-thierry.reding@gmail.com> X-Mailer: git-send-email 2.1.3 Cc: Alexandre Courbot , Thomas Hellstrom , Allen Martin , Arnd Bergmann , Konrad Rzeszutek Wilk X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 From: Thierry Reding dma_alloc_coherent() returns a kernel virtual address that is part of the linear range. Passing such an address to virt_to_page() is illegal on non-coherent architectures. This causes the kernel to oops on 64-bit ARM because the struct page * obtained from virt_to_page() points to unmapped memory. This commit fixes this by using phys_to_page() since we get a physical address from dma_alloc_coherent(). Note that this is not a proper fix because if an IOMMU is set up to translate addresses for the GPU this address will be an I/O virtual address rather than a physical one. The proper fix probably involves not getting a pointer to the struct page in the first place, but that would be a much more intrusive change, if at all possible. Until that time, this temporary fix will allow TTM to work on 32-bit and 64-bit ARM as well, provided that no IOMMU translations are enabled for the GPU. Signed-off-by: Thierry Reding --- Arnd, I realize that this isn't a proper fix according to what we discussed on IRC yesterday, but I can't see a way to remove access to the pages array that would be as simple as this. I've marked this as RFC in the hope that it will trigger some discussion that will lead to a proper solution. drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c index c96db433f8af..d7993985752c 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c @@ -343,7 +343,11 @@ static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool) &d_page->dma, pool->gfp_flags); if (d_page->vaddr) +#if defined(CONFIG_ARM) || defined(CONFIG_ARM64) + d_page->p = phys_to_page(d_page->dma); +#else d_page->p = virt_to_page(d_page->vaddr); +#endif else { kfree(d_page); d_page = NULL;