drm/i915: Use uabi engines for the default engine map
[platform/kernel/linux-starfive.git] / drivers / gpu / drm / i915 / gem / i915_gem_context.c
index 7f2831e..42a39e1 100644 (file)
@@ -257,7 +257,7 @@ static int proto_context_set_protected(struct drm_i915_private *i915,
 
        if (!protected) {
                pc->uses_protected_content = false;
-       } else if (!intel_pxp_is_enabled(&to_gt(i915)->pxp)) {
+       } else if (!intel_pxp_is_enabled(i915->pxp)) {
                ret = -ENODEV;
        } else if ((pc->user_flags & BIT(UCONTEXT_RECOVERABLE)) ||
                   !(pc->user_flags & BIT(UCONTEXT_BANNABLE))) {
@@ -271,8 +271,8 @@ static int proto_context_set_protected(struct drm_i915_private *i915,
                 */
                pc->pxp_wakeref = intel_runtime_pm_get(&i915->runtime_pm);
 
-               if (!intel_pxp_is_active(&to_gt(i915)->pxp))
-                       ret = intel_pxp_start(&to_gt(i915)->pxp);
+               if (!intel_pxp_is_active(i915->pxp))
+                       ret = intel_pxp_start(i915->pxp);
        }
 
        return ret;
@@ -1096,16 +1096,15 @@ static struct i915_gem_engines *alloc_engines(unsigned int count)
 static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx,
                                                struct intel_sseu rcs_sseu)
 {
-       const struct intel_gt *gt = to_gt(ctx->i915);
+       const unsigned int max = I915_NUM_ENGINES;
        struct intel_engine_cs *engine;
        struct i915_gem_engines *e, *err;
-       enum intel_engine_id id;
 
-       e = alloc_engines(I915_NUM_ENGINES);
+       e = alloc_engines(max);
        if (!e)
                return ERR_PTR(-ENOMEM);
 
-       for_each_engine(engine, gt, id) {
+       for_each_uabi_engine(engine, ctx->i915) {
                struct intel_context *ce;
                struct intel_sseu sseu = {};
                int ret;
@@ -1113,7 +1112,7 @@ static struct i915_gem_engines *default_engines(struct i915_gem_context *ctx,
                if (engine->legacy_idx == INVALID_ENGINE)
                        continue;
 
-               GEM_BUG_ON(engine->legacy_idx >= I915_NUM_ENGINES);
+               GEM_BUG_ON(engine->legacy_idx >= max);
                GEM_BUG_ON(e->engines[engine->legacy_idx]);
 
                ce = intel_context_create(engine);
@@ -1688,6 +1687,10 @@ void i915_gem_init__contexts(struct drm_i915_private *i915)
        init_contexts(&i915->gem.contexts);
 }
 
+/*
+ * Note that this implicitly consumes the ctx reference, by placing
+ * the ctx in the context_xa.
+ */
 static void gem_context_register(struct i915_gem_context *ctx,
                                 struct drm_i915_file_private *fpriv,
                                 u32 id)
@@ -1703,10 +1706,6 @@ static void gem_context_register(struct i915_gem_context *ctx,
        snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
                 current->comm, pid_nr(ctx->pid));
 
-       /* And finally expose ourselves to userspace via the idr */
-       old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
-       WARN_ON(old);
-
        spin_lock(&ctx->client->ctx_lock);
        list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
        spin_unlock(&ctx->client->ctx_lock);
@@ -1714,6 +1713,10 @@ static void gem_context_register(struct i915_gem_context *ctx,
        spin_lock(&i915->gem.contexts.lock);
        list_add_tail(&ctx->link, &i915->gem.contexts.list);
        spin_unlock(&i915->gem.contexts.lock);
+
+       /* And finally expose ourselves to userspace via the idr */
+       old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
+       WARN_ON(old);
 }
 
 int i915_gem_context_open(struct drm_i915_private *i915,
@@ -2199,14 +2202,22 @@ finalize_create_context_locked(struct drm_i915_file_private *file_priv,
        if (IS_ERR(ctx))
                return ctx;
 
+       /*
+        * One for the xarray and one for the caller.  We need to grab
+        * the reference *prior* to making the ctx visble to userspace
+        * in gem_context_register(), as at any point after that
+        * userspace can try to race us with another thread destroying
+        * the context under our feet.
+        */
+       i915_gem_context_get(ctx);
+
        gem_context_register(ctx, file_priv, id);
 
        old = xa_erase(&file_priv->proto_context_xa, id);
        GEM_BUG_ON(old != pc);
        proto_context_close(file_priv->dev_priv, pc);
 
-       /* One for the xarray and one for the caller */
-       return i915_gem_context_get(ctx);
+       return ctx;
 }
 
 struct i915_gem_context *