From 3fe4107643ba029dd48e3d12ec9bc97d07112300 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Thu, 8 Sep 2016 09:30:31 +0200 Subject: glamor: Fix crash when master gpu is using glamor and another gpu is hotplugged When a GPU gets hotplugged while X is already running, glamor_egl_init() gets called and changes the current egl context, without updating lastGLContext, potentially causing the next glamor call on another GPU to run in the wrong context. This causes glamor to e.g. crash in the next glamor_create_pixmap() call (called through the master's screen->CreatePixmap), note this is not the only troublesome entry point I've seen other backtraces when using a compositing window manager. Set lastGLContext to NULL to force the next glamor_make_current() call to set the right context. Note that we cannot use glamor_make_current() here to replace the eglMakeCurrent() call and update lastGLContext for us because glamor_make_current takes a glamor_priv struct as argument and that has not been created yet when glamor_egl_init() gets called. Signed-off-by: Hans de Goede Reviewed-by: Keith Packard --- glamor/glamor_egl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c index 16a20a7f8..2b9e0e109 100644 --- a/glamor/glamor_egl.c +++ b/glamor/glamor_egl.c @@ -703,6 +703,11 @@ static void glamor_egl_cleanup(struct glamor_egl_screen_private *glamor_egl) if (glamor_egl->display != EGL_NO_DISPLAY) { eglMakeCurrent(glamor_egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + /* + * Force the next glamor_make_current call to update the context + * (on hot unplug another GPU may still be using glamor) + */ + lastGLContext = NULL; eglTerminate(glamor_egl->display); } #ifdef GLAMOR_HAS_GBM @@ -831,6 +836,11 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) "Failed to make EGL context current\n"); goto error; } + /* + * Force the next glamor_make_current call to set the right context + * (in case of multiple GPUs using glamor) + */ + lastGLContext = NULL; #ifdef GLAMOR_HAS_GBM if (epoxy_has_egl_extension(glamor_egl->display, "EGL_KHR_gl_texture_2D_image") && -- cgit v1.2.3