From patchwork Fri May 15 12:03:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yalin wang X-Patchwork-Id: 6413671 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E656C9F1C1 for ; Fri, 15 May 2015 12:06:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0B7F20461 for ; Fri, 15 May 2015 12:06:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 15E2F20454 for ; Fri, 15 May 2015 12:06:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtELK-0008AA-H6; Fri, 15 May 2015 12:03:54 +0000 Received: from mail-ig0-x231.google.com ([2607:f8b0:4001:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtELH-00082v-8p for linux-arm-kernel@lists.infradead.org; Fri, 15 May 2015 12:03:51 +0000 Received: by igbyr2 with SMTP id yr2so215264883igb.0 for ; Fri, 15 May 2015 05:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=tpEijUHKnp8mZxVtKs2ERstxA3qdmVpQ2N+C/pkq4YE=; b=jleGjS+beOVo32SQVzR3SdIrRBDmufzQbYdTV6yewWpRiNkVm2+heWLjGY3F2zzlHO 6cVsjsKYBhtxqs/YFErCZrmjvzLVx5gqOLmzPMSNWQWYsU6RH9zVIYRzctHia5r3GUPs rDg0i8X0uE6kyNN9dcDEhhc1Br/jgwqa4ORv8JjkiKcekqvl6gAcIeaIjzR4eUnQgRPQ ATisset8JMKLDRFAYvCZjEU0jVRFnptlO8t4YPC9eK91i196Fay4La1as0j/gIXJ9StX 5hTHqiXuAbX+cImIdFHO37DWfwMynXKb9TVX/h0NfenJ/uC4uuo/pifd0fHIVXmuIflT 3fJA== MIME-Version: 1.0 X-Received: by 10.50.111.198 with SMTP id ik6mr41419032igb.24.1431691409091; Fri, 15 May 2015 05:03:29 -0700 (PDT) Received: by 10.107.34.72 with HTTP; Fri, 15 May 2015 05:03:29 -0700 (PDT) In-Reply-To: <1431673794-16169-1-git-send-email-acourbot@nvidia.com> References: <1431673794-16169-1-git-send-email-acourbot@nvidia.com> Date: Fri, 15 May 2015 20:03:29 +0800 Message-ID: Subject: Re: [PATCH] drm/ttm: dma: Don't crash on memory in the vmalloc range From: yalin wang To: Alexandre Courbot X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150515_050351_389139_33E786E5 X-CRM114-Status: GOOD ( 20.18 ) X-Spam-Score: -0.6 (/) Cc: gnurou@gmail.com, Thomas Hellstrom , Arnd Bergmann , Konrad Rzeszutek Wilk , David Airlie , will.deacon@arm.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Thierry Reding , Neil.Gao@sonymobile.com, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 2015-05-15 15:09 GMT+08:00 Alexandre Courbot : > dma_alloc_coherent() can return memory in the vmalloc range. > virt_to_page() cannot handle such addresses and crashes. This > patch detects such cases and obtains the struct page * using > vmalloc_to_page() instead. > > Signed-off-by: Alexandre Courbot > --- > This patch is a follow-up of the following discussion: > > https://www.marc.info/?l=dri-devel&m=141579595431254&w=3 > > It works for me on both 32-bit and 64-bit Tegra, so I am not convinced > that Thierry's initial change from virt_to_page() to phys_to_page() is > still required - Thierry, can you confirm whether your patch is still > relevant after this one? > > drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c > index 01e1d27eb078..3077f1554099 100644 > --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c > +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c > @@ -342,9 +342,12 @@ static struct dma_page *__ttm_dma_alloc_page(struct dma_pool *pool) > d_page->vaddr = dma_alloc_coherent(pool->dev, pool->size, > &d_page->dma, > pool->gfp_flags); > - if (d_page->vaddr) > - d_page->p = virt_to_page(d_page->vaddr); > - else { > + if (d_page->vaddr) { > + if (is_vmalloc_addr(d_page->vaddr)) > + d_page->p = vmalloc_to_page(d_page->vaddr); > + else > + d_page->p = virt_to_page(d_page->vaddr); > + } else { > kfree(d_page); > d_page = NULL; > } > -- > 2.4.0 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ for safe , i think we can add this patch: BRs Yalin diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index f800d45..3463f4f 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -77,7 +77,8 @@ * private definitions which should NOT be used outside memory.h * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. */ -#define __virt_to_phys(x) (((phys_addr_t)(x) - PAGE_OFFSET + PHYS_OFFSET)) +#define __virt_to_phys(x) ({BUG_ON(x < PAGE_OFFSET);\ + (phys_addr_t)(x) - PAGE_OFFSET + PHYS_OFFSET;}) #define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET)) /*