dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer
@ 2017-09-01 14:57 Chris Wilson
  2017-09-01 14:57 ` [PATCH 2/2] dma-buf/fence: Sparse wants __rcu on the object itself Chris Wilson
  2017-09-01 16:27 ` [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Ville Syrjälä
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Wilson @ 2017-09-01 14:57 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

We take advantage of that syncobj->fence is an RCU-protected pointer, and
so sparse complains that it is lacking annotation.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 include/drm/drm_syncobj.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index c00fee539822..455660673259 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -49,7 +49,7 @@ struct drm_syncobj {
 	 * This field should not be used directly.  Use drm_syncobj_fence_get
 	 * and drm_syncobj_replace_fence instead.
 	 */
-	struct dma_fence *fence;
+	struct dma_fence __rcu *fence;
 	/**
 	 * @cb_list:
 	 * List of callbacks to call when the fence gets replaced
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] dma-buf/fence: Sparse wants __rcu on the object itself
  2017-09-01 14:57 [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Chris Wilson
@ 2017-09-01 14:57 ` Chris Wilson
  2017-09-01 16:27 ` [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Ville Syrjälä
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Wilson @ 2017-09-01 14:57 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

In order to silent sparse in dma_fence_get_rcu_safe(), we need to mark
the incoming fence object as being RCU protected and not the pointer to
the object.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 include/linux/dma-fence.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 171895072435..bad861f8f914 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -242,7 +242,7 @@ static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence)
  * The caller is required to hold the RCU read lock.
  */
 static inline struct dma_fence *
-dma_fence_get_rcu_safe(struct dma_fence * __rcu *fencep)
+dma_fence_get_rcu_safe(struct dma_fence __rcu **fencep)
 {
 	do {
 		struct dma_fence *fence;
-- 
2.14.1

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer
  2017-09-01 14:57 [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Chris Wilson
  2017-09-01 14:57 ` [PATCH 2/2] dma-buf/fence: Sparse wants __rcu on the object itself Chris Wilson
@ 2017-09-01 16:27 ` Ville Syrjälä
  1 sibling, 0 replies; 3+ messages in thread
From: Ville Syrjälä @ 2017-09-01 16:27 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx, dri-devel

On Fri, Sep 01, 2017 at 03:57:06PM +0100, Chris Wilson wrote:
> We take advantage of that syncobj->fence is an RCU-protected pointer, and
> so sparse complains that it is lacking annotation.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  include/drm/drm_syncobj.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
> index c00fee539822..455660673259 100644
> --- a/include/drm/drm_syncobj.h
> +++ b/include/drm/drm_syncobj.h
> @@ -49,7 +49,7 @@ struct drm_syncobj {
>  	 * This field should not be used directly.  Use drm_syncobj_fence_get
>  	 * and drm_syncobj_replace_fence instead.
>  	 */
> -	struct dma_fence *fence;
> +	struct dma_fence __rcu *fence;

drm_syncobj.c uses that pointer directly quite a bit which seems to
generate more sparse warnings.

Would something like this be needed (just typing stuff blindly here)?

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 0422b8c2c2e7..1786787ecc30 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -106,7 +106,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
 	 * callback when a fence has already been set.
 	 */
 	if (syncobj->fence) {
-		*fence = dma_fence_get(syncobj->fence);
+		*fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
+								 lockdep_is_held(&syncobj->lock)));
 		ret = 1;
 	} else {
 		*fence = NULL;
@@ -168,8 +169,9 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
 
 	spin_lock(&syncobj->lock);
 
-	old_fence = syncobj->fence;
-	syncobj->fence = fence;
+	old_fence = rcu_dereference_protected(syncobj->fence,
+					      lockdep_is_held(&syncobj->lock));
+	rcu_assign_pointer(syncobj->fence, fence);
 
 	if (fence != old_fence) {
 		list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
@@ -613,7 +615,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,
 		container_of(cb, struct syncobj_wait_entry, syncobj_cb);
 
 	/* This happens inside the syncobj lock */
-	wait->fence = dma_fence_get(syncobj->fence);
+	wait->fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
+							      lockdep_is_held(&syncobj->lock)));
 	wake_up_process(wait->task);
 }
 
-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-01 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-01 14:57 [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Chris Wilson
2017-09-01 14:57 ` [PATCH 2/2] dma-buf/fence: Sparse wants __rcu on the object itself Chris Wilson
2017-09-01 16:27 ` [PATCH 1/2] drm/syncobj: Mark up the fence as an RCU protected pointer Ville Syrjälä

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox