xserver: Branch 'xwayland-23.1' - 12 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 9 09:30:15 UTC 2023


 .gitlab-ci.yml                    |    2 
 .gitlab-ci/debian-install.sh      |    8 +
 hw/xwayland/xwayland-glamor-gbm.c |  156 +++++++++++++++++++++++++-------------
 hw/xwayland/xwayland-glamor.c     |   34 +++++---
 hw/xwayland/xwayland-glamor.h     |    7 +
 hw/xwayland/xwayland-input.c      |    2 
 hw/xwayland/xwayland-output.c     |    2 
 hw/xwayland/xwayland-window.c     |    1 
 hw/xwayland/xwayland-window.h     |    8 +
 include/extinit.h                 |    1 
 meson.build                       |    2 
 mi/miinitext.c                    |    2 
 os/utils.c                        |    1 
 13 files changed, 157 insertions(+), 69 deletions(-)

New commits:
commit d11237f11a546002955fdc39b888f697fa26bb6f
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Tue Mar 7 10:53:16 2023 +0100

    xwayland: Fix uninitialised value created by a stack allocation
    
    Commit 3c07a01c4 (xwayland: Use xdg-output name for XRandR) changed the
    logic to use a fixed sized buffer allocated on the stack to pass to
    RROutputCreate() which would then copy it.
    
    Valgrind complains about this:
    
      == Conditional jump or move depends on uninitialised value(s)
      ==    at 0x49954B: MakeAtom (atom.c:87)
      ==    by 0x5108B3: RRMonitorCrtcName (rrmonitor.c:33)
      ==    by 0x510BBB: RRMonitorSetFromServer (rrmonitor.c:92)
      ==    by 0x511882: RRMonitorMakeList (rrmonitor.c:373)
      ==    by 0x512175: ProcRRGetMonitors (rrmonitor.c:634)
      ==    by 0x508091: ProcRRDispatch (randr.c:748)
      ==    by 0x4A860E: Dispatch (dispatch.c:546)
      ==    by 0x4B692F: dix_main (main.c:271)
      ==    by 0x431C90: main (stubmain.c:34)
      ==  Uninitialised value was created by a stack allocation
      ==    at 0x42122C: xwl_output_create (xwayland-output.c:816)
    
    This is actually harmless, but also simple to avoid by just initializing
    the content of the array with zeros, so let's just fix that.
    
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Fixes: commit 3c07a01c4 - xwayland: Use xdg-output name for XRandR
    (cherry picked from commit 1209a1bb57628df108600b09a77b15104e1bf1e2)

diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c
index afc416560..661e1828d 100644
--- a/hw/xwayland/xwayland-output.c
+++ b/hw/xwayland/xwayland-output.c
@@ -815,7 +815,7 @@ xwl_output_create(struct xwl_screen *xwl_screen, uint32_t id,
                   Bool with_xrandr, uint32_t version)
 {
     struct xwl_output *xwl_output;
-    char name[MAX_OUTPUT_NAME];
+    char name[MAX_OUTPUT_NAME] = { '\0', };
 
     xwl_output = calloc(1, sizeof *xwl_output);
     if (xwl_output == NULL) {
commit d06f27078416ba2bea2b17f72ad2635b71048932
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Tue Mar 7 18:21:22 2023 +0100

    xwayland/glamor: Track if a xwl_pixmap uses explicit modifiers
    
    If we allocated with implicit modifiers, then we shouldn't use the
    modifier returned by gbm_bo when checking whether the modifier is
    supported or not, since it won't be if the compositor only advertises
    implicit modifiers, nor should we use the modifier when creating the
    Wayland buffer object, as it wasn't explicitly advertised.
    
    Fixes: c6f2598a4 ("xwayland: don't fall back to wl_drm with explicit modifier")
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
    (cherry picked from commit 4e20d96e8dfc9d19b5730c23ae3cc8da811c346e)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index d545a570d..04cb5bc23 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -69,6 +69,7 @@ struct xwl_pixmap {
     EGLImage image;
     unsigned int texture;
     struct gbm_bo *bo;
+    Bool implicit_modifier;
 };
 
 static DevPrivateKeyRec xwl_gbm_private_key;
@@ -116,7 +117,8 @@ is_device_path_render_node (const char *device_path)
 
 static PixmapPtr
 xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
-                                    int depth)
+                                    int depth,
+                                    Bool implicit_modifier)
 {
     PixmapPtr pixmap;
     struct xwl_pixmap *xwl_pixmap;
@@ -188,6 +190,7 @@ xwl_glamor_gbm_create_pixmap_for_bo(ScreenPtr screen, struct gbm_bo *bo,
     xwl_glamor_egl_make_current(xwl_screen);
     xwl_pixmap->bo = bo;
     xwl_pixmap->buffer = NULL;
+    xwl_pixmap->implicit_modifier = implicit_modifier;
 
 #ifdef GBM_BO_FD_FOR_PLANE
     if (xwl_gbm->dmabuf_capable) {
@@ -286,6 +289,7 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
          hint == CREATE_PIXMAP_USAGE_SHARED ||
          (xwl_screen->rootless && hint == 0))) {
         uint32_t format = gbm_format_for_depth(depth);
+        Bool implicit = FALSE;
 
 #ifdef GBM_BO_WITH_MODIFIERS
         if (xwl_gbm->dmabuf_capable) {
@@ -301,12 +305,13 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
         }
 #endif
         if (bo == NULL) {
+            implicit = TRUE;
             bo = gbm_bo_create(xwl_gbm->gbm, width, height, format,
                                GBM_BO_USE_RENDERING);
         }
 
         if (bo) {
-            pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth);
+            pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth, implicit);
 
             if (!pixmap) {
                 gbm_bo_destroy(bo);
@@ -395,7 +400,8 @@ init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
-#else
+#endif
+
 static Bool
 init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
                             uint64_t          *modifier,
@@ -415,7 +421,6 @@ init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
-#endif
 
 static struct wl_buffer *
 xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
@@ -447,22 +452,25 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
     format = wl_drm_format_for_depth(pixmap->drawable.depth);
 
 #ifdef GBM_BO_WITH_MODIFIERS
-    if (!init_buffer_params_with_modifiers(xwl_pixmap,
-                                           &modifier,
-                                           &num_planes,
-                                           prime_fds,
-                                           strides,
-                                           offsets))
-        return NULL;
-#else
-    if (!init_buffer_params_fallback(xwl_pixmap,
-                                     &modifier,
-                                     &num_planes,
-                                     prime_fds,
-                                     strides,
-                                     offsets))
-        return NULL;
+    if (!xwl_pixmap->implicit_modifier) {
+        if (!init_buffer_params_with_modifiers(xwl_pixmap,
+                                               &modifier,
+                                               &num_planes,
+                                               prime_fds,
+                                               strides,
+                                               offsets))
+            return NULL;
+    } else
 #endif
+    {
+        if (!init_buffer_params_fallback(xwl_pixmap,
+                                         &modifier,
+                                         &num_planes,
+                                         prime_fds,
+                                         strides,
+                                         offsets))
+            return NULL;
+    }
 
     if (xwl_screen->dmabuf &&
         xwl_glamor_is_modifier_supported(xwl_screen, format, modifier)) {
@@ -626,6 +634,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
     struct gbm_bo *bo = NULL;
     PixmapPtr pixmap;
     int i;
+    Bool implicit = FALSE;
 
     if (width == 0 || height == 0 || num_fds == 0 ||
         depth < 15 || bpp != BitsPerPixel(depth) ||
@@ -659,6 +668,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
        data.format = gbm_format_for_depth(depth);
        bo = gbm_bo_import(xwl_gbm->gbm, GBM_BO_IMPORT_FD, &data,
                           GBM_BO_USE_RENDERING);
+       implicit = TRUE;
     } else {
        goto error;
     }
@@ -666,7 +676,7 @@ glamor_pixmap_from_fds(ScreenPtr screen, CARD8 num_fds, const int *fds,
     if (bo == NULL)
        goto error;
 
-    pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth);
+    pixmap = xwl_glamor_gbm_create_pixmap_for_bo(screen, bo, depth, implicit);
     if (pixmap == NULL) {
        gbm_bo_destroy(bo);
        goto error;
commit 8c1cad5b75507f0f6e9d19c1f42eeade3181115e
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 16:54:30 2023 +0100

    xwayland/glamor/gbm: Use helper for implicit buffer params too
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
    (cherry picked from commit 9bd83c02a8e02b902303a145de15c13ee650b910)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 2e1a4bfd5..d545a570d 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -395,6 +395,26 @@ init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
 
     return TRUE;
 }
+#else
+static Bool
+init_buffer_params_fallback(struct xwl_pixmap *xwl_pixmap,
+                            uint64_t          *modifier,
+                            int               *num_planes,
+                            int               *prime_fds,
+                            uint32_t          *strides,
+                            uint32_t          *offsets)
+{
+    *num_planes = 1;
+    *modifier = DRM_FORMAT_MOD_INVALID;
+    prime_fds[0] = gbm_bo_get_fd(xwl_pixmap->bo);
+    if (prime_fds[0] == -1)
+        return FALSE;
+
+    strides[0] = gbm_bo_get_stride(xwl_pixmap->bo);
+    offsets[0] = 0;
+
+    return TRUE;
+}
 #endif
 
 static struct wl_buffer *
@@ -435,13 +455,13 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
                                            offsets))
         return NULL;
 #else
-    num_planes = 1;
-    modifier = DRM_FORMAT_MOD_INVALID;
-    prime_fds[0] = gbm_bo_get_fd(xwl_pixmap->bo);
-    if (prime_fds[0] == -1)
+    if (!init_buffer_params_fallback(xwl_pixmap,
+                                     &modifier,
+                                     &num_planes,
+                                     prime_fds,
+                                     strides,
+                                     offsets))
         return NULL;
-    strides[0] = gbm_bo_get_stride(xwl_pixmap->bo);
-    offsets[0] = 0;
 #endif
 
     if (xwl_screen->dmabuf &&
commit 7d05c05367641c99532ad38c18f7670394f69c53
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 16:53:32 2023 +0100

    xwayland/glamor/gbm: Initialize explicit buffer params in helper
    
    This is preparing for cleaning up the macro mess.
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
    (cherry picked from commit af255b16513bab34bfc527cae139eb09c3fdbf82)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 82d9e7880..2e1a4bfd5 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -347,42 +347,24 @@ static const struct wl_buffer_listener xwl_glamor_gbm_buffer_listener = {
     xwl_pixmap_buffer_release_cb,
 };
 
-static struct wl_buffer *
-xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
+#ifdef GBM_BO_WITH_MODIFIERS
+static Bool
+init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap,
+                                  uint64_t          *modifier,
+                                  int               *num_planes,
+                                  int               *prime_fds,
+                                  uint32_t          *strides,
+                                  uint32_t          *offsets)
 {
-    struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen);
-    struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap);
-    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
-    unsigned short width = pixmap->drawable.width;
-    unsigned short height = pixmap->drawable.height;
-    uint32_t format;
-    int num_planes;
-    int prime_fds[4];
-    uint32_t strides[4];
-    uint32_t offsets[4];
-    uint64_t modifier;
-    int i;
 #ifndef GBM_BO_FD_FOR_PLANE
     int32_t first_handle;
 #endif
+    int i;
 
-    if (xwl_pixmap == NULL)
-       return NULL;
-
-    if (xwl_pixmap->buffer) {
-        /* Buffer already exists. */
-        return xwl_pixmap->buffer;
-    }
-
-    if (!xwl_pixmap->bo)
-       return NULL;
-
-    format = wl_drm_format_for_depth(pixmap->drawable.depth);
+    *num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo);
+    *modifier = gbm_bo_get_modifier(xwl_pixmap->bo);
 
-#ifdef GBM_BO_WITH_MODIFIERS
-    num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo);
-    modifier = gbm_bo_get_modifier(xwl_pixmap->bo);
-    for (i = 0; i < num_planes; i++) {
+    for (i = 0; i < *num_planes; i++) {
 #ifdef GBM_BO_FD_FOR_PLANE
         prime_fds[i] = gbm_bo_get_fd_for_plane(xwl_pixmap->bo, i);
 #else
@@ -405,11 +387,53 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
         if (prime_fds[i] == -1) {
             while (--i >= 0)
                 close(prime_fds[i]);
-            return NULL;
+            return FALSE;
         }
         strides[i] = gbm_bo_get_stride_for_plane(xwl_pixmap->bo, i);
         offsets[i] = gbm_bo_get_offset(xwl_pixmap->bo, i);
     }
+
+    return TRUE;
+}
+#endif
+
+static struct wl_buffer *
+xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
+{
+    struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen);
+    struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap);
+    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
+    unsigned short width = pixmap->drawable.width;
+    unsigned short height = pixmap->drawable.height;
+    uint32_t format;
+    int num_planes;
+    int prime_fds[4];
+    uint32_t strides[4];
+    uint32_t offsets[4];
+    uint64_t modifier;
+    int i;
+
+    if (xwl_pixmap == NULL)
+       return NULL;
+
+    if (xwl_pixmap->buffer) {
+        /* Buffer already exists. */
+        return xwl_pixmap->buffer;
+    }
+
+    if (!xwl_pixmap->bo)
+       return NULL;
+
+    format = wl_drm_format_for_depth(pixmap->drawable.depth);
+
+#ifdef GBM_BO_WITH_MODIFIERS
+    if (!init_buffer_params_with_modifiers(xwl_pixmap,
+                                           &modifier,
+                                           &num_planes,
+                                           prime_fds,
+                                           strides,
+                                           offsets))
+        return NULL;
 #else
     num_planes = 1;
     modifier = DRM_FORMAT_MOD_INVALID;
commit 8e7a131e80b7f835fa74776b4c7943a0ff62d2ad
Author: Jonas Ådahl <jadahl at gmail.com>
Date:   Wed Mar 8 13:58:40 2023 +0100

    xwayland/glamor/gbm: Only use modifier gbm API if explicit
    
    If we're using implicit modifiers, we'll pass NULL and zero modifiers.
    Lets just use the legacy API directly instead.
    
    Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
    (cherry picked from commit 08b0ea09de120a64c498238cc15b6cc04276ca22)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 8e46f30f7..82d9e7880 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -293,8 +293,10 @@ xwl_glamor_gbm_create_pixmap(ScreenPtr screen,
             uint64_t *modifiers = NULL;
 
             xwl_glamor_get_modifiers(screen, format, &num_modifiers, &modifiers);
-            bo = gbm_bo_create_with_modifiers(xwl_gbm->gbm, width, height,
-                                              format, modifiers, num_modifiers);
+
+            if (num_modifiers > 0)
+                bo = gbm_bo_create_with_modifiers(xwl_gbm->gbm, width, height,
+                                                  format, modifiers, num_modifiers);
             free(modifiers);
         }
 #endif
commit 8ff38327633eebf61d418a6d75b18ea98a1cb891
Author: Simon Ser <contact at emersion.fr>
Date:   Mon Feb 27 17:36:03 2023 +0100

    Allow disabling the SHAPE extension at runtime
    
    To correctly render a window making use of SHAPE, a compositor
    must query the shape rectangles. This may not be a desirable
    feature for a Wayland compositor. Allow SHAPE to be turned off at
    runtime, so that the compositor can opt-out.
    
    Signed-off-by: Simon Ser <contact at emersion.fr>
    (cherry picked from commit 21b3dad2380639573c251d95910bcb644049ee5f)

diff --git a/include/extinit.h b/include/extinit.h
index 46081ad30..59d18962f 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -108,6 +108,7 @@ extern _X_EXPORT Bool noScreenSaverExtension;
 extern void ScreenSaverExtensionInit(void);
 #endif
 
+extern _X_EXPORT Bool noShapeExtension;
 extern void ShapeExtensionInit(void);
 
 #ifdef MITSHM
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 2e4aba534..26c1eb03c 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -109,7 +109,7 @@ SOFTWARE.
 /* List of built-in (statically linked) extensions */
 static const ExtensionModule staticExtensions[] = {
     {GEExtensionInit, "Generic Event Extension", &noGEExtension},
-    {ShapeExtensionInit, "SHAPE", NULL},
+    {ShapeExtensionInit, "SHAPE", &noShapeExtension},
 #ifdef MITSHM
     {ShmExtensionInit, "MIT-SHM", &noMITShmExtension},
 #endif
diff --git a/os/utils.c b/os/utils.c
index 405bf7d8b..a4712d0bf 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -143,6 +143,7 @@ Bool noMITShmExtension = FALSE;
 Bool noRRExtension = FALSE;
 #endif
 Bool noRenderExtension = FALSE;
+Bool noShapeExtension = FALSE;
 
 #ifdef XCSECURITY
 Bool noSecurityExtension = FALSE;
commit 97233c9858bb19af11753454a4d394b0e1bca89c
Author: Simon Ser <contact at emersion.fr>
Date:   Mon Feb 27 17:06:51 2023 +0100

    xwayland: use drmDevice to compare DRM devices
    
    The linux_dmabuf_v1 protocol doesn't guarantee any DRM node type:
    the compositor may send a primary node or a render node. Use
    drmDevice so that device comparisons are node-type-insensitive.
    
    Signed-off-by: Simon Ser <contact at emersion.fr>
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1447
    (cherry picked from commit 6f0b9deed66882aa18983eb35abca45207e37316)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index dcad1df04..8e46f30f7 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -53,7 +53,7 @@
 #include "linux-dmabuf-unstable-v1-client-protocol.h"
 
 struct xwl_gbm_private {
-    dev_t device;
+    drmDevice *device;
     char *device_name;
     struct gbm_device *gbm;
     struct wl_drm *drm;
@@ -460,6 +460,7 @@ xwl_glamor_gbm_cleanup(struct xwl_screen *xwl_screen)
 
     if (xwl_gbm->device_name)
         free(xwl_gbm->device_name);
+    drmFreeDevice(&xwl_gbm->device);
     if (xwl_gbm->drm_fd)
         close(xwl_gbm->drm_fd);
     if (xwl_gbm->drm)
@@ -784,7 +785,6 @@ xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
    struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
    drm_magic_t magic;
    char *render_node_path = NULL;
-   struct stat stat;
 
    if (!is_device_path_render_node(device))
        render_node_path = get_render_node_path(device);
@@ -807,12 +807,11 @@ xwl_drm_handle_device(void *data, struct wl_drm *drm, const char *device)
        return;
    }
 
-   if (fstat(xwl_gbm->drm_fd, &stat)) {
-       ErrorF("wayland-egl: Could not stat file %s (%s)\n",
-              xwl_gbm->device_name, strerror(errno));
+   if (drmGetDevice2(xwl_gbm->drm_fd, 0, &xwl_gbm->device) != 0) {
+       ErrorF("wayland-egl: Could not fetch DRM device %s\n",
+              xwl_gbm->device_name);
        return;
    }
-   xwl_gbm->device = stat.st_rdev;
 
    if (drmGetNodeTypeFromFd(xwl_gbm->drm_fd) == DRM_NODE_RENDER) {
        xwl_gbm->fd_render_node = 1;
@@ -1111,7 +1110,7 @@ error:
     return FALSE;
 }
 
-static dev_t xwl_gbm_get_main_device(struct xwl_screen *xwl_screen)
+static drmDevice *xwl_gbm_get_main_device(struct xwl_screen *xwl_screen)
 {
     struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen);
 
diff --git a/hw/xwayland/xwayland-glamor.c b/hw/xwayland/xwayland-glamor.c
index e7cc7eaf0..edb028978 100644
--- a/hw/xwayland/xwayland-glamor.c
+++ b/hw/xwayland/xwayland-glamor.c
@@ -187,7 +187,7 @@ wl_drm_format_for_depth(int depth)
     }
 }
 
-static dev_t
+static drmDevice *
 xwl_screen_get_main_dev(struct xwl_screen *xwl_screen)
 {
     /*
@@ -222,7 +222,7 @@ xwl_get_formats(struct xwl_format *format_array, int format_array_len,
 }
 
 static Bool
-xwl_get_formats_for_device(struct xwl_dmabuf_feedback *xwl_feedback, dev_t device,
+xwl_get_formats_for_device(struct xwl_dmabuf_feedback *xwl_feedback, drmDevice *device,
                            uint32_t *num_formats, uint32_t **formats)
 {
     uint32_t *ret = NULL;
@@ -230,7 +230,7 @@ xwl_get_formats_for_device(struct xwl_dmabuf_feedback *xwl_feedback, dev_t devic
 
     /* go through all matching sets of tranches for the window's device */
     for (int i = 0; i < xwl_feedback->dev_formats_len; i++) {
-        if (xwl_feedback->dev_formats[i].drm_dev == device) {
+        if (drmDevicesEqual(xwl_feedback->dev_formats[i].drm_dev, device)) {
             struct xwl_device_formats *dev_formats = &xwl_feedback->dev_formats[i];
 
             /* Append the formats from this tranche to the list */
@@ -273,7 +273,7 @@ xwl_glamor_get_formats(ScreenPtr screen,
         return FALSE;
 
     if (xwl_screen->dmabuf_protocol_version >= 4) {
-        dev_t main_dev = xwl_screen_get_main_dev(xwl_screen);
+        drmDevice *main_dev = xwl_screen_get_main_dev(xwl_screen);
 
         return xwl_get_formats_for_device(&xwl_screen->default_feedback, main_dev,
                                           num_formats, formats);
@@ -320,7 +320,7 @@ xwl_get_modifiers_for_format(struct xwl_format *format_array, int num_formats,
 }
 
 static Bool
-xwl_get_modifiers_for_device(struct xwl_dmabuf_feedback *feedback, dev_t device,
+xwl_get_modifiers_for_device(struct xwl_dmabuf_feedback *feedback, drmDevice *device,
                              uint32_t format, uint32_t *num_modifiers,
                              uint64_t **modifiers)
 {
@@ -328,7 +328,7 @@ xwl_get_modifiers_for_device(struct xwl_dmabuf_feedback *feedback, dev_t device,
     for (int i = 0; i < feedback->dev_formats_len; i++) {
         struct xwl_device_formats *dev_formats = &feedback->dev_formats[i];
 
-        if (dev_formats->drm_dev == device &&
+        if (drmDevicesEqual(dev_formats->drm_dev, device) &&
             xwl_get_modifiers_for_format(dev_formats->formats, dev_formats->num_formats,
                                          format, num_modifiers, modifiers))
             return TRUE;
@@ -342,7 +342,7 @@ xwl_glamor_get_modifiers(ScreenPtr screen, uint32_t format,
                          uint32_t *num_modifiers, uint64_t **modifiers)
 {
     struct xwl_screen *xwl_screen = xwl_screen_get(screen);
-    dev_t main_dev;
+    drmDevice *main_dev;
 
     /* Explicitly zero the count as the caller may ignore the return value */
     *num_modifiers = 0;
@@ -368,7 +368,7 @@ xwl_glamor_get_drawable_modifiers(DrawablePtr drawable, uint32_t format,
 {
     struct xwl_screen *xwl_screen = xwl_screen_get(drawable->pScreen);
     struct xwl_window *xwl_window;
-    dev_t main_dev;
+    drmDevice *main_dev;
 
     *num_modifiers = 0;
     *modifiers = NULL;
@@ -475,11 +475,15 @@ xwl_dmabuf_feedback_main_device(void *data,
                                 struct wl_array *dev)
 {
     struct xwl_dmabuf_feedback *xwl_feedback = data;
+    dev_t devid;
 
     xwl_check_reset_tranche_info(xwl_feedback);
 
     assert(dev->size == sizeof(dev_t));
-    memcpy(&xwl_feedback->main_dev, dev->data, sizeof(dev_t));
+    memcpy(&devid, dev->data, sizeof(dev_t));
+
+    if (drmGetDeviceFromDevId(devid, 0, &xwl_feedback->main_dev) != 0)
+        ErrorF("linux_dmabuf_feedback.main_device: Failed to fetch DRM device\n");
 }
 
 static void
@@ -488,11 +492,15 @@ xwl_dmabuf_feedback_tranche_target_device(void *data,
                                           struct wl_array *dev)
 {
     struct xwl_dmabuf_feedback *xwl_feedback = data;
+    dev_t devid;
 
     xwl_check_reset_tranche_info(xwl_feedback);
 
     assert(dev->size == sizeof(dev_t));
-    memcpy(&xwl_feedback->tmp_tranche.drm_dev, dev->data, sizeof(dev_t));
+    memcpy(&devid, dev->data, sizeof(dev_t));
+
+    if (drmGetDeviceFromDevId(devid, 0, &xwl_feedback->tmp_tranche.drm_dev) != 0)
+        ErrorF("linux_dmabuf_feedback.tranche_target_device: Failed to fetch DRM device\n");
 }
 
 static void
@@ -564,6 +572,11 @@ xwl_dmabuf_feedback_tranche_done(void *data,
      * triggered first
      */
 
+    if (xwl_feedback->tmp_tranche.drm_dev == NULL) {
+        xwl_device_formats_destroy(&xwl_feedback->tmp_tranche);
+        goto out;
+    }
+
     /*
      * First check if there is an existing tranche for this device+flags combo. We
      * will combine it with this tranche, since we can only send one modifier list
@@ -598,6 +611,7 @@ xwl_dmabuf_feedback_tranche_done(void *data,
                sizeof(struct xwl_device_formats));
     }
 
+out:
     /* reset the tranche */
     memset(&xwl_feedback->tmp_tranche, 0, sizeof(struct xwl_device_formats));
 }
diff --git a/hw/xwayland/xwayland-glamor.h b/hw/xwayland/xwayland-glamor.h
index aed65b50f..0ecd25b38 100644
--- a/hw/xwayland/xwayland-glamor.h
+++ b/hw/xwayland/xwayland-glamor.h
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 
 #include <wayland-client.h>
+#include <xf86drm.h>
 
 #include "xwayland-types.h"
 
@@ -99,10 +100,10 @@ struct xwl_egl_backend {
      */
     Bool (*check_flip)(PixmapPtr pixmap);
 
-    /* Called to get the dev_t of the primary GPU that this backend
+    /* Called to get the DRM device of the primary GPU that this backend
      * is set up on.
      */
-    dev_t (*get_main_device)(struct xwl_screen *xwl_screen);
+    drmDevice *(*get_main_device)(struct xwl_screen *xwl_screen);
 };
 
 #ifdef XWL_HAS_GLAMOR
diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c
index eba81b8cb..e159743a0 100644
--- a/hw/xwayland/xwayland-window.c
+++ b/hw/xwayland/xwayland-window.c
@@ -1014,6 +1014,7 @@ xwl_device_formats_destroy(struct xwl_device_formats *dev_formats)
     for (int j = 0; j < dev_formats->num_formats; j++)
         free(dev_formats->formats[j].modifiers);
     free(dev_formats->formats);
+    drmFreeDevice(&dev_formats->drm_dev);
 }
 
 void
diff --git a/hw/xwayland/xwayland-window.h b/hw/xwayland/xwayland-window.h
index c5c42f097..65dfb69ff 100644
--- a/hw/xwayland/xwayland-window.h
+++ b/hw/xwayland/xwayland-window.h
@@ -38,6 +38,7 @@
 #include <propertyst.h>
 #include <validate.h>
 #include <wayland-util.h>
+#include <xf86drm.h>
 
 #include "xwayland-types.h"
 
@@ -54,7 +55,7 @@ struct xwl_format_table_entry {
 };
 
 struct xwl_device_formats {
-    dev_t drm_dev;
+    drmDevice *drm_dev;
     int supports_scanout;
     uint32_t num_formats;
     struct xwl_format *formats;
@@ -74,7 +75,7 @@ struct xwl_format_table {
 struct xwl_dmabuf_feedback {
     struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback;
     struct xwl_format_table format_table;
-    dev_t main_dev;
+    drmDevice *main_dev;
     /*
      * This will be filled in during wl events and copied to
      * dev_formats on dmabuf_feedback.tranche_done
commit bdb023b34af5ef519fd8dc621b6e29f0c25d3612
Author: Austin Shafer <ashafer at nvidia.com>
Date:   Fri Sep 2 11:54:05 2022 -0400

    Add libdrm 2.4.109 requirement
    
    Reviewed-by: Olivier Fourdan <ofourdan at redhat.com>
    (cherry picked from commit 5a742ab8763d7b041c427f1d725f6bbd7ae82fa1)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3658fd76d..aebb3038a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,7 +19,7 @@ variables:
     FDO_UPSTREAM_REPO: xorg/xserver
     FDO_DISTRIBUTION_VERSION: bullseye-slim
     FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/debian-install.sh'
-    FDO_DISTRIBUTION_TAG: "2023-02-09-no-mingw"
+    FDO_DISTRIBUTION_TAG: "2023-02-02-libdrm-update"
 
 include:
   - project: 'freedesktop/ci-templates'
diff --git a/.gitlab-ci/debian-install.sh b/.gitlab-ci/debian-install.sh
index 239608a99..9dcb405bb 100644
--- a/.gitlab-ci/debian-install.sh
+++ b/.gitlab-ci/debian-install.sh
@@ -107,6 +107,14 @@ apt-get install -y \
 
 cd /root
 
+# Xwayland requires drm 2.4.109 for drmGetDeviceFromDevId
+git clone https://gitlab.freedesktop.org/mesa/drm --depth 1 --branch=libdrm-2.4.109
+cd drm
+meson _build
+ninja -C _build -j${FDO_CI_CONCURRENT:-4} install
+cd ..
+rm -rf drm
+
 # xserver requires libxcvt
 git clone https://gitlab.freedesktop.org/xorg/lib/libxcvt.git --depth 1 --branch=libxcvt-0.1.0
 cd libxcvt
diff --git a/meson.build b/meson.build
index 12dbaff23..08779bd5a 100644
--- a/meson.build
+++ b/meson.build
@@ -60,7 +60,7 @@ endforeach
 
 add_project_arguments(common_wflags, language : ['c', 'objc'])
 
-libdrm_req = '>= 2.4.89'
+libdrm_req = '>= 2.4.109'
 libselinux_req = '>= 2.0.86'
 xext_req = '>= 1.0.99.4'
 wayland_req = '>= 1.21.0'
commit 2b441cea76c32efc0a3360761947f86309604c31
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Mar 2 10:12:25 2023 +0100

    xwayland: Use MAP_PRIVATE for keymaps
    
    With wl_pointer.axis_v120 support, the wl_seat supported version has
    been bumped to 8, but Xwayland is still using MAP_SHARED which is
    prohibited, wl_seat version 7 and above enforces the use of MAP_PRIVATE
    for keymaps.
    
    Use MAP_PRIVATE for the keymaps mmap().
    
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1512
    Fixes: 3a02f56b4 - hook up wl_pointer.axis_v120 events
    (cherry picked from commit d5dd3f3ceea30034e0bde1d11b460149c9373b93)

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 862544866..6e0600e4e 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -1110,7 +1110,7 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
         munmap(xwl_seat->keymap, xwl_seat->keymap_size);
 
     xwl_seat->keymap_size = size;
-    xwl_seat->keymap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+    xwl_seat->keymap = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
     if (xwl_seat->keymap == MAP_FAILED) {
         xwl_seat->keymap_size = 0;
         xwl_seat->keymap = NULL;
commit e1133bcd52889cac541ca9f15c9d516d3a1d1578
Author: Simon Ser <contact at emersion.fr>
Date:   Mon Feb 27 14:43:49 2023 +0100

    xwayland: don't fall back to wl_drm with explicit modifier
    
    It's incorrect to strip an explicit modifier. Daniels' docs [1]
    states:
    
    > when importing a buffer, the user may supply `DRM_FORMAT_MOD_INVALID` as the
    > buffer modifier (or not supply a modifier) to indicate that the modifier is
    > unknown for whatever reason; this is only acceptable when the buffer has
    > not been allocated with an explicit modifier
    
    [1]: https://lore.kernel.org/dri-devel/20210905122742.86029-1-daniels@collabora.com/
    
    Signed-off-by: Simon Ser <contact at emersion.fr>
    (cherry picked from commit c6f2598a4e62ea6c0d5244faf1488b20985df908)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 2d42bbba3..dcad1df04 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -433,7 +433,7 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
            zwp_linux_buffer_params_v1_create_immed(params, width, height,
                                                    format, 0);
         zwp_linux_buffer_params_v1_destroy(params);
-    } else if (num_planes == 1) {
+    } else if (num_planes == 1 && modifier == DRM_FORMAT_MOD_INVALID) {
         xwl_pixmap->buffer =
             wl_drm_create_prime_buffer(xwl_gbm->drm, prime_fds[0], width, height,
                                        format,
commit fd27fc3f2226fc62cf0af272609291a74e4d85d4
Author: Simon Ser <contact at emersion.fr>
Date:   Mon Feb 27 14:41:37 2023 +0100

    xwayland: fix error path when modifier is not supported
    
    When the modifier is not supported by the compositor, and the
    DMA-BUF contains multiple planes, xwl_pixmap->buffer is NULL.
    Avoid crashing when calling wl_buffer_add_listener().
    
    Signed-off-by: Simon Ser <contact at emersion.fr>
    (cherry picked from commit 76a329e55c34e2d60a0b1d92bf61bbf3baf5dd41)

diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c
index 3984d0b38..2d42bbba3 100644
--- a/hw/xwayland/xwayland-glamor-gbm.c
+++ b/hw/xwayland/xwayland-glamor-gbm.c
@@ -446,8 +446,9 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap)
         close(prime_fds[i]);
 
     /* Add our listener now */
-    wl_buffer_add_listener(xwl_pixmap->buffer,
-                           &xwl_glamor_gbm_buffer_listener, pixmap);
+    if (xwl_pixmap->buffer)
+        wl_buffer_add_listener(xwl_pixmap->buffer,
+                               &xwl_glamor_gbm_buffer_listener, pixmap);
 
     return xwl_pixmap->buffer;
 }
commit 29d75b092b08d7fb1b5a68ac151d4c005a410bf7
Author: Olivier Fourdan <ofourdan at redhat.com>
Date:   Thu Feb 23 08:40:15 2023 +0100

    xwayland: Include <sys/type.h> where needed
    
    With the addition of linux_dmabuf v4, the code adds dev_t in various
    places but did not include <sys/types.h>.
    
    While that works on glibc, it may fail to build on other libc
    implementations such as musl libc.
    
    Make sure to explicitly include <sys/types.h> where we use dev_t.
    
    Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
    Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1445
    Fixes: bddfe190de - Implement linux_dmabuf_feedback event handlers
    (cherry picked from commit 24171bb71010a90f1ac323be49121c1503658567)

diff --git a/hw/xwayland/xwayland-glamor.h b/hw/xwayland/xwayland-glamor.h
index ed9ec40de..aed65b50f 100644
--- a/hw/xwayland/xwayland-glamor.h
+++ b/hw/xwayland/xwayland-glamor.h
@@ -28,6 +28,8 @@
 
 #include <xwayland-config.h>
 
+#include <sys/types.h>
+
 #include <wayland-client.h>
 
 #include "xwayland-types.h"
diff --git a/hw/xwayland/xwayland-window.h b/hw/xwayland/xwayland-window.h
index 2e8313f56..c5c42f097 100644
--- a/hw/xwayland/xwayland-window.h
+++ b/hw/xwayland/xwayland-window.h
@@ -28,8 +28,11 @@
 
 #include <xwayland-config.h>
 
+#include <sys/types.h>
+
 #include <stdio.h>
 #include <unistd.h>
+
 #include <X11/X.h>
 #include <dix.h>
 #include <propertyst.h>


More information about the xorg-commit mailing list