Bug 1854674

Summary: Bug in xf86-video-intel (xorg-x11-drv-intel) prevents iris driver from working properly when DRI2 and intel DDX driver are in use
Product: Red Hat Enterprise Linux 7 Reporter: Tomasz Tomasik <scx.mail>
Component: xorg-x11-drv-intelAssignee: Adam Jackson <ajax>
Status: CLOSED WONTFIX QA Contact: Desktop QE <desktop-qa-list>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 7.8CC: ajax, csoriano, ndegraef, pvlasin, scx.mail, tpelka, yanhua1.wu
Target Milestone: rcKeywords: Regression, Triaged
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1856737 1856738 (view as bug list) Environment:
Last Closed: 2021-11-10 14:49:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1856737, 1856738    
Attachments:
Description Flags
Upstream patch for xf86-video-intel (xorg-x11-drv-intel)
none
X.Org configuration
none
RPM SPEC for EL7
none
dmesg log
none
gdb log
none
SRPM for EL6
none
SRPM for EL7
none
SRPM for EL8
none
SRPM for FC30-FC31
none
SRPM for FC32-FC33 none

Description Tomasz Tomasik 2020-07-08 00:37:41 UTC
Description of problem:
Even the simplest SDL2 applications are not able to work with the iris DRI driver, if DRI2 and the intel DDX driver is in use instead of modesetting.

Version-Release number of selected component (if applicable):
EL up to version 8
Fedora up to version 33 (Rawhide)
Basically, everything up to xorg-x11-drv-intel-2.99.917-45.20200205.fc33 is affected.
https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/issues/1071#note_374809227

Steps to reproduce:
1. Configure X.Org to use DRI2 and the intel DDX driver.
2. Reboot system.
3. Log-in in any desktop environment that uses X.Org (GNOME on X.Org, GNOME Classic, MATE, etc.).
4. Run Widelands from Flathub. When it comes to Fedora, you can use the native package instead. For EL, please use the flatpak package.

X.Org configuration:
```
# cat /etc/X11/xorg.conf.d/20-intel.conf 
Section "Device"
        Identifier  "Intel"
        #Driver     "modesetting"
        Driver      "intel"
        ###
        Option      "TearFree"              "True"
        #Option     "DRI"                   "3"
        Option      "DRI"                   "2"
EndSection
```

Widelands packages:
https://flathub.org/apps/details/org.widelands.Widelands
https://github.com/scx/widelands-flatpak
https://koji.fedoraproject.org/koji/packageinfo?packageID=4332
https://copr.fedorainfracloud.org/coprs/scx/widelands

Expected results:
Run the application.

Actual results:
Crash the application.

Additional info:
https://github.com/widelands/widelands/issues/3937
https://github.com/flatpak/flatpak/issues/3673
https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/issues/1071
https://gitlab.freedesktop.org/mesa/mesa/-/issues/3188

dmesg log:
```
[  399.377617] widelands[5462]: segfault at 24 ip 00007f7d795db1dc sp 00007ffe6c3f8d30 error 6 in libgallium_dri.so[7f7d78bd6000+cfd000]
```

gdb log:
```
$ flatpak run -d --command=sh org.widelands.Widelands
[📦 org.widelands.Widelands ~]$ gdb
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) file widelands
Reading symbols from widelands...
(No debugging symbols found in widelands)
(gdb) run
Starting program: /app/bin/widelands 
warning: File "/usr/lib/x86_64-linux-gnu/libthread_db-1.0.so" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
	add-auto-load-safe-path /usr/lib/x86_64-linux-gnu/libthread_db-1.0.so
line to your configuration file "/home/scx/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/scx/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
This is Widelands Version build-20 (Release)
Set home directory: /home/scx/.widelands
Adding directory: /app/share/widelands
selected language: (system language)
using locale en_US.UTF-8
[New LWP 9]
[New LWP 10]
[New LWP 11]
[New LWP 12]
Graphics: Try to set Videomode 800x600
Graphics: OpenGL: Version "4.6 (Compatibility Profile) Mesa 20.0.5"
Graphics: SDL_GL_RED_SIZE is 8
Graphics: SDL_GL_GREEN_SIZE is 8
Graphics: SDL_GL_BLUE_SIZE is 8
Graphics: SDL_GL_ALPHA_SIZE is 0
Graphics: SDL_GL_BUFFER_SIZE is 24
Graphics: SDL_GL_DOUBLEBUFFER is 1
Graphics: SDL_GL_DEPTH_SIZE is 24
Graphics: SDL_GL_STENCIL_SIZE is 8
Graphics: SDL_GL_ACCUM_RED_SIZE is 0
Graphics: SDL_GL_ACCUM_GREEN_SIZE is 0
Graphics: SDL_GL_ACCUM_BLUE_SIZE is 0
Graphics: SDL_GL_ACCUM_ALPHA_SIZE is 0
Graphics: SDL_GL_STEREO is 0
Graphics: SDL_GL_MULTISAMPLEBUFFERS is 0
Graphics: SDL_GL_MULTISAMPLESAMPLES is 0
Graphics: SDL_GL_ACCELERATED_VISUAL is 1
Graphics: SDL_GL_CONTEXT_MAJOR_VERSION is 2
Graphics: SDL_GL_CONTEXT_MINOR_VERSION is 1
Graphics: SDL_GL_CONTEXT_FLAGS is 0
Graphics: SDL_GL_CONTEXT_PROFILE_MASK is 2
Graphics: SDL_GL_SHARE_WITH_CURRENT_CONTEXT is 0
Graphics: SDL_GL_FRAMEBUFFER_SRGB_CAPABLE is 0
Graphics: OpenGL: Double buffering enabled
Graphics: OpenGL: Max texture size: 16384
Graphics: OpenGL: ShadingLanguage: "4.60"

Thread 1 "widelands" received signal SIGSEGV, Segmentation fault.
0x00007ffff3fb71dc in ?? ()
   from /usr/lib/x86_64-linux-gnu/GL/default/lib/dri/iris_dri.so
(gdb) quit
A debugging session is active.

	Inferior 1 [process 5] will be killed.

Quit anyway? (y or n) y
[📦 org.widelands.Widelands ~]$ exit
exit
```

The reason of using DRI2 and the intel DDX driver instead of modesetting:
https://github.com/flatpak/flatpak/issues/3673#issuecomment-650287489

In my opinion, it is the iris driver breaking ABI, but it seems that Intel is not interested into fixing it in Mesa. Instead, they provided fix in xf86-video-intel.
https://gitlab.freedesktop.org/xorg/driver/xf86-video-intel/-/commit/f2a54e256dd7539633c476a379db2b1e60eec811

Related issues:
https://gitlab.freedesktop.org/xorg/driver/xf86-video-intel/-/issues/193
https://gitlab.freedesktop.org/mesa/mesa/-/issues/2845
https://gitlab.freedesktop.org/mesa/mesa/-/issues/2858
https://gitlab.freedesktop.org/mesa/mesa/-/issues/3188

Currently, almost all Linux distributions are affected, including Fedora Rawhide and openSUSE Tumbleweed. When it comes to major Linux distributions, only Arch or Gentoo are not affected, because they tend to use the latest commit.
Although CentOS 7 doesn't provide the iris driver, it is affected as well, because Freedesktop 19.08 uses Mesa 20.x, in which iris is the default driver. This means that all current flatpak packages from Flathub are affected.

The solution is to patch xf86-video-intel in all current Linux distributions.
I've created the xorg-x11-drv-intel repo for EL 6-8 and Fedora 30-33:
https://copr.fedorainfracloud.org/coprs/scx/xorg-x11-drv-intel/

I've already tested it in RHEL 7 and Fedora 32. I can confirm it works.

SRC RPM:
https://copr-be.cloud.fedoraproject.org/results/scx/xorg-x11-drv-intel/epel-7-x86_64/01523758-xorg-x11-drv-intel/xorg-x11-drv-intel-2.99.917-29.20180530.el7.src.rpm

Full RPM SPEC:
https://copr-be.cloud.fedoraproject.org/results/scx/xorg-x11-drv-intel/epel-7-x86_64/01523758-xorg-x11-drv-intel/xorg-x11-drv-intel.spec

Patch ("0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"):
https://gitlab.freedesktop.org/xorg/driver/xf86-video-intel/-/commit/f2a54e256dd7539633c476a379db2b1e60eec811.patch

Comment 2 Tomasz Tomasik 2020-07-08 00:39:20 UTC
Created attachment 1700230 [details]
Upstream patch for xf86-video-intel (xorg-x11-drv-intel)

In mesa i915/i965 pass the bpp to use when creating the surface, but the gallium state tracker passed the depth. As it happens that BitsPerPixel(format) will do the right thing for both, use that.

Comment 3 Tomasz Tomasik 2020-07-08 00:39:50 UTC
Created attachment 1700231 [details]
X.Org configuration

X.Org configuration with DRI2 and the intel DDX driver instead of modesetting

Comment 4 Tomasz Tomasik 2020-07-08 00:41:04 UTC
Created attachment 1700232 [details]
RPM SPEC for EL7

RPM SPEC for EL7 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"

Comment 5 Tomasz Tomasik 2020-07-08 00:41:30 UTC
Created attachment 1700233 [details]
dmesg log

Error in libgallium_dri.so

Comment 6 Tomasz Tomasik 2020-07-08 00:41:51 UTC
Created attachment 1700235 [details]
gdb log

Error in /usr/lib/x86_64-linux-gnu/GL/default/lib/dri/iris_dri.so

Comment 7 Tomasz Tomasik 2020-07-08 00:42:31 UTC
Created attachment 1700236 [details]
SRPM for EL6

SRPM for EL6 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"

Comment 8 Tomasz Tomasik 2020-07-08 00:42:54 UTC
Created attachment 1700237 [details]
SRPM for EL7

SRPM for EL7 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"

Comment 9 Tomasz Tomasik 2020-07-08 00:43:26 UTC
Created attachment 1700238 [details]
SRPM for EL8

SRPM for EL8 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"

Comment 10 Tomasz Tomasik 2020-07-08 00:43:52 UTC
Created attachment 1700239 [details]
SRPM for FC30-FC31

SRPM for FC30-FC31 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"

Comment 11 Tomasz Tomasik 2020-07-08 00:44:10 UTC
Created attachment 1700240 [details]
SRPM for FC32-FC33

SRPM for FC32-FC33 with "0002-dri2-Interpret-DRI2ATTACH_FORMAT-as-depth-not-bpp.patch"