Skip to contentSkip to conversation

dma-buf: fix reservation_object_wait_timeout_rcu once more v2

PATCH In review Christian König 2 participants 3 messages Jan 22, 2018 – Jan 23, 2018 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: fix reservation_object_wait_timeout_rcu once more v2

We need to set shared_count even if we already have a fence to wait for.

v2: init i to -1 as well

---
 drivers/dma-buf/reservation.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma-buf/reservation.c +5 -3
index 461afa9febd4..314eb1071cce 100644
@@ -484,13 +484,15 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 					 unsigned long timeout)
 {
 	struct dma_fence *fence;
-	unsigned seq, shared_count, i = 0;
+	unsigned seq, shared_count;
 	long ret = timeout ? timeout : 1;
+	int i;
 
 retry:
 	shared_count = 0;
 	seq = read_seqcount_begin(&obj->seq);
 	rcu_read_lock();
+	i = -1;
 
 	fence = rcu_dereference(obj->fence_excl);
 	if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
@@ -506,14 +508,14 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
 		fence = NULL;
 	}
 
-	if (!fence && wait_all) {
+	if (wait_all) {
 		struct reservation_object_list *fobj =
 						rcu_dereference(obj->fence);
 
 		if (fobj)
 			shared_count = fobj->shared_count;
 
-		for (i = 0; i < shared_count; ++i) {
+		for (i = 0; !fence && i < shared_count; ++i) {
 			struct dma_fence *lfence = rcu_dereference(fobj->shared[i]);
 
 			if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Signature · 6 lines
2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw

Quoting Christian König (2018-01-22 20:00:03)

Quoted 20 lines

We need to set shared_count even if we already have a fence to wait for.

v2: init i to -1 as well

---
 drivers/dma-buf/reservation.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma-buf/reservation.c +0 -0
index 461afa9febd4..314eb1071cce 100644
@@ -484,13 +484,15 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
                                         unsigned long timeout)
 {
        struct dma_fence *fence;

drivers/dma-buf/reservation.c long reservation_object_wait_timeout_rcu(struct reservation_object *obj, · line 495

Quoted 10 lines
drivers/dma-buf/reservation.c +3 -1
-       unsigned seq, shared_count, i = 0;
+       unsigned seq, shared_count;
        long ret = timeout ? timeout : 1;
+       int i;
 
 retry:
        shared_count = 0;
        seq = read_seqcount_begin(&obj->seq);
        rcu_read_lock();
+       i = -1;

Could be before the seqlock, but

Are we at the point where just grabbing the snapshot of fences with your new get_fences_rcu() returning a single array will be simpler? (It also has the change in behaviour of not updating the snapshot across the long lived wait.)

If you want to avoid the kmalloc, we could teach it populate the caller's stack allocated array first.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Am 22.01.2018 um 21:09 schrieb Chris Wilson:

Quoted 33 lines

Quoting Christian König (2018-01-22 20:00:03)

Quoted 20 lines

We need to set shared_count even if we already have a fence to wait for.

v2: init i to -1 as well

---
  drivers/dma-buf/reservation.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/dma-buf/reservation.c +0 -0
index 461afa9febd4..314eb1071cce 100644
@@ -484,13 +484,15 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
                                          unsigned long timeout)
  {
         struct dma_fence *fence;

drivers/dma-buf/reservation.c long reservation_object_wait_timeout_rcu(struct reservation_object *obj, · line 495

Quoted 10 lines
drivers/dma-buf/reservation.c +3 -1
-       unsigned seq, shared_count, i = 0;
+       unsigned seq, shared_count;
         long ret = timeout ? timeout : 1;
+       int i;
 
  retry:
         shared_count = 0;
         seq = read_seqcount_begin(&obj->seq);
         rcu_read_lock();
+       i = -1;

Could be before the seqlock, but

Quoted 6 lines

Are we at the point where just grabbing the snapshot of fences with your new get_fences_rcu() returning a single array will be simpler? (It also has the change in behaviour of not updating the snapshot across the long lived wait.)

Yeah, thought about that as well.

Quoted 2 lines

If you want to avoid the kmalloc, we could teach it populate the caller's stack allocated array first.

Something like a helper function which just grabs all fences and puts them in an array of size n? And if the array is to small we return -ENOSPC and the caller needs to resize it.

Good idea, putting this on my TODO list, but no idea when I can get around to actually doing it.

Christian.

Quoted 1 line

-Chris

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