dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/buddy: Fix alloc_range() error handling code
@ 2024-02-07 17:44 Arunpravin Paneer Selvam
  2024-02-08  6:57 ` Christian König
  2024-02-08 13:30 ` Matthew Auld
  0 siblings, 2 replies; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-07 17:44 UTC (permalink / raw)
  To: dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, matthew.auld,
	mario.limonciello, Arunpravin Paneer Selvam

Few users have observed display corruption when they boot
the machine to KDE Plasma or playing games. We have root
caused the problem that whenever alloc_range() couldn't
find the required memory blocks the function was returning
SUCCESS in some of the corner cases.

The right approach would be if the total allocated size
is less than the required size, the function should
return -ENOSPC.

Gitlab ticket link - https://gitlab.freedesktop.org/drm/amd/-/issues/3097
Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Tested-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/gpu/drm/drm_buddy.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index f57e6d74fb0e..c1a99bf4dffd 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
 	} while (1);
 
 	list_splice_tail(&allocated, blocks);
+
+	if (total_allocated < size) {
+		err = -ENOSPC;
+		goto err_free;
+	}
+
 	return 0;
 
 err_undo:
-- 
2.25.1


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-07 17:44 [PATCH] drm/buddy: Fix alloc_range() error handling code Arunpravin Paneer Selvam
@ 2024-02-08  6:57 ` Christian König
  2024-02-08 12:06   ` Arunpravin Paneer Selvam
  2024-02-08 13:30 ` Matthew Auld
  1 sibling, 1 reply; 14+ messages in thread
From: Christian König @ 2024-02-08  6:57 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, dri-devel, amd-gfx, intel-gfx
  Cc: alexander.deucher, matthew.auld, mario.limonciello

Am 07.02.24 um 18:44 schrieb Arunpravin Paneer Selvam:
> Few users have observed display corruption when they boot
> the machine to KDE Plasma or playing games. We have root
> caused the problem that whenever alloc_range() couldn't
> find the required memory blocks the function was returning
> SUCCESS in some of the corner cases.
>
> The right approach would be if the total allocated size
> is less than the required size, the function should
> return -ENOSPC.
>
> Gitlab ticket link - https://gitlab.freedesktop.org/drm/amd/-/issues/3097
> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Tested-by: Mario Limonciello <mario.limonciello@amd.com>

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

CC: stable.. ?

> ---
>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>   1 file changed, 6 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index f57e6d74fb0e..c1a99bf4dffd 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>   	} while (1);
>   
>   	list_splice_tail(&allocated, blocks);
> +
> +	if (total_allocated < size) {
> +		err = -ENOSPC;
> +		goto err_free;
> +	}
> +
>   	return 0;
>   
>   err_undo:


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08  6:57 ` Christian König
@ 2024-02-08 12:06   ` Arunpravin Paneer Selvam
  2024-02-08 13:59     ` Mario Limonciello
  0 siblings, 1 reply; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-08 12:06 UTC (permalink / raw)
  To: Christian König, dri-devel, amd-gfx, intel-gfx
  Cc: alexander.deucher, matthew.auld, mario.limonciello

Hi Christian,

On 2/8/2024 12:27 PM, Christian König wrote:
> Am 07.02.24 um 18:44 schrieb Arunpravin Paneer Selvam:
>> Few users have observed display corruption when they boot
>> the machine to KDE Plasma or playing games. We have root
>> caused the problem that whenever alloc_range() couldn't
>> find the required memory blocks the function was returning
>> SUCCESS in some of the corner cases.
>>
>> The right approach would be if the total allocated size
>> is less than the required size, the function should
>> return -ENOSPC.
>>
>> Gitlab ticket link - 
>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>> Signed-off-by: Arunpravin Paneer Selvam 
>> <Arunpravin.PaneerSelvam@amd.com>
>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>
> Acked-by: Christian König <christian.koenig@amd.com>
>
> CC: stable.. ?
I will check and add the stable kernel version.

Thanks,
Arun.
>
>> ---
>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>> index f57e6d74fb0e..c1a99bf4dffd 100644
>> --- a/drivers/gpu/drm/drm_buddy.c
>> +++ b/drivers/gpu/drm/drm_buddy.c
>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>       } while (1);
>>         list_splice_tail(&allocated, blocks);
>> +
>> +    if (total_allocated < size) {
>> +        err = -ENOSPC;
>> +        goto err_free;
>> +    }
>> +
>>       return 0;
>>     err_undo:
>


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-07 17:44 [PATCH] drm/buddy: Fix alloc_range() error handling code Arunpravin Paneer Selvam
  2024-02-08  6:57 ` Christian König
@ 2024-02-08 13:30 ` Matthew Auld
  2024-02-08 13:47   ` Arunpravin Paneer Selvam
  1 sibling, 1 reply; 14+ messages in thread
From: Matthew Auld @ 2024-02-08 13:30 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, mario.limonciello

On 07/02/2024 17:44, Arunpravin Paneer Selvam wrote:
> Few users have observed display corruption when they boot
> the machine to KDE Plasma or playing games. We have root
> caused the problem that whenever alloc_range() couldn't
> find the required memory blocks the function was returning
> SUCCESS in some of the corner cases.

Can you please give an example here?

> 
> The right approach would be if the total allocated size
> is less than the required size, the function should
> return -ENOSPC.
> 
> Gitlab ticket link - https://gitlab.freedesktop.org/drm/amd/-/issues/3097
> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index f57e6d74fb0e..c1a99bf4dffd 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>   	} while (1);
>   
>   	list_splice_tail(&allocated, blocks);
> +
> +	if (total_allocated < size) {
> +		err = -ENOSPC;
> +		goto err_free;
> +	}
> +
>   	return 0;
>   
>   err_undo:

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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08 13:30 ` Matthew Auld
@ 2024-02-08 13:47   ` Arunpravin Paneer Selvam
  2024-02-08 14:17     ` Matthew Auld
  0 siblings, 1 reply; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-08 13:47 UTC (permalink / raw)
  To: Matthew Auld, dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, mario.limonciello

Hi Matthew,

On 2/8/2024 7:00 PM, Matthew Auld wrote:
> On 07/02/2024 17:44, Arunpravin Paneer Selvam wrote:
>> Few users have observed display corruption when they boot
>> the machine to KDE Plasma or playing games. We have root
>> caused the problem that whenever alloc_range() couldn't
>> find the required memory blocks the function was returning
>> SUCCESS in some of the corner cases.
>
> Can you please give an example here?
>
In the try hard contiguous allocation, for example the requested memory 
is 1024 pages,
it might go and pick the highest and last block (of size 512 pages) in 
the freelist where
there are no more space exist in the total address range. In this kind 
of corner case,
alloc_range was returning success though the allocated size is less than 
the requested size.
Hence in try_hard_contiguous_allocation, we will not proceed to the LHS 
allocation and
we return only with the RHS allocation having only the 512 pages of 
allocation. This
leads to display corruption in many use cases (I think mainly when 
requested for contiguous huge buffer)
mainly on APU platforms.

Thanks,
Arun.
>>
>> The right approach would be if the total allocated size
>> is less than the required size, the function should
>> return -ENOSPC.
>>
>> Gitlab ticket link - 
>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>> Signed-off-by: Arunpravin Paneer Selvam 
>> <Arunpravin.PaneerSelvam@amd.com>
>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>> index f57e6d74fb0e..c1a99bf4dffd 100644
>> --- a/drivers/gpu/drm/drm_buddy.c
>> +++ b/drivers/gpu/drm/drm_buddy.c
>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>       } while (1);
>>         list_splice_tail(&allocated, blocks);
>> +
>> +    if (total_allocated < size) {
>> +        err = -ENOSPC;
>> +        goto err_free;
>> +    }
>> +
>>       return 0;
>>     err_undo:


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08 12:06   ` Arunpravin Paneer Selvam
@ 2024-02-08 13:59     ` Mario Limonciello
  0 siblings, 0 replies; 14+ messages in thread
From: Mario Limonciello @ 2024-02-08 13:59 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, Christian König, dri-devel,
	amd-gfx, intel-gfx
  Cc: alexander.deucher, matthew.auld

On 2/8/2024 06:06, Arunpravin Paneer Selvam wrote:
> Hi Christian,
> 
> On 2/8/2024 12:27 PM, Christian König wrote:
>> Am 07.02.24 um 18:44 schrieb Arunpravin Paneer Selvam:
>>> Few users have observed display corruption when they boot
>>> the machine to KDE Plasma or playing games. We have root
>>> caused the problem that whenever alloc_range() couldn't
>>> find the required memory blocks the function was returning
>>> SUCCESS in some of the corner cases.
>>>
>>> The right approach would be if the total allocated size
>>> is less than the required size, the function should
>>> return -ENOSPC.
>>>
>>> Gitlab ticket link - 
>>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097

Syntax should be "Closes: $URL"

>>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>>> Signed-off-by: Arunpravin Paneer Selvam 
>>> <Arunpravin.PaneerSelvam@amd.com>
>>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>>
>> Acked-by: Christian König <christian.koenig@amd.com>
>>
>> CC: stable.. ?
> I will check and add the stable kernel version.

Should be 6.7.

> 
> Thanks,
> Arun.
>>
>>> ---
>>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>>   1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index f57e6d74fb0e..c1a99bf4dffd 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>>       } while (1);
>>>         list_splice_tail(&allocated, blocks);
>>> +
>>> +    if (total_allocated < size) {
>>> +        err = -ENOSPC;
>>> +        goto err_free;
>>> +    }
>>> +
>>>       return 0;
>>>     err_undo:
>>
> 


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08 13:47   ` Arunpravin Paneer Selvam
@ 2024-02-08 14:17     ` Matthew Auld
  2024-02-08 14:44       ` Matthew Auld
  2024-02-09 12:58       ` Arunpravin Paneer Selvam
  0 siblings, 2 replies; 14+ messages in thread
From: Matthew Auld @ 2024-02-08 14:17 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, mario.limonciello

On 08/02/2024 13:47, Arunpravin Paneer Selvam wrote:
> Hi Matthew,
> 
> On 2/8/2024 7:00 PM, Matthew Auld wrote:
>> On 07/02/2024 17:44, Arunpravin Paneer Selvam wrote:
>>> Few users have observed display corruption when they boot
>>> the machine to KDE Plasma or playing games. We have root
>>> caused the problem that whenever alloc_range() couldn't
>>> find the required memory blocks the function was returning
>>> SUCCESS in some of the corner cases.
>>
>> Can you please give an example here?
>>
> In the try hard contiguous allocation, for example the requested memory 
> is 1024 pages,
> it might go and pick the highest and last block (of size 512 pages) in 
> the freelist where
> there are no more space exist in the total address range. In this kind 
> of corner case,
> alloc_range was returning success though the allocated size is less than 
> the requested size.
> Hence in try_hard_contiguous_allocation, we will not proceed to the LHS 
> allocation and
> we return only with the RHS allocation having only the 512 pages of 
> allocation. This
> leads to display corruption in many use cases (I think mainly when 
> requested for contiguous huge buffer)
> mainly on APU platforms.

Ok, I guess other thing is doing:

lhs_offset = drm_buddy_block_offset(block) - lhs_size;

I presume it's possible for block_offset < lhs_size here, which might be 
funny?

> 
> Thanks,
> Arun.
>>>
>>> The right approach would be if the total allocated size
>>> is less than the required size, the function should
>>> return -ENOSPC.
>>>
>>> Gitlab ticket link - 
>>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>>> Signed-off-by: Arunpravin Paneer Selvam 
>>> <Arunpravin.PaneerSelvam@amd.com>
>>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>>> ---
>>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>>   1 file changed, 6 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index f57e6d74fb0e..c1a99bf4dffd 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>>       } while (1);
>>>         list_splice_tail(&allocated, blocks);
>>> +
>>> +    if (total_allocated < size) {
>>> +        err = -ENOSPC;
>>> +        goto err_free;
>>> +    }
>>> +
>>>       return 0;
>>>     err_undo:
> 

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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08 14:17     ` Matthew Auld
@ 2024-02-08 14:44       ` Matthew Auld
  2024-02-09 12:58       ` Arunpravin Paneer Selvam
  1 sibling, 0 replies; 14+ messages in thread
From: Matthew Auld @ 2024-02-08 14:44 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, mario.limonciello

On 08/02/2024 14:17, Matthew Auld wrote:
> On 08/02/2024 13:47, Arunpravin Paneer Selvam wrote:
>> Hi Matthew,
>>
>> On 2/8/2024 7:00 PM, Matthew Auld wrote:
>>> On 07/02/2024 17:44, Arunpravin Paneer Selvam wrote:
>>>> Few users have observed display corruption when they boot
>>>> the machine to KDE Plasma or playing games. We have root
>>>> caused the problem that whenever alloc_range() couldn't
>>>> find the required memory blocks the function was returning
>>>> SUCCESS in some of the corner cases.
>>>
>>> Can you please give an example here?
>>>
>> In the try hard contiguous allocation, for example the requested 
>> memory is 1024 pages,
>> it might go and pick the highest and last block (of size 512 pages) in 
>> the freelist where
>> there are no more space exist in the total address range. In this kind 
>> of corner case,
>> alloc_range was returning success though the allocated size is less 
>> than the requested size.
>> Hence in try_hard_contiguous_allocation, we will not proceed to the 
>> LHS allocation and
>> we return only with the RHS allocation having only the 512 pages of 
>> allocation. This
>> leads to display corruption in many use cases (I think mainly when 
>> requested for contiguous huge buffer)
>> mainly on APU platforms.
> 
> Ok, I guess other thing is doing:
> 
> lhs_offset = drm_buddy_block_offset(block) - lhs_size;
> 
> I presume it's possible for block_offset < lhs_size here, which might be 
> funny?

I think would also be good to add some basic unit test here:
https://patchwork.freedesktop.org/patch/577497/?series=129671&rev=1

Test passes with your patch, and ofc fails without it.

Just the question of the lhs_offset above,
Reviewed-by: Matthew Auld <matthew.auld@intel.com>

> 
>>
>> Thanks,
>> Arun.
>>>>
>>>> The right approach would be if the total allocated size
>>>> is less than the required size, the function should
>>>> return -ENOSPC.
>>>>
>>>> Gitlab ticket link - 
>>>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>>>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>>>> Signed-off-by: Arunpravin Paneer Selvam 
>>>> <Arunpravin.PaneerSelvam@amd.com>
>>>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>>>> ---
>>>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>>>   1 file changed, 6 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>>> index f57e6d74fb0e..c1a99bf4dffd 100644
>>>> --- a/drivers/gpu/drm/drm_buddy.c
>>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>>>       } while (1);
>>>>         list_splice_tail(&allocated, blocks);
>>>> +
>>>> +    if (total_allocated < size) {
>>>> +        err = -ENOSPC;
>>>> +        goto err_free;
>>>> +    }
>>>> +
>>>>       return 0;
>>>>     err_undo:
>>

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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-08 14:17     ` Matthew Auld
  2024-02-08 14:44       ` Matthew Auld
@ 2024-02-09 12:58       ` Arunpravin Paneer Selvam
  1 sibling, 0 replies; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-09 12:58 UTC (permalink / raw)
  To: Matthew Auld, dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, mario.limonciello



On 2/8/2024 7:47 PM, Matthew Auld wrote:
> On 08/02/2024 13:47, Arunpravin Paneer Selvam wrote:
>> Hi Matthew,
>>
>> On 2/8/2024 7:00 PM, Matthew Auld wrote:
>>> On 07/02/2024 17:44, Arunpravin Paneer Selvam wrote:
>>>> Few users have observed display corruption when they boot
>>>> the machine to KDE Plasma or playing games. We have root
>>>> caused the problem that whenever alloc_range() couldn't
>>>> find the required memory blocks the function was returning
>>>> SUCCESS in some of the corner cases.
>>>
>>> Can you please give an example here?
>>>
>> In the try hard contiguous allocation, for example the requested 
>> memory is 1024 pages,
>> it might go and pick the highest and last block (of size 512 pages) 
>> in the freelist where
>> there are no more space exist in the total address range. In this 
>> kind of corner case,
>> alloc_range was returning success though the allocated size is less 
>> than the requested size.
>> Hence in try_hard_contiguous_allocation, we will not proceed to the 
>> LHS allocation and
>> we return only with the RHS allocation having only the 512 pages of 
>> allocation. This
>> leads to display corruption in many use cases (I think mainly when 
>> requested for contiguous huge buffer)
>> mainly on APU platforms.
>
> Ok, I guess other thing is doing:
>
> lhs_offset = drm_buddy_block_offset(block) - lhs_size;
>
> I presume it's possible for block_offset < lhs_size here, which might 
> be funny?
yes, seems it is possible, I will modify the lhs_offset calculation and 
send the patch for review.

Thanks,
Arun.
>
>>
>> Thanks,
>> Arun.
>>>>
>>>> The right approach would be if the total allocated size
>>>> is less than the required size, the function should
>>>> return -ENOSPC.
>>>>
>>>> Gitlab ticket link - 
>>>> https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>>>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory 
>>>> allocation")
>>>> Signed-off-by: Arunpravin Paneer Selvam 
>>>> <Arunpravin.PaneerSelvam@amd.com>
>>>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>>>> ---
>>>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>>>   1 file changed, 6 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>>> index f57e6d74fb0e..c1a99bf4dffd 100644
>>>> --- a/drivers/gpu/drm/drm_buddy.c
>>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>>>       } while (1);
>>>>         list_splice_tail(&allocated, blocks);
>>>> +
>>>> +    if (total_allocated < size) {
>>>> +        err = -ENOSPC;
>>>> +        goto err_free;
>>>> +    }
>>>> +
>>>>       return 0;
>>>>     err_undo:
>>


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-09 18:36   ` Arunpravin Paneer Selvam
@ 2024-02-09 19:40     ` Daniel Vetter
  0 siblings, 0 replies; 14+ messages in thread
From: Daniel Vetter @ 2024-02-09 19:40 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam
  Cc: Daniel Vetter, dri-devel, amd-gfx, intel-gfx, christian.koenig,
	alexander.deucher, matthew.auld, mario.limonciello, stable

On Sat, Feb 10, 2024 at 12:06:58AM +0530, Arunpravin Paneer Selvam wrote:
> Hi Daniel,
> 
> On 2/9/2024 11:34 PM, Daniel Vetter wrote:
> > On Fri, Feb 09, 2024 at 08:56:24PM +0530, Arunpravin Paneer Selvam wrote:
> > > Few users have observed display corruption when they boot
> > > the machine to KDE Plasma or playing games. We have root
> > > caused the problem that whenever alloc_range() couldn't
> > > find the required memory blocks the function was returning
> > > SUCCESS in some of the corner cases.
> > > 
> > > The right approach would be if the total allocated size
> > > is less than the required size, the function should
> > > return -ENOSPC.
> > > 
> > > Cc:  <stable@vger.kernel.org> # 6.7+
> > > Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
> > > Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097
> > > Tested-by: Mario Limonciello <mario.limonciello@amd.com>
> > > Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/
> > > Acked-by: Christian König <christian.koenig@amd.com>
> > > Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> > > Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> > New unit test for this would be most excellent - these kind of missed edge
> > cases is exactly what kunit is for. Can you please follow up with, since
> > we don't want to hold up the bugfix for longer?
> Matthew Auld has added a new unit test for this case. Please let us know if
> this will suffice.
> https://patchwork.freedesktop.org/patch/577497/?series=129671&rev=1

Ah yeah, might be best to submit them both together as one series (you
just need to add your own signed-off-by if you resend other people's
patches). That way bots can pick it up together, since new testcase and
bugfix only make sense together.
-Sima

> 
> Thanks,
> Arun.
> > -Sima
> > 
> > > ---
> > >   drivers/gpu/drm/drm_buddy.c | 6 ++++++
> > >   1 file changed, 6 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> > > index f57e6d74fb0e..c1a99bf4dffd 100644
> > > --- a/drivers/gpu/drm/drm_buddy.c
> > > +++ b/drivers/gpu/drm/drm_buddy.c
> > > @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
> > >   	} while (1);
> > >   	list_splice_tail(&allocated, blocks);
> > > +
> > > +	if (total_allocated < size) {
> > > +		err = -ENOSPC;
> > > +		goto err_free;
> > > +	}
> > > +
> > >   	return 0;
> > >   err_undo:
> > > -- 
> > > 2.25.1
> > > 
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-09 18:04 ` Daniel Vetter
@ 2024-02-09 18:36   ` Arunpravin Paneer Selvam
  2024-02-09 19:40     ` Daniel Vetter
  0 siblings, 1 reply; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-09 18:36 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: dri-devel, amd-gfx, intel-gfx, christian.koenig,
	alexander.deucher, matthew.auld, mario.limonciello, stable

Hi Daniel,

On 2/9/2024 11:34 PM, Daniel Vetter wrote:
> On Fri, Feb 09, 2024 at 08:56:24PM +0530, Arunpravin Paneer Selvam wrote:
>> Few users have observed display corruption when they boot
>> the machine to KDE Plasma or playing games. We have root
>> caused the problem that whenever alloc_range() couldn't
>> find the required memory blocks the function was returning
>> SUCCESS in some of the corner cases.
>>
>> The right approach would be if the total allocated size
>> is less than the required size, the function should
>> return -ENOSPC.
>>
>> Cc:  <stable@vger.kernel.org> # 6.7+
>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097
>> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
>> Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/
>> Acked-by: Christian König <christian.koenig@amd.com>
>> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> New unit test for this would be most excellent - these kind of missed edge
> cases is exactly what kunit is for. Can you please follow up with, since
> we don't want to hold up the bugfix for longer?
Matthew Auld has added a new unit test for this case. Please let us know 
if this will suffice.
https://patchwork.freedesktop.org/patch/577497/?series=129671&rev=1

Thanks,
Arun.
> -Sima
>
>> ---
>>   drivers/gpu/drm/drm_buddy.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>> index f57e6d74fb0e..c1a99bf4dffd 100644
>> --- a/drivers/gpu/drm/drm_buddy.c
>> +++ b/drivers/gpu/drm/drm_buddy.c
>> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>>   	} while (1);
>>   
>>   	list_splice_tail(&allocated, blocks);
>> +
>> +	if (total_allocated < size) {
>> +		err = -ENOSPC;
>> +		goto err_free;
>> +	}
>> +
>>   	return 0;
>>   
>>   err_undo:
>> -- 
>> 2.25.1
>>


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

* Re: [PATCH] drm/buddy: Fix alloc_range() error handling code
  2024-02-09 15:26 Arunpravin Paneer Selvam
@ 2024-02-09 18:04 ` Daniel Vetter
  2024-02-09 18:36   ` Arunpravin Paneer Selvam
  0 siblings, 1 reply; 14+ messages in thread
From: Daniel Vetter @ 2024-02-09 18:04 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam
  Cc: dri-devel, amd-gfx, intel-gfx, christian.koenig,
	alexander.deucher, matthew.auld, mario.limonciello, stable

On Fri, Feb 09, 2024 at 08:56:24PM +0530, Arunpravin Paneer Selvam wrote:
> Few users have observed display corruption when they boot
> the machine to KDE Plasma or playing games. We have root
> caused the problem that whenever alloc_range() couldn't
> find the required memory blocks the function was returning
> SUCCESS in some of the corner cases.
> 
> The right approach would be if the total allocated size
> is less than the required size, the function should
> return -ENOSPC.
> 
> Cc:  <stable@vger.kernel.org> # 6.7+
> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097
> Tested-by: Mario Limonciello <mario.limonciello@amd.com>
> Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/
> Acked-by: Christian König <christian.koenig@amd.com>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

New unit test for this would be most excellent - these kind of missed edge
cases is exactly what kunit is for. Can you please follow up with, since
we don't want to hold up the bugfix for longer?
-Sima

> ---
>  drivers/gpu/drm/drm_buddy.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index f57e6d74fb0e..c1a99bf4dffd 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
>  	} while (1);
>  
>  	list_splice_tail(&allocated, blocks);
> +
> +	if (total_allocated < size) {
> +		err = -ENOSPC;
> +		goto err_free;
> +	}
> +
>  	return 0;
>  
>  err_undo:
> -- 
> 2.25.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

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

* [PATCH] drm/buddy: Fix alloc_range() error handling code
@ 2024-02-09 15:26 Arunpravin Paneer Selvam
  2024-02-09 18:04 ` Daniel Vetter
  0 siblings, 1 reply; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-09 15:26 UTC (permalink / raw)
  To: dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, matthew.auld,
	mario.limonciello, Arunpravin Paneer Selvam, stable

Few users have observed display corruption when they boot
the machine to KDE Plasma or playing games. We have root
caused the problem that whenever alloc_range() couldn't
find the required memory blocks the function was returning
SUCCESS in some of the corner cases.

The right approach would be if the total allocated size
is less than the required size, the function should
return -ENOSPC.

Cc:  <stable@vger.kernel.org> # 6.7+
Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097
Tested-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/
Acked-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
---
 drivers/gpu/drm/drm_buddy.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index f57e6d74fb0e..c1a99bf4dffd 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
 	} while (1);
 
 	list_splice_tail(&allocated, blocks);
+
+	if (total_allocated < size) {
+		err = -ENOSPC;
+		goto err_free;
+	}
+
 	return 0;
 
 err_undo:
-- 
2.25.1


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

* [PATCH] drm/buddy: Fix alloc_range() error handling code
@ 2024-02-09 15:18 Arunpravin Paneer Selvam
  0 siblings, 0 replies; 14+ messages in thread
From: Arunpravin Paneer Selvam @ 2024-02-09 15:18 UTC (permalink / raw)
  To: dri-devel, amd-gfx, intel-gfx
  Cc: christian.koenig, alexander.deucher, matthew.auld,
	mario.limonciello, Arunpravin Paneer Selvam, stable

Few users have observed display corruption when they boot
the machine to KDE Plasma or playing games. We have root
caused the problem that whenever alloc_range() couldn't
find the required memory blocks the function was returning
SUCCESS in some of the corner cases.

The right approach would be if the total allocated size
is less than the required size, the function should
return -ENOSPC.

Cc:  <stable@vger.kernel.org> # 6.7+
Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3097
Tested-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20240207174456.341121-1-Arunpravin.PaneerSelvam@amd.com/
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
---
 drivers/gpu/drm/drm_buddy.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index f57e6d74fb0e..c1a99bf4dffd 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -539,6 +539,12 @@ static int __alloc_range(struct drm_buddy *mm,
 	} while (1);
 
 	list_splice_tail(&allocated, blocks);
+
+	if (total_allocated < size) {
+		err = -ENOSPC;
+		goto err_free;
+	}
+
 	return 0;
 
 err_undo:
-- 
2.25.1


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

end of thread, other threads:[~2024-02-09 19:40 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 17:44 [PATCH] drm/buddy: Fix alloc_range() error handling code Arunpravin Paneer Selvam
2024-02-08  6:57 ` Christian König
2024-02-08 12:06   ` Arunpravin Paneer Selvam
2024-02-08 13:59     ` Mario Limonciello
2024-02-08 13:30 ` Matthew Auld
2024-02-08 13:47   ` Arunpravin Paneer Selvam
2024-02-08 14:17     ` Matthew Auld
2024-02-08 14:44       ` Matthew Auld
2024-02-09 12:58       ` Arunpravin Paneer Selvam
2024-02-09 15:18 Arunpravin Paneer Selvam
2024-02-09 15:26 Arunpravin Paneer Selvam
2024-02-09 18:04 ` Daniel Vetter
2024-02-09 18:36   ` Arunpravin Paneer Selvam
2024-02-09 19:40     ` Daniel Vetter

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