freedreno/drm: don't crash in heap allocator when run under valgrind

If Mesa is executed under valgrind, fd_bo_init_common() calls
fd_bo_map() internally. For the heap (sub-block) allocator this causes a
segfault in fd_bo_map(), when this function tries to call the offset()
callback.

To prevent this from happening, preallocate fb->map before calling into
fd_bo_init_common(), stop calling VG_BO_ALLOC() if the memory map is
already initialised and disable the VG_BO_FREE call for the heap
allocator.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26277>
This commit is contained in:
Dmitry Baryshkov 2023-11-19 14:36:28 +02:00 committed by Marge Bot
parent fd6b3bf267
commit c8c8c5a3cf
2 changed files with 9 additions and 5 deletions

View file

@ -105,7 +105,8 @@ fd_bo_init_common(struct fd_bo *bo, struct fd_device *dev)
bo->max_fences = 1;
bo->fences = &bo->_inline_fence;
VG_BO_ALLOC(bo);
if (!bo->map)
VG_BO_ALLOC(bo);
}
/* allocate a new buffer object, call w/ table_lock held */

View file

@ -123,7 +123,10 @@ sa_release(struct fd_bo *bo)
simple_mtx_assert_locked(&s->heap->lock);
VG_BO_FREE(bo);
/*
* We don't track heap allocs in valgrind
* VG_BO_FREE(bo);
*/
fd_bo_fini_fences(bo);
@ -258,12 +261,12 @@ fd_bo_heap_alloc(struct fd_bo_heap *heap, uint32_t size)
bo->handle = 1; /* dummy handle to make fd_bo_init_common() happy */
bo->alloc_flags = heap->flags;
/* Pre-initialize mmap ptr, to avoid trying to os_mmap() */
bo->map = ((uint8_t *)fd_bo_map(heap->blocks[idx])) + block_offset(s);
fd_bo_init_common(bo, heap->dev);
bo->handle = FD_BO_SUBALLOC_HANDLE;
/* Pre-initialize mmap ptr, to avoid trying to os_mmap() */
bo->map = ((uint8_t *)fd_bo_map(heap->blocks[idx])) + block_offset(s);
return bo;
}