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 05/17] drm/i915: Protect i915_request_await_start from early waits
Date: Wed, 26 Feb 2020 09:43:02 +0000	[thread overview]
Message-ID: <20200226094314.1500667-5-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20200226094314.1500667-1-chris@chris-wilson.co.uk>

We need to be extremely careful inside i915_request_await_start() as it
needs to walk the list of requests in the foreign timeline with very
little protection. As we hold our own timeline mutex, we can not nest
inside the signaler's timeline mutex, so all that remains is our RCU
protection. However, to be safe we need to tell the compiler that we may
be traversing the list only under RCU protection, and furthermore we
need to start declaring requests as elements of the timeline from their
construction.

Fixes: 9ddc8ec027a3 ("drm/i915: Eliminate the trylock for awaiting an earlier request")
Fixes: 6a79d848403d ("drm/i915: Lock signaler timeline while navigating")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_request.c | 41 ++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c
index d53af93b919b..e5a55801f753 100644
--- a/drivers/gpu/drm/i915/i915_request.c
+++ b/drivers/gpu/drm/i915/i915_request.c
@@ -290,7 +290,7 @@ bool i915_request_retire(struct i915_request *rq)
 	spin_unlock_irq(&rq->lock);
 
 	remove_from_client(rq);
-	list_del(&rq->link);
+	list_del_rcu(&rq->link);
 
 	intel_context_exit(rq->context);
 	intel_context_unpin(rq->context);
@@ -736,6 +736,8 @@ __i915_request_create(struct intel_context *ce, gfp_t gfp)
 	rq->infix = rq->ring->emit; /* end of header; start of user payload */
 
 	intel_context_mark_active(ce);
+	list_add_tail_rcu(&rq->link, &tl->requests);
+
 	return rq;
 
 err_unwind:
@@ -792,13 +794,23 @@ i915_request_await_start(struct i915_request *rq, struct i915_request *signal)
 	GEM_BUG_ON(i915_request_timeline(rq) ==
 		   rcu_access_pointer(signal->timeline));
 
+	if (i915_request_started(signal))
+		return 0;
+
 	fence = NULL;
 	rcu_read_lock();
 	spin_lock_irq(&signal->lock);
-	if (!i915_request_started(signal) &&
-	    !list_is_first(&signal->link,
-			   &rcu_dereference(signal->timeline)->requests)) {
-		struct i915_request *prev = list_prev_entry(signal, link);
+	do {
+		struct list_head *pos = READ_ONCE(signal->link.prev);
+		struct i915_request *prev;
+
+		/* Confirm signal has not been retired, the link is valid */
+		if (unlikely(i915_request_started(signal)))
+			break;
+
+		/* Is signal the earliest request on its timeline? */
+		if (pos == &rcu_dereference(signal->timeline)->requests)
+			break;
 
 		/*
 		 * Peek at the request before us in the timeline. That
@@ -806,13 +818,18 @@ i915_request_await_start(struct i915_request *rq, struct i915_request *signal)
 		 * after acquiring a reference to it, confirm that it is
 		 * still part of the signaler's timeline.
 		 */
-		if (i915_request_get_rcu(prev)) {
-			if (list_next_entry(prev, link) == signal)
-				fence = &prev->fence;
-			else
-				i915_request_put(prev);
+		prev = list_entry(pos, typeof(*prev), link);
+		if (!i915_request_get_rcu(prev))
+			break;
+
+		/* After the strong barrier, confirm prev is still attached */
+		if (unlikely(READ_ONCE(prev->link.next) != &signal->link)) {
+			i915_request_put(prev);
+			break;
 		}
-	}
+
+		fence = &prev->fence;
+	} while (0);
 	spin_unlock_irq(&signal->lock);
 	rcu_read_unlock();
 	if (!fence)
@@ -1253,8 +1270,6 @@ __i915_request_add_to_timeline(struct i915_request *rq)
 							 0);
 	}
 
-	list_add_tail(&rq->link, &timeline->requests);
-
 	/*
 	 * Make sure that no request gazumped us - if it was allocated after
 	 * our i915_request_alloc() and called __i915_request_add() before
-- 
2.25.1

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

  parent 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 ` [Intel-gfx] [PATCH 02/17] drm/i915/perf: Mark up the racy use of perf->exclusive_stream Chris Wilson
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 ` Chris Wilson [this message]
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-5-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.