Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking
@ 2016-08-05 16:37 Daniel Vetter
  2016-08-05 17:38 ` Chris Wilson
  2016-08-06  6:50 ` ✗ Ro.CI.BAT: failure for " Patchwork
  0 siblings, 2 replies; 4+ messages in thread
From: Daniel Vetter @ 2016-08-05 16:37 UTC (permalink / raw)
  To: Intel Graphics Development; +Cc: Daniel Vetter, Goel, Akash

When only rcu-protected we might peek at a reinitializing request.
Prevent carnage by making sure we don't accidentally chase a NULL
pointer.

The proper fix for this is to drop the memset (with kzalloc) in the
request allocation function, since that avoids both the NULL check in
these fastpaths and makes request allocation a notch lighter. But it
also means we need to careful audit all the paths to make sure nothing
gets upset and runs into garbage. And that's a bit much on a late Friday
with Joonas already on w/e. Also, today is drm-intel-next tag day, and
this will be the tag for the first 4.9 pull request.

Hence this easier to review interim fix, which will be replaced early next
week by the proper fix Chris is working on.

Fixes: 0eafec6d3244 ("drm/i915: Enable lockless lookup of request...")
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: "Goel, Akash" <akash.goel@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/i915_gem_request.h | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_request.h b/drivers/gpu/drm/i915/i915_gem_request.h
index 6002adc43523..e55492ba20ec 100644
--- a/drivers/gpu/drm/i915/i915_gem_request.h
+++ b/drivers/gpu/drm/i915/i915_gem_request.h
@@ -244,6 +244,26 @@ i915_gem_request_started(const struct drm_i915_gem_request *req)
 }
 
 static inline bool
+i915_gem_request_completed_rcu(const struct drm_i915_gem_request *req)
+{
+	struct intel_engine_cs *engine = READ_ONCE(req->engine);
+
+	/* When we peek at a request solely under rcu protection, without
+	 * hodling a full reference, the request might be in the process of
+	 * getting freed and reallocated. Make sure we don't stumble over a NULL
+	 * engine in that case.
+	 *
+	 * If we are hitting this race it means that the old request has been
+	 * released, which only happens once it has completed.
+	 */
+	if (!engine)
+		return true;
+
+	return i915_seqno_passed(intel_engine_get_seqno(engine),
+				 req->fence.seqno);
+}
+
+static inline bool
 i915_gem_request_completed(const struct drm_i915_gem_request *req)
 {
 	return i915_seqno_passed(intel_engine_get_seqno(req->engine),
@@ -384,7 +404,7 @@ i915_gem_active_peek_rcu(const struct i915_gem_active *active)
 	struct drm_i915_gem_request *request;
 
 	request = rcu_dereference(active->request);
-	if (!request || i915_gem_request_completed(request))
+	if (!request || i915_gem_request_completed_rcu(request))
 		return NULL;
 
 	return request;
@@ -459,7 +479,7 @@ __i915_gem_active_get_rcu(const struct i915_gem_active *active)
 		struct drm_i915_gem_request *request;
 
 		request = rcu_dereference(active->request);
-		if (!request || i915_gem_request_completed(request))
+		if (!request || i915_gem_request_completed_rcu(request))
 			return NULL;
 
 		request = i915_gem_request_get_rcu(request);
-- 
2.8.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking
  2016-08-05 16:37 [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking Daniel Vetter
@ 2016-08-05 17:38 ` Chris Wilson
  2016-08-05 19:24   ` Daniel Vetter
  2016-08-06  6:50 ` ✗ Ro.CI.BAT: failure for " Patchwork
  1 sibling, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2016-08-05 17:38 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: Intel Graphics Development, Goel, Akash

On Fri, Aug 05, 2016 at 06:37:00PM +0200, Daniel Vetter wrote:
> When only rcu-protected we might peek at a reinitializing request.
> Prevent carnage by making sure we don't accidentally chase a NULL
> pointer.
> 
> The proper fix for this is to drop the memset (with kzalloc) in the
> request allocation function, since that avoids both the NULL check in
> these fastpaths and makes request allocation a notch lighter. But it
> also means we need to careful audit all the paths to make sure nothing
> gets upset and runs into garbage. And that's a bit much on a late Friday
> with Joonas already on w/e. Also, today is drm-intel-next tag day, and
> this will be the tag for the first 4.9 pull request.
> 
> Hence this easier to review interim fix, which will be replaced early next
> week by the proper fix Chris is working on.
> 
> Fixes: 0eafec6d3244 ("drm/i915: Enable lockless lookup of request...")
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: "Goel, Akash" <akash.goel@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>

This is not complete either since we do RCU lookups elsewhere as well.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking
  2016-08-05 17:38 ` Chris Wilson
@ 2016-08-05 19:24   ` Daniel Vetter
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Vetter @ 2016-08-05 19:24 UTC (permalink / raw)
  To: Chris Wilson, Daniel Vetter, Intel Graphics Development,
	Goel, Akash, Joonas Lahtinen

On Fri, Aug 05, 2016 at 06:38:13PM +0100, Chris Wilson wrote:
> On Fri, Aug 05, 2016 at 06:37:00PM +0200, Daniel Vetter wrote:
> > When only rcu-protected we might peek at a reinitializing request.
> > Prevent carnage by making sure we don't accidentally chase a NULL
> > pointer.
> > 
> > The proper fix for this is to drop the memset (with kzalloc) in the
> > request allocation function, since that avoids both the NULL check in
> > these fastpaths and makes request allocation a notch lighter. But it
> > also means we need to careful audit all the paths to make sure nothing
> > gets upset and runs into garbage. And that's a bit much on a late Friday
> > with Joonas already on w/e. Also, today is drm-intel-next tag day, and
> > this will be the tag for the first 4.9 pull request.
> > 
> > Hence this easier to review interim fix, which will be replaced early next
> > week by the proper fix Chris is working on.
> > 
> > Fixes: 0eafec6d3244 ("drm/i915: Enable lockless lookup of request...")
> > Cc: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: "Goel, Akash" <akash.goel@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> This is not complete either since we do RCU lookups elsewhere as well.

Hunting throughout the code, the only other place I've found is in
i915_gpu_error.c. Only __active_get_engine_id looks at req->engine, and it
already has a NULL check.

I know that there's plenty of your patches pending which will add tons of
lockless request lockups, but I think for a short-term fix over the w/e
this is fine. Is there another place I've missed.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* ✗ Ro.CI.BAT: failure for drm/i915: Prevent oops on req->engine in rcu-protected peeking
  2016-08-05 16:37 [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking Daniel Vetter
  2016-08-05 17:38 ` Chris Wilson
@ 2016-08-06  6:50 ` Patchwork
  1 sibling, 0 replies; 4+ messages in thread
From: Patchwork @ 2016-08-06  6:50 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: Prevent oops on req->engine in rcu-protected peeking
URL   : https://patchwork.freedesktop.org/series/10724/
State : failure

== Summary ==

Series 10724v1 drm/i915: Prevent oops on req->engine in rcu-protected peeking
http://patchwork.freedesktop.org/api/1.0/series/10724/revisions/1/mbox

Test drv_module_reload_basic:
                pass       -> SKIP       (ro-skl3-i5-6260u)
Test kms_cursor_legacy:
        Subgroup basic-cursor-vs-flip-varying-size:
                pass       -> FAIL       (ro-ilk1-i5-650)
        Subgroup basic-flip-vs-cursor-legacy:
                pass       -> FAIL       (ro-hsw-i7-4770r)
                pass       -> FAIL       (ro-skl3-i5-6260u)
                fail       -> PASS       (ro-bdw-i5-5250u)
        Subgroup basic-flip-vs-cursor-varying-size:
                fail       -> PASS       (ro-bdw-i5-5250u)
Test kms_flip:
        Subgroup basic-flip-vs-wf_vblank:
                pass       -> FAIL       (ro-ivb-i7-3770)
                pass       -> FAIL       (ro-byt-n2820)

fi-kbl-qkkr      total:244  pass:185  dwarn:28  dfail:1   fail:3   skip:27 
ro-bdw-i5-5250u  total:240  pass:220  dwarn:4   dfail:0   fail:0   skip:16 
ro-bdw-i7-5557U  total:240  pass:224  dwarn:0   dfail:0   fail:0   skip:16 
ro-bdw-i7-5600u  total:240  pass:207  dwarn:0   dfail:0   fail:1   skip:32 
ro-bsw-n3050     total:240  pass:194  dwarn:0   dfail:1   fail:3   skip:42 
ro-byt-n2820     total:240  pass:196  dwarn:0   dfail:0   fail:4   skip:40 
ro-hsw-i3-4010u  total:240  pass:214  dwarn:0   dfail:0   fail:0   skip:26 
ro-hsw-i7-4770r  total:240  pass:213  dwarn:0   dfail:0   fail:1   skip:26 
ro-ilk-i7-620lm  total:240  pass:173  dwarn:1   dfail:0   fail:1   skip:65 
ro-ilk1-i5-650   total:235  pass:173  dwarn:0   dfail:0   fail:2   skip:60 
ro-ivb-i7-3770   total:240  pass:204  dwarn:0   dfail:0   fail:1   skip:35 
ro-ivb2-i7-3770  total:240  pass:209  dwarn:0   dfail:0   fail:0   skip:31 
ro-skl3-i5-6260u total:240  pass:221  dwarn:0   dfail:0   fail:4   skip:15 
ro-snb-i7-2620M  total:240  pass:198  dwarn:0   dfail:0   fail:1   skip:41 

Results at /archive/results/CI_IGT_test/RO_Patchwork_1735/

b834992 drm-intel-nightly: 2016y-08m-05d-20h-40m-44s UTC integration manifest
b6d8316 drm/i915: Prevent oops on req->engine in rcu-protected peeking

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-06  6:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-05 16:37 [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking Daniel Vetter
2016-08-05 17:38 ` Chris Wilson
2016-08-05 19:24   ` Daniel Vetter
2016-08-06  6:50 ` ✗ Ro.CI.BAT: failure for " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox