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

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-pra...@amd.com>
Date:   Tue Jan 24 21:42:49 2023 +0100

yegl/wayland: fix glthread deadlocks

We need to make sure that glthread is idle before using wl_*
functions or they might be used from 2 threads at the same
time.

Thanks to @deltib for the investigation of this issue.

Fixes: 58f90fd03f4 ("egl/wayland: fix glthread crashes")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7624
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8136
Reviewed-by: Michel Dänzer <mdaen...@redhat.com>
Reviewed-by: Marek Olšák <marek.ol...@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20887>
(cherry picked from commit a98e4195f567b39af9fd8a6cfccec6f772efe9fc)

---

 .pick_status.json                       |  2 +-
 src/egl/drivers/dri2/platform_wayland.c | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 0c6987c7a7f..3f2eaae4315 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -3793,7 +3793,7 @@
         "description": "yegl/wayland: fix glthread deadlocks",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "58f90fd03f4aaf2ee19010e9cbd9cee2deda9711"
     },
diff --git a/src/egl/drivers/dri2/platform_wayland.c 
b/src/egl/drivers/dri2/platform_wayland.c
index 248d217f5e7..32b0ff70002 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -1522,15 +1522,6 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp,
    if (!dri2_surf->wl_win)
       return _eglError(EGL_BAD_NATIVE_WINDOW, "dri2_swap_buffers");
 
-   while (dri2_surf->throttle_callback != NULL)
-      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy,
-                                    dri2_surf->wl_queue) == -1)
-         return -1;
-
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)
-      if (dri2_surf->color_buffers[i].age > 0)
-         dri2_surf->color_buffers[i].age++;
-
    /* Flush (and finish glthread) before:
     *   - update_buffers_if_needed because the unmarshalling thread
     *     may be running currently, and we would concurrently alloc/free
@@ -1538,10 +1529,21 @@ dri2_wl_swap_buffers_with_damage(_EGLDisplay *disp,
     *   - swapping current/back because flushing may free the buffer and
     *     dri_image and reallocate them using get_back_bo (which causes a
     *     a crash because 'current' becomes NULL).
+    *   - using any wl_* function because accessing them from this thread
+    *     and glthread causes troubles (see #7624 and #8136)
     */
    dri2_flush_drawable_for_swapbuffers(disp, draw);
    dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
 
+   while (dri2_surf->throttle_callback != NULL)
+      if (wl_display_dispatch_queue(dri2_dpy->wl_dpy,
+                                    dri2_surf->wl_queue) == -1)
+         return -1;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++)
+      if (dri2_surf->color_buffers[i].age > 0)
+         dri2_surf->color_buffers[i].age++;
+
    /* Make sure we have a back buffer in case we're swapping without ever
     * rendering. */
    if (update_buffers_if_needed(dri2_surf) < 0)

Reply via email to