All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexdeucher@gmail.com>
To: stable@vger.kernel.org
Cc: nicholas.kazlauskas@amd.com,
	Alex Deucher <alexander.deucher@amd.com>,
	David Francis <david.francis@amd.com>
Subject: [PATCH 3/3] drm/amd/display: Don't replace the dc_state for fast updates
Date: Fri, 20 Sep 2019 09:03:38 -0500	[thread overview]
Message-ID: <20190920140338.3172-4-alexander.deucher@amd.com> (raw)
In-Reply-To: <20190920140338.3172-1-alexander.deucher@amd.com>

From: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>

[Why]
DRM private objects have no hw_done/flip_done fencing mechanism on their
own and cannot be used to sequence commits accordingly.

When issuing commits that don't touch the same set of hardware resources
like page-flips on different CRTCs we can run into the issue below
because of this:

1. Client requests non-blocking Commit #1, has a new dc_state #1,
state is swapped, commit tail is deferred to work queue

2. Client requests non-blocking Commit #2, has a new dc_state #2,
state is swapped, commit tail is deferred to work queue

3. Commit #2 work starts, commit tail finishes,
atomic state is cleared, dc_state #1 is freed

4. Commit #1 work starts,
commit tail encounters null pointer deref on dc_state #1

In order to change the DC state as in the private object we need to
ensure that we wait for all outstanding commits to finish and that
any other pending commits must wait for the current one to finish as
well.

We do this for MEDIUM and FULL updates. But not for FAST updates, nor
would we want to since it would cause stuttering from the delays.

FAST updates that go through dm_determine_update_type_for_commit always
create a new dc_state and lock the DRM private object if there are
any changed planes.

We need the old state to validate, but we don't actually need the new
state here.

[How]
If the commit isn't a full update then the use after free can be
resolved by simply discarding the new state entirely and retaining
the existing one instead.

With this change the sequence above can be reexamined. Commit #2 will
still free Commit #1's reference, but before this happens we actually
added an additional reference as part of Commit #2.

If an update comes in during this that needs to change the dc_state
it will need to wait on Commit #1 and Commit #2 to finish. Then it'll
swap the state, finish the work in commit tail and drop the last
reference on Commit #2's dc_state.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204181
Fixes: 004b3938e637 ("drm/amd/display: Check scaling info when determing update type")

Bug: https://bugzilla.kernel.org/show_bug.cgi?id=204181
Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: David Francis <david.francis@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit bd200d190f45b62c006d1ad0a63eeffd87db7a47)
Cc: stable@vger.kernel.org
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 8df49740518e..beb2d268d1ef 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -7346,6 +7346,29 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
 			ret = -EINVAL;
 			goto fail;
 		}
+	} else {
+		/*
+		 * The commit is a fast update. Fast updates shouldn't change
+		 * the DC context, affect global validation, and can have their
+		 * commit work done in parallel with other commits not touching
+		 * the same resource. If we have a new DC context as part of
+		 * the DM atomic state from validation we need to free it and
+		 * retain the existing one instead.
+		 */
+		struct dm_atomic_state *new_dm_state, *old_dm_state;
+
+		new_dm_state = dm_atomic_get_new_state(state);
+		old_dm_state = dm_atomic_get_old_state(state);
+
+		if (new_dm_state && old_dm_state) {
+			if (new_dm_state->context)
+				dc_release_state(new_dm_state->context);
+
+			new_dm_state->context = old_dm_state->context;
+
+			if (old_dm_state->context)
+				dc_retain_state(old_dm_state->context);
+		}
 	}
 
 	/* Must be success */
-- 
2.20.1


  parent reply	other threads:[~2019-09-20 14:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-20 14:03 [PATCH 0/3] amdgpu DC fixes for stable Alex Deucher
2019-09-20 14:03 ` [PATCH 1/3] drm/amd/display: Allow cursor async updates for framebuffer swaps Alex Deucher
2019-09-20 14:03 ` [PATCH 2/3] drm/amd/display: Skip determining update type for async updates Alex Deucher
2019-09-20 14:03 ` Alex Deucher [this message]
2019-09-20 14:11 ` [PATCH 0/3] amdgpu DC fixes for stable Greg KH
2019-09-20 14:15   ` Deucher, Alexander
2019-09-22  8:14     ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2019-07-31 16:26 [PATCH 1/3] drm/amd/display: Allow cursor async updates for framebuffer swaps Nicholas Kazlauskas
     [not found] ` <20190731162604.28509-1-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org>
2019-07-31 16:26   ` [PATCH 3/3] drm/amd/display: Don't replace the dc_state for fast updates Nicholas Kazlauskas
     [not found]     ` <20190731162604.28509-3-nicholas.kazlauskas-5C7GfCeVMHo@public.gmane.org>
2019-08-01 18:58       ` Alex Deucher
     [not found]         ` <CADnq5_O+v6GC+DYOXkPRwT6S9tjiRs9uNEntS4wdCZVTUpmdAA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-08-01 19:25           ` Francis, David
     [not found]             ` <BN8PR12MB3217433D27E25905A31FC8EFEFDE0-h6+T2+wrnx1RCczRXbE7rwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-08-01 19:40               ` Kazlauskas, Nicholas

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=20190920140338.3172-4-alexander.deucher@amd.com \
    --to=alexdeucher@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=david.francis@amd.com \
    --cc=nicholas.kazlauskas@amd.com \
    --cc=stable@vger.kernel.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.