<div dir="ltr"><div>Would you please review this fixed version:</div><div><a href="https://cgit.freedesktop.org/~mareko/mesa/commit/?h=master&id=40e4702ef815410f74130f349e2b40cc0524e422">https://cgit.freedesktop.org/~mareko/mesa/commit/?h=master&id=40e4702ef815410f74130f349e2b40cc0524e422</a></div><div><br></div><div>It trivially solves the GBM crash by checking that gbm_surf != NULL before using it.</div><div><br></div><div>Marek<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 20, 2019 at 3:03 PM Mathias Fröhlich <<a href="mailto:Mathias.Froehlich@gmx.net">Mathias.Froehlich@gmx.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I did not have time to really look into the series, but a quick retest:<br>
<br>
wflinfo --platform=gbm -a gl<br>
<br>
still crashes on my site.<br>
Can you recheck that?<br>
<br>
best<br>
<br>
Mathias<br>
<br>
On Thursday, 16 May 2019 19:01:38 CEST Emil Velikov wrote:<br>
> From: Emil Velikov <<a href="mailto:emil.velikov@collabora.com" target="_blank">emil.velikov@collabora.com</a>><br>
> <br>
> Wrap the loader->createNewDrawable() dance into a helper and use it<br>
> throughout the codebase.<br>
> <br>
> This addresses a cases like surfaceless (SL) on swrast (SL on kms_swrast<br>
> is fine) where we'd attempt using the wrong driver and crash out.<br>
> <br>
> v2: fixup quirky GBM (Mathias)<br>
> <br>
> Cc: <a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop.org</a><br>
> Cc: Mathias Fröhlich <<a href="mailto:Mathias.Froehlich@web.de" target="_blank">Mathias.Froehlich@web.de</a>><br>
> Reviewed-by: Mathias Fröhlich <<a href="mailto:Mathias.Froehlich@web.de" target="_blank">Mathias.Froehlich@web.de</a>> (v1)<br>
> Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>> (v1)<br>
> Signed-off-by: Emil Velikov <<a href="mailto:emil.velikov@collabora.com" target="_blank">emil.velikov@collabora.com</a>><br>
> ---<br>
>  src/egl/drivers/dri2/egl_dri2.c             | 39 +++++++++++++++++++++<br>
>  src/egl/drivers/dri2/egl_dri2.h             |  5 +++<br>
>  src/egl/drivers/dri2/platform_android.c     | 12 +------<br>
>  src/egl/drivers/dri2/platform_drm.c         | 17 +--------<br>
>  src/egl/drivers/dri2/platform_surfaceless.c |  7 +---<br>
>  src/egl/drivers/dri2/platform_wayland.c     | 14 +-------<br>
>  src/egl/drivers/dri2/platform_x11.c         | 15 +-------<br>
>  7 files changed, 49 insertions(+), 60 deletions(-)<br>
> <br>
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c<br>
> index 09d6315b19e..17a0176b646 100644<br>
> --- a/src/egl/drivers/dri2/egl_dri2.c<br>
> +++ b/src/egl/drivers/dri2/egl_dri2.c<br>
> @@ -1425,6 +1425,45 @@ dri2_surf_update_fence_fd(_EGLContext *ctx,<br>
>     dri2_surface_set_out_fence_fd(surf, fence_fd);<br>
>  }<br>
>  <br>
> +static inline _EGLDisplay *<br>
> +dri2_display_to_egl_display(struct dri2_egl_display *dri2_dpy)<br>
> +{<br>
> +   const size_t offset = offsetof(_EGLDisplay, DriverData);<br>
> +   return (_EGLDisplay *)(((void*) dri2_dpy) - offset);<br>
> +}<br>
> +<br>
> +EGLBoolean<br>
> +dri2_create_drawable(struct dri2_egl_display *dri2_dpy,<br>
> +                     const __DRIconfig *config,<br>
> +                     struct dri2_egl_surface *dri2_surf)<br>
> +{<br>
> +   __DRIcreateNewDrawableFunc createNewDrawable;<br>
> +   _EGLDisplay *disp = dri2_display_to_egl_display(dri2_dpy);<br>
> +   void *loaderPrivate = dri2_surf;<br>
> +<br>
> +   if (dri2_dpy->image_driver)<br>
> +      createNewDrawable = dri2_dpy->image_driver->createNewDrawable;<br>
> +   else if (dri2_dpy->dri2)<br>
> +      createNewDrawable = dri2_dpy->dri2->createNewDrawable;<br>
> +   else if (dri2_dpy->swrast)<br>
> +      createNewDrawable = dri2_dpy->swrast->createNewDrawable;<br>
> +   else<br>
> +      return _eglError(EGL_BAD_ALLOC, "no createNewDrawable");<br>
> +<br>
> +   /* As always gbm is a bit special.. */<br>
> +#ifdef HAVE_DRM_PLATFORM<br>
> +   if (disp->Platform == _EGL_PLATFORM_DRM)<br>
> +      loaderPrivate = dri2_surf->gbm_surf;<br>
> +#endif<br>
> +<br>
> +   dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen,<br>
> +                                                  config, loaderPrivate);<br>
> +   if (dri2_surf->dri_drawable == NULL)<br>
> +      return _eglError(EGL_BAD_ALLOC, "createNewDrawable");<br>
> +<br>
> +   return EGL_TRUE;<br>
> +}<br>
> +<br>
>  /**<br>
>   * Called via eglMakeCurrent(), drv->API.MakeCurrent().<br>
>   */<br>
> diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h<br>
> index 4918517b572..5555bcea3ab 100644<br>
> --- a/src/egl/drivers/dri2/egl_dri2.h<br>
> +++ b/src/egl/drivers/dri2/egl_dri2.h<br>
> @@ -541,6 +541,11 @@ dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,<br>
>  void<br>
>  dri2_fini_surface(_EGLSurface *surf);<br>
>  <br>
> +EGLBoolean<br>
> +dri2_create_drawable(struct dri2_egl_display *dri2_dpy,<br>
> +                     const __DRIconfig *config,<br>
> +                     struct dri2_egl_surface *dri2_surf);<br>
> +<br>
>  static inline uint64_t<br>
>  combine_u32_into_u64(uint32_t hi, uint32_t lo)<br>
>  {<br>
> diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c<br>
> index fece214d939..e44447c7df7 100644<br>
> --- a/src/egl/drivers/dri2/platform_android.c<br>
> +++ b/src/egl/drivers/dri2/platform_android.c<br>
> @@ -341,7 +341,6 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,<br>
>                   _EGLConfig *conf, void *native_window,<br>
>                   const EGLint *attrib_list)<br>
>  {<br>
> -   __DRIcreateNewDrawableFunc createNewDrawable;<br>
>     struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);<br>
>     struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);<br>
>     struct dri2_egl_surface *dri2_surf;<br>
> @@ -386,17 +385,8 @@ droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,<br>
>        goto cleanup_surface;<br>
>     }<br>
>  <br>
> -   if (dri2_dpy->image_driver)<br>
> -      createNewDrawable = dri2_dpy->image_driver->createNewDrawable;<br>
> -   else<br>
> -      createNewDrawable = dri2_dpy->dri2->createNewDrawable;<br>
> -<br>
> -   dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,<br>
> -                                                  dri2_surf);<br>
> -   if (dri2_surf->dri_drawable == NULL) {<br>
> -      _eglError(EGL_BAD_ALLOC, "createNewDrawable");<br>
> +   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf))<br>
>        goto cleanup_surface;<br>
> -   }<br>
>  <br>
>     if (window) {<br>
>        window->common.incRef(&window->common);<br>
> diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c<br>
> index 7d916fe92b7..c59b9341d87 100644<br>
> --- a/src/egl/drivers/dri2/platform_drm.c<br>
> +++ b/src/egl/drivers/dri2/platform_drm.c<br>
> @@ -171,23 +171,8 @@ dri2_drm_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,<br>
>     dri2_surf->base.Height = surf->base.height;<br>
>     surf->dri_private = dri2_surf;<br>
>  <br>
> -   if (dri2_dpy->dri2) {<br>
> -      dri2_surf->dri_drawable =<br>
> -         dri2_dpy->dri2->createNewDrawable(dri2_dpy->dri_screen, config,<br>
> -                                           dri2_surf->gbm_surf);<br>
> -<br>
> -   } else {<br>
> -      assert(dri2_dpy->swrast != NULL);<br>
> -<br>
> -      dri2_surf->dri_drawable =<br>
> -         dri2_dpy->swrast->createNewDrawable(dri2_dpy->dri_screen, config,<br>
> -                                             dri2_surf->gbm_surf);<br>
> -<br>
> -   }<br>
> -   if (dri2_surf->dri_drawable == NULL) {<br>
> -      _eglError(EGL_BAD_ALLOC, "createNewDrawable()");<br>
> +   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf))<br>
>        goto cleanup_surf;<br>
> -   }<br>
>  <br>
>     return &dri2_surf->base;<br>
>  <br>
> diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c<br>
> index 27b1d44ebec..ce9f7d0f980 100644<br>
> --- a/src/egl/drivers/dri2/platform_surfaceless.c<br>
> +++ b/src/egl/drivers/dri2/platform_surfaceless.c<br>
> @@ -136,13 +136,8 @@ dri2_surfaceless_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,<br>
>        goto cleanup_surface;<br>
>     }<br>
>  <br>
> -   dri2_surf->dri_drawable =<br>
> -      dri2_dpy->image_driver->createNewDrawable(dri2_dpy->dri_screen, config,<br>
> -                                                dri2_surf);<br>
> -   if (dri2_surf->dri_drawable == NULL) {<br>
> -      _eglError(EGL_BAD_ALLOC, "image->createNewDrawable");<br>
> +   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf))<br>
>        goto cleanup_surface;<br>
> -    }<br>
>  <br>
>     if (conf->RedSize == 5)<br>
>        dri2_surf->visual = __DRI_IMAGE_FORMAT_RGB565;<br>
> diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c<br>
> index 0f5d85be326..fb5ecdab2c5 100644<br>
> --- a/src/egl/drivers/dri2/platform_wayland.c<br>
> +++ b/src/egl/drivers/dri2/platform_wayland.c<br>
> @@ -272,7 +272,6 @@ dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,<br>
>                                _EGLConfig *conf, void *native_window,<br>
>                                const EGLint *attrib_list)<br>
>  {<br>
> -   __DRIcreateNewDrawableFunc createNewDrawable;<br>
>     struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);<br>
>     struct dri2_egl_config *dri2_conf = dri2_egl_config(conf);<br>
>     struct wl_egl_window *window = native_window;<br>
> @@ -349,19 +348,8 @@ dri2_wl_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,<br>
>     if (dri2_dpy->flush)<br>
>        dri2_surf->wl_win->resize_callback = resize_callback;<br>
>  <br>
> -   if (dri2_dpy->image_driver)<br>
> -      createNewDrawable = dri2_dpy->image_driver->createNewDrawable;<br>
> -   else if (dri2_dpy->dri2)<br>
> -      createNewDrawable = dri2_dpy->dri2->createNewDrawable;<br>
> -   else<br>
> -      createNewDrawable = dri2_dpy->swrast->createNewDrawable;<br>
> -<br>
> -   dri2_surf->dri_drawable = (*createNewDrawable)(dri2_dpy->dri_screen, config,<br>
> -                                                  dri2_surf);<br>
> -    if (dri2_surf->dri_drawable == NULL) {<br>
> -      _eglError(EGL_BAD_ALLOC, "createNewDrawable");<br>
> +   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf))<br>
>         goto cleanup_surf_wrapper;<br>
> -    }<br>
>  <br>
>     dri2_surf->base.SwapInterval = dri2_dpy->default_swap_interval;<br>
>  <br>
> diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c<br>
> index 538cffd6a76..be9eb513243 100644<br>
> --- a/src/egl/drivers/dri2/platform_x11.c<br>
> +++ b/src/egl/drivers/dri2/platform_x11.c<br>
> @@ -290,21 +290,8 @@ dri2_x11_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,<br>
>        goto cleanup_pixmap;<br>
>     }<br>
>  <br>
> -   if (dri2_dpy->dri2) {<br>
> -      dri2_surf->dri_drawable =<br>
> -         dri2_dpy->dri2->createNewDrawable(dri2_dpy->dri_screen, config,<br>
> -                                           dri2_surf);<br>
> -   } else {<br>
> -      assert(dri2_dpy->swrast);<br>
> -      dri2_surf->dri_drawable = <br>
> -         dri2_dpy->swrast->createNewDrawable(dri2_dpy->dri_screen, config,<br>
> -                                             dri2_surf);<br>
> -   }<br>
> -<br>
> -   if (dri2_surf->dri_drawable == NULL) {<br>
> -      _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable");<br>
> +   if (!dri2_create_drawable(dri2_dpy, config, dri2_surf))<br>
>        goto cleanup_pixmap;<br>
> -   }<br>
>  <br>
>     if (type != EGL_PBUFFER_BIT) {<br>
>        cookie = xcb_get_geometry (dri2_dpy->conn, dri2_surf->drawable);<br>
> <br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
mesa-stable mailing list<br>
<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-stable" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-stable</a></blockquote></div>