[Devel] [PATCH hci-8.2 4/4] ms/gpu/buddy: do not pass caller list to __alloc_contig_try_harder()
Mirian Shilakadze
mirian.shilakadze at virtuozzo.com
Wed Nov 18 14:38:13 MSK 2026
From: Matthew Auld <matthew.auld at 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 at 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 at amd.com>
Cc: Joel Fernandes <joelagnelf at nvidia.com>
Cc: <stable at vger.kernel.org>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam at amd.com>
Signed-off-by: Matthew Auld <matthew.auld at intel.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam at 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 at 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
More information about the Devel
mailing list