drm/i915: Fix a use after free, and unbalanced refcounting
Subsystems (2)
PATCH 1/1 drm/i915: Fix a use after free, and unbalanced refcounting
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88652
When converting from implicitly tracked execlist queue items to ref counted requests, not all free's of requests were replaced with unrefs, and extraneous refs/unrefs of contexts were added.
Correct the unbalanced refcount & replace the free's.
Problem introduced in:
commit 6d3d8274bc45de4babb62d64562d92af984dd238
Author: Nick Hoath <[email protected]> AuthorDate: Thu Jan 15 13:10:39 2015 +0000
drm/i915: Subsume intel_ctx_submit_request in to drm_i915_gem_request
--- drivers/gpu/drm/i915/i915_gem.c | 3 +-- drivers/gpu/drm/i915/intel_lrc.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/i915_gem.c +1 -2
@@ -2660,8 +2660,7 @@ static void i915_gem_reset_ring_cleanup(struct drm_i915_private *dev_priv,if (submit_req->ctx != ring->default_context)intel_lr_context_unpin (ring, submit_req->ctx); -i915_gem_context_unreference (submit_req->ctx); -kfree (submit_req); +i915_gem_request_unreference (submit_req); }/*
drivers/gpu/drm/i915/intel_lrc.c +1 -2
@@ -518,12 +518,12 @@ static int execlists_context_queue(struct intel_engine_cs *ring,return -ENOMEM ; request->ring = ring; request->ctx = to; +i915_gem_context_reference (request->ctx); }else {WARN_ON (to != request->ctx); } request->tail = tail;i915_gem_request_reference (request); -i915_gem_context_reference (request->ctx);intel_runtime_pm_get (dev_priv);
@@ -740,7 +740,6 @@ void intel_execlists_retire_requests(struct intel_engine_cs *ring)if (ctx_obj && (ctx != ring->default_context))intel_lr_context_unpin (ring, ctx);intel_runtime_pm_put (dev_priv); -i915_gem_context_unreference (ctx);list_del (&req->execlist_link);i915_gem_request_unreference (req); }
Signature · 6 lines
2.1.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 7 lines · Nick Hoath
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88652
When converting from implicitly tracked execlist queue items to ref counted requests, not all free's of requests were replaced with unrefs, and extraneous refs/unrefs of contexts were added.
Correct the unbalanced refcount & replace the free's.
Quoted 6 lines
Problem introduced in:
commit6d3d8274bc45de4babb62d64562d92af984dd238Author: Nick Hoath <[email protected]> AuthorDate: Thu Jan 15 13:10:39 2015 +0000drm/i915: Subsume
intel_ctx_submit_requestin todrm_i915_gem_request
Imo the commit message should be ammended with a short paragraph explainig the various pointers and implied and explicit references we now have around requests and contexts. That way review of this will get a bit easier and we'll avoid another misunderstanding.
I even think we should add a comment in the header to request.ctx to explain the rules since apparently they've not been fully clear.
Quoted 1 line
Signed-off-by Nick Hoath <[email protected]>
But yeah this makes a lot more sense imo. Please feed this to QA for stress-testing in all the relevant bugs. Today I have my head full with kms code so not a good time for a full in-depth review. But I think it'd be good if other people take a look anyway, so please throw this at a few ppl from the vpg core team too.
Thanks, Daniel
Quoted 48 lines
--- drivers/gpu/drm/i915/i915_gem.c | 3 +-- drivers/gpu/drm/i915/intel_lrc.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)drivers/gpu/drm/i915/i915_gem.c +1
-2@@ -2660,8 +2660,7 @@ static void i915_gem_reset_ring_cleanup(struct drm_i915_private *dev_priv,if (submit_req->ctx != ring->default_context)intel_lr_context_unpin (ring, submit_req->ctx); -i915_gem_context_unreference (submit_req->ctx); -kfree (submit_req); +i915_gem_request_unreference (submit_req); }/* drivers/gpu/drm/i915/intel_lrc.c +1
-2@@ -518,12 +518,12 @@ static int execlists_context_queue(struct intel_engine_cs *ring,return -ENOMEM ; request->ring = ring; request->ctx = to; +i915_gem_context_reference (request->ctx); }else {WARN_ON (to != request->ctx); } request->tail = tail;i915_gem_request_reference (request); -i915_gem_context_reference (request->ctx);intel_runtime_pm_get (dev_priv);@@ -740,7 +740,6 @@ void intel_execlists_retire_requests(struct intel_engine_cs *ring)if (ctx_obj && (ctx != ring->default_context))intel_lr_context_unpin (ring, ctx);intel_runtime_pm_put (dev_priv); -i915_gem_context_unreference (ctx);list_del (&req->execlist_link);i915_gem_request_unreference (req); }Signature · 1 line
2.1.1
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 24 lines
-----Original Message-----
From: Intel-gfx [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Friday, February 13, 2015 1:50 PM
To: Hoath, Nicholas
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Fix a use after free, and unbalanced refcountingQuoted 7 lines · Nick Hoath
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88652
When converting from implicitly tracked execlist queue items to ref counted requests, not all free's of requests were replaced with unrefs, and extraneous refs/unrefs of contexts were added.
Correct the unbalanced refcount & replace the free's.Quoted 6 lines
Problem introduced in:
commit6d3d8274bc45de4babb62d64562d92af984dd238Author: Nick Hoath <[email protected]> AuthorDate: Thu Jan 15 13:10:39 2015 +0000drm/i915: Subsume
intel_ctx_submit_requestin todrm_i915_gem_request
Quoted 7 lines
Imo the commit message should be ammended with a short paragraph explainig the various pointers and implied and explicit references we now have around requests and contexts. That way review of this will get a bit easier and we'll avoid another misunderstanding.
I even think we should add a comment in the header to request.ctx to explain the rules since apparently they've not been fully clear.
Agree that more documentation around these ctx refs would be good to have to clear up confusion.
For example, I initially thought that this patch introduced a new use-after-free because of the removal of the ctx ref in execlists_context_queue().
Quoted 8 lines
Quoted 2 lines
Signed-off-by Nick Hoath <[email protected]>But yeah this makes a lot more sense imo. Please feed this to QA for stress-testing in all the relevant bugs. Today I have my head full with kms code so not a good time for a full in-depth review. But I think it'd be good if other people take a look anyway, so please throw this at a few ppl from the vpg core team too.
I guess that would be me...
The code changes look OK, would like to see the updated comments and QA results.
Cheers,
Thomas.
Quoted 55 lines
Thanks, Daniel
Review
Quoted 6 lines
--- drivers/gpu/drm/i915/i915_gem.c | 3 +-- drivers/gpu/drm/i915/intel_lrc.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/i915/i915_gem.cdrivers/gpu/drm/i915/i915_gem.c static void i915_gem_reset_ring_cleanup(struct
Quoted 4 lines
index 1765989..79e48b2 100644
drivers/gpu/drm/i915/i915_gem.c +0
-0@@ -2660,8 +2660,7 @@ static void i915_gem_reset_ring_cleanup(struct
drm_i915_private*dev_priv,drivers/gpu/drm/i915/intel_lrc.c static int execlists_context_queue(struct
Quoted 14 lines
drivers/gpu/drm/i915/i915_gem.c +1
-2if (submit_req->ctx != ring->default_context)intel_lr_context_unpin (ring, submit_req->ctx); -i915_gem_context_unreference (submit_req->ctx); -kfree (submit_req); +i915_gem_request_unreference (submit_req); }/* drivers/gpu/drm/i915/intel_lrc.c +0
-0@@ -518,12 +518,12 @@ static int execlists_context_queue(struct
intel_engine_cs*ring,drivers/gpu/drm/i915/intel_lrc.c void intel_execlists_retire_requests(struct
Quoted 14 lines
drivers/gpu/drm/i915/intel_lrc.c +1
-1return -ENOMEM ; request->ring = ring; request->ctx = to; +i915_gem_context_reference (request->ctx); }else {WARN_ON (to != request->ctx); } request->tail = tail;i915_gem_request_reference (request); -i915_gem_context_reference (request->ctx);intel_runtime_pm_get (dev_priv);@@ -740,7 +740,6 @@ void intel_execlists_retire_requests(struct
intel_engine_cs*ring)Quoted 10 lines
drivers/gpu/drm/i915/intel_lrc.c +0
-2if (ctx_obj && (ctx != ring->default_context))intel_lr_context_unpin (ring, ctx);intel_runtime_pm_put (dev_priv); -i915_gem_context_unreference (ctx);list_del (&req->execlist_link);i915_gem_request_unreference (req); } --2.1.1
Quoted 8 lines
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Task id: 5771 -------------------------------------Summary-------------------------------------
Platform Delta drm-intel-nightly Series Applied
PNV 281/281 281/281 ILK 313/313 313/313 SNB 309/309 309/309 IVB 382/382 382/382 BYT 296/296 296/296 HSW -1 426/426 425/426 BDW -1 318/318 317/318
-------------------------------------Detailed-------------------------------------
Platform Test drm-intel-nightly Series Applied
*HSW igt_kms_flip_dpms-off-confusion PASS(1) TIMEOUT(1)
*BDW igt_gem_gtt_hog PASS(1) DMESG_WARN(1)
Note: You need to pay more attention to line start with '*'
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx