Skip to content

Commit 1fc9af8

Browse files
bbrezillondigetx
authored andcommitted
drm/panfrost: Fix the error path in panfrost_mmu_map_fault_addr()
Subject: [PATCH] drm/panfrost: Fix the error path in panfrost_mmu_map_fault_addr() If some the pages or sgt allocation failed, we shouldn't release the pages ref we got earlier, otherwise we will end up with unbalanced get/put_pages() calls. We should instead leave everything in place and let the BO release function deal with extra cleanup when the object is destroyed, or let the fault handler try again next time it's called. Fixes: 187d292 ("drm/panfrost: Add support for GPU heap allocations") Cc: <stable@vger.kernel.org> Reviewed-by: Steven Price <steven.price@arm.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Co-developed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240105184624.508603-18-dmitry.osipenko@collabora.com
1 parent fddf092 commit 1fc9af8

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/gpu/drm/panfrost/panfrost_mmu.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,19 +502,26 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
502502
mapping_set_unevictable(mapping);
503503

504504
for (i = page_offset; i < page_offset + NUM_FAULT_PAGES; i++) {
505+
/* Can happen if the last fault only partially filled this
506+
* section of the pages array before failing. In that case
507+
* we skip already filled pages.
508+
*/
509+
if (pages[i])
510+
continue;
511+
505512
pages[i] = shmem_read_mapping_page(mapping, i);
506513
if (IS_ERR(pages[i])) {
507514
ret = PTR_ERR(pages[i]);
508515
pages[i] = NULL;
509-
goto err_pages;
516+
goto err_unlock;
510517
}
511518
}
512519

513520
sgt = &bo->sgts[page_offset / (SZ_2M / PAGE_SIZE)];
514521
ret = sg_alloc_table_from_pages(sgt, pages + page_offset,
515522
NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL);
516523
if (ret)
517-
goto err_pages;
524+
goto err_unlock;
518525

519526
ret = dma_map_sgtable(pfdev->dev, sgt, DMA_BIDIRECTIONAL, 0);
520527
if (ret)
@@ -537,8 +544,6 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
537544

538545
err_map:
539546
sg_free_table(sgt);
540-
err_pages:
541-
drm_gem_shmem_put_pages(&bo->base);
542547
err_unlock:
543548
dma_resv_unlock(obj->resv);
544549
err_bo:

0 commit comments

Comments
 (0)