diff mbox series

[v2] drm: Fix a infinite loop condition when order becomes 0

Message ID 20220316063416.3051-1-Arunpravin.PaneerSelvam@amd.com (mailing list archive)
State New, archived
Headers show
Series [v2] drm: Fix a infinite loop condition when order becomes 0 | expand

Commit Message

Paneer Selvam, Arunpravin March 16, 2022, 6:34 a.m. UTC
handle a situation in the condition order-- == min_order,
when order = 0 and min_order = 0, leading to order = -1,
it now won't exit the loop. To avoid this problem,
added a order check in the same condition, (i.e)
when order is 0, we return -ENOSPC

v2: use full name in email program and in Signed-off tag

Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
---
 drivers/gpu/drm/drm_buddy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175

Comments

Christian König March 16, 2022, 9:49 a.m. UTC | #1
Am 16.03.22 um 07:34 schrieb Arunpravin Paneer Selvam:
> handle a situation in the condition order-- == min_order,
> when order = 0 and min_order = 0, leading to order = -1,
> it now won't exit the loop. To avoid this problem,
> added a order check in the same condition, (i.e)
> when order is 0, we return -ENOSPC
>
> v2: use full name in email program and in Signed-off tag
>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

Acked-by: Christian König <christian.koenig@amd.com>

BTW while going over the code I've seen this here in the function:

...
                 if (!pages)
                         break;
         } while (1);


Can that be changed to "} while (pages);" instead? Would probably be a 
little bit cleaner.

Regards,
Christian.

> ---
>   drivers/gpu/drm/drm_buddy.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index 72f52f293249..5ab66aaf2bbd 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>   			if (!IS_ERR(block))
>   				break;
>   
> -			if (order-- == min_order) {
> +			if (!order || order-- == min_order) {
>   				err = -ENOSPC;
>   				goto err_free;
>   			}
>
> base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175
Matthew Auld March 16, 2022, 11:31 a.m. UTC | #2
On 16/03/2022 06:34, Arunpravin Paneer Selvam wrote:
> handle a situation in the condition order-- == min_order,
> when order = 0 and min_order = 0, leading to order = -1,
> it now won't exit the loop. To avoid this problem,
> added a order check in the same condition, (i.e)
> when order is 0, we return -ENOSPC
> 
> v2: use full name in email program and in Signed-off tag
> 
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> ---
>   drivers/gpu/drm/drm_buddy.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index 72f52f293249..5ab66aaf2bbd 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>   			if (!IS_ERR(block))
>   				break;
>   
> -			if (order-- == min_order) {
> +			if (!order || order-- == min_order) {

It shouldn't be possible to enter an infinite loop here, without first 
tripping up the BUG_ON(order < min_order) further up, and for that, as 
we discussed here[1], it sounded like the conclusion was to rather add a 
simple check somewhere in drm_buddy_alloc_blocks() to reject any size 
not aligned to the min_page_size?

[1] https://patchwork.freedesktop.org/patch/477414/?series=101108&rev=1

>   				err = -ENOSPC;
>   				goto err_free;
>   			}
> 
> base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175
Christian König March 16, 2022, 12:32 p.m. UTC | #3
Am 16.03.22 um 12:31 schrieb Matthew Auld:
> On 16/03/2022 06:34, Arunpravin Paneer Selvam wrote:
>> handle a situation in the condition order-- == min_order,
>> when order = 0 and min_order = 0, leading to order = -1,
>> it now won't exit the loop. To avoid this problem,
>> added a order check in the same condition, (i.e)
>> when order is 0, we return -ENOSPC
>>
>> v2: use full name in email program and in Signed-off tag
>>
>> Signed-off-by: Arunpravin Paneer Selvam 
>> <Arunpravin.PaneerSelvam@amd.com>
>> ---
>>   drivers/gpu/drm/drm_buddy.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>> index 72f52f293249..5ab66aaf2bbd 100644
>> --- a/drivers/gpu/drm/drm_buddy.c
>> +++ b/drivers/gpu/drm/drm_buddy.c
>> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>               if (!IS_ERR(block))
>>                   break;
>>   -            if (order-- == min_order) {
>> +            if (!order || order-- == min_order) {
>
> It shouldn't be possible to enter an infinite loop here, without first 
> tripping up the BUG_ON(order < min_order) further up, and for that, as 
> we discussed here[1], it sounded like the conclusion was to rather add 
> a simple check somewhere in drm_buddy_alloc_blocks() to reject any 
> size not aligned to the min_page_size?

Sounds good to me as well.

And just to make it clear: I don't review the functionality here, that's 
up to you guys.

Just giving my Ack on things like style and pushing the end result 
upstream as necessary.

So let me know when you have settled on a solution.

Regards,
Christian.

>
> [1] https://patchwork.freedesktop.org/patch/477414/?series=101108&rev=1
>
>>                   err = -ENOSPC;
>>                   goto err_free;
>>               }
>>
>> base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175
Paneer Selvam, Arunpravin March 21, 2022, 6:09 a.m. UTC | #4
On 16/03/22 5:01 pm, Matthew Auld wrote:
> On 16/03/2022 06:34, Arunpravin Paneer Selvam wrote:
>> handle a situation in the condition order-- == min_order,
>> when order = 0 and min_order = 0, leading to order = -1,
>> it now won't exit the loop. To avoid this problem,
>> added a order check in the same condition, (i.e)
>> when order is 0, we return -ENOSPC
>>
>> v2: use full name in email program and in Signed-off tag
>>
>> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
>> ---
>>   drivers/gpu/drm/drm_buddy.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>> index 72f52f293249..5ab66aaf2bbd 100644
>> --- a/drivers/gpu/drm/drm_buddy.c
>> +++ b/drivers/gpu/drm/drm_buddy.c
>> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>   			if (!IS_ERR(block))
>>   				break;
>>   
>> -			if (order-- == min_order) {
>> +			if (!order || order-- == min_order) {
> 
> It shouldn't be possible to enter an infinite loop here, without first 
> tripping up the BUG_ON(order < min_order) further up, and for that, as 
> we discussed here[1], it sounded like the conclusion was to rather add a 
> simple check somewhere in drm_buddy_alloc_blocks() to reject any size 
> not aligned to the min_page_size?

I sent a patch adding a check to reject any size not aligned to the
min_page_size. Please review
> 
> [1] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.freedesktop.org%2Fpatch%2F477414%2F%3Fseries%3D101108%26rev%3D1&amp;data=04%7C01%7CArunpravin.PaneerSelvam%40amd.com%7C51e60632b18847b73da808da074085d6%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637830270945242954%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=wVVqKzjUoL6jL00uxXiXZz7%2FzJQeuC%2BuBdB8hPKqQao%3D&amp;reserved=0
> 
>>   				err = -ENOSPC;
>>   				goto err_free;
>>   			}
>>
>> base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175
Paneer Selvam, Arunpravin March 21, 2022, 6:24 a.m. UTC | #5
On 16/03/22 6:02 pm, Christian König wrote:
> Am 16.03.22 um 12:31 schrieb Matthew Auld:
>> On 16/03/2022 06:34, Arunpravin Paneer Selvam wrote:
>>> handle a situation in the condition order-- == min_order,
>>> when order = 0 and min_order = 0, leading to order = -1,
>>> it now won't exit the loop. To avoid this problem,
>>> added a order check in the same condition, (i.e)
>>> when order is 0, we return -ENOSPC
>>>
>>> v2: use full name in email program and in Signed-off tag
>>>
>>> Signed-off-by: Arunpravin Paneer Selvam 
>>> <Arunpravin.PaneerSelvam@amd.com>
>>> ---
>>>   drivers/gpu/drm/drm_buddy.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 72f52f293249..5ab66aaf2bbd 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>               if (!IS_ERR(block))
>>>                   break;
>>>   -            if (order-- == min_order) {
>>> +            if (!order || order-- == min_order) {
>>
>> It shouldn't be possible to enter an infinite loop here, without first 
>> tripping up the BUG_ON(order < min_order) further up, and for that, as 
>> we discussed here[1], it sounded like the conclusion was to rather add 
>> a simple check somewhere in drm_buddy_alloc_blocks() to reject any 
>> size not aligned to the min_page_size?
> 
> Sounds good to me as well.
> 
> And just to make it clear: I don't review the functionality here, that's 
> up to you guys.
> 
> Just giving my Ack on things like style and pushing the end result 
> upstream as necessary.
> 
> So let me know when you have settled on a solution.

I sent a drm buddy patch adding a simple check to verify the size
aligned to the min_page_size.

In amdgpu part patch, I have a check if size is not aligned to the
min_page_size, we are enabling the is_contiguous flag, therefore the
size value round up to the power of two and allocated, Later, the
allocated block trimmed to the original requested size.

> 
> Regards,
> Christian.
> 
>>
>> [1] https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.freedesktop.org%2Fpatch%2F477414%2F%3Fseries%3D101108%26rev%3D1&amp;data=04%7C01%7CArunpravin.PaneerSelvam%40amd.com%7Cf03d93b31c7d47b1389c08da074915cf%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637830307722869478%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=i3Pw3Go9Niu20Z4CF0IiWKPgTYTBPyK0SJYVq02fx0A%3D&amp;reserved=0
>>
>>>                   err = -ENOSPC;
>>>                   goto err_free;
>>>               }
>>>
>>> base-commit: 3bd60c0259406c5ca3ce5cdc958fb910ad4b8175
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 72f52f293249..5ab66aaf2bbd 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -685,7 +685,7 @@  int drm_buddy_alloc_blocks(struct drm_buddy *mm,
 			if (!IS_ERR(block))
 				break;
 
-			if (order-- == min_order) {
+			if (!order || order-- == min_order) {
 				err = -ENOSPC;
 				goto err_free;
 			}