Mesa (main): compiler/glsl: Use mutex lock while freeing up mem_ctx

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 16 23:37:41 UTC 2021


Module: Mesa
Branch: main
Commit: eb272f65715c21c38c0dc0f5a84f431851aa87d0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb272f65715c21c38c0dc0f5a84f431851aa87d0

Author: Martin Krastev <krastevm at vmware.com>
Date:   Tue Jun 15 12:18:31 2021 -0700

compiler/glsl: Use mutex lock while freeing up mem_ctx

builtin_builder::~builtin_builder() and builtin_builder::release()
are running into race condition. This leads lightsmark to crash at
the end because both calls ralloc_free which mutates the arguments state

This patch fixes lightsmark2008 crash

Fixes: e4da8b9c331cc3a ("mesa/compiler: rework tear down of builtin/types")

Reviewed-by: Charmaine Lee <charmainel at vmware.com>
Reviewed-by: Neha Bhende <bhenden at vmware.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Tested-by: Neha Bhende <bhenden at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11385>

---

 src/compiler/glsl/builtin_functions.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 6d700c14bec..9f3b526671e 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -90,6 +90,8 @@
 
 using namespace ir_builder;
 
+static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
+
 /**
  * Availability predicates:
  *  @{
@@ -1296,7 +1298,15 @@ builtin_builder::builtin_builder()
 
 builtin_builder::~builtin_builder()
 {
+   mtx_lock(&builtins_lock);
+
    ralloc_free(mem_ctx);
+   mem_ctx = NULL;
+
+   ralloc_free(shader);
+   shader = NULL;
+
+   mtx_unlock(&builtins_lock);
 }
 
 ir_function_signature *
@@ -7753,7 +7763,6 @@ builtin_builder::_helper_invocation()
 
 /* The singleton instance of builtin_builder. */
 static builtin_builder builtins;
-static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
 static uint32_t builtin_users = 0;
 
 /**



More information about the mesa-commit mailing list