* [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes
@ 2026-11-18 11:38 Mirian Shilakadze
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation Mirian Shilakadze
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:38 UTC (permalink / raw)
To: khorenko; +Cc: devel
Item 1 from the review of VSTOR-154850 v1. Upstream fixes for the buddy
allocator code that came with the RHEL import:
1. 5488a29596cd: a rounded up allocation larger than the memory size
hits BUG_ON(order > mm->max_order).
2. 0251963afd22: a failed split_block() leaves a freed block in the free
tree (use-after-free).
3. 56bc6384314f: the contiguous fallback can return a start that ignores
min_block_size.
4. fb26cf4f1df4: when the contiguous fallback fails or retries, it
frees the whole list the caller passed in, including blocks the
caller allocated before. Not in the ticket and not in mainline yet
(linux-next, Cc stable). Taken because it fixes the same fallback as
3 and the drm_buddy suite catches it: without 4, alloc_contiguous
fails on the check that 4 adds.
Patches 2 to 4 are adapted to the drm_buddy names. 264.x already has 1
from RHEL, and 2 to 4 apply to it as is.
Tested with KUnit on the 211.75.1.26.2 debug kernel (KASAN, failslab),
stock and patched drm_buddy.ko built from this tree:
- drm_buddy suite with the test from 4: stock and 1-3 fail only
alloc_contiguous, on the check that 4 adds. 1-4 pass.
- dc0e3aa54eaa, the mainline test for 1: stock hits the BUG_ON, patched
passes.
- try_harder alignment (own test): stock returns 12K at 8K for a 16K
min_block_size, patched returns -ENOSPC.
- split_block() failing in alloc_from_freetree(), __alloc_range() and
__alloc_range_bias() via failslab (own test): stock gives KASAN
slab-use-after-free and then the BUG_ON in alloc_from_freetree(),
patched passes at every injection point.
- ve selftests: the same with stock and patched drm_buddy.ko
(ve_ns_owner_test and ve_vtty_stress fail on both).
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Arunpravin Paneer Selvam (1):
ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
Francois Dugast (1):
ms/gpu/buddy: Fix use-after-free in split_block() call sites
Matthew Auld (1):
ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder()
Sanjay Yadav (1):
ms/drm/buddy: Prevent BUG_ON by validating rounded allocation
drivers/gpu/drm/drm_buddy.c | 107 ++++++++++++++++++-------
drivers/gpu/drm/tests/drm_buddy_test.c | 9 +++
2 files changed, 89 insertions(+), 27 deletions(-)
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
@ 2026-11-18 11:38 ` Mirian Shilakadze
2026-11-18 11:43 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites Mirian Shilakadze
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:38 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
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>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patch.msgid.link/20260108113227.2101872-5-sanjay.kumar.yadav@intel.com
(cherry picked from commit 5488a29596cdba93a60a79398dc9b69d5bdadf92)
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
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 3f1a9892f2a3..640d93070bb7 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);
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation Mirian Shilakadze
@ 2026-11-18 11:38 ` Mirian Shilakadze
2026-11-18 11:43 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured Mirian Shilakadze
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:38 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Francois Dugast <francois.dugast@intel.com>
When split_block() fails it returns before calling mark_split(), leaving
the block in the FREE state and still linked in the rbtree. The four
err_undo paths then call __gpu_buddy_free() without first removing the
block from the tree, which leads to two distinct bugs:
- If the buddy is also free, __gpu_buddy_free() merges the two siblings
by calling gpu_block_free(mm, block) while block->rb is still linked
in the tree. Any subsequent rbtree traversal will follow the now-
dangling pointer, causing a use-after-free.
- In alloc_from_freetree(), where there is no buddy guard,
__gpu_buddy_free() always reaches mark_free() -> rbtree_insert() with
block still in the tree, corrupting the rbtree.
The same pattern is already used correctly in __force_merge(): call
rbtree_remove() to unlink the block before handing it to
__gpu_buddy_free(). Apply the same fix to all four err_undo sites.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://lore.kernel.org/r/20260522092600.32818-2-francois.dugast@intel.com
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
(cherry picked from commit 0251963afd22d1365d07bf81135ef0c694f6c3b5)
Context adjusted: the allocator is drivers/gpu/drm/drm_buddy.c with drm_
names here, and only three of the four err_undo sites exist (there is
no offset aligned allocation function).
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
drivers/gpu/drm/drm_buddy.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 640d93070bb7..87c65923259f 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -684,8 +684,10 @@ __alloc_range_bias(struct drm_buddy *mm,
buddy = __get_buddy(block);
if (buddy &&
(drm_buddy_block_is_free(block) &&
- drm_buddy_block_is_free(buddy)))
+ drm_buddy_block_is_free(buddy))) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
return ERR_PTR(err);
}
@@ -794,8 +796,10 @@ alloc_from_freetree(struct drm_buddy *mm,
return block;
err_undo:
- if (tmp != order)
+ if (tmp != order) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
return ERR_PTR(err);
}
@@ -880,8 +884,10 @@ static int __alloc_range(struct drm_buddy *mm,
buddy = __get_buddy(block);
if (buddy &&
(drm_buddy_block_is_free(block) &&
- drm_buddy_block_is_free(buddy)))
+ drm_buddy_block_is_free(buddy))) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
err_free:
if (err == -ENOSPC && total_allocated_on_err) {
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation Mirian Shilakadze
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites Mirian Shilakadze
@ 2026-11-18 11:38 ` Mirian Shilakadze
2026-11-18 11:47 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder() Mirian Shilakadze
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:38 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
The try_harder contiguous fallback could return a range whose start
offset did not match the caller's min_block_size. When a candidate's
start is misaligned, realign it: free the misaligned run and reallocate
exactly @size at the next lower min_block_size boundary. This keeps the
returned size unchanged with no surplus to trim, and rejects the request
only when no aligned candidate fits.
v2: align misaligned candidates down to min_block_size instead of
bailing out, for both the RHS and LHS paths (Matthew).
Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
Suggested-by: Christian König <christian.koenig@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Timur Kristóf <timur.kristof@gmail.com>
Cc: stable@vger.kernel.org
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Tested-by: John Olender <john.olender@gmail.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patch.msgid.link/20260709131050.1022759-1-Arunpravin.PaneerSelvam@amd.com
(cherry picked from commit 56bc6384314fb9ae98975fb2af8b143097ede3dc)
Context adjusted: drivers/gpu/drm/drm_buddy.c with drm_ names.
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
drivers/gpu/drm/drm_buddy.c | 63 ++++++++++++++++++++++++++-----------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 87c65923259f..78e20814c218 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -916,22 +916,30 @@ static int __drm_buddy_alloc_range(struct drm_buddy *mm,
blocks, total_allocated_on_err);
}
+static int __alloc_contig_aligned_retry(struct drm_buddy *mm,
+ u64 unaligned_offset,
+ u64 size,
+ u64 min_block_size,
+ struct list_head *blocks)
+{
+ u64 aligned_offset = round_down(unaligned_offset, min_block_size);
+
+ return __drm_buddy_alloc_range(mm, aligned_offset, size, NULL, blocks);
+}
+
static int __alloc_contig_try_harder(struct drm_buddy *mm,
u64 size,
u64 min_block_size,
struct list_head *blocks)
{
- u64 rhs_offset, lhs_offset, lhs_size, filled;
+ u64 rhs_offset, lhs_offset, filled;
struct drm_buddy_block *block;
unsigned int tree, order;
- LIST_HEAD(blocks_lhs);
- unsigned long pages;
u64 modify_size;
int err;
modify_size = rounddown_pow_of_two(size);
- pages = modify_size >> ilog2(mm->chunk_size);
- order = fls(pages) - 1;
+ order = ilog2(modify_size) - ilog2(mm->chunk_size);
if (order == 0)
return -ENOSPC;
@@ -947,31 +955,48 @@ static int __alloc_contig_try_harder(struct drm_buddy *mm,
while (iter) {
block = rbtree_get_free_block(iter);
- /* Allocate blocks traversing RHS */
rhs_offset = drm_buddy_block_offset(block);
+
+ /* Allocate blocks traversing RHS */
err = __drm_buddy_alloc_range(mm, rhs_offset, size,
&filled, blocks);
- if (!err || err != -ENOSPC)
+ if (err && err != -ENOSPC)
return err;
+ if (!err && IS_ALIGNED(rhs_offset, min_block_size))
+ return 0;
+ if (!err) {
+ /* Allocate the unaligned RHS offset using round_down */
+ drm_buddy_free_list_internal(mm, blocks);
+ err = __alloc_contig_aligned_retry(mm, rhs_offset,
+ size,
+ min_block_size,
+ blocks);
+ if (!err)
+ return 0;
+ if (err != -ENOSPC) {
+ drm_buddy_free_list_internal(mm, blocks);
+ return err;
+ }
+ goto next;
+ }
- lhs_size = max((size - filled), min_block_size);
- if (!IS_ALIGNED(lhs_size, min_block_size))
- lhs_size = round_up(lhs_size, min_block_size);
+ if (size - filled > rhs_offset)
+ goto next;
- /* Allocate blocks traversing LHS */
- lhs_offset = drm_buddy_block_offset(block) - lhs_size;
- err = __drm_buddy_alloc_range(mm, lhs_offset, lhs_size,
- NULL, &blocks_lhs);
- if (!err) {
- list_splice(&blocks_lhs, blocks);
+ lhs_offset = rhs_offset - (size - filled);
+
+ /* Allocate the unaligned LHS offset using round_down */
+ drm_buddy_free_list_internal(mm, blocks);
+ err = __alloc_contig_aligned_retry(mm, lhs_offset, size,
+ min_block_size, blocks);
+ if (!err)
return 0;
- } else if (err != -ENOSPC) {
+ if (err != -ENOSPC) {
drm_buddy_free_list_internal(mm, blocks);
return err;
}
- /* Free blocks for the next iteration */
+next:
drm_buddy_free_list_internal(mm, blocks);
-
iter = rb_prev(iter);
}
}
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder()
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
` (2 preceding siblings ...)
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured Mirian Shilakadze
@ 2026-11-18 11:38 ` Mirian Shilakadze
2026-11-18 11:45 ` no-reply
2026-11-18 15:37 ` [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Konstantin Khorenko
2026-11-18 15:37 ` Konstantin Khorenko
5 siblings, 1 reply; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-18 11:38 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Matthew Auld <matthew.auld@intel.com>
If the caller passes a non-empty blocks list, __alloc_contig_try_harder()
unconditionally frees it on failure or during retry.
Pass the local allocated list instead and only splice it onto the caller's
list upon success.
Assisted-by: LLM
Reported-by: Shashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-fa721daf-7333-48b5-a26b-624c7f5791d7
Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Cc: Joel Fernandes <joelagnelf@nvidia.com>
Cc: <stable@vger.kernel.org>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patch.msgid.link/20261006110706.1636971-2-matthew.auld@intel.com
(cherry picked from commit fb26cf4f1df40a462ea65552a3fbcc8cfafab523)
Not in mainline yet, taken from linux-next.
Context adjusted: drm_ names and paths, __alloc_contig_try_harder()
takes no flags here, and the second call site returned its result
directly, so it now does the same as the first one. Upstream's goto
err_free on -ENOSPC is not needed there: the local list is always empty
at that point.
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
drivers/gpu/drm/drm_buddy.c | 29 +++++++++++++++++++-------
drivers/gpu/drm/tests/drm_buddy_test.c | 9 ++++++++
2 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 78e20814c218..901599526fec 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -1188,9 +1188,16 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
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);
+ !(flags & DRM_BUDDY_RANGE_ALLOCATION)) {
+ err = __alloc_contig_try_harder(mm, original_size,
+ original_min_size,
+ &allocated);
+ if (err)
+ return err;
+
+ list_splice_tail(&allocated, blocks);
+ return 0;
+ }
return -EINVAL;
}
@@ -1227,11 +1234,17 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
* try harder method.
*/
if (flags & DRM_BUDDY_CONTIGUOUS_ALLOCATION &&
- !(flags & DRM_BUDDY_RANGE_ALLOCATION))
- return __alloc_contig_try_harder(mm,
- original_size,
- original_min_size,
- blocks);
+ !(flags & DRM_BUDDY_RANGE_ALLOCATION)) {
+ err = __alloc_contig_try_harder(mm,
+ original_size,
+ original_min_size,
+ &allocated);
+ if (err)
+ return err;
+
+ list_splice_tail(&allocated, blocks);
+ return 0;
+ }
err = -ENOSPC;
goto err_free;
}
diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
index 7a0e523651f0..ec0f6892ac1b 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -480,6 +480,15 @@ static void drm_test_buddy_alloc_contiguous(struct kunit *test)
DRM_BUDDY_CONTIGUOUS_ALLOCATION),
"buddy_alloc hit an error size=%lu\n", 2 * ps);
+ /*
+ * A failed contiguous allocation with a non-empty blocks list
+ * must NOT corrupt or free pre-existing blocks.
+ */
+ KUNIT_EXPECT_TRUE(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
+ 3 * ps, ps, &allocated,
+ DRM_BUDDY_CONTIGUOUS_ALLOCATION));
+ KUNIT_EXPECT_FALSE(test, list_empty(&allocated));
+
drm_buddy_free_list(&mm, &left, 0);
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
3 * ps, ps, &allocated,
--
2.47.3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation Mirian Shilakadze
@ 2026-11-18 11:43 ` no-reply
0 siblings, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-18 11:43 UTC (permalink / raw)
To: Mirian Shilakadze, khorenko; +Cc: devel
> From: Sanjay Yadav <sanjay.kumar.yadav@intel.com>
>
> 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
>
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155318
> Feature: fix ms/drm
>
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118113935.381228-1-mirian.shilakadze@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites Mirian Shilakadze
@ 2026-11-18 11:43 ` no-reply
0 siblings, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-18 11:43 UTC (permalink / raw)
To: Mirian Shilakadze, khorenko; +Cc: devel
> From: Francois Dugast <francois.dugast@intel.com>
>
> When split_block() fails it returns before calling mark_split(), leaving
> the block in the FREE state and still linked in the rbtree. The four
> err_undo paths then call __gpu_buddy_free() without first removing the
> block from the tree, which leads to two distinct bugs:
>
> - If the buddy is also free, __gpu_buddy_free() merges the two siblings
> by calling gpu_block_free(mm, block) while block->rb is still linked
> in the tree. Any subsequent rbtree traversal will follow the now-
> dangling pointer, causing a use-after-free.
>
> - In alloc_from_freetree(), where there is no buddy guard,
> __gpu_buddy_free() always reaches mark_free() -> rbtree_insert() with
> block still in the tree, corrupting the rbtree.
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155318
> Feature: fix ms/drm
>
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118113935.381228-1-mirian.shilakadze@virtuozzo.com?part=2
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder()
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder() Mirian Shilakadze
@ 2026-11-18 11:45 ` no-reply
0 siblings, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-18 11:45 UTC (permalink / raw)
To: Mirian Shilakadze, khorenko; +Cc: devel
> From: Matthew Auld <matthew.auld@intel.com>
>
> If the caller passes a non-empty blocks list, __alloc_contig_try_harder()
> unconditionally frees it on failure or during retry.
>
> Pass the local allocated list instead and only splice it onto the caller's
> list upon success.
>
> Assisted-by: LLM
> Reported-by: Shashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-fa721daf-7333-48b5-a26b-624c7f5791d7
> Fixes: 0a1844bf0b53 ("drm/buddy: Improve contiguous memory allocation")
> Cc: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
> Cc: Joel Fernandes <joelagnelf@nvidia.com>
> Cc: <stable@vger.kernel.org>
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155318
> Feature: fix ms/drm
>
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118113935.381228-1-mirian.shilakadze@virtuozzo.com?part=4
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured Mirian Shilakadze
@ 2026-11-18 11:47 ` no-reply
0 siblings, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-18 11:47 UTC (permalink / raw)
To: Mirian Shilakadze, khorenko; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/buddy: subject and changelog do not match realign-and-retry
in try_harder
--
commit ac045c7116949555587c6ac992862d6b75574a02
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
This commit changes __alloc_contig_try_harder() so that a candidate range
whose start is not aligned to min_block_size is freed and reallocated at
the rounded-down offset. The request fails with -ENOSPC only when no
aligned candidate fits.
Link: https://patch.msgid.link/20260709131050.1022759-1-Arunpravin.PaneerSelvam@amd.com
> ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
[Severity: Low]
This isn't a bug, but does the subject match what the patch does? The
code no longer bails out on misalignment. It frees the misaligned run
and reallocates exactly size at round_down(offset, min_block_size). The
v2 changelog line ("align misaligned candidates down to min_block_size
instead of bailing out") contradicts the subject, so the subject looks
stale.
The message also leaves out the rewrite of the LHS path. The old code
allocated only the missing remainder below the RHS run and spliced it
onto the RHS blocks. The new code frees the partial RHS run and
reallocates the full size at the aligned LHS offset. It also adds a
"size - filled > rhs_offset" guard and computes order as
ilog2(modify_size) - ilog2(mm->chunk_size) instead of fls(pages) - 1.
Could the subject and body describe these changes, so reviewers and
stable backporters know what is being changed?
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261118113935.381228-1-mirian.shilakadze@virtuozzo.com?part=3
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
` (3 preceding siblings ...)
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder() Mirian Shilakadze
@ 2026-11-18 15:37 ` Konstantin Khorenko
2026-11-18 15:37 ` Konstantin Khorenko
5 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 15:37 UTC (permalink / raw)
To: Mirian Shilakadze; +Cc: devel
Applying with these fixes on my side:
- 4/4 adaptation note: both call sites returned the result of
__alloc_contig_try_harder() directly, not only the second one, and
upstream's goto err_free came with 1ad5e807f716 ("gpu/buddy: replace
dual-tree/force_merge with decoupled dirty tracker"), which is not in
this tree
On Wed, 18 Nov 2026 15:38:09 +0400, Mirian Shilakadze wrote:
> 4. fb26cf4f1df4: when the contiguous fallback fails or retries, it
> frees the whole list the caller passed in, including blocks the
> caller allocated before. Not in the ticket and not in mainline yet
> (linux-next, Cc stable). Taken because it fixes the same fallback as
> 3 and the drm_buddy suite catches it: without 4, alloc_contiguous
> fails on the check that 4 adds.
Fine to take, but the suite catches it only through the check 4 adds
itself, and no driver here passes a non-empty list with
DRM_BUDDY_CONTIGUOUS_ALLOCATION. It hardens the API; at the next RHEL
rebase check that it reached mainline under the same id.
Thanks.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
` (4 preceding siblings ...)
2026-11-18 15:37 ` [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Konstantin Khorenko
@ 2026-11-18 15:37 ` Konstantin Khorenko
5 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-18 15:37 UTC (permalink / raw)
To: Mirian Shilakadze; +Cc: devel
On Wed, 18 Nov 2026 15:38:09 +0400, Mirian Shilakadze wrote:
> drm/buddy: backport buddy allocator fixes
>
> Item 1 from the review of VSTOR-154850 v1. Upstream fixes for the buddy
> allocator code that came with the RHEL import:
>
> 1. 5488a29596cd: a rounded up allocation larger than the memory size
> hits BUG_ON(order > mm->max_order).
> 2. 0251963afd22: a failed split_block() leaves a freed block in the free
> tree (use-after-free).
> 3. 56bc6384314f: the contiguous fallback can return a start that ignores
> min_block_size.
> 4. fb26cf4f1df4: when the contiguous fallback fails or retries, it
> frees the whole list the caller passed in, including blocks the
> caller allocated before. Not in the ticket and not in mainline yet
> (linux-next, Cc stable). Taken because it fixes the same fallback as
> 3 and the drm_buddy suite catches it: without 4, alloc_contiguous
> fails on the check that 4 adds.
>
> [...]
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.3.vz10, thanks!
[1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/4b873b5a7f3e
[2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/704a31674110
[3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/f7ca97237c53
[4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/9ea6fbb9f78f
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-18 15:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 11:38 [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Mirian Shilakadze
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 1/4] ms/drm/buddy: Prevent BUG_ON by validating rounded allocation Mirian Shilakadze
2026-11-18 11:43 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites Mirian Shilakadze
2026-11-18 11:43 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 3/4] ms/gpu/buddy: bail out of try_harder when alignment cannot be honoured Mirian Shilakadze
2026-11-18 11:47 ` no-reply
2026-11-18 11:38 ` [Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder() Mirian Shilakadze
2026-11-18 11:45 ` no-reply
2026-11-18 15:37 ` [Devel] [PATCH hci-8.2 0/4] drm/buddy: backport buddy allocator fixes Konstantin Khorenko
2026-11-18 15:37 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox