<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>364740</bug_id>
          
          <creation_ts>2016-06-25 10:50:08 +0000</creation_ts>
          <short_desc>DRM backend crashes on QEmu</short_desc>
          <delta_ts>2016-06-29 06:51:25 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Plasma</classification>
          <product>kwin</product>
          <component>platform-drm</component>
          <version>git master</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>crash</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fabian Vogt">fabian</reporter>
          <assigned_to name="KWin default assignee">kwin-bugs-null</assigned_to>
          
          
          <cf_commitlink>http://commits.kde.org/kwin/7ea84cd346424161affbfddf653b16b6f90442f1</cf_commitlink>
          <cf_versionfixedin>5.7</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      <flag name="ReviewRequest"
          id="1344"
          type_id="14"
          status="+"
          setter="mgraesslin"
    />

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1603378</commentid>
    <comment_count>0</comment_count>
    <who name="Fabian Vogt">fabian</who>
    <bug_when>2016-06-25 10:50:08 +0000</bug_when>
    <thetext>KWIN_COMPOSE=Q kwin_wayland --drm [...] crashes directly on startup on QEmu (QXL).
The crash cause is a nullptr dereference in a comparision, with the following backtrace:

#0  0x00007fffee75471a in QImage::fill(QColor const&amp;) () from /usr/lib64/libQt5Gui.so.5                                         
#1  0x00007fffee7549ec in QImage::fill(Qt::GlobalColor) () from /usr/lib64/libQt5Gui.so.5                                       
#2  0x00007fffdcccd021 in KWin::DrmBackend::initCursor() () from /usr/lib64/qt5/plugins/org.kde.kwin.waylandbackends/KWinWayland
DrmBackend.so                                                                                                                   
#3  0x00007fffdccce52f in KWin::DrmBackend::openDrm() () from /usr/lib64/qt5/plugins/org.kde.kwin.waylandbackends/KWinWaylandDrm
Backend.so                                                                                                                      
#4  0x00007ffff5e7b44e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5                  
#5  0x00007ffff7b29652 in KWin::LogindIntegration::hasSessionControlChanged(bool) () from /usr/lib64/libkwin.so.5               
#6  0x00007ffff7abc894 in ?? () from /usr/lib64/libkwin.so.5                                                                    
#7  0x00007ffff5e7b44e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5                  
#8  0x00007fffeefc35ff in QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher*) () from /usr/lib64/libQt5DBus.so.5        
#9  0x00007fffeefc36f8 in ?? () from /usr/lib64/libQt5DBus.so.5                                                                 
#10 0x00007ffff5e7bf99 in QObject::event(QEvent*) () from /usr/lib64/libQt5Core.so.5                                            
#11 0x00007ffff63fd9ac in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5           
#12 0x00007ffff6405151 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5                         
#13 0x00007ffff5e4f018 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5               
#14 0x00007ffff5e517f0 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.s
o.5                                                                                                                             
#15 0x00007ffff5ea086a in QEventDispatcherUNIX::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQt5Co
re.so.5                                                                                                                         
#16 0x00007fffdee3196d in ?? () from /usr/lib64/qt5/plugins/platforms/KWinQpaPlugin.so
#17 0x00007ffff5e4cfca in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQt5Core.so.5
#18 0x00007ffff5e558bc in QCoreApplication::exec() () from /usr/lib64/libQt5Core.so.5
#19 0x0000000000408cb5 in ?? ()
#20 0x00007ffff5297741 in __libc_start_main () from /lib64/libc.so.6
#21 0x00000000004093e9 in _start ()

Reproducible: Always</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603388</commentid>
    <comment_count>1</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-25 11:28:35 +0000</bug_when>
    <thetext>I have an idea what going on. Can you get a backtrace with debug symbols and would you be able to compile a KWin with a patch?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603389</commentid>
    <comment_count>2</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-25 11:29:33 +0000</bug_when>
    <thetext>Adding my idea in case I forget again: the mmap of the DrmBuffer fails for the cursor buffer. We need to catch this situation properly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603392</commentid>
    <comment_count>3</comment_count>
    <who name="Fabian Vogt">fabian</who>
    <bug_when>2016-06-25 11:39:27 +0000</bug_when>
    <thetext>(In reply to Martin Gräßlin from comment #1)
&gt; I have an idea what going on. Can you get a backtrace with debug symbols and
&gt; would you be able to compile a KWin with a patch?
Sure!

Backtrace with debug symbols:

#0  0x00007fffee75471a in QImage::fill(QColor const&amp;) () from /usr/lib64/libQt5Gui.so.5                                         
#1  0x00007fffee7549ec in QImage::fill(Qt::GlobalColor) () from /usr/lib64/libQt5Gui.so.5                                       
#2  0x00007fffdcccd021 in KWin::DrmBackend::initCursor (this=this@entry=0x66dd60) at /usr/src/debug/kwin-5.6.90git~20160623T210703~03f0dc5/plugins/platforms/drm/drm_backend.cpp:499                                                                            
#3  0x00007fffdccce52f in KWin::DrmBackend::openDrm (this=0x66dd60) at /usr/src/debug/kwin-5.6.90git~20160623T210703~03f0dc5/plugins/platforms/drm/drm_backend.cpp:267                                                                                          
#4  0x00007ffff5e7b44e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5                  
#5  0x00007ffff7b29652 in KWin::LogindIntegration::hasSessionControlChanged (this=&lt;optimized out&gt;, _t1=&lt;optimized out&gt;, _t1@entry=true) at /usr/src/debug/kwin-5.6.90git~20160623T210703~03f0dc5/build/moc_logind.cpp:187                                       
#6  0x00007ffff7abc894 in KWin::LogindIntegration::&lt;lambda(QDBusPendingCallWatcher*)&gt;::operator() (self=&lt;optimized out&gt;, __closure=0x6dd050) at /usr/src/debug/kwin-5.6.90git~20160623T210703~03f0dc5/logind.cpp:281                                            
#7  QtPrivate::FunctorCall&lt;QtPrivate::IndexesList&lt;0&gt;, QtPrivate::List&lt;QDBusPendingCallWatcher*&gt;, void, KWin::LogindIntegration::takeControl()::&lt;lambda(QDBusPendingCallWatcher*)&gt; &gt;::call (arg=&lt;optimized out&gt;, f=...) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:501                                                                                                                        
#8  QtPrivate::Functor&lt;KWin::LogindIntegration::takeControl()::&lt;lambda(QDBusPendingCallWatcher*)&gt;, 1&gt;::call&lt;QtPrivate::List&lt;QDBusPendingCallWatcher*&gt;, void&gt; (arg=&lt;optimized out&gt;, f=...) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:558                     
#9  QtPrivate::QFunctorSlotObject&lt;KWin::LogindIntegration::takeControl()::&lt;lambda(QDBusPendingCallWatcher*)&gt;, 1, QtPrivate::List&lt;QDBusPendingCallWatcher*&gt;,void&gt;::impl(int, QtPrivate::QSlotObjectBase *, QObject *, void **, bool *) (which=&lt;optimized out&gt;, this_=0x6dd040, r=&lt;optimized out&gt;, a=&lt;optimized out&gt;, ret=&lt;optimized out&gt;) at /usr/include/qt5/QtCore/qobject_impl.h:198         
#10 0x00007ffff5e7b44e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib64/libQt5Core.so.5                  
#11 0x00007fffeefc35ff in QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher*) () from /usr/lib64/libQt5DBus.so.5        
#12 0x00007fffeefc36f8 in ?? () from /usr/lib64/libQt5DBus.so.5                                                                 
#13 0x00007ffff5e7bf99 in QObject::event(QEvent*) () from /usr/lib64/libQt5Core.so.5                                            
#14 0x00007ffff63fd9ac in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5           
#15 0x00007ffff6405151 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5                         
#16 0x00007ffff5e4f018 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5               
#17 0x00007ffff5e517f0 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5                                                                                                                             
#18 0x00007ffff5ea086a in QEventDispatcherUNIX::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQt5Core.so.5                                                                                                                         
#19 0x00007fffdee3196d in QUnixEventDispatcherQPA::processEvents (this=&lt;optimized out&gt;, flags=...) at eventdispatchers/qunixeventdispatcher.cpp:68                                                                                                              
#20 0x00007ffff5e4cfca in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQt5Core.so.5            
#21 0x00007ffff5e558bc in QCoreApplication::exec() () from /usr/lib64/libQt5Core.so.5                                           
#22 0x0000000000408cb5 in main (argc=&lt;optimized out&gt;, argv=&lt;optimized out&gt;) at /usr/src/debug/kwin-5.6.90git~20160623T210703~03f0dc5/main_wayland.cpp:724

&gt; Adding my idea in case I forget again: the mmap of the DrmBuffer fails for the
cursor buffer. We need to catch this situation properly.

Looks like you&apos;re right:

(gdb) print *m_cursor[0]                                                                                                        |
$2 = {m_backend = 0x66dd60, m_surface = 0x0, m_bo = 0x0, m_size = {wd = 64, ht = 64}, m_handle = 2, m_bufferId = 0, m_stride = 2|
56, m_bufferSize = 16384, m_memory = 0x0, m_image = 0x0}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603396</commentid>
    <comment_count>4</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-25 12:02:02 +0000</bug_when>
    <thetext>thanks for checking my theory in the debugger.

Now I&apos;m wondering why did the map fail and what&apos;s the best thing to handle the fail. We could just not update the cursor, but that&apos;s not really a solution. Or we could terminate, because we can expect that it won&apos;t work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603402</commentid>
    <comment_count>5</comment_count>
    <who name="Fabian Vogt">fabian</who>
    <bug_when>2016-06-25 12:36:08 +0000</bug_when>
    <thetext>(In reply to Martin Gräßlin from comment #4)
&gt; thanks for checking my theory in the debugger.
&gt; 
&gt; Now I&apos;m wondering why did the map fail and what&apos;s the best thing to handle
&gt; the fail. We could just not update the cursor, but that&apos;s not really a
&gt; solution. Or we could terminate, because we can expect that it won&apos;t work.

Some more information: drmModeAddFB fails because the DRM ioctl returns -1 with errno set to 22 (EINVAL). A guess: Maybe 32 bpp or 24 bit depth aren&apos;t supported?

if ((ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ADDFB, &amp;f)))
(gdb) print f
$9 = {fb_id = 0, width = 64, height = 64, pitch = 256, bpp = 32, depth = 24, handle = 2}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603516</commentid>
    <comment_count>6</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-26 08:16:50 +0000</bug_when>
    <thetext>&gt; A guess: Maybe 32 bpp or 24 bit depth aren&apos;t supported?

quite likely. In that case it doesn&apos;t make sense to try an RGB only buffer for the cursor. That would be not usable either. So the way forward seems to me to catch the condition and enable software cursor rendering. Which probably will trigger the same problem as the framebuffer backend.

I think I need to setup a qemu instance tomorrow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603919</commentid>
    <comment_count>7</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-28 08:27:21 +0000</bug_when>
    <thetext>Patch which should resolve the problem: https://phabricator.kde.org/D2026</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1603925</commentid>
    <comment_count>8</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-28 08:40:15 +0000</bug_when>
    <thetext>and for proper rendering of the now used software cursor in the QPainter backend we have:
* https://phabricator.kde.org/D2027
* https://phabricator.kde.org/D2028</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1604134</commentid>
    <comment_count>9</comment_count>
    <who name="Martin Flöser">mgraesslin</who>
    <bug_when>2016-06-29 06:51:25 +0000</bug_when>
    <thetext>Git commit 7ea84cd346424161affbfddf653b16b6f90442f1 by Martin Gräßlin.
Committed on 29/06/2016 at 06:49.
Pushed by graesslin into branch &apos;Plasma/5.7&apos;.

[platforms/drm] If mapping a DrmBuffer for a cursor fails, fallback to software cursor

Summary:
So far the drm platform did not verify whether creating and mapping a
DrmBuffer for a cursor works. This could result in a crash in the worst
case.

This change verfies whether mapping the two cursor buffers works, if
not software cursor is enabled. The code is adjusted to ensure that
none of the cursor buffers is accessed in case software cursor are
enabled.

Please note that right now the drm platform&apos;s rendering does not
support software cursors. Thus currently this change results in no
cursor at all. This will be addressed by following patches.
FIXED-IN: 5.7

Test Plan:
Verfied that it properly falls back to software cursor,
but could not verify that the crash is actually fixed.

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D2026

M  +28   -14   plugins/platforms/drm/drm_backend.cpp

http://commits.kde.org/kwin/7ea84cd346424161affbfddf653b16b6f90442f1</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>