Skip to content

Commit dbd0da2

Browse files
drm/ttm: fix locking in vmap/vunmap TTM GEM helpers
I've stumbled over this while reviewing patches for DMA-buf and it looks like we completely messed the locking up here. In general most TTM function should only be called while holding the appropriate BO resv lock. Without this we could break the internal buffer object state here. Only compile tested! Signed-off-by: Christian König <christian.koenig@amd.com> Fixes: 4367660 ("drm/ttm: Add vmap/vunmap to TTM and TTM GEM helpers") Cc: stable@vger.kernel.org Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220715111533.467012-1-christian.koenig@amd.com
1 parent 9b04369 commit dbd0da2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/gpu/drm/drm_gem_ttm_helper.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ int drm_gem_ttm_vmap(struct drm_gem_object *gem,
6464
struct iosys_map *map)
6565
{
6666
struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
67+
int ret;
68+
69+
dma_resv_lock(gem->resv, NULL);
70+
ret = ttm_bo_vmap(bo, map);
71+
dma_resv_unlock(gem->resv);
6772

68-
return ttm_bo_vmap(bo, map);
73+
return ret;
6974
}
7075
EXPORT_SYMBOL(drm_gem_ttm_vmap);
7176

@@ -82,7 +87,9 @@ void drm_gem_ttm_vunmap(struct drm_gem_object *gem,
8287
{
8388
struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(gem);
8489

90+
dma_resv_lock(gem->resv, NULL);
8591
ttm_bo_vunmap(bo, map);
92+
dma_resv_unlock(gem->resv);
8693
}
8794
EXPORT_SYMBOL(drm_gem_ttm_vunmap);
8895

0 commit comments

Comments
 (0)