drm/i915: Use internal class when counting engine resets
authorTvrtko Ursulin <tvrtko.ursulin@intel.com>
Fri, 1 Dec 2023 12:21:09 +0000 (12:21 +0000)
committerJani Nikula <jani.nikula@intel.com>
Mon, 11 Dec 2023 11:14:02 +0000 (13:14 +0200)
Commit 503579448db9 ("drm/i915/gsc: Mark internal GSC engine with reserved uabi class")
made the GSC0 engine not have a valid uabi class and so broke the engine
reset counting, which in turn was made class based in cb823ed9915b ("drm/i915/gt: Use intel_gt as the primary object for handling resets").

Despite the title and commit text of the latter is not mentioning it (and
has left the storage array incorrectly sized), tracking by class, despite
it adding aliasing in hypthotetical multi-tile systems, is handy for
virtual engines which for instance do not have a valid engine->id.

Therefore we keep that but just change it to use the internal class which
is always valid. We also add a helper to increment the count, which
aligns with the existing getter.

What was broken without this fix were out of bounds reads every time a
reset would happen on the GSC0 engine, or during selftests when storing
and cross-checking the counts in igt_live_test_begin and
igt_live_test_end.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Fixes: 503579448db9 ("drm/i915/gsc: Mark internal GSC engine with reserved uabi class")
[tursulin: fixed Fixes tag]
Reported-by: Alan Previn Teres Alexis <alan.previn.teres.alexis@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231201122109.729006-2-tvrtko.ursulin@linux.intel.com
(cherry picked from commit cf9cb028ac56696ff879af1154c4b2f0b12701fd)
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
drivers/gpu/drm/i915/gt/intel_reset.c
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
drivers/gpu/drm/i915/i915_gpu_error.h

index d5ed904f355d5addffa56446f4be412c7b1a385d..6801f8b95c53d1ed989f6bb7c72205b2d7cd236a 100644 (file)
@@ -1293,7 +1293,7 @@ int __intel_engine_reset_bh(struct intel_engine_cs *engine, const char *msg)
        if (msg)
                drm_notice(&engine->i915->drm,
                           "Resetting %s for %s\n", engine->name, msg);
-       atomic_inc(&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]);
+       i915_increase_reset_engine_count(&engine->i915->gpu_error, engine);
 
        ret = intel_gt_reset_engine(engine);
        if (ret) {
index d37698bd6b91aeb1b39ffe729a1cbd76463d361e..17df71117cc70de27e057af8d1b0ac392db3aa5c 100644 (file)
@@ -5001,7 +5001,8 @@ static void capture_error_state(struct intel_guc *guc,
                        if (match) {
                                intel_engine_set_hung_context(e, ce);
                                engine_mask |= e->mask;
-                               atomic_inc(&i915->gpu_error.reset_engine_count[e->uabi_class]);
+                               i915_increase_reset_engine_count(&i915->gpu_error,
+                                                                e);
                        }
                }
 
@@ -5013,7 +5014,7 @@ static void capture_error_state(struct intel_guc *guc,
        } else {
                intel_engine_set_hung_context(ce->engine, ce);
                engine_mask = ce->engine->mask;
-               atomic_inc(&i915->gpu_error.reset_engine_count[ce->engine->uabi_class]);
+               i915_increase_reset_engine_count(&i915->gpu_error, ce->engine);
        }
 
        with_intel_runtime_pm(&i915->runtime_pm, wakeref)
index 9f5971f5e980145d940bb5c59701471071d393cd..48f6c00402c47a255d2cd0fc56fc5b5be3e80a38 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "display/intel_display_device.h"
 #include "gt/intel_engine.h"
+#include "gt/intel_engine_types.h"
 #include "gt/intel_gt_types.h"
 #include "gt/uc/intel_uc_fw.h"
 
@@ -232,7 +233,7 @@ struct i915_gpu_error {
        atomic_t reset_count;
 
        /** Number of times an engine has been reset */
-       atomic_t reset_engine_count[I915_NUM_ENGINES];
+       atomic_t reset_engine_count[MAX_ENGINE_CLASS];
 };
 
 struct drm_i915_error_state_buf {
@@ -255,7 +256,14 @@ static inline u32 i915_reset_count(struct i915_gpu_error *error)
 static inline u32 i915_reset_engine_count(struct i915_gpu_error *error,
                                          const struct intel_engine_cs *engine)
 {
-       return atomic_read(&error->reset_engine_count[engine->uabi_class]);
+       return atomic_read(&error->reset_engine_count[engine->class]);
+}
+
+static inline void
+i915_increase_reset_engine_count(struct i915_gpu_error *error,
+                                const struct intel_engine_cs *engine)
+{
+       atomic_inc(&error->reset_engine_count[engine->class]);
 }
 
 #define CORE_DUMP_FLAG_NONE           0x0