drm/i915/guc: Fix locking when searching for a hung request
authorjsg <jsg@openbsd.org>
Fri, 10 Feb 2023 14:27:01 +0000 (14:27 +0000)
committerjsg <jsg@openbsd.org>
Fri, 10 Feb 2023 14:27:01 +0000 (14:27 +0000)
From John Harrison
de997938a7a5da3cb3bd3b914456656963ca1d1c in linux-6.1.y/6.1.11
87b04e53daf806945c415e94de9f90943d434aed in mainline linux

sys/dev/pci/drm/i915/gt/uc/intel_guc_submission.c

index 8874cb3..418fe6f 100644 (file)
@@ -4597,6 +4597,8 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine)
 
        xa_lock_irqsave(&guc->context_lookup, flags);
        xa_for_each(&guc->context_lookup, index, ce) {
+               bool found;
+
                if (!kref_get_unless_zero(&ce->ref))
                        continue;
 
@@ -4613,10 +4615,18 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine)
                                goto next;
                }
 
+               found = false;
+               spin_lock(&ce->guc_state.lock);
                list_for_each_entry(rq, &ce->guc_state.requests, sched.link) {
                        if (i915_test_request_state(rq) != I915_REQUEST_ACTIVE)
                                continue;
 
+                       found = true;
+                       break;
+               }
+               spin_unlock(&ce->guc_state.lock);
+
+               if (found) {
                        intel_engine_set_hung_context(engine, ce);
 
                        /* Can only cope with one hang at a time... */
@@ -4624,6 +4634,7 @@ void intel_guc_find_hung_context(struct intel_engine_cs *engine)
                        xa_lock(&guc->context_lookup);
                        goto done;
                }
+
 next:
                intel_context_put(ce);
                xa_lock(&guc->context_lookup);