<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WARNING: CPU: 6 PID: 102 at drivers/gpu/drm/i915/intel_display.c:8977 intel_fb_obj_invalidate+0xe1/0xf0 [i915]()"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=87955#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - WARNING: CPU: 6 PID: 102 at drivers/gpu/drm/i915/intel_display.c:8977 intel_fb_obj_invalidate+0xe1/0xf0 [i915]()"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=87955">bug 87955</a>
              from <span class="vcard"><a class="email" href="mailto:chris@chris-wilson.co.uk" title="Chris Wilson <chris@chris-wilson.co.uk>"> <span class="fn">Chris Wilson</span></a>
</span></b>
        <pre>That should correspond to:

WARN_ON(!mutex_is_locked(&dev->struct_mutex));

which is presumably a race in mutex_is_locked_by(), specifically if we inspect
mutex->owner after the atomic_dec(&mutex->count) in mutex_lock() but before
mutex_set_owner().

This appears to be an issue for CONFIG_DEBUG_MUTEXES since:

void mutex_lock()
{
#ifndef CONFIG_DEBUG_MUTEXES
        /*
         * When debugging is enabled we must not clear the owner before time,
         * the slow path will always be taken, and that clears the owner field
         * after verifying that it was indeed current.
         */
        mutex_clear_owner(lock);
#endif
}

So the correct fix is:

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index ad55b06a3cb1..4c14db9587a6 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -5024,7 +5024,7 @@ static bool mutex_is_locked_by(struct mutex *mutex,
struct task_struct *task)
        if (!mutex_is_locked(mutex))
                return false;

-#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
+#if defined(CONFIG_SMP) && !defined(CONFIG_DEBUG_MUTEXES)
        return mutex->owner == task;
 #else
        /* Since UP may be pre-empted, we cannot assume that we own the lock */</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are on the CC list for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>