Skip to content

Commit

Permalink
drm/i915: Wedge the GPU if command parser setup fails
Browse files Browse the repository at this point in the history
Commit 311a50e ("drm/i915: Add support for mandatory cmdparsing")
introduced mandatory command parsing but setup failures were not
translated into wedging the GPU which was probably the intent.

Possible errors come in two categories. Either the sanity check on
internal tables has failed, which should be caught in CI unless an
affected platform would be missed in testing; or memory allocation failure
happened during driver load, which should be extremely unlikely but for
correctness should still be handled.

v2:
 * Tidy coding style. (Chris)

Signed-off-by: Tvrtko Ursulin <[email protected]>
Fixes: 311a50e ("drm/i915: Add support for mandatory cmdparsing")
Cc: Jon Bloomfield <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Chris Wilson <[email protected]>
Reviewed-by: Chris Wilson <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
tursulin committed Mar 3, 2021
1 parent 1914911 commit 5a1a659
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
7 changes: 6 additions & 1 deletion drivers/gpu/drm/i915/gt/intel_engine_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,17 @@ static int engine_setup_common(struct intel_engine_cs *engine)
goto err_status;
}

err = intel_engine_init_cmd_parser(engine);
if (err)
goto err_cmd_parser;

i915_sched_init(&engine->sched,
engine->i915->drm.dev,
engine->name,
engine->mask,
ENGINE_PHYSICAL);

intel_engine_init_execlists(engine);
intel_engine_init_cmd_parser(engine);
intel_engine_init__pm(engine);
intel_engine_init_retire(engine);

Expand All @@ -720,6 +723,8 @@ static int engine_setup_common(struct intel_engine_cs *engine)

return 0;

err_cmd_parser:
intel_breadcrumbs_free(engine->breadcrumbs);
err_status:
cleanup_status_page(engine);
return err;
Expand Down
19 changes: 13 additions & 6 deletions drivers/gpu/drm/i915/i915_cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,15 +940,15 @@ static void fini_hash_table(struct intel_engine_cs *engine)
* struct intel_engine_cs based on whether the platform requires software
* command parsing.
*/
void intel_engine_init_cmd_parser(struct intel_engine_cs *engine)
int intel_engine_init_cmd_parser(struct intel_engine_cs *engine)
{
const struct drm_i915_cmd_table *cmd_tables;
int cmd_table_count;
int ret;

if (!IS_GEN(engine->i915, 7) && !(IS_GEN(engine->i915, 9) &&
engine->class == COPY_ENGINE_CLASS))
return;
return 0;

switch (engine->class) {
case RENDER_CLASS:
Expand Down Expand Up @@ -1013,30 +1013,37 @@ void intel_engine_init_cmd_parser(struct intel_engine_cs *engine)
break;
default:
MISSING_CASE(engine->class);
return;
goto out;
}

if (!validate_cmds_sorted(engine, cmd_tables, cmd_table_count)) {
drm_err(&engine->i915->drm,
"%s: command descriptions are not sorted\n",
engine->name);
return;
goto out;
}
if (!validate_regs_sorted(engine)) {
drm_err(&engine->i915->drm,
"%s: registers are not sorted\n", engine->name);
return;
goto out;
}

ret = init_hash_table(engine, cmd_tables, cmd_table_count);
if (ret) {
drm_err(&engine->i915->drm,
"%s: initialised failed!\n", engine->name);
fini_hash_table(engine);
return;
goto out;
}

engine->flags |= I915_ENGINE_USING_CMD_PARSER;

out:
if (intel_engine_requires_cmd_parser(engine) &&
!intel_engine_using_cmd_parser(engine))
return -EINVAL;

return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ const char *i915_cache_level_str(struct drm_i915_private *i915, int type);

/* i915_cmd_parser.c */
int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv);
void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
int intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
int intel_engine_cmd_parser(struct intel_engine_cs *engine,
struct i915_vma *batch,
Expand Down

0 comments on commit 5a1a659

Please sign in to comment.