From 46a493a2f00f70ec2cd3c5e9403ddf508bd20118 Mon Sep 17 00:00:00 2001 From: Erico Nunes Date: Tue, 27 Dec 2022 12:32:07 +0100 Subject: [PATCH] st/mesa: Fix free of non-shareable shaders on context destroy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On drivers that do not set PIPE_CAP_SHAREABLE_SHADERS, st_destroy_program_variants() may reach st_save_zombie_shader() which accesses st->zombie_shaders.mutex. Destroying st->zombie_shaders.mutex before destroying program variants may result in an invalid access in a multiple context scenario for those drivers. Move the mutex destroy call to after program variants destroy so that it doesn't hit a deadlock on context destroy. Signed-off-by: Erico Nunes Reviewed-by: Marek Olšák Part-of: --- src/mesa/state_tracker/st_context.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 7722eb6cc81..7d50658f660 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -947,11 +947,6 @@ st_destroy_context(struct st_context *st) } } - st_context_free_zombie_objects(st); - - simple_mtx_destroy(&st->zombie_sampler_views.mutex); - simple_mtx_destroy(&st->zombie_shaders.mutex); - st_release_program(st, &st->fp); st_release_program(st, &st->gp); st_release_program(st, &st->vp); @@ -979,6 +974,11 @@ st_destroy_context(struct st_context *st) st_destroy_program_variants(st); + st_context_free_zombie_objects(st); + + simple_mtx_destroy(&st->zombie_sampler_views.mutex); + simple_mtx_destroy(&st->zombie_shaders.mutex); + /* Do not release debug_output yet because it might be in use by other threads. * These threads will be terminated by _mesa_free_context_data and * st_destroy_context_priv.