diff mbox series

[v3] drm: add a check to verify the size alignment

Message ID 20220411073834.15210-1-Arunpravin.PaneerSelvam@amd.com (mailing list archive)
State New, archived
Headers show
Series [v3] drm: add a check to verify the size alignment | expand

Commit Message

Paneer Selvam, Arunpravin April 11, 2022, 7:38 a.m. UTC
Add a simple check to reject any size not aligned to the
min_page_size.

when size is not aligned to min_page_size, driver module
should handle in their own way either to round_up() the
size value to min_page_size or just to enable WARN_ON().

If we dont handle the alignment properly, we may hit the
following bug, Unigine Heaven has allocation requests for
example required pages are 257 and alignment request is 256.
To allocate the left over 1 page, continues the iteration to
find the order value which is 0 and when it compares with
min_order = 8, triggers the BUG_ON(order < min_order).

v2: add more commit description
v3: remove WARN_ON()

Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Suggested-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/drm_buddy.c | 3 +++
 1 file changed, 3 insertions(+)


base-commit: 4dcdb745569d8eef8db09e24e8ff2e5dffc0664c

Comments

Matthew Auld April 11, 2022, 9:47 a.m. UTC | #1
On 11/04/2022 08:38, Arunpravin Paneer Selvam wrote:
> Add a simple check to reject any size not aligned to the
> min_page_size.
> 
> when size is not aligned to min_page_size, driver module
> should handle in their own way either to round_up() the
> size value to min_page_size or just to enable WARN_ON().
> 
> If we dont handle the alignment properly, we may hit the
> following bug, Unigine Heaven has allocation requests for
> example required pages are 257 and alignment request is 256.
> To allocate the left over 1 page, continues the iteration to
> find the order value which is 0 and when it compares with
> min_order = 8, triggers the BUG_ON(order < min_order).
> 
> v2: add more commit description
> v3: remove WARN_ON()
> 
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Suggested-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Christian König April 11, 2022, 12:42 p.m. UTC | #2
Am 11.04.22 um 11:47 schrieb Matthew Auld:
> On 11/04/2022 08:38, Arunpravin Paneer Selvam wrote:
>> Add a simple check to reject any size not aligned to the
>> min_page_size.
>>
>> when size is not aligned to min_page_size, driver module
>> should handle in their own way either to round_up() the
>> size value to min_page_size or just to enable WARN_ON().
>>
>> If we dont handle the alignment properly, we may hit the
>> following bug, Unigine Heaven has allocation requests for
>> example required pages are 257 and alignment request is 256.
>> To allocate the left over 1 page, continues the iteration to
>> find the order value which is 0 and when it compares with
>> min_order = 8, triggers the BUG_ON(order < min_order).
>>
>> v2: add more commit description
>> v3: remove WARN_ON()
>>
>> Signed-off-by: Arunpravin Paneer Selvam 
>> <Arunpravin.PaneerSelvam@amd.com>
>> Suggested-by: Matthew Auld <matthew.auld@intel.com>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>

Question here is who will be pushing that to drm-misc-next? Should I 
take care of that?

I think it's time that Arun should request push permission for 
drm-misc-next.

Thanks,
Christian.
Matthew Auld April 11, 2022, 1:32 p.m. UTC | #3
On 11/04/2022 13:42, Christian König wrote:
> 
> Am 11.04.22 um 11:47 schrieb Matthew Auld:
>> On 11/04/2022 08:38, Arunpravin Paneer Selvam wrote:
>>> Add a simple check to reject any size not aligned to the
>>> min_page_size.
>>>
>>> when size is not aligned to min_page_size, driver module
>>> should handle in their own way either to round_up() the
>>> size value to min_page_size or just to enable WARN_ON().
>>>
>>> If we dont handle the alignment properly, we may hit the
>>> following bug, Unigine Heaven has allocation requests for
>>> example required pages are 257 and alignment request is 256.
>>> To allocate the left over 1 page, continues the iteration to
>>> find the order value which is 0 and when it compares with
>>> min_order = 8, triggers the BUG_ON(order < min_order).
>>>
>>> v2: add more commit description
>>> v3: remove WARN_ON()
>>>
>>> Signed-off-by: Arunpravin Paneer Selvam 
>>> <Arunpravin.PaneerSelvam@amd.com>
>>> Suggested-by: Matthew Auld <matthew.auld@intel.com>
>> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>>
> 
> Question here is who will be pushing that to drm-misc-next? Should I 
> take care of that?

Yes, please do.

> 
> I think it's time that Arun should request push permission for 
> drm-misc-next.
> 
> Thanks,
> Christian.
Christian König April 11, 2022, 1:44 p.m. UTC | #4
Am 11.04.22 um 15:49 schrieb Arunpravin Paneer Selvam:
>
> On 11/04/22 7:02 pm, Matthew Auld wrote:
>> On 11/04/2022 13:42, Christian König wrote:
>>> Am 11.04.22 um 11:47 schrieb Matthew Auld:
>>>> On 11/04/2022 08:38, Arunpravin Paneer Selvam wrote:
>>>>> Add a simple check to reject any size not aligned to the
>>>>> min_page_size.
>>>>>
>>>>> when size is not aligned to min_page_size, driver module
>>>>> should handle in their own way either to round_up() the
>>>>> size value to min_page_size or just to enable WARN_ON().
>>>>>
>>>>> If we dont handle the alignment properly, we may hit the
>>>>> following bug, Unigine Heaven has allocation requests for
>>>>> example required pages are 257 and alignment request is 256.
>>>>> To allocate the left over 1 page, continues the iteration to
>>>>> find the order value which is 0 and when it compares with
>>>>> min_order = 8, triggers the BUG_ON(order < min_order).
>>>>>
>>>>> v2: add more commit description
>>>>> v3: remove WARN_ON()
>>>>>
>>>>> Signed-off-by: Arunpravin Paneer Selvam
>>>>> <Arunpravin.PaneerSelvam@amd.com>
>>>>> Suggested-by: Matthew Auld <matthew.auld@intel.com>
>>>> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>>>>
>>> Question here is who will be pushing that to drm-misc-next? Should I
>>> take care of that?
>> Yes, please do.
>>
>>> I think it's time that Arun should request push permission for
>>> drm-misc-next.
> How to get push permission for drm-misc-next, should I send request mail
> to maintainers, may be next time I will push myself.

See here 
https://drm.pages.freedesktop.org/maintainer-tools/commit-access.html

Regards,
Christian.

>
> Thanks,
> Arun
>>> Thanks,
>>> Christian.
Paneer Selvam, Arunpravin April 11, 2022, 1:49 p.m. UTC | #5
On 11/04/22 7:02 pm, Matthew Auld wrote:
> On 11/04/2022 13:42, Christian König wrote:
>>
>> Am 11.04.22 um 11:47 schrieb Matthew Auld:
>>> On 11/04/2022 08:38, Arunpravin Paneer Selvam wrote:
>>>> Add a simple check to reject any size not aligned to the
>>>> min_page_size.
>>>>
>>>> when size is not aligned to min_page_size, driver module
>>>> should handle in their own way either to round_up() the
>>>> size value to min_page_size or just to enable WARN_ON().
>>>>
>>>> If we dont handle the alignment properly, we may hit the
>>>> following bug, Unigine Heaven has allocation requests for
>>>> example required pages are 257 and alignment request is 256.
>>>> To allocate the left over 1 page, continues the iteration to
>>>> find the order value which is 0 and when it compares with
>>>> min_order = 8, triggers the BUG_ON(order < min_order).
>>>>
>>>> v2: add more commit description
>>>> v3: remove WARN_ON()
>>>>
>>>> Signed-off-by: Arunpravin Paneer Selvam 
>>>> <Arunpravin.PaneerSelvam@amd.com>
>>>> Suggested-by: Matthew Auld <matthew.auld@intel.com>
>>> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>>>
>>
>> Question here is who will be pushing that to drm-misc-next? Should I 
>> take care of that?
> 
> Yes, please do.
> 
>>
>> I think it's time that Arun should request push permission for 
>> drm-misc-next.

How to get push permission for drm-misc-next, should I send request mail
to maintainers, may be next time I will push myself.

Thanks,
Arun
>>
>> Thanks,
>> Christian.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 72f52f293249..11bb59399471 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -665,6 +665,9 @@  int drm_buddy_alloc_blocks(struct drm_buddy *mm,
 	if (start + size == end)
 		return __drm_buddy_alloc_range(mm, start, size, blocks);
 
+	if (!IS_ALIGNED(size, min_page_size))
+		return -EINVAL;
+
 	pages = size >> ilog2(mm->chunk_size);
 	order = fls(pages) - 1;
 	min_order = ilog2(min_page_size) - ilog2(mm->chunk_size);