aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-12-12 13:06:52 -0500
committerChris Wilson <chris@chris-wilson.co.uk>2017-12-13 08:17:59 -0500
commit31c70f97bec3107805df0f491485e7eacbc3a3ae (patch)
tree5e9b017c890aa15f7480982951967eda7e232ba4
parent2abe2f844645402e5d47012a04839d1c5cbffd0d (diff)
drm/i915: Ratelimit request allocation under oom
If we fail to allocate a request, we can reap the outstanding requests and push them to the request's slab's freelist before trying again. This forces us to ratelimit malicious clients that tie up all of the system resources in requests, instead of causing a system-wide oom. Testcase: igt/gem_shrink/execbuf1 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20171212180652.22061-3-chris@chris-wilson.co.uk
-rw-r--r--drivers/gpu/drm/i915/i915_gem_request.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c
index 4d5e2b714382..59f023bb7015 100644
--- a/drivers/gpu/drm/i915/i915_gem_request.c
+++ b/drivers/gpu/drm/i915/i915_gem_request.c
@@ -677,10 +677,21 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
677 * 677 *
678 * Do not use kmem_cache_zalloc() here! 678 * Do not use kmem_cache_zalloc() here!
679 */ 679 */
680 req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL); 680 req = kmem_cache_alloc(dev_priv->requests,
681 if (!req) { 681 GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
682 ret = -ENOMEM; 682 if (unlikely(!req)) {
683 goto err_unreserve; 683 /* Ratelimit ourselves to prevent oom from malicious clients */
684 ret = i915_gem_wait_for_idle(dev_priv,
685 I915_WAIT_LOCKED |
686 I915_WAIT_INTERRUPTIBLE);
687 if (ret)
688 goto err_unreserve;
689
690 req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
691 if (!req) {
692 ret = -ENOMEM;
693 goto err_unreserve;
694 }
684 } 695 }
685 696
686 req->timeline = i915_gem_context_lookup_timeline(ctx, engine); 697 req->timeline = i915_gem_context_lookup_timeline(ctx, engine);