Bug 97214

Summary: X not running with error "Failed to make EGL context current"
Product: Mesa Reporter: Alexandr Zelinsky <mexahotabop>
Component: EGLAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium CC: chadversary, drinkcat, emil.l.velikov, mexahotabop
Version: gitKeywords: bisected
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: xinit log with LIBGL_DEBUG=verbose
EGL_LOG_LEVEL=debug
Add tracing to egl_dri2.c
EGL_LOG_LEVEL=debug with patches
More tracing in egl_dri2.c
Possible fix

Description Alexandr Zelinsky 2016-08-05 11:24:26 UTC
bisected in commit 9ee683f877b283020c6f24776236f1145cb7a4ea
xorg log https://bpaste.net/show/1bede21ad143
Comment 1 Nicolas Boichat 2016-08-07 07:24:53 UTC
Not sure what's going on, but, as a first step, can you try to apply these 2 patches?

https://patchwork.freedesktop.org/patch/101934/
https://patchwork.freedesktop.org/patch/102770/
Comment 2 Alexandr Zelinsky 2016-08-07 11:48:05 UTC
didnt help 
same error
Comment 3 Nicolas Boichat 2016-08-09 09:30:19 UTC
Ok, thanks for trying those out.

Can you try again, setting LIBGL_DEBUG=verbose ? Hopefully that'll give us more logs and a better idea of what is going on...
Comment 4 Alexandr Zelinsky 2016-08-09 13:48:14 UTC
Created attachment 125637 [details]
xinit log with LIBGL_DEBUG=verbose

seems not very usefull
what your nickname on #dri-devel?
Comment 5 Michel Dänzer 2016-08-09 14:06:59 UTC
Try EGL_LOG_LEVEL=debug as well.
Comment 6 Alexandr Zelinsky 2016-08-09 14:10:02 UTC
Created attachment 125640 [details]
EGL_LOG_LEVEL=debug
Comment 7 Nicolas Boichat 2016-08-09 17:07:19 UTC
Created attachment 125643 [details] [review]
Add tracing to egl_dri2.c

libEGL debug: EGL user error 0x3001 (EGL_NOT_INITIALIZED) in eglMakeCurrent

Is due to the new code in dri2_make_current:
   if (!dri2_dpy)
      return _eglError(EGL_NOT_INITIALIZED, "eglMakeCurrent");

I don't quite understand how dri2_dpy could end up being uninitialized, unless eglMakeCurrent is called after eglTerminate...

I'd start by adding traces in dri2_initialize, dri2_terminate, dri2_make_current, which is what this patch does...
Comment 8 Alexandr Zelinsky 2016-08-09 17:25:09 UTC
Created attachment 125644 [details]
EGL_LOG_LEVEL=debug with patches
Comment 9 Nicolas Boichat 2016-08-09 18:26:46 UTC
Created attachment 125647 [details] [review]
More tracing in egl_dri2.c

I see. When the second display is initialized, there is still an active context, it seems (dri2_display_release should not be called on the first call to dri2_make_current):

libEGL debug: Native platform type: drm (autodetected)
libEGL debug: dri2_initialize 0x90d7a0 0x9a2f10 (dri2_dpy=(null))
libEGL debug: the best driver is DRI2
libEGL debug: EGL user error 0x3009 (EGL_BAD_MATCH) in dri2_create_context
libEGL debug: dri2_make_current 0x90d7a0 0x9a2f10 (nil) (nil) 0x99dbf0
libEGL debug: dri2_display_release 0x9a2f10 2
refcount -> 1

This causes the reference count to drop to zero later on:
libEGL debug: dri2_make_current 0x90d7a0 0x9a2f10 (nil) (nil) (nil)
libEGL debug: dri2_display_release 0x9a2f10 1
refcount -> 0 => display is destroyed
libEGL debug: dri2_make_current 0x90d7a0 0x9a2f10 (nil) (nil) 0x99dbf0
libEGL debug: EGL user error 0x3001 (EGL_NOT_INITIALIZED) in eglMakeCurrent

One more patch to confirm this.
Comment 10 Nicolas Boichat 2016-08-09 20:00:46 UTC
Created attachment 125652 [details] [review]
Possible fix

Possible fix attached, please give it a try. Thanks!
Comment 11 Alexandr Zelinsky 2016-08-09 23:25:02 UTC
fix working
if you need logs with last tracing patch https://bpaste.net/show/6b49674b4e26
Comment 12 Nicolas Boichat 2016-08-10 06:01:20 UTC
Patch on list here https://patchwork.freedesktop.org/patch/104229/, thanks for testing!
Comment 13 Michel Dänzer 2016-08-16 08:32:41 UTC
Module: Mesa
Branch: master
Commit: 78e3cea4197802253401766fc44362786898e024
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=78e3cea4197802253401766fc44362786898e024

Author: Nicolas Boichat <drinkcat@chromium.org>
Date:   Thu Aug 11 16:43:32 2016 +0800

egl/dri2: dri2_make_current: Release previous context's display

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.