dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] dma-buf changes for ttm and amdgpu
@ 2017-08-07 21:32 Alex Deucher
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alex Deucher @ 2017-08-07 21:32 UTC (permalink / raw)
  To: amd-gfx, dri-devel, sumit.semwal, christian.koenig; +Cc: 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?

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(-)

-- 
2.5.5

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

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

* [PATCH 1/3] dma-buf: dma_fence_put is NULL safe
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
@ 2017-08-07 21:32   ` Alex Deucher
  2017-08-07 21:32   ` [PATCH 2/3] dma-buf: add reservation_object_copy_fences Alex Deucher
  2017-08-08  7:00   ` [PATCH 0/3] dma-buf changes for ttm and amdgpu Christian König
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2017-08-07 21:32 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	sumit.semwal-QSEj5FYQhm4dnm+yROfE0A,
	christian.koenig-5C7GfCeVMHo
  Cc: Alex Deucher

From: Christian König <christian.koenig@amd.com>

No need to check.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/dma-buf/reservation.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 393817e..87f8f57 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -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);
 
-- 
2.5.5

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

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

* [PATCH 2/3] dma-buf: add reservation_object_copy_fences
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
  2017-08-07 21:32   ` [PATCH 1/3] dma-buf: dma_fence_put is NULL safe Alex Deucher
@ 2017-08-07 21:32   ` Alex Deucher
  2017-08-08  7:00   ` [PATCH 0/3] dma-buf changes for ttm and amdgpu Christian König
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2017-08-07 21:32 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	sumit.semwal-QSEj5FYQhm4dnm+yROfE0A,
	christian.koenig-5C7GfCeVMHo
  Cc: Alex Deucher

From: Christian König <christian.koenig@amd.com>

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

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/dma-buf/reservation.c | 58 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/reservation.h   |  3 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 87f8f57..e2eff86 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -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
diff --git a/include/linux/reservation.h b/include/linux/reservation.h
index 156cfd3..21fc84d 100644
--- a/include/linux/reservation.h
+++ b/include/linux/reservation.h
@@ -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);
-- 
2.5.5

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

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

* [PATCH 3/3] dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2
  2017-08-07 21:32 [PATCH 0/3] dma-buf changes for ttm and amdgpu Alex Deucher
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
@ 2017-08-07 21:32 ` Alex Deucher
  2017-08-08 11:56 ` [PATCH 0/3] dma-buf changes for ttm and amdgpu Daniel Vetter
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2017-08-07 21:32 UTC (permalink / raw)
  To: amd-gfx, dri-devel, sumit.semwal, christian.koenig; +Cc: Alex Deucher

From: Christian König <christian.koenig@amd.com>

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

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/dma-buf/reservation.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index e2eff86..302c137 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -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)) {
-- 
2.5.5

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

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

* Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
  2017-08-07 21:32   ` [PATCH 1/3] dma-buf: dma_fence_put is NULL safe Alex Deucher
  2017-08-07 21:32   ` [PATCH 2/3] dma-buf: add reservation_object_copy_fences Alex Deucher
@ 2017-08-08  7:00   ` Christian König
  2 siblings, 0 replies; 8+ messages in thread
From: Christian König @ 2017-08-08  7:00 UTC (permalink / raw)
  To: Alex Deucher, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	sumit.semwal-QSEj5FYQhm4dnm+yROfE0A,
	christian.koenig-5C7GfCeVMHo
  Cc: Alex Deucher

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:
> 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(-)
>

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

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

* Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu
  2017-08-07 21:32 [PATCH 0/3] dma-buf changes for ttm and amdgpu Alex Deucher
       [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
  2017-08-07 21:32 ` [PATCH 3/3] dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2 Alex Deucher
@ 2017-08-08 11:56 ` Daniel Vetter
       [not found]   ` <20170808115635.75rsu3xlady3duam-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
  2 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2017-08-08 11:56 UTC (permalink / raw)
  To: Alex Deucher; +Cc: Alex Deucher, christian.koenig, dri-devel, amd-gfx

On Mon, Aug 07, 2017 at 05:32:20PM -0400, Alex Deucher wrote:
> 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

> 
> 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(-)
> 
> -- 
> 2.5.5
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* RE: [PATCH 0/3] dma-buf changes for ttm and amdgpu
       [not found]   ` <20170808115635.75rsu3xlady3duam-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
@ 2017-08-08 15:43     ` Deucher, Alexander
  2017-08-09 13:41       ` Sumit Semwal
  0 siblings, 1 reply; 8+ messages in thread
From: Deucher, Alexander @ 2017-08-08 15:43 UTC (permalink / raw)
  To: 'Daniel Vetter', Alex Deucher
  Cc: Koenig, Christian, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	sumit.semwal-QSEj5FYQhm4dnm+yROfE0A

> -----Original Message-----
> From: Daniel Vetter [mailto:daniel.vetter@ffwll.ch] On Behalf Of Daniel
> Vetter
> Sent: Tuesday, August 08, 2017 7:57 AM
> To: Alex Deucher
> Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org;
> sumit.semwal@linaro.org; Koenig, Christian; Deucher, Alexander
> Subject: Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu
> 
> On Mon, Aug 07, 2017 at 05:32:20PM -0400, Alex Deucher wrote:
> > 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

> -Daniel
> 
> >
> > 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(-)
> >
> > --
> > 2.5.5
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu
  2017-08-08 15:43     ` Deucher, Alexander
@ 2017-08-09 13:41       ` Sumit Semwal
  0 siblings, 0 replies; 8+ messages in thread
From: Sumit Semwal @ 2017-08-09 13:41 UTC (permalink / raw)
  To: Deucher, Alexander; +Cc: dri-devel, amd-gfx, Koenig, Christian

Hi Alex,

On 8 August 2017 at 21:13, Deucher, Alexander <Alexander.Deucher@amd.com> wrote:
>> -----Original Message-----
>> From: Daniel Vetter [mailto:daniel.vetter@ffwll.ch] On Behalf Of Daniel
>> Vetter
>> Sent: Tuesday, August 08, 2017 7:57 AM
>> To: Alex Deucher
>> Cc: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org;
>> sumit.semwal@linaro.org; Koenig, Christian; Deucher, Alexander
>> Subject: Re: [PATCH 0/3] dma-buf changes for ttm and amdgpu
>>
>> On Mon, Aug 07, 2017 at 05:32:20PM -0400, Alex Deucher wrote:
>> > 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.
>
Apologies for missing your ping!

Please feel free to take this via drm-misc, with my
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>

> Alex
>
>> -Daniel
Best,
Sumit.
>>
>> >
>> > 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(-)
>> >
>> > --
>> > 2.5.5
>> >
>> > _______________________________________________
>> > dri-devel mailing list
>> > dri-devel@lists.freedesktop.org
>> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>>
>> --
>> Daniel Vetter
>> Software Engineer, Intel Corporation
>> http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2017-08-09 13:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07 21:32 [PATCH 0/3] dma-buf changes for ttm and amdgpu Alex Deucher
     [not found] ` <1502141543-13455-1-git-send-email-alexander.deucher-5C7GfCeVMHo@public.gmane.org>
2017-08-07 21:32   ` [PATCH 1/3] dma-buf: dma_fence_put is NULL safe Alex Deucher
2017-08-07 21:32   ` [PATCH 2/3] dma-buf: add reservation_object_copy_fences Alex Deucher
2017-08-08  7:00   ` [PATCH 0/3] dma-buf changes for ttm and amdgpu Christian König
2017-08-07 21:32 ` [PATCH 3/3] dma-buf: fix reservation_object_wait_timeout_rcu to wait correctly v2 Alex Deucher
2017-08-08 11:56 ` [PATCH 0/3] dma-buf changes for ttm and amdgpu Daniel Vetter
     [not found]   ` <20170808115635.75rsu3xlady3duam-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2017-08-08 15:43     ` Deucher, Alexander
2017-08-09 13:41       ` Sumit Semwal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).