Mesa (staging/22.0): ac/surface: fix an addrlib race condition on gfx9

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 25 04:04:42 UTC 2022


Module: Mesa
Branch: staging/22.0
Commit: ea7d41c6ac0bb3cd8018ec58f4f0fd4f221e0940
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ea7d41c6ac0bb3cd8018ec58f4f0fd4f221e0940

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Apr 22 02:16:23 2022 -0400

ac/surface: fix an addrlib race condition on gfx9

Addrlib calls GetMetaEquation, which generates and saves address equations
in a global table that is not thread safe.

Fixes: df2cbdd2e32 - amd/addrlib: expose DCC address equations to drivers
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6361

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16091>
(cherry picked from commit c4ca059dee4c902c1a736b3f77bd938679411c0d)

---

 .pick_status.json           |  2 +-
 src/amd/common/ac_surface.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index 38a49b2d14f..0994f17ea17 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -492,7 +492,7 @@
         "description": "ac/surface: fix an addrlib race condition on gfx9",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "because_sha": "df2cbdd2e321d198e973be21eea25e9b296cceff"
     },
     {
diff --git a/src/amd/common/ac_surface.c b/src/amd/common/ac_surface.c
index e554b87e193..37bb1e0ec18 100644
--- a/src/amd/common/ac_surface.c
+++ b/src/amd/common/ac_surface.c
@@ -93,6 +93,7 @@
 
 struct ac_addrlib {
    ADDR_HANDLE handle;
+   simple_mtx_t lock;
 };
 
 bool ac_modifier_has_dcc(uint64_t modifier)
@@ -503,11 +504,13 @@ struct ac_addrlib *ac_addrlib_create(const struct radeon_info *info,
    }
 
    addrlib->handle = addrCreateOutput.hLib;
+   simple_mtx_init(&addrlib->lock, mtx_plain);
    return addrlib;
 }
 
 void ac_addrlib_destroy(struct ac_addrlib *addrlib)
 {
+   simple_mtx_destroy(&addrlib->lock);
    AddrDestroy(addrlib->handle);
    free(addrlib);
 }
@@ -1828,7 +1831,12 @@ static int gfx9_compute_miptree(struct ac_addrlib *addrlib, const struct radeon_
          din.dataSurfaceSize = out.surfSize;
          din.firstMipIdInTail = out.firstMipIdInTail;
 
+         if (info->chip_class == GFX9)
+            simple_mtx_lock(&addrlib->lock);
          ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout);
+         if (info->chip_class == GFX9)
+            simple_mtx_unlock(&addrlib->lock);
+
          if (ret != ADDR_OK)
             return ret;
 
@@ -1909,7 +1917,12 @@ static int gfx9_compute_miptree(struct ac_addrlib *addrlib, const struct radeon_
             assert(surf->tile_swizzle == 0);
             assert(surf->u.gfx9.color.dcc.pipe_aligned || surf->u.gfx9.color.dcc.rb_aligned);
 
+            if (info->chip_class == GFX9)
+               simple_mtx_lock(&addrlib->lock);
             ret = Addr2ComputeDccInfo(addrlib->handle, &din, &dout);
+            if (info->chip_class == GFX9)
+               simple_mtx_unlock(&addrlib->lock);
+
             if (ret != ADDR_OK)
                return ret;
 
@@ -2009,7 +2022,12 @@ static int gfx9_compute_miptree(struct ac_addrlib *addrlib, const struct radeon_
          else
             cin.swizzleMode = in->swizzleMode;
 
+         if (info->chip_class == GFX9)
+            simple_mtx_lock(&addrlib->lock);
          ret = Addr2ComputeCmaskInfo(addrlib->handle, &cin, &cout);
+         if (info->chip_class == GFX9)
+            simple_mtx_unlock(&addrlib->lock);
+
          if (ret != ADDR_OK)
             return ret;
 



More information about the mesa-commit mailing list