Skip to contentSkip to conversation

dma-buf changes for ttm and amdgpu

PATCH In review Alex Deucher 6 participants 8 messages Aug 7, 2017 – Aug 9, 2017 2 messages not in the archive DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

cover dma-buf changes for ttm and amdgpu

We have some changes in ttm and amdgpu that depend on these patches. Sumit, can you pull these in via dma-buf or should I roll them up through my amdgpu tree?

Christian König (3):
dma-buf: dma_fence_put is NULL safe
dma-buf: add reservation_object_copy_fences
dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

 drivers/dma-buf/reservation.c | 97 +++++++++++++++++++++++++++++++++----------
 include/linux/reservation.h   |  3 ++
 2 files changed, 78 insertions(+), 22 deletions(-)
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 1/3 dma-buf: dma_fence_put is NULL safe

From: Christian König <[email protected]>

No need to check.

---
 drivers/dma-buf/reservation.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma-buf/reservation.c +2 -4
index 393817e..87f8f57 100644
@@ -195,8 +195,7 @@ reservation_object_add_shared_replace(struct reservation_object *obj,
 	if (old)
 		kfree_rcu(old, rcu);
 
-	if (old_fence)
-		dma_fence_put(old_fence);
+	dma_fence_put(old_fence);
 }
 
 /**
@@ -258,8 +257,7 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
 		dma_fence_put(rcu_dereference_protected(old->shared[i],
 						reservation_object_held(obj)));
 
-	if (old_fence)
-		dma_fence_put(old_fence);
+	dma_fence_put(old_fence);
 }
 EXPORT_SYMBOL(reservation_object_add_excl_fence);
 
Signature · 6 lines
2.5.5

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw

PATCH 2/3 dma-buf: add reservation_object_copy_fences

In reply to a message not in the archive

From: Christian König <[email protected]>

Allows us to copy all the fences in a reservation object to another one.

---
 drivers/dma-buf/reservation.c | 58 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/reservation.h   |  3 +++
 2 files changed, 61 insertions(+)
drivers/dma-buf/reservation.c +58 -0
index 87f8f57..e2eff86 100644
@@ -262,6 +262,64 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
 EXPORT_SYMBOL(reservation_object_add_excl_fence);
 
 /**
+* reservation_object_copy_fences - Copy all fences from src to dst.
+* @dst: the destination reservation object
+* @src: the source reservation object
+*
+* Copy all fences from src to dst. Both src->lock as well as dst-lock must be
+* held.
+*/
+int reservation_object_copy_fences(struct reservation_object *dst,
+				   struct reservation_object *src)
+{
+	struct reservation_object_list *src_list, *dst_list;
+	struct dma_fence *old, *new;
+	size_t size;
+	unsigned i;
+
+	src_list = reservation_object_get_list(src);
+
+	/*
+	 * resize dst->fence or allocate if it doesn't exist,
+	 * noop if already correct size
+	 */
+	size = offsetof(typeof(*src_list), shared[src_list->shared_count]);
+	dst_list = kmalloc(size, GFP_KERNEL);
+	if (!dst_list)
+		return -ENOMEM;
+
+	kfree(dst->staged);
+	dst->staged = NULL;
+
+	dst_list->shared_count = src_list->shared_count;
+	dst_list->shared_max = src_list->shared_count;
+	for (i = 0; i < src_list->shared_count; ++i)
+		dst_list->shared[i] = dma_fence_get(src_list->shared[i]);
+
+	src_list = reservation_object_get_list(dst);
+
+	old = reservation_object_get_excl(dst);
+	new = reservation_object_get_excl(src);
+
+	dma_fence_get(new);
+
+	preempt_disable();
+	write_seqcount_begin(&dst->seq);
+	/* write_seqcount_begin provides the necessary memory barrier */
+	RCU_INIT_POINTER(dst->fence_excl, new);
+	RCU_INIT_POINTER(dst->fence, dst_list);
+	write_seqcount_end(&dst->seq);
+	preempt_enable();
+
+	if (src_list)
+		kfree_rcu(src_list, rcu);
+	dma_fence_put(old);
+
+	return 0;
+}
+EXPORT_SYMBOL(reservation_object_copy_fences);
+
+/**
  * reservation_object_get_fences_rcu - Get an object's shared and exclusive
  * fences without update side lock held
  * @obj: the reservation object
include/linux/reservation.h +3 -0
index 156cfd3..21fc84d 100644
@@ -254,6 +254,9 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj,
 				      unsigned *pshared_count,
 				      struct dma_fence ***pshared);
 
+int reservation_object_copy_fences(struct reservation_object *dst,
+				   struct reservation_object *src);
+
 long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 					 bool wait_all, bool intr,
 					 unsigned long timeout);
Signature · 6 lines
2.5.5

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw
In reply to a message not in the archive

Sorry, I wanted to ping once more on those patch but completely forgot about it.

Thanks Alex for picking this up once more,
Christian.

Am 07.08.2017 um 23:32 schrieb Alex Deucher:

Quoted 4 lines

We have some changes in ttm and amdgpu that depend on these patches. Sumit, can you pull these in via dma-buf or should I roll them up through my amdgpu tree?

Quoted 9 lines

Christian König (3):
dma-buf: dma_fence_put is NULL safe
dma-buf: add reservation_object_copy_fences
dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

  drivers/dma-buf/reservation.c | 97 +++++++++++++++++++++++++++++++++----------
  include/linux/reservation.h   |  3 ++
  2 files changed, 78 insertions(+), 22 deletions(-)

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

PATCH 3/3 dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

In reply to Alex Deucher

From: Christian König <[email protected]>

With hardware resets in mind it is possible that all shared fences are signaled, but the exlusive isn't. Fix waiting for everything in this situation.

v2: make sure we always wait for the exclusive fence

---
 drivers/dma-buf/reservation.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)
drivers/dma-buf/reservation.c +15 -18
index e2eff86..302c137 100644
@@ -429,12 +429,25 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 	long ret = timeout ? timeout : 1;
 
 retry:
-	fence = NULL;
 	shared_count = 0;
 	seq = read_seqcount_begin(&obj->seq);
 	rcu_read_lock();
 
-	if (wait_all) {
+	fence = rcu_dereference(obj->fence_excl);
+	if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+		if (!dma_fence_get_rcu(fence))
+			goto unlock_retry;
+
+		if (dma_fence_is_signaled(fence)) {
+			dma_fence_put(fence);
+			fence = NULL;
+		}
+
+	} else {
+		fence = NULL;
+	}
+
+	if (!fence && wait_all) {
 		struct reservation_object_list *fobj =
 						rcu_dereference(obj->fence);
 
@@ -461,22 +474,6 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 		}
 	}
 
-	if (!shared_count) {
-		struct dma_fence *fence_excl = rcu_dereference(obj->fence_excl);
-
-		if (fence_excl &&
-		    !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
-			      &fence_excl->flags)) {
-			if (!dma_fence_get_rcu(fence_excl))
-				goto unlock_retry;
-
-			if (dma_fence_is_signaled(fence_excl))
-				dma_fence_put(fence_excl);
-			else
-				fence = fence_excl;
-		}
-	}
-
 	rcu_read_unlock();
 	if (fence) {
 		if (read_seqcount_retry(&obj->seq, seq)) {
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
In reply to Alex Deucher
Quoted 3 lines · Alex Deucher

We have some changes in ttm and amdgpu that depend on these patches. Sumit, can you pull these in via dma-buf or should I roll them up through my amdgpu tree?

We could just throw them all into drm-misc too, that's kinda what it's for (dma-buf doesn't exist anymore, all the dma-buf stuff is in drm-misc now). And you have commit rights for that even :-)
-Daniel

Quoted 17 lines

Christian König (3):
dma-buf: dma_fence_put is NULL safe
dma-buf: add reservation_object_copy_fences
dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

 drivers/dma-buf/reservation.c | 97 +++++++++++++++++++++++++++++++++----------
 include/linux/reservation.h   |  3 ++
 2 files changed, 78 insertions(+), 22 deletions(-)
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20170808115635.75rsu3xlady3duam-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#8 lore raw
Quoted 9 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, August 08, 2017 7:57 AM
To: Alex Deucher
Cc: [email protected]; [email protected]; [email protected]; Koenig, Christian; Deucher, Alexander
Subject: Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu

Quoted 8 lines
Quoted 3 lines · Alex Deucher

We have some changes in ttm and amdgpu that depend on these patches. Sumit, can you pull these in via dma-buf or should I roll them up through my amdgpu tree?

We could just throw them all into drm-misc too, that's kinda what it's for (dma-buf doesn't exist anymore, all the dma-buf stuff is in drm-misc now). And you have commit rights for that even :-)

Yeah, I just didn't want to step on Sumit's toes in case he preferred to handle dma-buf patches himself.

Alex

Quoted 21 lines

-Daniel

Quoted 7 lines

Christian König (3):
dma-buf: dma_fence_put is NULL safe
dma-buf: add reservation_object_copy_fences
dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

 drivers/dma-buf/reservation.c | 97

+++++++++++++++++++++++++++++++++----------

Quoted 10 lines
 include/linux/reservation.h   |  3 ++
 2 files changed, 78 insertions(+), 22 deletions(-)

--
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Quoted 4 lines

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer Acked-by
#9 lore raw

Hi Alex,

Quoted 14 lines · Alexander
Quoted 14 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, August 08, 2017 7:57 AM
To: Alex Deucher
Cc: [email protected]; [email protected]; [email protected]; Koenig, Christian; Deucher, Alexander
Subject: Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu

Quoted 3 lines · Alex Deucher

We have some changes in ttm and amdgpu that depend on these patches. Sumit, can you pull these in via dma-buf or should I roll them up through my amdgpu tree?

Quoted 6 lines
Quoted 3 lines

We could just throw them all into drm-misc too, that's kinda what it's for (dma-buf doesn't exist anymore, all the dma-buf stuff is in drm-misc now). And you have commit rights for that even :-)

Yeah, I just didn't want to step on Sumit's toes in case he preferred to handle dma-buf patches himself.

Apologies for missing your ping!

Please feel free to take this via drm-misc, with my

Quoted 3 lines

Alex

Quoted 1 line

-Daniel

Best,
Sumit.

Quoted 20 lines
Quoted 20 lines
Quoted 8 lines

Christian König (3):
dma-buf: dma_fence_put is NULL safe
dma-buf: add reservation_object_copy_fences
dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2

 drivers/dma-buf/reservation.c | 97

+++++++++++++++++++++++++++++++++----------

Quoted 10 lines
 include/linux/reservation.h   |  3 ++
 2 files changed, 78 insertions(+), 22 deletions(-)

--
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Quoted 4 lines
Quoted 4 lines

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel