drm/ttm: dma: Don't crash on memory in the vmalloc range
authorAlexandre Courbot <acourbot@nvidia.com>
Fri, 15 May 2015 07:09:54 +0000 (16:09 +0900)
committerDave Airlie <airlied@redhat.com>
Tue, 2 Jun 2015 07:24:49 +0000 (17:24 +1000)
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 <acourbot@nvidia.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c

index 01e1d27eb078396cd97dc2f3a51cbda8dec95a9f..3077f1554099932f6f477841182fb4eb278c60ea 100644 (file)
@@ -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;
        }