Module: Mesa Branch: main Commit: fd6b3bf2672b0036dd26a30a67fc8542d50254c7 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fd6b3bf2672b0036dd26a30a67fc8542d50254c7
Author: Dmitry Baryshkov <dmitry.barysh...@linaro.org> Date: Sun Nov 19 16:59:51 2023 +0200 freedreno/drm: notify valgrind about FD_BO_NOMAP maps If the shader memory has been allocated with the FD_BO_NOMAP and got later allocated a memory chunk during fd_bo_upload(), this can result in the valgrind splat when it tries to release the free and/or cache the BO. To fix this issue, notify valgrind about newly mmaped shader memory. Signed-off-by: Dmitry Baryshkov <dmitry.barysh...@linaro.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26277> --- src/freedreno/drm/freedreno_bo.c | 12 +++++++++++- src/freedreno/drm/freedreno_priv.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c index d0e871e17ea..33780d824b9 100644 --- a/src/freedreno/drm/freedreno_bo.c +++ b/src/freedreno/drm/freedreno_bo.c @@ -659,6 +659,16 @@ fd_bo_map(struct fd_bo *bo) return __fd_bo_map(bo); } +static void * +fd_bo_map_for_upload(struct fd_bo *bo) +{ + void *addr = __fd_bo_map(bo); + if (bo->alloc_flags & FD_BO_NOMAP) + VG_BO_MAPPED(bo); + + return addr; +} + void fd_bo_upload(struct fd_bo *bo, void *src, unsigned off, unsigned len) { @@ -667,7 +677,7 @@ fd_bo_upload(struct fd_bo *bo, void *src, unsigned off, unsigned len) return; } - memcpy((uint8_t *)__fd_bo_map(bo) + off, src, len); + memcpy((uint8_t *)fd_bo_map_for_upload(bo) + off, src, len); } bool diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index 7f213a243c8..95bf0478330 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -556,6 +556,12 @@ VG_BO_OBTAIN(struct fd_bo *bo) VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, 1); } } +/* special case for fd_bo_upload */ +static inline void +VG_BO_MAPPED(struct fd_bo *bo) +{ + VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, 1); +} #else static inline void VG_BO_ALLOC(struct fd_bo *bo) @@ -573,6 +579,10 @@ static inline void VG_BO_OBTAIN(struct fd_bo *bo) { } +static inline void +VG_BO_MAPPED(struct fd_bo *bo) +{ +} #endif #define FD_DEFINE_CAST(parent, child) \