From: Jason Ekstrand <jason@jlekstrand.net>
To: dri-devel@lists.freedesktop.org
Cc: Jason Ekstrand <jason.ekstrand@intel.com>,
Jason Ekstrand <jason@jlekstrand.net>
Subject: [PATCH 2/7] drm/syncobj: Add a race-free drm_syncobj_fence_get helper (v2)
Date: Tue, 15 Aug 2017 21:13:50 -0700 [thread overview]
Message-ID: <1502856835-9433-3-git-send-email-jason.ekstrand@intel.com> (raw)
In-Reply-To: <1502856835-9433-1-git-send-email-jason.ekstrand@intel.com>
The atomic exchange operation in drm_syncobj_replace_fence is sufficient
for the case where it races with itself. However, if you have a race
between a replace_fence and dma_fence_get(syncobj->fence), you may end
up with the entire replace_fence happening between the point in time
where the one thread gets the syncobj->fence pointer and when it calls
dma_fence_get() on it. If this happens, then the reference may be
dropped before we get a chance to get a new one. The new helper uses
dma_fence_get_rcu_safe to get rid of the race.
This is also needed because it allows us to do a bit more than just get
a reference in drm_syncobj_fence_get should we wish to do so.
v2:
- RCU isn't that scary
- Call rcu_read_lock/unlock
- Don't rename fence to _fence
- Make the helper static inline
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Acked-by: Christian König <christian.koenig@amd.com> (v1)
---
drivers/gpu/drm/drm_syncobj.c | 2 +-
include/drm/drm_syncobj.h | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 0412b0b..eea38d8 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -105,7 +105,7 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
if (!syncobj)
return -ENOENT;
- *fence = dma_fence_get(syncobj->fence);
+ *fence = drm_syncobj_fence_get(syncobj);
if (!*fence) {
ret = -EINVAL;
}
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 7d4ad77..ce94d14 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -77,6 +77,18 @@ drm_syncobj_put(struct drm_syncobj *obj)
kref_put(&obj->refcount, drm_syncobj_free);
}
+static inline struct dma_fence *
+drm_syncobj_fence_get(struct drm_syncobj *syncobj)
+{
+ struct dma_fence *fence;
+
+ rcu_read_lock();
+ fence = dma_fence_get_rcu_safe(&syncobj->fence);
+ rcu_read_unlock();
+
+ return fence;
+}
+
struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
u32 handle);
void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
--
2.5.0.400.gff86faf
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-08-16 4:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-16 4:13 [PATCH 0/7] drm/syncobj: Add full-featured wait support (v3) Jason Ekstrand
2017-08-16 4:13 ` [PATCH 1/7] drm/syncobj: Rename fence_get to find_fence Jason Ekstrand
2017-08-16 4:13 ` Jason Ekstrand [this message]
2017-08-16 4:13 ` [PATCH 3/7] i915: Use drm_syncobj_fence_get Jason Ekstrand
2017-08-16 4:13 ` [PATCH 4/7] drm/syncobj: add sync obj wait interface. (v8) Jason Ekstrand
2017-08-16 4:13 ` [PATCH 5/7] drm/syncobj: Add a reset ioctl Jason Ekstrand
2017-08-16 4:13 ` [PATCH 6/7] drm/syncobj: Add a callback mechanism for replace_fence (v2) Jason Ekstrand
2017-08-16 4:13 ` [PATCH 7/7] drm/syncobj: Allow wait for submit and signal behavior (v5) Jason Ekstrand
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=1502856835-9433-3-git-send-email-jason.ekstrand@intel.com \
--to=jason@jlekstrand.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=jason.ekstrand@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox