Bug 485318

Summary: kwin_wayland crashes in KWin::Workspace::updateOutputs() when displays are intermittently available after waking from suspend
Product: [Plasma] kwin Reporter: FK <fk-kde-bugs>
Component: multi-screenAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: leandrosansilva, nate, vlad.zahorodnii, xaver.hugl
Priority: NOR Keywords: multiscreen, wayland
Version: 6.0.3   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In: 6.1
Sentry Crash Report:

Description FK 2024-04-10 11:28:16 UTC
SUMMARY
kwin_wayland crashes when displays are intermittently available.

I have three displays attached, two through usb-c mst and one through usb->hdmi adapter (LG TV). When waking from suspend and having only the LG TV configured kwin_wayland sometimes crashes, when the display isn't yet turned on properly. Then one of the other displays gets activated as fallback. Seemingly upon seeing the TV available  it tries to switch back and sometimes crashes.

                Stack trace of thread 1815:
                #0  0x00007dc3e4d79d04 _ZNK4KWin6Output5scaleEv (libkwin.so.6 + 0x179d04)
                #1  0x00007dc3e4d7a8c2 _ZNK4KWin6Output8geometryEv (libkwin.so.6 + 0x17a8c2)
                #2  0x00007dc3e4ed2496 _ZN4KWin11ScreenEdges19createEdgeForClientEPNS_6WindowENS_14ElectricBorderE (libkwin.so.6 + 0x2d2496)
                #3  0x00007dc3e4ed2e46 _ZN4KWin11ScreenEdges13recreateEdgesEv (libkwin.so.6 + 0x2d2e46)
                #4  0x00007dc3e4f797c6 _ZN4KWin9Workspace14desktopResizedEv (libkwin.so.6 + 0x3797c6)
                #5  0x00007dc3e4f679ed _ZN4KWin9Workspace13updateOutputsERK5QListIPNS_6OutputEE (libkwin.so.6 + 0x3679ed)
                #6  0x00007dc3e4f5ec39 _ZN4KWin9Workspace24applyOutputConfigurationERKNS_19OutputConfigurationERK5QListIPNS_6OutputEE (libkwin.so.6 + 0x35ec39)
                #7  0x00007dc3e4f5f03d _ZN4KWin9Workspace25updateOutputConfigurationEv (libkwin.so.6 + 0x35f03d)
                #8  0x00007dc3e4f68b3d _ZN4KWin9Workspace31slotOutputBackendOutputsQueriedEv (libkwin.so.6 + 0x368b3d)
                #9  0x00007dc3e2591599 n/a (libQt6Core.so.6 + 0x191599)
                #10 0x00007dc3e4fc72bc _ZN4KWin10DrmBackend13updateOutputsEv (libkwin.so.6 + 0x3c72bc)
                #11 0x00007dc3e4fc9384 _ZN4KWin10DrmBackend15handleUdevEventEv (libkwin.so.6 + 0x3c9384)
                #12 0x00007dc3e2591599 n/a (libQt6Core.so.6 + 0x191599)
                #13 0x00007dc3e2598e20 _ZN15QSocketNotifier5eventEP6QEvent (libQt6Core.so.6 + 0x198e20)
                #14 0x00007dc3e36f437b _ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent (libQt6Widgets.so.6 + 0xf437b)
                #15 0x00007dc3e253a198 _ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent (libQt6Core.so.6 + 0x13a198)
                #16 0x00007dc3e269f149 _ZN27QEventDispatcherUNIXPrivate23activateSocketNotifiersEv (libQt6Core.so.6 + 0x29f149)
                #17 0x00007dc3e26a05ac _ZN20QEventDispatcherUNIX13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE (libQt6Core.so.6 + 0x2a05ac)
                #18 0x00007dc3e2fb3472 _ZN23QUnixEventDispatcherQPA13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE (libQt6Gui.so.6 + 0x5b3472)
                #19 0x00007dc3e25446ee _ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE (libQt6Core.so.6 + 0x1446ee)
                #20 0x00007dc3e253cc38 _ZN16QCoreApplication4execEv (libQt6Core.so.6 + 0x13cc38)
                #21 0x00006020443fadee n/a (kwin_wayland + 0x3cdee)
                #22 0x00007dc3e1e43cd0 n/a (libc.so.6 + 0x25cd0)
                #23 0x00007dc3e1e43d8a __libc_start_main (libc.so.6 + 0x25d8a)
                #24 0x0000602044401425 n/a (kwin_wayland + 0x43425)
                
                Stack trace of thread 1851:
                #0  0x00007dc3e1ea5ebe n/a (libc.so.6 + 0x87ebe)
                #1  0x00007dc3e1ea8750 pthread_cond_wait (libc.so.6 + 0x8a750)
                #2  0x00007dc3d98863ec n/a (radeonsi_dri.so + 0x863ec)
                #3  0x00007dc3d989e39c n/a (radeonsi_dri.so + 0x9e39c)
                #4  0x00007dc3e1ea955a n/a (libc.so.6 + 0x8b55a)
                #5  0x00007dc3e1f26a3c n/a (libc.so.6 + 0x108a3c)


STEPS TO REPRODUCE
1. I can't properly reproduce this always, but it happens sometimes. I'll try to install debug symbols for the next time it happens.

OBSERVED RESULT
kwin_wayland crashes when displays are intermittently available upon wakeup from suspend and additionally all currently opened applications exit.

EXPECTED RESULT
kwin_wayland shouldn't crash

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 6.0.3
(available in About System)
KDE Plasma Version: 6.0.3
KDE Frameworks Version: 6.0.0
Qt Version: Version 6.6.3 (built against 6.6.2)

ADDITIONAL INFORMATION
Comment 1 FK 2024-04-10 11:46:25 UTC
Hopefully these are helpful:
#0  KWin::Output::scale (this=this@entry=0x0) at /usr/src/debug/kwin/kwin-6.0.3.1/src/core/output.cpp:457
#1  0x00007dc3e4d7a8c2 in KWin::Output::geometry (this=0x0) at /usr/src/debug/kwin/kwin-6.0.3.1/src/core/output.cpp:462
#2  0x00007dc3e4ed2496 in KWin::ScreenEdges::createEdgeForClient
    (this=this@entry=0x602046684550, client=0x60204987d1a0, border=KWin::ElectricBottom, border@entry=3847592469)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/screenedge.cpp:1345
#3  0x00007dc3e4ed2816 in KWin::ScreenEdges::reserve (this=this@entry=0x602046684550, client=<optimized out>, border=3847592469)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/screenedge.cpp:1310
#4  0x00007dc3e4ed2e46 in KWin::ScreenEdges::recreateEdges (this=<optimized out>) at /usr/src/debug/kwin/kwin-6.0.3.1/src/screenedge.h:523
#5  0x00007dc3e4f797c6 in KWin::Workspace::desktopResized (this=<optimized out>) at /usr/include/c++/13.2.1/bits/unique_ptr.h:199
#6  0x00007dc3e4f679ed in KWin::Workspace::updateOutputs (this=0x602046591030, outputOrder=<optimized out>)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/workspace.cpp:1401
#7  0x00007dc3e4f5ec39 in KWin::Workspace::applyOutputConfiguration (outputOrder=..., config=..., this=0x602046591030)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/workspace.cpp:482
#8  KWin::Workspace::applyOutputConfiguration (this=this@entry=0x602046591030, config=..., outputOrder=...)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/workspace.cpp:477
#9  0x00007dc3e4f5f03d in KWin::Workspace::updateOutputConfiguration (this=0x602046591030)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/workspace.cpp:533
#10 0x00007dc3e4f68b3d in KWin::Workspace::slotOutputBackendOutputsQueried (this=0x602046591030)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/workspace.cpp:1288
#11 0x00007dc3e2591599 in QtPrivate::QSlotObjectBase::call
    (a=0x7ffd0f15e098, r=0x602046591030, this=0x602046731560, this=<optimized out>, r=<optimized out>, a=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qobjectdefs_impl.h:433
#12 doActivate<false> (sender=0x7dc3d40099a0, signal_index=3, argv=0x7ffd0f15e098)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qobject.cpp:4039
#13 0x00007dc3e4fc72bc in KWin::DrmBackend::updateOutputs (this=this@entry=0x7dc3d40099a0)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/backends/drm/drm_backend.cpp:266
#14 0x00007dc3e4fc9384 in KWin::DrmBackend::handleUdevEvent (this=0x7dc3d40099a0)
    at /usr/src/debug/kwin/kwin-6.0.3.1/src/backends/drm/drm_backend.cpp:179
#15 0x00007dc3e2591599 in QtPrivate::QSlotObjectBase::call
    (a=0x7ffd0f15e680, r=0x7dc3d40099a0, this=0x6020462c9c40, this=<optimized out>, r=<optimized out>, a=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qobjectdefs_impl.h:433
#16 doActivate<false> (sender=0x6020464526c0, signal_index=3, argv=0x7ffd0f15e680)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qobject.cpp:4039
#17 0x00007dc3e2598e20 in QSocketNotifier::activated (_t3=..., _t2=<optimized out>, _t1=..., this=0x6020464526c0)
    at /usr/src/debug/qt6-base/build/src/corelib/Core_autogen/include/moc_qsocketnotifier.cpp:231
#18 QSocketNotifier::event (this=0x6020464526c0, e=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qsocketnotifier.cpp:326
#19 0x00007dc3e36f437b in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x6020464526c0, e=0x7ffd0f15e780)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/widgets/kernel/qapplication.cpp:3296
#20 0x00007dc3e253a198 in QCoreApplication::notifyInternal2 (receiver=0x6020464526c0, event=0x7ffd0f15e780)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qcoreapplication.cpp:1121
#21 0x00007dc3e269f149 in QCoreApplication::sendEvent (event=0x7ffd0f15e780, receiver=<optimized out>)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qcoreapplication.cpp:1539
#22 QEventDispatcherUNIXPrivate::activateSocketNotifiers (this=this@entry=0x6020461aa560)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qeventdispatcher_unix.cpp:268
#23 0x00007dc3e26a05ac in QEventDispatcherUNIX::processEvents (this=<optimized out>, flags=..., flags@entry=...)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qeventdispatcher_unix.cpp:477
#24 0x00007dc3e2fb3472 in QUnixEventDispatcherQPA::processEvents (this=<optimized out>, flags=...)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/gui/platform/unix/qunixeventdispatcher.cpp:27
#25 0x00007dc3e25446ee in QEventLoop::processEvents (flags=..., this=0x7ffd0f15e960)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qeventloop.cpp:100
#26 QEventLoop::exec (this=0x7ffd0f15e960, flags=...)
    at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/kernel/qeventloop.cpp:182
#27 0x00007dc3e253cc38 in QCoreApplication::exec () at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/corelib/global/qflags.h:74
#28 0x00007dc3e36f0efa in QApplication::exec () at /usr/src/debug/qt6-base/qtbase-everywhere-src-6.6.3/src/widgets/kernel/qapplication.cpp:2574
#29 0x00006020443fadee in main (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/kwin/kwin-6.0.3.1/src/main_wayland.cpp:609
Comment 2 Nate Graham 2024-04-10 16:28:12 UTC
It would appear that it's trying to create edges for a disconnected/unavailable screen and failing. Probably needs a guard somewhere.
Comment 3 Vlad Zahorodnii 2024-05-16 11:10:22 UTC
> Probably needs a guard somewhere.

No, it seems like some window has a null output. That should never happen.

---

https://crash-reports.kde.org/organizations/kde/issues/7733
Comment 4 Vlad Zahorodnii 2024-06-03 14:54:43 UTC
Git commit cadf16b12e10c591b746d6f8228a16ec0101362b by Vlad Zahorodnii.
Committed on 03/06/2024 at 14:54.
Pushed by vladz into branch 'master'.

Improve handling of closed windows

A layer shell window can request a screen edge without having a chance
to map the surface. In that case, no Workspace::windowRemoved() signal
is not going to be emitted because no surface has been mapped. Perhaps
it needs some re-wiring, but on the other hand, it is also more reasonable
to monitor Window::closed() signal.

With this change, the ScreenEdges manager will reject any request to
reserve a screen edge for a closed window. And in addition to that,
the ScreenEdges will unreserve screen edges when the window is closed
rather than when the window is unmapped.

M  +8    -4    src/screenedge.cpp

https://invent.kde.org/plasma/kwin/-/commit/cadf16b12e10c591b746d6f8228a16ec0101362b
Comment 5 Bug Janitor Service 2024-06-03 14:55:22 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/5820
Comment 6 Vlad Zahorodnii 2024-06-03 14:56:59 UTC
I believe the changes above should fix the crash, but I'm unable to reproduce the crash myself. Reopen this bug report if you still see this crash in 6.1.0
Comment 7 Vlad Zahorodnii 2024-06-03 15:03:41 UTC
Git commit e1bb824eb5ece286781877514199307f2b02c91e by Vlad Zahorodnii.
Committed on 03/06/2024 at 14:55.
Pushed by vladz into branch 'Plasma/6.1'.

Improve handling of closed windows

A layer shell window can request a screen edge without having a chance
to map the surface. In that case, no Workspace::windowRemoved() signal
is not going to be emitted because no surface has been mapped. Perhaps
it needs some re-wiring, but on the other hand, it is also more reasonable
to monitor Window::closed() signal.

With this change, the ScreenEdges manager will reject any request to
reserve a screen edge for a closed window. And in addition to that,
the ScreenEdges will unreserve screen edges when the window is closed
rather than when the window is unmapped.


(cherry picked from commit cadf16b12e10c591b746d6f8228a16ec0101362b)

1fb3e1a9 Improve handling of closed windows

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>

M  +8    -4    src/screenedge.cpp

https://invent.kde.org/plasma/kwin/-/commit/e1bb824eb5ece286781877514199307f2b02c91e
Comment 8 Zamundaaa 2024-06-18 12:34:38 UTC
*** Bug 488640 has been marked as a duplicate of this bug. ***