All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH 02/17] drm/i915/perf: Mark up the racy use of perf->exclusive_stream
Date: Wed, 26 Feb 2020 09:42:59 +0000	[thread overview]
Message-ID: <20200226094314.1500667-2-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20200226094314.1500667-1-chris@chris-wilson.co.uk>

Inside the general i915_oa_init_reg_state() we avoid using the
perf->mutex. However, we rely on perf->exclusive_stream being valid to
access at that point, and for that we have to control the race with
disabling perf. This relies on the disabling being a heavy barrier that
inspects all active contexts, after marking the perf->exclusive_stream
as not available. This should ensure that there are no more concurrent
accesses to the perf->exclusive_stream as we destroy it.

Mark up the races around the perf->exclusive_stream so that they stand
out much more. (And hopefully we will be running kcsan to start
validating that the only races we have are carefully controlled.)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
---
 drivers/gpu/drm/i915/i915_perf.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index e34c79df6ebc..0838a12e2dc5 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -1405,8 +1405,10 @@ static void i915_oa_stream_destroy(struct i915_perf_stream *stream)
 	/*
 	 * Unset exclusive_stream first, it will be checked while disabling
 	 * the metric set on gen8+.
+	 *
+	 * See i915_oa_init_reg_state() and lrc_configure_all_contexts()
 	 */
-	perf->exclusive_stream = NULL;
+	WRITE_ONCE(perf->exclusive_stream, NULL);
 	perf->ops.disable_metric_set(stream);
 
 	free_oa_buffer(stream);
@@ -2847,7 +2849,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
 		goto err_oa_buf_alloc;
 
 	stream->ops = &i915_oa_stream_ops;
-	perf->exclusive_stream = stream;
+	WRITE_ONCE(perf->exclusive_stream, stream);
 
 	ret = perf->ops.enable_metric_set(stream);
 	if (ret) {
@@ -2867,7 +2869,7 @@ static int i915_oa_stream_init(struct i915_perf_stream *stream,
 	return 0;
 
 err_enable:
-	perf->exclusive_stream = NULL;
+	WRITE_ONCE(perf->exclusive_stream, NULL);
 	perf->ops.disable_metric_set(stream);
 
 	free_oa_buffer(stream);
@@ -2893,12 +2895,11 @@ void i915_oa_init_reg_state(const struct intel_context *ce,
 {
 	struct i915_perf_stream *stream;
 
-	/* perf.exclusive_stream serialised by lrc_configure_all_contexts() */
-
 	if (engine->class != RENDER_CLASS)
 		return;
 
-	stream = engine->i915->perf.exclusive_stream;
+	/* perf.exclusive_stream serialised by lrc_configure_all_contexts() */
+	stream = READ_ONCE(engine->i915->perf.exclusive_stream);
 	/*
 	 * For gen12, only CTX_R_PWR_CLK_STATE needs update, but the caller
 	 * is already doing that, so nothing to be done for gen12 here.
-- 
2.25.1

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

  reply	other threads:[~2020-02-26  9:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  9:42 [Intel-gfx] [PATCH 01/17] drm/i915/gt: Reset queue_priority_hint after wedging Chris Wilson
2020-02-26  9:42 ` Chris Wilson [this message]
2020-02-26  9:43 ` [Intel-gfx] [PATCH 03/17] drm/i915: Manually acquire engine-wakeref around use of kernel_context Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 04/17] drm/i915/gt: Pull marking vm as closed underneath the vm->mutex Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 05/17] drm/i915: Protect i915_request_await_start from early waits Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 06/17] drm/i915/selftests: Verify LRC isolation Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 07/17] drm/i915/selftests: Check recovery from corrupted LRC Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 08/17] drm/i915/selftests: Wait for the kernel context switch Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 09/17] drm/i915/selftests: Be a little more lenient for reset workers Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 10/17] drm/i915/selftests: Add request throughput measurement to perf Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 11/17] drm/i915/gem: Consolidate ctx->engines[] release Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 12/17] drm/i915/gt: Prevent allocation on a banned context Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 13/17] drm/i915/gem: Check that the context wasn't closed during setup Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 14/17] drm/i915/gt: Declare when we enabled timeslicing Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 15/17] drm/i915/gt: Yield the timeslice if caught waiting on a user semaphore Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 16/17] drm/i915/execlists: Check the sentinel is alone in the ELSP Chris Wilson
2020-02-26  9:43 ` [Intel-gfx] [PATCH 17/17] drm/i915/execlists: Reduce preempt-to-busy roundtrip delay Chris Wilson
2020-02-26 19:12 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for series starting with [01/17] drm/i915/gt: Reset queue_priority_hint after wedging Patchwork
2020-02-26 19:39 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-02-27 10:25 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " 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=20200226094314.1500667-2-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.