mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
mesa: fix potential race condition in with TexObjects
The calls look up a texture object and create it if it doesn't already exist. However they weren't locking the hash between looking up the name and adding it to the hash so it could be possible another thread also generated the same name. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Fixes:842c9130("mesa: enable GL name reuse by default for all drivers except virgl") Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34091> (cherry picked from commit95e87f6a6a)
This commit is contained in:
parent
0c5a31f597
commit
d44e9736d1
3 changed files with 17 additions and 5 deletions
|
|
@ -4094,7 +4094,7 @@
|
|||
"description": "mesa: fix potential race condition in with TexObjects",
|
||||
"nominated": true,
|
||||
"nomination_type": 2,
|
||||
"resolution": 0,
|
||||
"resolution": 1,
|
||||
"main_sha": null,
|
||||
"because_sha": "842c91300fd041cf35398d05d2995f16d76870ae",
|
||||
"notes": null
|
||||
|
|
|
|||
|
|
@ -3074,9 +3074,12 @@ lookup_texture_ext_dsa(struct gl_context *ctx, GLenum target, GLuint texture,
|
|||
texObj = ctx->Shared->DefaultTex[targetIndex];
|
||||
assert(texObj);
|
||||
} else {
|
||||
texObj = _mesa_lookup_texture(ctx, texture);
|
||||
_mesa_HashLockMutex(&ctx->Shared->TexObjects);
|
||||
|
||||
texObj = _mesa_lookup_texture_locked(ctx, texture);
|
||||
if (!texObj && _mesa_is_desktop_gl_core(ctx)) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", caller);
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -3084,12 +3087,14 @@ lookup_texture_ext_dsa(struct gl_context *ctx, GLenum target, GLuint texture,
|
|||
texObj = _mesa_new_texture_object(ctx, texture, boundTarget);
|
||||
if (!texObj) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* insert into hash table */
|
||||
_mesa_HashInsert(&ctx->Shared->TexObjects, texObj->Name, texObj);
|
||||
_mesa_HashInsertLocked(&ctx->Shared->TexObjects, texObj->Name, texObj);
|
||||
}
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
|
||||
if (texObj->Target != boundTarget) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(%s != %s)",
|
||||
|
|
|
|||
|
|
@ -1765,9 +1765,13 @@ _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
|
|||
/* Use a default texture object */
|
||||
newTexObj = ctx->Shared->DefaultTex[targetIndex];
|
||||
} else {
|
||||
_mesa_HashLockMutex(&ctx->Shared->TexObjects);
|
||||
|
||||
/* non-default texture object */
|
||||
newTexObj = _mesa_lookup_texture(ctx, texName);
|
||||
newTexObj = _mesa_lookup_texture_locked(ctx, texName);
|
||||
if (newTexObj) {
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
|
||||
/* error checking */
|
||||
if (!no_error &&
|
||||
newTexObj->Target != 0 && newTexObj->Target != target) {
|
||||
|
|
@ -1785,6 +1789,7 @@ _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
|
|||
if (!no_error && _mesa_is_desktop_gl_core(ctx)) {
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION,
|
||||
"%s(non-gen name)", caller);
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1792,11 +1797,13 @@ _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
|
|||
newTexObj = _mesa_new_texture_object(ctx, texName, target);
|
||||
if (!newTexObj) {
|
||||
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* and insert it into hash table */
|
||||
_mesa_HashInsert(&ctx->Shared->TexObjects, texName, newTexObj);
|
||||
_mesa_HashInsertLocked(&ctx->Shared->TexObjects, texName, newTexObj);
|
||||
_mesa_HashUnlockMutex(&ctx->Shared->TexObjects);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue