Segfault/Valgrind errors in multithreaded OpenGL context sharing scenario
System information
- OS: Ubuntu 18.04.3 LTS
- GPU: Nvidia
- Mesa version: Mesa 20.0.8
Describe the issue
OpenGL 3.1 application with mutiple contextes and context sharing. All contextes are created by the main thread which is also the render thread using eglCreateContext, then passed to the background worker threads who make them their own using eglMakeCurrent. Worker threads create buffers with OpenGL sync objects via glFenceSync followed by glClientWaitSync. Buffer is passed to the main thread which waits for the fences using glWaitSync. Application crashes with segfault after short time, usually with double free error malloc message, usually in glClientWaitSync. A run with valgrind procued some invalid read errors.
Regression
Did it used to work? It can greatly help to know when the issue started.
Log files as attachment
Valgrind output:
==22413== Invalid read of size 8
==22413== at 0x2294F04C: nouveau_fence_kick (nouveau_fence.c:164)
==22413== by 0x2294F176: nouveau_fence_wait (nouveau_fence.c:200)
==22413== by 0x22150270: dri_flush (dri_drawable.c:530)
==22413== by 0x20DB9147: dri2_x11_swap_buffers_msc (platform_x11.c:903)
==22413== by 0x20DB9147: dri2_x11_swap_buffers (platform_x11.c:945)
==22413== by 0x20DB3D17: dri2_swap_buffers (egl_dri2.c:1932)
==22413== by 0x20DAB68D: eglSwapBuffers (eglapi.c:1340)
==22413== Address 0x3352d508 is 8 bytes inside a block of size 48 free'd
==22413== at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22413== by 0x22975AFB: nouveau_fence_ref (nouveau_fence.h:53)
==22413== by 0x22975AFB: nv50_resource_fence (nv50_screen.h:142)
==22413== by 0x22975AFB: nv50_resource_validate (nv50_screen.h:158)
==22413== by 0x22975AFB: nv50_bufctx_fence (nv50_context.c:417)
==22413== by 0x22980BC5: nv50_state_validate (nv50_state_validate.c:559)
==22413== by 0x22980D16: nv50_state_validate_3d (nv50_state_validate.c:572)
==22413== by 0x2298217D: nv50_draw_vbo (nv50_vbo.c:799)
==22413== by 0x22172F2E: st_draw_vbo (st_draw.c:268)
==22413== by 0x223A8010: _mesa_validated_drawrangeelements (draw.c:816)
==22413== by 0x223A831B: _mesa_DrawElements (draw.c:970)
glDrawElements
==22413== Block was alloc'd at
==22413== at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==22413== by 0x2294ECEA: nouveau_fence_new (nouveau_fence.c:35)
==22413== by 0x22974AA1: nv50_default_kick_notify (nv50_context.c:123)
==22413== by 0x28A35A28: pushbuf_submit.isra.4 (pushbuf.c:324)
==22413== by 0x28A35EAE: pushbuf_flush (pushbuf.c:401)
==22413== by 0x28A36A3F: nouveau_pushbuf_kick (pushbuf.c:775)
==22413== by 0x22974F65: PUSH_KICK (nouveau_winsys.h:59)
==22413== by 0x22974F65: nv50_flush (nv50_context.c:41)
==22413== by 0x222B8AA0: fence_sync (syncobj.c:292)
glFenceSync