Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-06 Thread Liu, Monk
okay


From: Chris Wilson 
Sent: Tuesday, March 6, 2018 4:24:21 PM
To: Liu, Monk; dri-de...@freedesktop.org
Cc: Liu, Monk
Subject: Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

Quoting Monk Liu (2018-03-06 03:53:10)
> v2:
> still check context first to avoid warning from dma_fence_is_later
> apply this fix in add_shared_replace as well
>
> Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
> Signed-off-by: Monk Liu 
> ---
>  drivers/dma-buf/reservation.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> index 314eb10..c6e3c86 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
> reservation_object *obj,
> old_fence = rcu_dereference_protected(fobj->shared[i],
> reservation_object_held(obj));
>
> -   if (old_fence->context == fence->context) {
> +   if (old_fence->context == fence->context &&
> +   dma_fence_is_later(fence, old_fence)) {

This should be true by construction. Adding an older fence on the same
context is a programming bug, imo. Between different callers the resv
should have been locked and the fenced operations serialised, from the
same caller, you shouldn't be handling more than one output fence?
-Chris
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-06 Thread Chris Wilson
Quoting Monk Liu (2018-03-06 03:53:10)
> v2:
> still check context first to avoid warning from dma_fence_is_later
> apply this fix in add_shared_replace as well
> 
> Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
> Signed-off-by: Monk Liu 
> ---
>  drivers/dma-buf/reservation.c | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
> index 314eb10..c6e3c86 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
> reservation_object *obj,
> old_fence = rcu_dereference_protected(fobj->shared[i],
> reservation_object_held(obj));
>  
> -   if (old_fence->context == fence->context) {
> +   if (old_fence->context == fence->context &&
> +   dma_fence_is_later(fence, old_fence)) {

This should be true by construction. Adding an older fence on the same
context is a programming bug, imo. Between different callers the resv
should have been locked and the fenced operations serialised, from the
same caller, you shouldn't be handling more than one output fence?
-Chris
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


RE: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-05 Thread Liu, Monk
Make sense, will give v3

-Original Message-
From: Zhou, David(ChunMing) 
Sent: 2018年3月6日 14:08
To: Liu, Monk ; Zhou, David(ChunMing) ; 
dri-de...@freedesktop.org
Subject: Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)



On 2018年03月06日 13:59, Liu, Monk wrote:
>>
>> -if (check->context == fence->context ||
>> +if ((check->context == fence->context &&
>> +dma_fence_is_later(fence, check)) ||
> We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
> we will don't need add new fence to resv slot.
>
> if ((check->context == fence->context) && dma_fence_is_later(fence, check))
>   fobj->shared_count = j;
>   RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
>   fobj->shared_count++;
> } else {
>   dma_fence_put(fence);
> }
>
> No you cannot do that, check is changed and not the one you want, 
> Besides, we don't need to consider the case you mentioned, take only one 
> fence in obj->staged for example:
>
> You add a fence whose context is equal to this fence (check), so 
> current logic will put this check into fobj->shared[++j],
Yes, if !dma_fence_is_later(fence, check), then 'check' will be put to 
fobj->shared[++j], so we don't need add new fence to resv slot, don't we?

Regards,
David Zhou
> so in the end
> Obj->fence will point to fobj, and original old would be rcu_kfree()
>
> No additional action actually needed...
>
> /Monk
>
> -----Original Message-
> From: Zhou, David(ChunMing)
> Sent: 2018年3月6日 12:25
> To: Liu, Monk ; dri-de...@freedesktop.org
> Subject: Re: [PATCH] dma-buf/reservation: should keep later one in add 
> fence(v2)
>
>
>
> On 2018年03月06日 11:53, Monk Liu wrote:
>> v2:
>> still check context first to avoid warning from dma_fence_is_later 
>> apply this fix in add_shared_replace as well
>>
>> Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
>> Signed-off-by: Monk Liu 
>> ---
>>drivers/dma-buf/reservation.c | 6 --
>>1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma-buf/reservation.c 
>> b/drivers/dma-buf/reservation.c index 314eb10..c6e3c86 100644
>> --- a/drivers/dma-buf/reservation.c
>> +++ b/drivers/dma-buf/reservation.c
>> @@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
>> reservation_object *obj,
>>  old_fence = rcu_dereference_protected(fobj->shared[i],
>>  reservation_object_held(obj));
>>
>> -if (old_fence->context == fence->context) {
>> +if (old_fence->context == fence->context &&
>> +dma_fence_is_later(fence, old_fence)) {
>>  /* memory barrier is added by write_seqcount_begin */
>>  RCU_INIT_POINTER(fobj->shared[i], fence);
>>  write_seqcount_end(&obj->seq);
>> @@ -179,7 +180,8 @@ reservation_object_add_shared_replace(struct 
>> reservation_object *obj,
>>  check = rcu_dereference_protected(old->shared[i],
>>  reservation_object_held(obj));
>>
>> -if (check->context == fence->context ||
>> +if ((check->context == fence->context &&
>> +dma_fence_is_later(fence, check)) ||
> We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
> we will don't need add new fence to resv slot.
>
> if ((check->context == fence->context) && dma_fence_is_later(fence, check))
>       fobj->shared_count = j;
>       RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
>       fobj->shared_count++;
> } else {
>       dma_fence_put(fence);
> }
>
>
> Regards,
> David Zhou
>>  dma_fence_is_signaled(check))
>>  RCU_INIT_POINTER(fobj->shared[--k], check);
>>  else

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


Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-05 Thread zhoucm1



On 2018年03月06日 13:59, Liu, Monk wrote:
   
-		if (check->context == fence->context ||

+   if ((check->context == fence->context &&
+   dma_fence_is_later(fence, check)) ||

We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
we will don't need add new fence to resv slot.

if ((check->context == fence->context) && dma_fence_is_later(fence, check))
  fobj->shared_count = j;
  RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
  fobj->shared_count++;
} else {
  dma_fence_put(fence);
}

No you cannot do that, check is changed and not the one you want,
Besides, we don't need to consider the case you mentioned, take only one fence in 
obj->staged for example:

You add a fence whose context is equal to this fence (check), so current logic 
will put this check into fobj->shared[++j],
Yes, if !dma_fence_is_later(fence, check), then 'check' will be put to 
fobj->shared[++j], so we don't need add new fence to resv slot, don't we?


Regards,
David Zhou

so in the end
Obj->fence will point to fobj, and original old would be rcu_kfree()

No additional action actually needed...

/Monk

-Original Message-
From: Zhou, David(ChunMing)
Sent: 2018年3月6日 12:25
To: Liu, Monk ; dri-de...@freedesktop.org
Subject: Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)



On 2018年03月06日 11:53, Monk Liu wrote:

v2:
still check context first to avoid warning from dma_fence_is_later
apply this fix in add_shared_replace as well

Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
Signed-off-by: Monk Liu 
---
   drivers/dma-buf/reservation.c | 6 --
   1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/reservation.c
b/drivers/dma-buf/reservation.c index 314eb10..c6e3c86 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
reservation_object *obj,
old_fence = rcu_dereference_protected(fobj->shared[i],
reservation_object_held(obj));
   
-		if (old_fence->context == fence->context) {

+   if (old_fence->context == fence->context &&
+   dma_fence_is_later(fence, old_fence)) {
/* memory barrier is added by write_seqcount_begin */
RCU_INIT_POINTER(fobj->shared[i], fence);
write_seqcount_end(&obj->seq);
@@ -179,7 +180,8 @@ reservation_object_add_shared_replace(struct 
reservation_object *obj,
check = rcu_dereference_protected(old->shared[i],
reservation_object_held(obj));
   
-		if (check->context == fence->context ||

+   if ((check->context == fence->context &&
+   dma_fence_is_later(fence, check)) ||

We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
we will don't need add new fence to resv slot.

if ((check->context == fence->context) && dma_fence_is_later(fence, check))
      fobj->shared_count = j;
      RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
      fobj->shared_count++;
} else {
      dma_fence_put(fence);
}


Regards,
David Zhou

dma_fence_is_signaled(check))
RCU_INIT_POINTER(fobj->shared[--k], check);
else


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


RE: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-05 Thread Liu, Monk
>   
> - if (check->context == fence->context ||
> + if ((check->context == fence->context &&
> + dma_fence_is_later(fence, check)) ||
We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
we will don't need add new fence to resv slot.

if ((check->context == fence->context) && dma_fence_is_later(fence, check))
 fobj->shared_count = j;
 RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
 fobj->shared_count++;
} else {
 dma_fence_put(fence);
}

No you cannot do that, check is changed and not the one you want,
Besides, we don't need to consider the case you mentioned, take only one fence 
in obj->staged for example:

You add a fence whose context is equal to this fence (check), so current logic 
will put this check into fobj->shared[++j], so in the end
Obj->fence will point to fobj, and original old would be rcu_kfree() 

No additional action actually needed...

/Monk

-Original Message-
From: Zhou, David(ChunMing) 
Sent: 2018年3月6日 12:25
To: Liu, Monk ; dri-de...@freedesktop.org
Subject: Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)



On 2018年03月06日 11:53, Monk Liu wrote:
> v2:
> still check context first to avoid warning from dma_fence_is_later 
> apply this fix in add_shared_replace as well
>
> Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
> Signed-off-by: Monk Liu 
> ---
>   drivers/dma-buf/reservation.c | 6 --
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dma-buf/reservation.c 
> b/drivers/dma-buf/reservation.c index 314eb10..c6e3c86 100644
> --- a/drivers/dma-buf/reservation.c
> +++ b/drivers/dma-buf/reservation.c
> @@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
> reservation_object *obj,
>   old_fence = rcu_dereference_protected(fobj->shared[i],
>   reservation_object_held(obj));
>   
> - if (old_fence->context == fence->context) {
> + if (old_fence->context == fence->context &&
> + dma_fence_is_later(fence, old_fence)) {
>   /* memory barrier is added by write_seqcount_begin */
>   RCU_INIT_POINTER(fobj->shared[i], fence);
>   write_seqcount_end(&obj->seq);
> @@ -179,7 +180,8 @@ reservation_object_add_shared_replace(struct 
> reservation_object *obj,
>   check = rcu_dereference_protected(old->shared[i],
>   reservation_object_held(obj));
>   
> - if (check->context == fence->context ||
> + if ((check->context == fence->context &&
> + dma_fence_is_later(fence, check)) ||
We still need do more for !dma_fence_is_later(fence, check)   case, in which, 
we will don't need add new fence to resv slot.

if ((check->context == fence->context) && dma_fence_is_later(fence, check))
     fobj->shared_count = j;
     RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
     fobj->shared_count++;
} else {
     dma_fence_put(fence);
}


Regards,
David Zhou
>   dma_fence_is_signaled(check))
>   RCU_INIT_POINTER(fobj->shared[--k], check);
>   else

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


Re: [PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-05 Thread zhoucm1



On 2018年03月06日 11:53, Monk Liu wrote:

v2:
still check context first to avoid warning from dma_fence_is_later
apply this fix in add_shared_replace as well

Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
Signed-off-by: Monk Liu 
---
  drivers/dma-buf/reservation.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 314eb10..c6e3c86 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
reservation_object *obj,
old_fence = rcu_dereference_protected(fobj->shared[i],
reservation_object_held(obj));
  
-		if (old_fence->context == fence->context) {

+   if (old_fence->context == fence->context &&
+   dma_fence_is_later(fence, old_fence)) {
/* memory barrier is added by write_seqcount_begin */
RCU_INIT_POINTER(fobj->shared[i], fence);
write_seqcount_end(&obj->seq);
@@ -179,7 +180,8 @@ reservation_object_add_shared_replace(struct 
reservation_object *obj,
check = rcu_dereference_protected(old->shared[i],
reservation_object_held(obj));
  
-		if (check->context == fence->context ||

+   if ((check->context == fence->context &&
+   dma_fence_is_later(fence, check)) ||
We still need do more for !dma_fence_is_later(fence, check)   case, in 
which, we will don't need add new fence to resv slot.


if ((check->context == fence->context) && dma_fence_is_later(fence, check))
    fobj->shared_count = j;
    RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence);
    fobj->shared_count++;
} else {
    dma_fence_put(fence);
}


Regards,
David Zhou

dma_fence_is_signaled(check))
RCU_INIT_POINTER(fobj->shared[--k], check);
else


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


[PATCH] dma-buf/reservation: should keep later one in add fence(v2)

2018-03-05 Thread Monk Liu
v2:
still check context first to avoid warning from dma_fence_is_later
apply this fix in add_shared_replace as well

Change-Id: If6a979ba9fd6c923b82212f35f07a9ff31c86767
Signed-off-by: Monk Liu 
---
 drivers/dma-buf/reservation.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 314eb10..c6e3c86 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -118,7 +118,8 @@ reservation_object_add_shared_inplace(struct 
reservation_object *obj,
old_fence = rcu_dereference_protected(fobj->shared[i],
reservation_object_held(obj));
 
-   if (old_fence->context == fence->context) {
+   if (old_fence->context == fence->context &&
+   dma_fence_is_later(fence, old_fence)) {
/* memory barrier is added by write_seqcount_begin */
RCU_INIT_POINTER(fobj->shared[i], fence);
write_seqcount_end(&obj->seq);
@@ -179,7 +180,8 @@ reservation_object_add_shared_replace(struct 
reservation_object *obj,
check = rcu_dereference_protected(old->shared[i],
reservation_object_held(obj));
 
-   if (check->context == fence->context ||
+   if ((check->context == fence->context &&
+   dma_fence_is_later(fence, check)) ||
dma_fence_is_signaled(check))
RCU_INIT_POINTER(fobj->shared[--k], check);
else
-- 
2.7.4

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