[PATCH 6/7] drm/i915: Fail too long user submissions by default
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Thu Mar 11 15:30:05 UTC 2021
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
...
10s default fence timeout
...
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
drivers/gpu/drm/i915/Kconfig.profile | 8 ++++
drivers/gpu/drm/i915/gem/i915_gem_context.c | 46 +++++++++++++++++----
2 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/i915/Kconfig.profile b/drivers/gpu/drm/i915/Kconfig.profile
index 35bbe2b80596..55e157ffff73 100644
--- a/drivers/gpu/drm/i915/Kconfig.profile
+++ b/drivers/gpu/drm/i915/Kconfig.profile
@@ -1,3 +1,11 @@
+config DRM_I915_REQUEST_TIMEOUT
+ int "Default timeout for requests (ms)"
+ default 10000 # milliseconds
+ help
+ ...
+
+ May be 0 to disable the timeout.
+
config DRM_I915_FENCE_TIMEOUT
int "Timeout for unsignaled foreign fences (ms, jiffy granularity)"
default 10000 # milliseconds
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index af69c27c7518..55fcc872b7c4 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -854,6 +854,25 @@ static void __assign_timeline(struct i915_gem_context *ctx,
context_apply_all(ctx, __apply_timeline, timeline);
}
+static int
+__set_watchdog(struct i915_gem_context *ctx, unsigned long timeout_us);
+
+static void __set_default_fence_expiry(struct i915_gem_context *ctx)
+{
+ struct drm_i915_private *i915 = ctx->i915;
+ int ret;
+
+ if (!IS_ACTIVE(CONFIG_DRM_I915_REQUEST_TIMEOUT))
+ return;
+
+ /* Default expiry for user fences. */
+ ret = __set_watchdog(ctx, CONFIG_DRM_I915_REQUEST_TIMEOUT * 1000);
+ if (ret)
+ drm_notice(&i915->drm,
+ "Failed to configure default fence expiry! (%d)",
+ ret);
+}
+
static struct i915_gem_context *
i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
{
@@ -898,6 +917,8 @@ i915_gem_create_context(struct drm_i915_private *i915, unsigned int flags)
intel_timeline_put(timeline);
}
+ __set_default_fence_expiry(ctx);
+
trace_i915_context_create(ctx);
return ctx;
@@ -1404,20 +1425,31 @@ static int __apply_watchdog(struct intel_context *ce, void *timeout_us)
return intel_context_set_watchdog_us(ce, (u64)timeout_us);
}
-static int set_watchdog(struct i915_gem_context *ctx,
- struct drm_i915_gem_context_param *args)
+static int
+__set_watchdog(struct i915_gem_context *ctx, unsigned long timeout_us)
{
int ret;
+ ret = context_apply_all(ctx, __apply_watchdog, (void *)timeout_us);
+ if (!ret)
+ ctx->watchdog.timeout_us = timeout_us;
+
+ return ret;
+}
+
+static int set_watchdog(struct i915_gem_context *ctx,
+ struct drm_i915_gem_context_param *args)
+{
if (args->size)
return -EINVAL;
- ret = context_apply_all(ctx, __apply_watchdog, (void *)args->value);
-
- if (!ret)
- ctx->watchdog.timeout_us = args->value;
+ /* Disallow disabling or configuring longer watchdog than default. */
+ if (IS_ACTIVE(CONFIG_DRM_I915_REQUEST_TIMEOUT) &&
+ (!args->value ||
+ args->value > CONFIG_DRM_I915_REQUEST_TIMEOUT * 1000))
+ return -EPERM;
- return ret;
+ return __set_watchdog(ctx, args->value);
}
static int __get_ringsize(struct intel_context *ce, void *arg)
--
2.27.0
More information about the Intel-gfx-trybot
mailing list