From 6ed6a28fc75d4ffade7e7bbd8a4e52c0f5abaefc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 22 Apr 2022 14:16:52 -0400 Subject: [PATCH] winsys/amdgpu: fix a mutex deadlock when we fail to create pipe_screen Fixes: 2eb067db0fe - winsys/amdgpu: add a new winsys for the new kernel driver Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: (cherry picked from commit 4a982aa5421780a90b812e7654d4d32459d9bdbd) --- .pick_status.json | 2 +- src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 84e519ad685..8c64e3e680e 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -468,7 +468,7 @@ "description": "winsys/amdgpu: fix a mutex deadlock when we fail to create pipe_screen", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "because_sha": "2eb067db0febcd71b4182153155e3e43f215624c" }, { diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index d042bc2472f..cc71b0e920b 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -155,7 +155,7 @@ static void do_winsys_deinit(struct amdgpu_winsys *ws) FREE(ws); } -static void amdgpu_winsys_destroy(struct radeon_winsys *rws) +static void amdgpu_winsys_destroy_locked(struct radeon_winsys *rws, bool locked) { struct amdgpu_screen_winsys *sws = amdgpu_screen_winsys(rws); struct amdgpu_winsys *ws = sws->aws; @@ -167,7 +167,8 @@ static void amdgpu_winsys_destroy(struct radeon_winsys *rws) * amdgpu_winsys_create in another thread doesn't get the winsys * from the table when the counter drops to 0. */ - simple_mtx_lock(&dev_tab_mutex); + if (!locked) + simple_mtx_lock(&dev_tab_mutex); destroy = pipe_reference(&ws->reference, NULL); if (destroy && dev_tab) { @@ -178,7 +179,8 @@ static void amdgpu_winsys_destroy(struct radeon_winsys *rws) } } - simple_mtx_unlock(&dev_tab_mutex); + if (!locked) + simple_mtx_unlock(&dev_tab_mutex); if (destroy) do_winsys_deinit(ws); @@ -187,6 +189,11 @@ static void amdgpu_winsys_destroy(struct radeon_winsys *rws) FREE(rws); } +static void amdgpu_winsys_destroy(struct radeon_winsys *rws) +{ + amdgpu_winsys_destroy_locked(rws, false); +} + static void amdgpu_winsys_query_info(struct radeon_winsys *rws, struct radeon_info *info, bool enable_smart_access_memory, @@ -556,7 +563,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config, * and link all drivers into one binary blob. */ ws->base.screen = screen_create(&ws->base, config); if (!ws->base.screen) { - amdgpu_winsys_destroy(&ws->base); + amdgpu_winsys_destroy_locked(&ws->base, true); simple_mtx_unlock(&dev_tab_mutex); return NULL; }