[470.42.01 and earlier, Geforce 940M/Optimus] Xorg crash in nvidia_drv.so (nvidiaUnlock+0x40b654), GNOME session with 3d fullscreen application

Hardware: Intel(R) Core™ i7-5600U, NVIDIA Geforce 940M (reverse PRIME configuration)
System: Fedora 33, Linux 5.12.x (various 5.12 versions tested)
Driver: NVIDIA 470.42.01 (also tested in 460 and 465 with same result)

Steps to reproduce:

  1. Login to GNOME Xorg session from gdm
  2. Start a 3D fullscreen game (tested with: factorio) with “__NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __VK_LAYER_NV_optimus=NVIDIA_only __GLX_VENDOR_LIBRARY_NAME=nvidia”
    → After a few seconds in fullscreen (with or without interaction, usually in the main menu) the Xorg server will crash to a black vt, switching to vt1 allows to log into a new session

Please note that starting a different Xorg session (e.g. cinnamon) avoids the crash.
Desktop applications are apparently not affected.

Backtraces from system journal:

/usr/libexec/gdm-x-session[2618]: (EE) Backtrace:
/usr/libexec/gdm-x-session[2618]: (EE) 0: /usr/libexec/Xorg (ErrorFSigSafe+0xd9) [0x55ba59aeacc9]
/usr/libexec/gdm-x-session[2618]: (EE) 1: /lib64/libpthread.so.0 (funlockfile+0x60) [0x7f07837be1b0]
/usr/libexec/gdm-x-session[2618]: (EE) 2: /usr/libexec/Xorg (DamageRegionAppend+0x47e6) [0x55ba59a6ddb6]
/usr/libexec/gdm-x-session[2618]: (EE) 3: /usr/libexec/Xorg (DRI2HasSwapControl+0x225) [0x55ba59ab02c5]
/usr/libexec/gdm-x-session[2618]: (EE) 4: /usr/libexec/Xorg (present_extension_init+0xd72) [0x55ba59a63c92]
/usr/libexec/gdm-x-session[2618]: (EE) 5: /usr/libexec/Xorg (DamageDamageRegion+0x331) [0x55ba59a68691]
/usr/libexec/gdm-x-session[2618]: (EE) 6: /usr/libexec/Xorg (DamageDamageRegion+0x408) [0x55ba59a68768]
/usr/libexec/gdm-x-session[2618]: (EE) 7: /usr/lib64/xorg/modules/drivers/nvidia_drv.so (nvidiaUnlock+0x40b654) [0x7f07826f3834]
systemd-coredump[4368]: Process 2618 (Xorg) of user 1000 dumped core.
                                               
                                               Stack trace of thread 2618:
                                               #0  0x00007f078361c9e5 raise (libc.so.6 + 0x3d9e5)
                                               #1  0x00007f07836058a4 abort (libc.so.6 + 0x268a4)
                                               #2  0x000055ba59ae7720 OsAbort (Xorg + 0x1c3720)
                                               #3  0x000055ba59ae8286 FatalError (Xorg + 0x1c4286)
                                               #4  0x000055ba59aead2d OsSigHandler (Xorg + 0x1c6d2d)
                                               #5  0x00007f07837be1b0 __restore_rt (libpthread.so.0 + 0x141b0)
                                               #6  0x000055ba59a6ddb6 damageSetWindowPixmap (Xorg + 0x149db6)
                                               #7  0x000055ba59ab02c5 DRI2SetWindowPixmap (Xorg + 0x18c2c5)
                                               #8  0x000055ba59a63c92 present_set_tree_pixmap (Xorg + 0x13fc92)
                                               #9  0x000055ba59a68691 present_execute (Xorg + 0x144691)
                                               #10 0x000055ba59a68768 present_re_execute.lto_priv.0 (Xorg + 0x144768)
                                               #11 0x00007f07826f3834 n/a (nvidia_drv.so + 0x472834)

attachment: nvidia-bug-report.sh run from a new gnome session
nvidia-bug-report.log.gz (911.1 KB)