diff mbox series

[3/6] drm/buddy: check range allocation matches alignment

Message ID 20240215174431.285069-9-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show
Series [1/6] drm/tests/drm_buddy: fix 32b build | expand

Commit Message

Matthew Auld Feb. 15, 2024, 5:44 p.m. UTC
Likely not a big deal for real users, but for consistency we should
respect the min_page_size here. Main issue is that bias allocations
turns into normal range allocation if the range and size matches
exactly, and in the next patch we want to add some unit tests for this
part of the api.

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Cc: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/drm_buddy.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Paneer Selvam, Arunpravin Feb. 16, 2024, 11:25 a.m. UTC | #1
Its good to check the alignment

Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>



On 2/15/2024 11:14 PM, Matthew Auld wrote:
> Likely not a big deal for real users, but for consistency we should
> respect the min_page_size here. Main issue is that bias allocations
> turns into normal range allocation if the range and size matches
> exactly, and in the next patch we want to add some unit tests for this
> part of the api.
>
> Signed-off-by: Matthew Auld<matthew.auld@intel.com>
> Cc: Arunpravin Paneer Selvam<Arunpravin.PaneerSelvam@amd.com>
> Cc: Christian König<christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/drm_buddy.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
> index d09540d4065b..ee9913016626 100644
> --- a/drivers/gpu/drm/drm_buddy.c
> +++ b/drivers/gpu/drm/drm_buddy.c
> @@ -771,8 +771,12 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>   		return -EINVAL;
>   
>   	/* Actual range allocation */
> -	if (start + size == end)
> +	if (start + size == end) {
> +		if (!IS_ALIGNED(start | end, min_block_size))
> +			return -EINVAL;
> +
>   		return __drm_buddy_alloc_range(mm, start, size, NULL, blocks);
> +	}
>   
>   	original_size = size;
>   	original_min_size = min_block_size;
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index d09540d4065b..ee9913016626 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -771,8 +771,12 @@  int drm_buddy_alloc_blocks(struct drm_buddy *mm,
 		return -EINVAL;
 
 	/* Actual range allocation */
-	if (start + size == end)
+	if (start + size == end) {
+		if (!IS_ALIGNED(start | end, min_block_size))
+			return -EINVAL;
+
 		return __drm_buddy_alloc_range(mm, start, size, NULL, blocks);
+	}
 
 	original_size = size;
 	original_min_size = min_block_size;