From f2e3285d8e2b72e7408845afa5402ce48c4e93a8 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 4 Dec 2023 09:06:59 -0800 Subject: [PATCH] freedreno/drm: Fix zombie BO import harder Fixes: 6ac133c646dd ("freedreno/drm: Fix race in zombie import") Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_bo.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c index efde63ec73f..3a52fc56c8d 100644 --- a/src/freedreno/drm/freedreno_bo.c +++ b/src/freedreno/drm/freedreno_bo.c @@ -64,6 +64,15 @@ lookup_bo(struct hash_table *tbl, uint32_t key) * checking for refcnt==0 (ie. 1 after p_atomic_inc_return). */ if (p_atomic_inc_return(&bo->refcnt) == 1) { + /* Restore the zombified reference count, so if another thread + * that ends up calling lookup_bo() gets the table_lock before + * the thread deleting the bo does, it doesn't mistakenly see + * that the BO is live. + * + * We are holding the table_lock here so we can't be racing + * with another caller of lookup_bo() + */ + p_atomic_dec(&bo->refcnt); return &zombie; }