drm urgent for 6.10-rc1 merge:
buddy: - fix breakage in buddy allocator. -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEEKbZHaGwW9KfbeusDHTzWXnEhr4FAmZFdOcACgkQDHTzWXnE hr7/yRAAqQDyP2dE0bD2/jxXX6WKp2TNCxX58zL2pyJDqBX9tND/EzSVU8nmvLBo UL7AfJjPL9KLXctrUV2/3QseXxobAFdfq45PsYCI82nuscS3ZY3rRd3k5+A+a2w4 3ANrl0lf/zZ0rVeXuxAbbDooLe5F8uIo4b6rYjaRH0dT+py2PfXSHsR1I0P+mXkt Xw9dso4UkPeXJ1Wbl98jTxgV0wvNlFRpvO6wukJITLr6U51FLZ5XAYu5AYcTDlNl +M2s14KlZq6WpCoz0rrUDOhU0LozA+wL7flClJQqcKGmoNtEC8o96GykdobkAfzU dYg8dwFlWcmYAJjzRW+9hAvwJW5KoGBXO2lVYOV3FQV7WJQSXmtnPEnmhhVC02MZ sQ7S2fw8nOLhwdmPYVtzhEb2OTRM0QLF/ahQTvZNQ5uRBTTCGpZU0+gVzsw90LP+ fg/wTmUAFFZDvAqAD1RJUHwSTVquEOTgsXifasH/xkxBFQyUdy79/E6Z5k6q2n5n sPqEhiwGqf0pfUhuVBl87ES8bu4QvbLUdT2dn4zn6m56zNgXArXF44Ddqi1mcbRQ eL5v5GVDSUyalPhL0cGnC8LPDfE2XqYxWY26aSVPguTWyUrTRsBoWGw9o5+8y7cW bxc6D3SBv42p6RLDRR7HtdNyn6fL19aVrG2WMXX0FNaL/lQathE= =w/fd -----END PGP SIGNATURE----- Merge tag 'drm-next-2024-05-16' of https://gitlab.freedesktop.org/drm/kernel Pull drm fix from Dave Airlie: - fix breakage in buddy allocator * tag 'drm-next-2024-05-16' of https://gitlab.freedesktop.org/drm/kernel: drm/tests: Add a unit test for range bias allocation drm/buddy: Fix the range bias clear memory allocation issue
This commit is contained in:
commit
972a2543e3
@ -249,6 +249,7 @@ int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size)
|
||||
|
||||
mm->size = size;
|
||||
mm->avail = size;
|
||||
mm->clear_avail = 0;
|
||||
mm->chunk_size = chunk_size;
|
||||
mm->max_order = ilog2(size) - ilog2(chunk_size);
|
||||
|
||||
@ -574,7 +575,7 @@ __drm_buddy_alloc_range_bias(struct drm_buddy *mm,
|
||||
|
||||
block = __alloc_range_bias(mm, start, end, order,
|
||||
flags, fallback);
|
||||
if (IS_ERR(block) && mm->clear_avail)
|
||||
if (IS_ERR(block))
|
||||
return __alloc_range_bias(mm, start, end, order,
|
||||
flags, !fallback);
|
||||
|
||||
|
@ -23,9 +23,11 @@ static inline u64 get_size(int order, u64 chunk_size)
|
||||
|
||||
static void drm_test_buddy_alloc_range_bias(struct kunit *test)
|
||||
{
|
||||
u32 mm_size, ps, bias_size, bias_start, bias_end, bias_rem;
|
||||
u32 mm_size, size, ps, bias_size, bias_start, bias_end, bias_rem;
|
||||
DRM_RND_STATE(prng, random_seed);
|
||||
unsigned int i, count, *order;
|
||||
struct drm_buddy_block *block;
|
||||
unsigned long flags;
|
||||
struct drm_buddy mm;
|
||||
LIST_HEAD(allocated);
|
||||
|
||||
@ -222,6 +224,38 @@ static void drm_test_buddy_alloc_range_bias(struct kunit *test)
|
||||
|
||||
drm_buddy_free_list(&mm, &allocated, 0);
|
||||
drm_buddy_fini(&mm);
|
||||
|
||||
/*
|
||||
* Allocate cleared blocks in the bias range when the DRM buddy's clear avail is
|
||||
* zero. This will validate the bias range allocation in scenarios like system boot
|
||||
* when no cleared blocks are available and exercise the fallback path too. The resulting
|
||||
* blocks should always be dirty.
|
||||
*/
|
||||
|
||||
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_init(&mm, mm_size, ps),
|
||||
"buddy_init failed\n");
|
||||
|
||||
bias_start = round_up(prandom_u32_state(&prng) % (mm_size - ps), ps);
|
||||
bias_end = round_up(bias_start + prandom_u32_state(&prng) % (mm_size - bias_start), ps);
|
||||
bias_end = max(bias_end, bias_start + ps);
|
||||
bias_rem = bias_end - bias_start;
|
||||
|
||||
flags = DRM_BUDDY_CLEAR_ALLOCATION | DRM_BUDDY_RANGE_ALLOCATION;
|
||||
size = max(round_up(prandom_u32_state(&prng) % bias_rem, ps), ps);
|
||||
|
||||
KUNIT_ASSERT_FALSE_MSG(test,
|
||||
drm_buddy_alloc_blocks(&mm, bias_start,
|
||||
bias_end, size, ps,
|
||||
&allocated,
|
||||
flags),
|
||||
"buddy_alloc failed with bias(%x-%x), size=%u, ps=%u\n",
|
||||
bias_start, bias_end, size, ps);
|
||||
|
||||
list_for_each_entry(block, &allocated, link)
|
||||
KUNIT_EXPECT_EQ(test, drm_buddy_block_is_clear(block), false);
|
||||
|
||||
drm_buddy_free_list(&mm, &allocated, 0);
|
||||
drm_buddy_fini(&mm);
|
||||
}
|
||||
|
||||
static void drm_test_buddy_alloc_clear(struct kunit *test)
|
||||
|
Loading…
Reference in New Issue
Block a user