From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
"Goel, Akash" <akash.goel@intel.com>
Subject: [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking
Date: Fri, 5 Aug 2016 18:37:00 +0200 [thread overview]
Message-ID: <1470415020-1769-1-git-send-email-daniel.vetter@ffwll.ch> (raw)
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
next reply other threads:[~2016-08-05 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 16:37 Daniel Vetter [this message]
2016-08-05 17:38 ` [PATCH] drm/i915: Prevent oops on req->engine in rcu-protected peeking Chris Wilson
2016-08-05 19:24 ` Daniel Vetter
2016-08-06 6:50 ` ✗ Ro.CI.BAT: failure for " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470415020-1769-1-git-send-email-daniel.vetter@ffwll.ch \
--to=daniel.vetter@ffwll.ch \
--cc=akash.goel@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox