All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oded Gabbay <oded.gabbay@gmail.com>
To: maarten.lankhorst@canonical.com, daniel.vetter@ffwll.ch,
	dri-devel@lists.freedesktop.org, robdclark@gmail.com
Subject: [PATCH] dma-fence: add comment for WARN_ON in dma_fence_release()
Date: Mon, 29 Jan 2018 17:40:02 +0200	[thread overview]
Message-ID: <20180129154002.3287-1-oded.gabbay@gmail.com> (raw)

In dma_fence_release() there is a WARN_ON which could be triggered by
several cases of wrong dma-fence usage. This patch adds a comment to
explain two use-cases to help driver developers that use dma-fence
and trigger that WARN_ON to better understand the reasons for it.

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
---
 drivers/dma-buf/dma-fence.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 5d101c4053e0..a7170ab23ec0 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -171,6 +171,39 @@ void dma_fence_release(struct kref *kref)
 
 	trace_dma_fence_destroy(fence);
 
+	/*
+	 * If the WARN_ON below is triggered it could be because the dma fence
+	 * was not signaled and therefore, the cb list is still not empty
+	 * because the cb functions were not called.
+	 *
+	 * A more subtle case is where the fence got signaled by a thread that
+	 * didn't hold a ref to the fence. The following describes the scenario:
+	 *
+	 *      Thread A                            Thread B
+	 *--------------------------        --------------------------
+	 * calls dma_fence_signal() {
+	 *      set signal bit
+	 *
+	 *            scheduled out
+	 *      ---------------------------> calls dma_fence_wait_timeout() and
+	 *                                   returns immediately
+	 *
+	 *                                   calls dma_fence_put()
+	 *                                         |
+	 *                                         |thread A doesn't hold ref
+	 *                                         |to fence so ref goes to 0
+	 *                                         |and release is called
+	 *                                         |
+	 *                                         -> dma_fence_release()
+	 *                                            |
+	 *                                            -> WARN_ON triggered
+	 *
+	 *      go over CB list,
+	 *      call each CB and remove it
+	 *      }
+	 *
+	 *
+	 */
 	WARN_ON(!list_empty(&fence->cb_list));
 
 	if (fence->ops->release)
-- 
2.14.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

             reply	other threads:[~2018-01-29 15:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 15:40 Oded Gabbay [this message]
2018-01-30 10:33 ` [PATCH] dma-fence: add comment for WARN_ON in dma_fence_release() Daniel Vetter
2018-01-31  9:03   ` Oded Gabbay
2018-01-31 10:18     ` Daniel Vetter

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=20180129154002.3287-1-oded.gabbay@gmail.com \
    --to=oded.gabbay@gmail.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=maarten.lankhorst@canonical.com \
    --cc=robdclark@gmail.com \
    /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.