All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
@ 2018-09-17 18:07 Christian König
       [not found] ` <20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2018-09-17 18:07 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Don't try to unreserve a BO we doesn't allocated.

Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 84d82d5382f9..c1387efc0c91 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
-	amdgpu_bo_unreserve(*bo_ptr);
+	if (*bo_ptr)
+		amdgpu_bo_unreserve(*bo_ptr);
 
 	return 0;
 }
-- 
2.14.1

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

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found] ` <20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-17 18:41   ` James Zhu
       [not found]     ` <4304faa2-5777-9d0a-c8e8-b00e431238f0-5C7GfCeVMHo@public.gmane.org>
  2018-09-18  5:48   ` Huang Rui
  2018-09-18  6:16   ` Zhu, Rex
  2 siblings, 1 reply; 11+ messages in thread
From: James Zhu @ 2018-09-17 18:41 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 2018-09-17 02:07 PM, Christian König wrote:
> Don't try to unreserve a BO we doesn't allocated.
>
> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 84d82d5382f9..c1387efc0c91 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
>   	if (r)
>   		return r;
>   
> -	amdgpu_bo_unreserve(*bo_ptr);
> +	if (*bo_ptr)
Can we put this check inside ttm_bo_unreserve?
James Zhu
> +		amdgpu_bo_unreserve(*bo_ptr);
>   
>   	return 0;
>   }

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

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found] ` <20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-09-17 18:41   ` James Zhu
@ 2018-09-18  5:48   ` Huang Rui
  2018-09-18  6:16   ` Zhu, Rex
  2 siblings, 0 replies; 11+ messages in thread
From: Huang Rui @ 2018-09-18  5:48 UTC (permalink / raw)
  To: Christian König; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Mon, Sep 17, 2018 at 08:07:24PM +0200, Christian König wrote:
> Don't try to unreserve a BO we doesn't allocated.
> 
> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

If we set size as 0 while create bo, the bo_ptr will be NULL after that.

Acked-by: Huang Rui <ray.huang@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 84d82d5382f9..c1387efc0c91 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
>  	if (r)
>  		return r;
>  
> -	amdgpu_bo_unreserve(*bo_ptr);
> +	if (*bo_ptr)
> +		amdgpu_bo_unreserve(*bo_ptr);
>  
>  	return 0;
>  }
> -- 
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* RE: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found] ` <20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-09-17 18:41   ` James Zhu
  2018-09-18  5:48   ` Huang Rui
@ 2018-09-18  6:16   ` Zhu, Rex
       [not found]     ` <BYAPR12MB27754BE2A5210C53B1054F53FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  2 siblings, 1 reply; 11+ messages in thread
From: Zhu, Rex @ 2018-09-18  6:16 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> Christian König
> Sent: Tuesday, September 18, 2018 2:07 AM
> To: amd-gfx@lists.freedesktop.org
> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> 
> Don't try to unreserve a BO we doesn't allocated.
> 
> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 84d82d5382f9..c1387efc0c91 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device
> *adev,
>  	if (r)
>  		return r;
> 
> -	amdgpu_bo_unreserve(*bo_ptr);
> +	if (*bo_ptr)
> +		amdgpu_bo_unreserve(*bo_ptr);
> 
>  	return 0;
>  }
It is weird. 
If we return true for allocate bo with size  0.
Does that mean we need to check all the bo_ptr before we use them.

Best Regards
Rex
 
> --
> 2.14.1
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]     ` <BYAPR12MB27754BE2A5210C53B1054F53FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-09-18  7:14       ` Christian König
       [not found]         ` <27a7e247-d895-17e8-5493-051dea82536d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2018-09-18  7:14 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
>
>> -----Original Message-----
>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
>> Christian König
>> Sent: Tuesday, September 18, 2018 2:07 AM
>> To: amd-gfx@lists.freedesktop.org
>> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>
>> Don't try to unreserve a BO we doesn't allocated.
>>
>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 84d82d5382f9..c1387efc0c91 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device
>> *adev,
>>   	if (r)
>>   		return r;
>>
>> -	amdgpu_bo_unreserve(*bo_ptr);
>> +	if (*bo_ptr)
>> +		amdgpu_bo_unreserve(*bo_ptr);
>>
>>   	return 0;
>>   }
> It is weird.
> If we return true for allocate bo with size  0.
> Does that mean we need to check all the bo_ptr before we use them.

No, allocating a BO with zero size doesn't make much sense and was 
essentially undefined behavior previously.

So now we get a defined behavior, but not necessary the one you expected.

Is that only a rhetorical question or really a problem somewhere?

Regards,
Christian.

>
> Best Regards
> Rex
>   
>> --
>> 2.14.1
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]     ` <4304faa2-5777-9d0a-c8e8-b00e431238f0-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-18  7:14       ` Christian König
  0 siblings, 0 replies; 11+ messages in thread
From: Christian König @ 2018-09-18  7:14 UTC (permalink / raw)
  To: James Zhu, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 17.09.2018 um 20:41 schrieb James Zhu:
>
>
> On 2018-09-17 02:07 PM, Christian König wrote:
>> Don't try to unreserve a BO we doesn't allocated.
>>
>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 84d82d5382f9..c1387efc0c91 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct amdgpu_device 
>> *adev,
>>       if (r)
>>           return r;
>>   -    amdgpu_bo_unreserve(*bo_ptr);
>> +    if (*bo_ptr)
> Can we put this check inside ttm_bo_unreserve?

No, calling amdgpu_bo_unreserve() with a NULL pointer is certainly a bug.

Christian.

> James Zhu
>> +        amdgpu_bo_unreserve(*bo_ptr);
>>         return 0;
>>   }
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* RE: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]         ` <27a7e247-d895-17e8-5493-051dea82536d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-09-18  8:16           ` Zhu, Rex
       [not found]             ` <BYAPR12MB27759724D41FECEEC1926845FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Zhu, Rex @ 2018-09-18  8:16 UTC (permalink / raw)
  To: Koenig, Christian, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



> -----Original Message-----
> From: Christian König <ckoenig.leichtzumerken@gmail.com>
> Sent: Tuesday, September 18, 2018 3:14 PM
> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> 
> Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
> >
> >> -----Original Message-----
> >> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> >> Christian König
> >> Sent: Tuesday, September 18, 2018 2:07 AM
> >> To: amd-gfx@lists.freedesktop.org
> >> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> >>
> >> Don't try to unreserve a BO we doesn't allocated.
> >>
> >> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
> >>
> >> Signed-off-by: Christian König <christian.koenig@amd.com>
> >> ---
> >>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
> >>   1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >> index 84d82d5382f9..c1387efc0c91 100644
> >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct
> amdgpu_device
> >> *adev,
> >>	if (r)
> >>   		return r;
> >> -	amdgpu_bo_unreserve(*bo_ptr);
> >> +	if (*bo_ptr)
> >> +		amdgpu_bo_unreserve(*bo_ptr);
> >>
> >>   	return 0;
> >>   }
> > It is weird.
> > If we return true for allocate bo with size  0.
> > Does that mean we need to check all the bo_ptr before we use them.
> 
> No, allocating a BO with zero size doesn't make much sense and was
> essentially undefined behavior previously.
> 
> So now we get a defined behavior, but not necessary the one you expected.
> 
> Is that only a rhetorical question or really a problem somewhere?

Logically, the code is trick. It also make the  code
if (r)
	return r; 
redundant.

Regards
Rex

> Regards,
> Christian.
> 
> >
> > Best Regards
> > Rex
> >
> >> --
> >> 2.14.1
> >>
> >> _______________________________________________
> >> amd-gfx mailing list
> >> amd-gfx@lists.freedesktop.org
> >> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]             ` <BYAPR12MB27759724D41FECEEC1926845FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-09-18  8:40               ` Christian König
       [not found]                 ` <248d2af0-e330-90e9-38c8-176a2bbd3649-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2018-09-18  8:40 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 18.09.2018 um 10:16 schrieb Zhu, Rex:
>
>> -----Original Message-----
>> From: Christian König <ckoenig.leichtzumerken@gmail.com>
>> Sent: Tuesday, September 18, 2018 3:14 PM
>> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
>> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>
>> Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
>>>> -----Original Message-----
>>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
>>>> Christian König
>>>> Sent: Tuesday, September 18, 2018 2:07 AM
>>>> To: amd-gfx@lists.freedesktop.org
>>>> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>>>
>>>> Don't try to unreserve a BO we doesn't allocated.
>>>>
>>>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel BOs
>>>>
>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> index 84d82d5382f9..c1387efc0c91 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct
>> amdgpu_device
>>>> *adev,
>>>> 	if (r)
>>>>    		return r;
>>>> -	amdgpu_bo_unreserve(*bo_ptr);
>>>> +	if (*bo_ptr)
>>>> +		amdgpu_bo_unreserve(*bo_ptr);
>>>>
>>>>    	return 0;
>>>>    }
>>> It is weird.
>>> If we return true for allocate bo with size  0.
>>> Does that mean we need to check all the bo_ptr before we use them.
>> No, allocating a BO with zero size doesn't make much sense and was
>> essentially undefined behavior previously.
>>
>> So now we get a defined behavior, but not necessary the one you expected.
>>
>> Is that only a rhetorical question or really a problem somewhere?
> Logically, the code is trick.

Yeah, that is not a bad argument.

But it also makes the function more useful, e.g. we don't need size 
checks any more whenever an optional BO is allocated.

>   It also make the  code
> if (r)
> 	return r;
> redundant.

Actually that is not correct.

When an error happens the *bo_ptr is not modified at all. So we could 
then try to unreserve a BO which was never reserved.

Christian.

>
> Regards
> Rex
>
>> Regards,
>> Christian.
>>
>>> Best Regards
>>> Rex
>>>
>>>> --
>>>> 2.14.1
>>>>
>>>> _______________________________________________
>>>> amd-gfx mailing list
>>>> amd-gfx@lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* RE: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]                 ` <248d2af0-e330-90e9-38c8-176a2bbd3649-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-18  9:27                   ` Zhu, Rex
       [not found]                     ` <BYAPR12MB27755971A03F2E03A5BF58BCFB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Zhu, Rex @ 2018-09-18  9:27 UTC (permalink / raw)
  To: Koenig, Christian, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



> -----Original Message-----
> From: Koenig, Christian
> Sent: Tuesday, September 18, 2018 4:41 PM
> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> 
> Am 18.09.2018 um 10:16 schrieb Zhu, Rex:
> >
> >> -----Original Message-----
> >> From: Christian König <ckoenig.leichtzumerken@gmail.com>
> >> Sent: Tuesday, September 18, 2018 3:14 PM
> >> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> >> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> >>
> >> Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
> >>>> -----Original Message-----
> >>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> >>>> Christian König
> >>>> Sent: Tuesday, September 18, 2018 2:07 AM
> >>>> To: amd-gfx@lists.freedesktop.org
> >>>> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> >>>>
> >>>> Don't try to unreserve a BO we doesn't allocated.
> >>>>
> >>>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel
> >>>> BOs
> >>>>
> >>>> Signed-off-by: Christian König <christian.koenig@amd.com>
> >>>> ---
> >>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
> >>>>    1 file changed, 2 insertions(+), 1 deletion(-)
> >>>>
> >>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>> index 84d82d5382f9..c1387efc0c91 100644
> >>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct
> >> amdgpu_device
> >>>> *adev,
> >>>> 	if (r)
> >>>>    		return r;
> >>>> -	amdgpu_bo_unreserve(*bo_ptr);
> >>>> +	if (*bo_ptr)
> >>>> +		amdgpu_bo_unreserve(*bo_ptr);
> >>>>
> >>>>    	return 0;
> >>>>    }
> >>> It is weird.
> >>> If we return true for allocate bo with size  0.
> >>> Does that mean we need to check all the bo_ptr before we use them.
> >> No, allocating a BO with zero size doesn't make much sense and was
> >> essentially undefined behavior previously.
> >>
> >> So now we get a defined behavior, but not necessary the one you
> expected.
> >>
> >> Is that only a rhetorical question or really a problem somewhere?
> > Logically, the code is trick.
> 
> Yeah, that is not a bad argument.
> 
> But it also makes the function more useful, e.g. we don't need size checks
> any more whenever an optional BO is allocated.

Yes, the problem is user don't need size check. But user have no way to check whether the bo is allocated successfully.

Because in size 0 case, the create function also return true.
And as you said below, check bo_ptr is not safe either(the *bo_ptr  may be not modified at all).

Regards
Rex




> >   It also make the  code
> > if (r)
> > 	return r;
> > redundant.
> 
> Actually that is not correct.
> 
> When an error happens the *bo_ptr is not modified at all. So we could then
> try to unreserve a BO which was never reserved.

Yes, You ae right.


> Christian.
> 
> >
> > Regards
> > Rex
> >
> >> Regards,
> >> Christian.
> >>
> >>> Best Regards
> >>> Rex
> >>>
> >>>> --
> >>>> 2.14.1
> >>>>
> >>>> _______________________________________________
> >>>> amd-gfx mailing list
> >>>> amd-gfx@lists.freedesktop.org
> >>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]                     ` <BYAPR12MB27755971A03F2E03A5BF58BCFB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-09-18  9:33                       ` Christian König
       [not found]                         ` <279b1ebf-326e-34b9-2878-bda3ffee21b8-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2018-09-18  9:33 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Am 18.09.2018 um 11:27 schrieb Zhu, Rex:
>
>> -----Original Message-----
>> From: Koenig, Christian
>> Sent: Tuesday, September 18, 2018 4:41 PM
>> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
>> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>
>> Am 18.09.2018 um 10:16 schrieb Zhu, Rex:
>>>> -----Original Message-----
>>>> From: Christian König <ckoenig.leichtzumerken@gmail.com>
>>>> Sent: Tuesday, September 18, 2018 3:14 PM
>>>> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
>>>> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>>>
>>>> Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
>>>>>> -----Original Message-----
>>>>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
>>>>>> Christian König
>>>>>> Sent: Tuesday, September 18, 2018 2:07 AM
>>>>>> To: amd-gfx@lists.freedesktop.org
>>>>>> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
>>>>>>
>>>>>> Don't try to unreserve a BO we doesn't allocated.
>>>>>>
>>>>>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel
>>>>>> BOs
>>>>>>
>>>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>>>> ---
>>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
>>>>>>     1 file changed, 2 insertions(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>>>> index 84d82d5382f9..c1387efc0c91 100644
>>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>>>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct
>>>> amdgpu_device
>>>>>> *adev,
>>>>>> 	if (r)
>>>>>>     		return r;
>>>>>> -	amdgpu_bo_unreserve(*bo_ptr);
>>>>>> +	if (*bo_ptr)
>>>>>> +		amdgpu_bo_unreserve(*bo_ptr);
>>>>>>
>>>>>>     	return 0;
>>>>>>     }
>>>>> It is weird.
>>>>> If we return true for allocate bo with size  0.
>>>>> Does that mean we need to check all the bo_ptr before we use them.
>>>> No, allocating a BO with zero size doesn't make much sense and was
>>>> essentially undefined behavior previously.
>>>>
>>>> So now we get a defined behavior, but not necessary the one you
>> expected.
>>>> Is that only a rhetorical question or really a problem somewhere?
>>> Logically, the code is trick.
>> Yeah, that is not a bad argument.
>>
>> But it also makes the function more useful, e.g. we don't need size checks
>> any more whenever an optional BO is allocated.
> Yes, the problem is user don't need size check. But user have no way to check whether the bo is allocated successfully.
>
> Because in size 0 case, the create function also return true.
> And as you said below, check bo_ptr is not safe either(the *bo_ptr  may be not modified at all).

That is not correct. When size==0 we call amdgpu_bo_unref(bo_ptr), and 
that one sets bo_ptr to NULL.

When size==0 was possible before, the calling code would have needed to 
check bo_ptr later on anyway.

In other words what we had before:

calling_function()
{
     if (size) {
         r = amdgpu_bo_create_kernel(..., size, &bo);
         if (r)
             goto error_handling;
     }
     ....
     if (bo)
         ....
}


But now that looks like:
calling_function()
{
     r = amdgpu_bo_create_kernel(..., size, &bo);
     if (r)
         goto error_handling;
     ....
     if (bo) {
         ....
}

So we just removed the extra size check of the calling function. I think 
that is a valid usage.

Christian.


>
> Regards
> Rex
>
>
>
>
>>>    It also make the  code
>>> if (r)
>>> 	return r;
>>> redundant.
>> Actually that is not correct.
>>
>> When an error happens the *bo_ptr is not modified at all. So we could then
>> try to unreserve a BO which was never reserved.
> Yes, You ae right.
>
>
>> Christian.
>>
>>> Regards
>>> Rex
>>>
>>>> Regards,
>>>> Christian.
>>>>
>>>>> Best Regards
>>>>> Rex
>>>>>
>>>>>> --
>>>>>> 2.14.1
>>>>>>
>>>>>> _______________________________________________
>>>>>> amd-gfx mailing list
>>>>>> amd-gfx@lists.freedesktop.org
>>>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* RE: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
       [not found]                         ` <279b1ebf-326e-34b9-2878-bda3ffee21b8-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-18  9:55                           ` Zhu, Rex
  0 siblings, 0 replies; 11+ messages in thread
From: Zhu, Rex @ 2018-09-18  9:55 UTC (permalink / raw)
  To: Koenig, Christian, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Thanks. 
So we still need to check the bo valid before use for the case that if we don't know the size when allocate.

Best Regards
Rex

> -----Original Message-----
> From: Koenig, Christian
> Sent: Tuesday, September 18, 2018 5:34 PM
> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> 
> Am 18.09.2018 um 11:27 schrieb Zhu, Rex:
> >
> >> -----Original Message-----
> >> From: Koenig, Christian
> >> Sent: Tuesday, September 18, 2018 4:41 PM
> >> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> >> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> >>
> >> Am 18.09.2018 um 10:16 schrieb Zhu, Rex:
> >>>> -----Original Message-----
> >>>> From: Christian König <ckoenig.leichtzumerken@gmail.com>
> >>>> Sent: Tuesday, September 18, 2018 3:14 PM
> >>>> To: Zhu, Rex <Rex.Zhu@amd.com>; amd-gfx@lists.freedesktop.org
> >>>> Subject: Re: [PATCH] drm/amdgpu: don't try to unreserve NULL
> >>>> pointer
> >>>>
> >>>> Am 18.09.2018 um 08:16 schrieb Zhu, Rex:
> >>>>>> -----Original Message-----
> >>>>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf
> >>>>>> Of Christian König
> >>>>>> Sent: Tuesday, September 18, 2018 2:07 AM
> >>>>>> To: amd-gfx@lists.freedesktop.org
> >>>>>> Subject: [PATCH] drm/amdgpu: don't try to unreserve NULL pointer
> >>>>>>
> >>>>>> Don't try to unreserve a BO we doesn't allocated.
> >>>>>>
> >>>>>> Fixes: 07012fdd497e drm/amdgpu: don't allocate zero sized kernel
> >>>>>> BOs
> >>>>>>
> >>>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
> >>>>>> ---
> >>>>>>     drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 ++-
> >>>>>>     1 file changed, 2 insertions(+), 1 deletion(-)
> >>>>>>
> >>>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>>>> index 84d82d5382f9..c1387efc0c91 100644
> >>>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> >>>>>> @@ -348,7 +348,8 @@ int amdgpu_bo_create_kernel(struct
> >>>> amdgpu_device
> >>>>>> *adev,
> >>>>>> 	if (r)
> >>>>>>     		return r;
> >>>>>> -	amdgpu_bo_unreserve(*bo_ptr);
> >>>>>> +	if (*bo_ptr)
> >>>>>> +		amdgpu_bo_unreserve(*bo_ptr);
> >>>>>>
> >>>>>>     	return 0;
> >>>>>>     }
> >>>>> It is weird.
> >>>>> If we return true for allocate bo with size  0.
> >>>>> Does that mean we need to check all the bo_ptr before we use them.
> >>>> No, allocating a BO with zero size doesn't make much sense and was
> >>>> essentially undefined behavior previously.
> >>>>
> >>>> So now we get a defined behavior, but not necessary the one you
> >> expected.
> >>>> Is that only a rhetorical question or really a problem somewhere?
> >>> Logically, the code is trick.
> >> Yeah, that is not a bad argument.
> >>
> >> But it also makes the function more useful, e.g. we don't need size
> >> checks any more whenever an optional BO is allocated.
> > Yes, the problem is user don't need size check. But user have no way to
> check whether the bo is allocated successfully.
> >
> > Because in size 0 case, the create function also return true.
> > And as you said below, check bo_ptr is not safe either(the *bo_ptr  may be
> not modified at all).
> 
> That is not correct. When size==0 we call amdgpu_bo_unref(bo_ptr), and
> that one sets bo_ptr to NULL.
> 
> When size==0 was possible before, the calling code would have needed to
> check bo_ptr later on anyway.
> 
> In other words what we had before:
> 
> calling_function()
> {
>      if (size) {
>          r = amdgpu_bo_create_kernel(..., size, &bo);
>          if (r)
>              goto error_handling;
>      }
>      ....
>      if (bo)
>          ....
> }
> 
> 
> But now that looks like:
> calling_function()
> {
>      r = amdgpu_bo_create_kernel(..., size, &bo);
>      if (r)
>          goto error_handling;
>      ....
>      if (bo) {
>          ....
> }
> 
> So we just removed the extra size check of the calling function. I think that is
> a valid usage.
> 
> Christian.
> 
> 
> >
> > Regards
> > Rex
> >
> >
> >
> >
> >>>    It also make the  code
> >>> if (r)
> >>> 	return r;
> >>> redundant.
> >> Actually that is not correct.
> >>
> >> When an error happens the *bo_ptr is not modified at all. So we could
> >> then try to unreserve a BO which was never reserved.
> > Yes, You ae right.
> >
> >
> >> Christian.
> >>
> >>> Regards
> >>> Rex
> >>>
> >>>> Regards,
> >>>> Christian.
> >>>>
> >>>>> Best Regards
> >>>>> Rex
> >>>>>
> >>>>>> --
> >>>>>> 2.14.1
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> amd-gfx mailing list
> >>>>>> amd-gfx@lists.freedesktop.org
> >>>>>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

end of thread, other threads:[~2018-09-18  9:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-17 18:07 [PATCH] drm/amdgpu: don't try to unreserve NULL pointer Christian König
     [not found] ` <20180917180724.1803-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-17 18:41   ` James Zhu
     [not found]     ` <4304faa2-5777-9d0a-c8e8-b00e431238f0-5C7GfCeVMHo@public.gmane.org>
2018-09-18  7:14       ` Christian König
2018-09-18  5:48   ` Huang Rui
2018-09-18  6:16   ` Zhu, Rex
     [not found]     ` <BYAPR12MB27754BE2A5210C53B1054F53FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-09-18  7:14       ` Christian König
     [not found]         ` <27a7e247-d895-17e8-5493-051dea82536d-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-09-18  8:16           ` Zhu, Rex
     [not found]             ` <BYAPR12MB27759724D41FECEEC1926845FB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-09-18  8:40               ` Christian König
     [not found]                 ` <248d2af0-e330-90e9-38c8-176a2bbd3649-5C7GfCeVMHo@public.gmane.org>
2018-09-18  9:27                   ` Zhu, Rex
     [not found]                     ` <BYAPR12MB27755971A03F2E03A5BF58BCFB1D0-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-09-18  9:33                       ` Christian König
     [not found]                         ` <279b1ebf-326e-34b9-2878-bda3ffee21b8-5C7GfCeVMHo@public.gmane.org>
2018-09-18  9:55                           ` Zhu, Rex

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.