public inbox for intel-xe@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Matthew Auld <matthew.auld@intel.com>
To: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>,
	Sanjay Yadav <sanjay.kumar.yadav@intel.com>,
	dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org, stable@vger.kernel.org,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH v2 1/2] drm/buddy: Prevent BUG_ON by validating rounded allocation
Date: Wed, 21 Jan 2026 10:00:11 +0000	[thread overview]
Message-ID: <8673cd9b-7140-4209-9d44-bbf3508cc266@intel.com> (raw)
In-Reply-To: <0b5fa253-1c2d-45ae-a6bd-0373e27af64c@amd.com>

On 21/01/2026 06:36, Arunpravin Paneer Selvam wrote:
> 
> On 20/01/26 16:11, Matthew Auld wrote:
>> On 08/01/2026 11:32, Sanjay Yadav wrote:
>>> When DRM_BUDDY_CONTIGUOUS_ALLOCATION is set, the requested size is
>>> rounded up to the next power-of-two via roundup_pow_of_two().
>>> Similarly, for non-contiguous allocations with large min_block_size,
>>> the size is aligned up via round_up(). Both operations can produce a
>>> rounded size that exceeds mm->size, which later triggers
>>> BUG_ON(order > mm->max_order).
>>>
>>> Example scenarios:
>>> - 9G CONTIGUOUS allocation on 10G VRAM memory:
>>>    roundup_pow_of_two(9G) = 16G > 10G
>>> - 9G allocation with 8G min_block_size on 10G VRAM memory:
>>>    round_up(9G, 8G) = 16G > 10G
>>>
>>> Fix this by checking the rounded size against mm->size. For
>>> non-contiguous or range allocations where size > mm->size is invalid,
>>> return -EINVAL immediately. For contiguous allocations without range
>>> restrictions, allow the request to fall through to the existing
>>> __alloc_contig_try_harder() fallback.
>>>
>>> This ensures invalid user input returns an error or uses the fallback
>>> path instead of hitting BUG_ON.
>>>
>>> v2: (Matt A)
>>> - Add Fixes, Cc stable, and Closes tags for context
>>>
>>> Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/6712
>>> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
>>> Cc: <stable@vger.kernel.org> # v6.7+
>>> Cc: Christian König <christian.koenig@amd.com>
>>> Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
>>> Suggested-by: Matthew Auld <matthew.auld@intel.com>
>>> Signed-off-by: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
>>> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
>>> Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
>>
>> Arun/Christian, when you get a chance could you also merge these two 
>> please?
> 
> I have merged these 2 patches as well.

Thanks.

> 
> Regards,
> 
> Arun.
> 
>>
>>> ---
>>>   drivers/gpu/drm/drm_buddy.c | 9 +++++++++
>>>   1 file changed, 9 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 2f279b46bd2c..5141348fc6c9 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>> @@ -1155,6 +1155,15 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>       order = fls(pages) - 1;
>>>       min_order = ilog2(min_block_size) - ilog2(mm->chunk_size);
>>>   +    if (order > mm->max_order || size > mm->size) {
>>> +        if ((flags & DRM_BUDDY_CONTIGUOUS_ALLOCATION) &&
>>> +            !(flags & DRM_BUDDY_RANGE_ALLOCATION))
>>> +            return __alloc_contig_try_harder(mm, original_size,
>>> +                             original_min_size, blocks);
>>> +
>>> +        return -EINVAL;
>>> +    }
>>> +
>>>       do {
>>>           order = min(order, (unsigned int)fls(pages) - 1);
>>>           BUG_ON(order > mm->max_order);
>>


  reply	other threads:[~2026-01-21 10:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 11:32 [PATCH v2 0/2] drm/buddy: Fix BUG_ON from oversized rounded allocations Sanjay Yadav
2026-01-08 11:32 ` [PATCH v2 1/2] drm/buddy: Prevent BUG_ON by validating rounded allocation Sanjay Yadav
2026-01-20 10:41   ` Matthew Auld
2026-01-21  6:36     ` Arunpravin Paneer Selvam
2026-01-21 10:00       ` Matthew Auld [this message]
2026-01-08 11:32 ` [PATCH v2 2/2] drm/tests/drm_buddy: Add tests for allocations exceeding max_order Sanjay Yadav
2026-01-08 11:46 ` ✓ CI.KUnit: success for drm/buddy: Fix BUG_ON from oversized rounded allocations (rev2) Patchwork
2026-01-08 12:01 ` ✗ CI.checksparse: warning " Patchwork
2026-01-08 12:24 ` ✓ Xe.CI.BAT: success " Patchwork
2026-01-08 15:36 ` ✗ Xe.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8673cd9b-7140-4209-9d44-bbf3508cc266@intel.com \
    --to=matthew.auld@intel.com \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sanjay.kumar.yadav@intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox