AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Wentland <harry.wentland-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	shirish.s-5C7GfCeVMHo@public.gmane.org,
	sunpeng.li-5C7GfCeVMHo@public.gmane.org
Cc: Harry Wentland <harry.wentland-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH] drm/amd/display: Work around race beetween hw_done and wait_for_flip
Date: Fri, 28 Sep 2018 09:16:06 -0400	[thread overview]
Message-ID: <20180928131606.15931-1-harry.wentland@amd.com> (raw)
In-Reply-To: <1537795907-1168-1-git-send-email-shirish.s-5C7GfCeVMHo@public.gmane.org>

[Why]
There is a race that between drm_crtc_commit_hw_done and
drm_atomic_helper_wait_for_flip where the possibilty exist for the
crtc->commit to be cleared after the null check in wait_for_flip_done
but before the call to wait_for_completion_timeout on commit->flip_done.

[How]
Take a reference to all commits in the state before
drm_crtc_commit_hw_done is called and release those after
drm_atomic_helper_wait_for_flip has finished.

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
---

Would something like this work? I get the strong sense that this happens
because Intel and IMX use the helpers in the other order, hence the
dependency between hw_done and wait_for_flip was missed.

I'd rather make it obvious that there's (a) no reason to reorder these
two calls on AMD HW (other than this unexpected dependency) and (b) this
is something we'll probably want to fix in DRM.

Sorry it took me a while to understand what was happening here. Been
busy at XDC until Jordan and Leo reminded me to take another look.

Harry

 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 15 +++++++++++++++
 1 file changed, 15 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 0f10d920a785..ed9a7d680b63 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -4626,12 +4626,27 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
 	}
 	spin_unlock_irqrestore(&adev->ddev->event_lock, flags);
 
+	/*
+	 * WORKAROUND: Take a ref for all crtc_state commits to avoid
+	 * a race where the commit gets freed before commit_hw_done had
+	 * a chance to look for commit->flip_done
+	 */
+	for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
+		drm_crtc_commit_get(new_crtc_state->commit);
+
 	/* Signal HW programming completion */
 	drm_atomic_helper_commit_hw_done(state);
 
 	if (wait_for_vblank)
 		drm_atomic_helper_wait_for_flip_done(dev, state);
 
+	/*
+	 * WORKAROUND: put the commit refs from above (see comment on
+	 * the drm_crtc_commit_get call above)
+	 */
+	for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
+		drm_crtc_commit_put(new_crtc_state->commit);
+
 	drm_atomic_helper_cleanup_planes(dev, state);
 
 	/*
-- 
2.17.1

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

  parent reply	other threads:[~2018-09-28 13:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-24 13:31 [PATCH] drm/amd/display: move the nonblocking commit helpers appropriately Shirish S
     [not found] ` <1537795907-1168-1-git-send-email-shirish.s-5C7GfCeVMHo@public.gmane.org>
2018-09-28 13:16   ` Harry Wentland [this message]
     [not found]     ` <20180928131606.15931-1-harry.wentland-5C7GfCeVMHo@public.gmane.org>
2018-10-01  9:06       ` [PATCH] drm/amd/display: Work around race beetween hw_done and wait_for_flip S, Shirish
2018-10-01 23:26   ` [PATCH v2] drm/amd/display: Signal hw_done() after waiting for flip_done() sunpeng.li-5C7GfCeVMHo
     [not found]     ` <1538436399-28084-1-git-send-email-sunpeng.li-5C7GfCeVMHo@public.gmane.org>
2018-10-02 14:41       ` Harry Wentland

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=20180928131606.15931-1-harry.wentland@amd.com \
    --to=harry.wentland-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=shirish.s-5C7GfCeVMHo@public.gmane.org \
    --cc=sunpeng.li-5C7GfCeVMHo@public.gmane.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