All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, intel-gfx@lists.freedesktop.org
Subject: [PATCH 2/2] drm/syncobj: Lookup the syncobj with RCU protection
Date: Fri,  2 Aug 2019 17:36:59 +0100	[thread overview]
Message-ID: <20190802163659.23255-2-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20190802163659.23255-1-chris@chris-wilson.co.uk>

Relax the spinlock used for looking up the handle in the XArray and
acquiring a reference to it to an RCU protected critical section. This
incurs the requirement that we protect the syncobj struct itself using
RCU, which we achieve by simply calling kfree_rcu() and being more
careful in acquiring our reference.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_syncobj.c | 12 +++++-------
 include/drm/drm_syncobj.h     |  2 ++
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 4fc71dc9fc43..aafc03986a48 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -86,13 +86,11 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
 {
 	struct drm_syncobj *syncobj;
 
-	xa_lock(&file_private->syncobjs);
-
+	rcu_read_lock();
 	syncobj = xa_load(&file_private->syncobjs, handle);
-	if (syncobj)
-		drm_syncobj_get(syncobj);
-
-	xa_unlock(&file_private->syncobjs);
+	if (syncobj && !kref_get_unless_zero(&syncobj->refcount))
+		syncobj = NULL;
+	rcu_read_unlock();
 
 	return syncobj;
 }
@@ -309,7 +307,7 @@ void drm_syncobj_free(struct kref *kref)
 						   struct drm_syncobj,
 						   refcount);
 	drm_syncobj_replace_fence(syncobj, NULL);
-	kfree(syncobj);
+	kfree_rcu(syncobj, rcu);
 }
 EXPORT_SYMBOL(drm_syncobj_free);
 
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 6cf7243a1dc5..7c1503d47abf 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -61,6 +61,8 @@ struct drm_syncobj {
 	 * @file: A file backing for this syncobj.
 	 */
 	struct file *file;
+
+	struct rcu_head rcu;
 };
 
 void drm_syncobj_free(struct kref *kref);
-- 
2.23.0.rc0

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

  reply	other threads:[~2019-08-02 16:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02 16:36 [PATCH 1/2] drm/syncobj: Convert syncobj_idr to XArray Chris Wilson
2019-08-02 16:36 ` Chris Wilson [this message]
2019-08-03 11:25   ` [PATCH 2/2] drm/syncobj: Lookup the syncobj with RCU protection kbuild test robot
2019-08-02 17:28 ` ✓ Fi.CI.BAT: success for series starting with [1/2] drm/syncobj: Convert syncobj_idr to XArray Patchwork
2019-08-04 11:49 ` ✓ Fi.CI.IGT: " 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=20190802163659.23255-2-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --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.