zink: force-add usage when adding last-ref tracking

this fixes desync+crash when:
1. usage is added for bs A
2. tracking is added for bs B
3. tracking is removed for bs B
4. context is destroyed
5. usage A is now dangling and will crash if accessed

as seen in glmark2

cc: mesa-stable

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15429>
(cherry picked from commit 7da211e24f)
This commit is contained in:
Mike Blumenkrantz 2022-03-17 11:26:34 -04:00 committed by Eric Engestrom
parent adde3a7cc2
commit 165e05d27d
2 changed files with 13 additions and 3 deletions

View file

@ -301,7 +301,7 @@
"description": "zink: force-add usage when adding last-ref tracking",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -73,8 +73,18 @@ debug_describe_zink_buffer_view(char *buf, const struct zink_buffer_view *ptr)
ALWAYS_INLINE static void
check_resource_for_batch_ref(struct zink_context *ctx, struct zink_resource *res)
{
if (!zink_resource_has_binds(res))
zink_batch_reference_resource(&ctx->batch, res);
if (!zink_resource_has_binds(res)) {
/* avoid desync between usage and tracking:
* - if usage exists, it must be removed before the context is destroyed
* - having usage does not imply having tracking
* - if tracking will be added here, also reapply usage to avoid dangling usage once tracking is removed
* TODO: somehow fix this for perf because it's an extra hash lookup
*/
if (res->obj->bo->reads || res->obj->bo->writes)
zink_batch_reference_resource_rw(&ctx->batch, res, !!res->obj->bo->writes);
else
zink_batch_reference_resource(&ctx->batch, res);
}
}
static void