Skip to content

Commit 16e87fe

Browse files
stonezdmdakr
authored andcommitted
nouveau/dmem: handle kcalloc() allocation failure
The kcalloc() in nouveau_dmem_evict_chunk() will return null if the physical memory has run out. As a result, if we dereference src_pfns, dst_pfns or dma_addrs, the null pointer dereference bugs will happen. Moreover, the GPU is going away. If the kcalloc() fails, we could not evict all pages mapping a chunk. So this patch adds a __GFP_NOFAIL flag in kcalloc(). Finally, as there is no need to have physically contiguous memory, this patch switches kcalloc() to kvcalloc() in order to avoid failing allocations. CC: <[email protected]> # v6.1 Fixes: 2498812 ("nouveau/dmem: evict device private memory during release") Suggested-by: Danilo Krummrich <[email protected]> Signed-off-by: Duoming Zhou <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 4ece8fc commit 16e87fe

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/gpu/drm/nouveau/nouveau_dmem.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chunk)
378378
dma_addr_t *dma_addrs;
379379
struct nouveau_fence *fence;
380380

381-
src_pfns = kcalloc(npages, sizeof(*src_pfns), GFP_KERNEL);
382-
dst_pfns = kcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL);
383-
dma_addrs = kcalloc(npages, sizeof(*dma_addrs), GFP_KERNEL);
381+
src_pfns = kvcalloc(npages, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL);
382+
dst_pfns = kvcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL);
383+
dma_addrs = kvcalloc(npages, sizeof(*dma_addrs), GFP_KERNEL | __GFP_NOFAIL);
384384

385385
migrate_device_range(src_pfns, chunk->pagemap.range.start >> PAGE_SHIFT,
386386
npages);
@@ -406,11 +406,11 @@ nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chunk)
406406
migrate_device_pages(src_pfns, dst_pfns, npages);
407407
nouveau_dmem_fence_done(&fence);
408408
migrate_device_finalize(src_pfns, dst_pfns, npages);
409-
kfree(src_pfns);
410-
kfree(dst_pfns);
409+
kvfree(src_pfns);
410+
kvfree(dst_pfns);
411411
for (i = 0; i < npages; i++)
412412
dma_unmap_page(chunk->drm->dev->dev, dma_addrs[i], PAGE_SIZE, DMA_BIDIRECTIONAL);
413-
kfree(dma_addrs);
413+
kvfree(dma_addrs);
414414
}
415415

416416
void

0 commit comments

Comments
 (0)