drm/i915/gt: Register the migrate contexts with their engines
authorjsg <jsg@openbsd.org>
Wed, 13 Jul 2022 03:37:55 +0000 (03:37 +0000)
committerjsg <jsg@openbsd.org>
Wed, 13 Jul 2022 03:37:55 +0000 (03:37 +0000)
From Thomas Hellstrom
9cf3a1c1288e43af00d70a8520ea9efbea01615e in linux 5.15.y/5.15.54
3e42cc61275f95fd7f022b6380b95428efe134d3 in mainline linux

sys/dev/pci/drm/i915/gt/intel_context_types.h
sys/dev/pci/drm/i915/gt/intel_engine_cs.c
sys/dev/pci/drm/i915/gt/intel_engine_pm.c
sys/dev/pci/drm/i915/gt/intel_engine_pm.h
sys/dev/pci/drm/i915/gt/intel_engine_types.h
sys/dev/pci/drm/i915/gt/intel_execlists_submission.c
sys/dev/pci/drm/i915/gt/intel_ring_submission.c
sys/dev/pci/drm/i915/gt/mock_engine.c
sys/dev/pci/drm/i915/gt/uc/intel_guc_submission.c

index e4a8971..bef5b78 100644 (file)
@@ -152,6 +152,14 @@ struct intel_context {
        /** sseu: Control eu/slice partitioning */
        struct intel_sseu sseu;
 
+       /**
+        * pinned_contexts_link: List link for the engine's pinned contexts.
+        * This is only used if this is a perma-pinned kernel context and
+        * the list is assumed to only be manipulated during driver load
+        * or unload time so no mutex protection currently.
+        */
+       struct list_head pinned_contexts_link;
+
        u8 wa_bb_page; /* if set, page num reserved for context workarounds */
 
        struct {
index 117a541..bc2c4bb 100644 (file)
@@ -320,6 +320,7 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
 
        BUILD_BUG_ON(BITS_PER_TYPE(engine->mask) < I915_NUM_ENGINES);
 
+       INIT_LIST_HEAD(&engine->pinned_contexts_list);
        engine->id = id;
        engine->legacy_idx = INVALID_ENGINE;
        engine->mask = BIT(id);
@@ -879,6 +880,8 @@ intel_engine_create_pinned_context(struct intel_engine_cs *engine,
                return ERR_PTR(err);
        }
 
+       list_add_tail(&ce->pinned_contexts_link, &engine->pinned_contexts_list);
+
        /*
         * Give our perma-pinned kernel timelines a separate lockdep class,
         * so that we can use them from within the normal user timelines
@@ -901,6 +904,7 @@ void intel_engine_destroy_pinned_context(struct intel_context *ce)
        list_del(&ce->timeline->engine_link);
        mutex_unlock(&hwsp->vm->mutex);
 
+       list_del(&ce->pinned_contexts_link);
        intel_context_unpin(ce);
        intel_context_put(ce);
 }
index 1f07ac4..dacd627 100644 (file)
@@ -298,6 +298,29 @@ void intel_engine_init__pm(struct intel_engine_cs *engine)
        intel_engine_init_heartbeat(engine);
 }
 
+/**
+ * intel_engine_reset_pinned_contexts - Reset the pinned contexts of
+ * an engine.
+ * @engine: The engine whose pinned contexts we want to reset.
+ *
+ * Typically the pinned context LMEM images lose or get their content
+ * corrupted on suspend. This function resets their images.
+ */
+void intel_engine_reset_pinned_contexts(struct intel_engine_cs *engine)
+{
+       struct intel_context *ce;
+
+       list_for_each_entry(ce, &engine->pinned_contexts_list,
+                           pinned_contexts_link) {
+               /* kernel context gets reset at __engine_unpark() */
+               if (ce == engine->kernel_context)
+                       continue;
+
+               dbg_poison_ce(ce);
+               ce->ops->reset(ce);
+       }
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftest_engine_pm.c"
 #endif
index 70ea46d..8520c59 100644 (file)
@@ -69,4 +69,6 @@ intel_engine_create_kernel_request(struct intel_engine_cs *engine)
 
 void intel_engine_init__pm(struct intel_engine_cs *engine);
 
+void intel_engine_reset_pinned_contexts(struct intel_engine_cs *engine);
+
 #endif /* INTEL_ENGINE_PM_H */
index 934e457..0ff133f 100644 (file)
@@ -304,6 +304,13 @@ struct intel_engine_cs {
 
        struct intel_context *kernel_context; /* pinned */
 
+       /**
+        * pinned_contexts_list: List of pinned contexts. This list is only
+        * assumed to be manipulated during driver load- or unload time and
+        * does therefore not have any additional protection.
+        */
+       struct list_head pinned_contexts_list;
+
        intel_engine_mask_t saturated; /* submitting semaphores too late? */
 
        struct {
index 6bdc43b..5bde03d 100644 (file)
@@ -2792,6 +2792,8 @@ static void execlists_sanitize(struct intel_engine_cs *engine)
 
        /* And scrub the dirty cachelines for the HWSP */
        clflush_cache_range(engine->status_page.addr, PAGE_SIZE);
+
+       intel_engine_reset_pinned_contexts(engine);
 }
 
 static void enable_error_interrupt(struct intel_engine_cs *engine)
index c4b09ee..09f7b95 100644 (file)
@@ -17,6 +17,7 @@
 #include "intel_ring.h"
 #include "shmem_utils.h"
 #include "intel_engine_heartbeat.h"
+#include "intel_engine_pm.h"
 
 /* Rough estimate of the typical request size, performing a flush,
  * set-context and then emitting the batch.
@@ -292,6 +293,8 @@ static void xcs_sanitize(struct intel_engine_cs *engine)
 
        /* And scrub the dirty cachelines for the HWSP */
        clflush_cache_range(engine->status_page.addr, PAGE_SIZE);
+
+       intel_engine_reset_pinned_contexts(engine);
 }
 
 static void reset_prepare(struct intel_engine_cs *engine)
index 53cc2f9..89ac051 100644 (file)
@@ -376,6 +376,8 @@ int mock_engine_init(struct intel_engine_cs *engine)
 {
        struct intel_context *ce;
 
+       INIT_LIST_HEAD(&engine->pinned_contexts_list);
+
        engine->sched_engine = i915_sched_engine_create(ENGINE_MOCK);
        if (!engine->sched_engine)
                return -ENOMEM;
index 7983409..8e1cc0a 100644 (file)
@@ -2347,6 +2347,8 @@ static void guc_sanitize(struct intel_engine_cs *engine)
 
        /* And scrub the dirty cachelines for the HWSP */
        clflush_cache_range(engine->status_page.addr, PAGE_SIZE);
+
+       intel_engine_reset_pinned_contexts(engine);
 }
 
 static void setup_hwsp(struct intel_engine_cs *engine)
@@ -2422,9 +2424,13 @@ static inline void guc_init_lrc_mapping(struct intel_guc *guc)
         * and even it did this code would be run again.
         */
 
-       for_each_engine(engine, gt, id)
-               if (engine->kernel_context)
-                       guc_kernel_context_pin(guc, engine->kernel_context);
+       for_each_engine(engine, gt, id) {
+               struct intel_context *ce;
+
+               list_for_each_entry(ce, &engine->pinned_contexts_list,
+                                   pinned_contexts_link)
+                       guc_kernel_context_pin(guc, ce);
+       }
 }
 
 static void guc_release(struct intel_engine_cs *engine)