Bug 431217 - Kwin_x11 crashes on rk3399 when OpenGL is enabled with Mesa 20.3 or above
Summary: Kwin_x11 crashes on rk3399 when OpenGL is enabled with Mesa 20.3 or above
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: scene-opengl (show other bugs)
Version: 5.20.4
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-06 10:36 UTC by Dan Johansen
Modified: 2021-02-18 16:54 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
kwin_x11 crash log (7.77 KB, text/x-log)
2021-01-06 10:36 UTC, Dan Johansen
Details
kwin_x11 crash log with debug symbols (1.81 KB, text/plain)
2021-01-20 19:24 UTC, Dan Johansen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Johansen 2021-01-06 10:36:26 UTC
Created attachment 134607 [details]
kwin_x11 crash log

SUMMARY
Since Mesa 20.3 release, Kwin 5.20.4 has not been able to run with OpenGL support on rk3399 ARM boards, like the Rock Pi 4 and Pinebook Pro.

I did a git bisect on mesa to see what commit of theirs caused this behaviour and found it to be: https://gitlab.freedesktop.org/mesa/mesa/-/commit/60ebeb4608a871ba89ba081c1c6e7ebdd5efec9a

While, undoing this commit, does indeed give me back OpenGL compositing, the Mesa devs pointed out in my bug report to them, that it's likely a kwin issue instead.
Mesa bug report: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4042

STEPS TO REPRODUCE
1. Install Mesa 20.3 on an rk3399 based device (Pinebook Pro was used here)
2. Make sure OpenGL 2.0 is selected in System Settings -> Display -> Compositor
3. Reboot

OBSERVED RESULT
When the Plasma session starts, Kwin_x11 immediately crashes with the attached output in the crash handler.

EXPECTED RESULT
OpenGL compositing should work just as it does on mesa 20.2.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Comment 1 Zamundaaa 2021-01-14 12:33:57 UTC
Could you build KWin with debug symbols (easiest with kdesrc-build) and generate a full backtrace?
Comment 2 Dan Johansen 2021-01-14 13:50:43 UTC
(In reply to Zamundaaa from comment #1)
> Could you build KWin with debug symbols (easiest with kdesrc-build) and
> generate a full backtrace?

I don't really know how to do this.

Building kwin with debug, I need to add something to the build options, right?
Right now we have:
cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_INSTALL_LIBEXECDIR=lib \
    -DBUILD_TESTING=OFF
  cmake --build build

What option do I need to add for debug symbols?
Comment 3 Vlad Zahorodnii 2021-01-14 13:59:04 UTC
You need to add -DCMAKE_BUILD_TYPE=Debug or -DCMAKE_BUILD_TYPE=RelWithDebInfo to the cmake command.
Comment 4 Dan Johansen 2021-01-14 14:18:42 UTC
(In reply to Vlad Zahorodnii from comment #3)
> You need to add -DCMAKE_BUILD_TYPE=Debug or
> -DCMAKE_BUILD_TYPE=RelWithDebInfo to the cmake command.

Thanks.

And how to do a full backtrace?
Comment 5 Zamundaaa 2021-01-14 15:06:58 UTC
gdb /path/to/kwin_x11

Then use the command "run" to start kwin_x11 and once it crashes, use the command "bt" to obtain the backtrace.
Comment 6 Dan Johansen 2021-01-14 15:30:39 UTC
(In reply to Zamundaaa from comment #5)
> gdb /path/to/kwin_x11
> 
> Then use the command "run" to start kwin_x11 and once it crashes, use the
> command "bt" to obtain the backtrace.

Okay. I just built kwin 5.10.5 with "-DCMAKE_BUILD_TYPE=RelWithDebInfo".

When running gdb /usr/bin/kwin_x11 after install of that kwin package, it tells me it can't find any debugging symbols in kwin_x11.
And when I try "run" I get a FATAL error, that a kwin is already running (if in a GUI session) and a FATAL error saying no displays found (if running from a CLi session).
Comment 7 Vlad Zahorodnii 2021-01-14 15:45:02 UTC
You probably forgot to pass "--replace" option. Since the screen will freeze when a debugger is attached to the kwin process, you should probably attach a debugger from a ssh session.

I'm not sure that you need to attach a debugger though. If kwin crashes, you can retrieve the backtrace by clicking sad icon (drkonqi) in the system tray.
Comment 8 Dan Johansen 2021-01-14 16:14:10 UTC
(In reply to Vlad Zahorodnii from comment #7)
> You probably forgot to pass "--replace" option. Since the screen will freeze
> when a debugger is attached to the kwin process, you should probably attach
> a debugger from a ssh session.
> 
> I'm not sure that you need to attach a debugger though. If kwin crashes, you
> can retrieve the backtrace by clicking sad icon (drkonqi) in the system tray.

That makes sense.

Yeah. But if the debugger says there's no debugging info in kwin_x11, even though I built it with the option, wouldn't it just create the same backtrace as before?
Comment 9 ixn 2021-01-14 21:20:38 UTC
(In reply to Dan Johansen from comment #6)
> When running gdb /usr/bin/kwin_x11 after install of that kwin package, it 
> tells me it can't find any debugging symbols in kwin_x11.

Unless you changed CMake options, programs are usually installed to
/usr/local/bin, so try using /usr/local/bin/kwin_x11 instead.

It's also possible that installing kwin stripped the debug symbols, so you
could also search for kwin_x11 in the build directory and use that copy.
Comment 10 Vlad Zahorodnii 2021-01-15 19:33:45 UTC
(In reply to Dan Johansen from comment #8)
> Yeah. But if the debugger says there's no debugging info in kwin_x11, even
> though I built it with the option, wouldn't it just create the same
> backtrace as before?

Did you run `kwin_x11 --replace` after building and installing kwin package?
Comment 11 Dan Johansen 2021-01-19 16:57:04 UTC
No, I rebooted, which should hopefully do about the same.
Comment 12 Dan Johansen 2021-01-20 19:24:18 UTC
Okay. I figured out why my kwin build was still missing debug symbols, so I added the backtrace from drkonqi with debug symbols.
Comment 13 Dan Johansen 2021-01-20 19:24:53 UTC
Created attachment 135026 [details]
kwin_x11 crash log with debug symbols
Comment 14 Vlad Zahorodnii 2021-01-21 08:56:35 UTC
Weird. Kwin crashes when it sets the swap interval. Does kwin crash when vsync is disabled?
Comment 15 Dan Johansen 2021-01-21 12:31:36 UTC
(In reply to Vlad Zahorodnii from comment #14)
> Weird. Kwin crashes when it sets the swap interval. Does kwin crash when
> vsync is disabled?

Just tried. Can confirm, that yes it does crash with Vsync option in Compositor set to Never.
Comment 16 Vlad Zahorodnii 2021-01-25 07:46:13 UTC
Can you post the backtrace of the crash when vsync is disabled?
Comment 17 Dan Johansen 2021-01-27 16:28:25 UTC
I would love to, but the Crash Handler always crashes "unexpectedly" now and gdb /usr/bin/kwin_x11 + run --replace either freezes the device (if run from the plasma session) or says it can't connect to the display (if run from TTY/SSH).
Comment 18 Dan Johansen 2021-02-02 22:05:49 UTC
I just found this "old" merge request in the KDE gitlab.

https://invent.kde.org/plasma/kwin/-/merge_requests/145

Does this mean it has been merged, but not released yet?
Comment 19 Dan Johansen 2021-02-03 09:02:26 UTC
Another thought just hit me.

Is it actually what caused this issue?

The above commits seems to be in both 5.20 and 5.21. And it started happening in 5.20 with the update to mesa 20.3, where they implemented some generalization around GLX swap control.
Comment 20 Dan Johansen 2021-02-18 16:54:19 UTC
Plasma 5.21 just got into our repositories, so I just tested with kwin 5.21 and Mesa 20.3.4 from Arch.

Issue seems to be resolved. There's no crash, and the OpenGL stuff seems to work.

Closing issue and thanks for the help.