st/mesa: Fix free of non-shareable shaders on context destroy
authorErico Nunes <nunes.erico@gmail.com>
Tue, 27 Dec 2022 11:32:07 +0000 (12:32 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 2 Jan 2023 13:50:52 +0000 (13:50 +0000)
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 <nunes.erico@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20458>

src/mesa/state_tracker/st_context.c

index 7722eb6..7d50658 100644 (file)
@@ -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.