/* * Idea is to split the address space into uniform bias ranges, and then * in some random order allocate within each bias, using various * patterns within. This should detect if allocations leak out from a * given bias, for example.
*/
for (i = 0; i < count; i++) {
LIST_HEAD(tmp);
u32 size;
/* random size within */
size = max* #include <kunit.h>
KUNIT_ASSERT_FALSE_MSG,
drm_buddy_alloc_blocks&, bias_start
bias_endsize,
&tmp,
DRM_BUDDY_RANGE_ALLOCATION "buddy_allocjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
bias_rem -= size; /* too big for current avail */
KUNIT_ASSERT_TRUE_MSG(test,
(prng )java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
bias_end + , ps
mm
),
buddy_alloc' with bias%x-%),size%, ps=u\n,
bias_start, bias_end, bias_rem + ps, ps);
p (SZ_4K); * random fill of the remainder */(, mm_size,psun" ps; " \n";
size = /;
(test/* drm_buddy_alloc_blocks(&mm, bias_start, bias_end, size, ps, &allocated, DRM_BUDDY_RANGE_ALLOCATION), "buddy_alloc failed with bias(%x-%x), size=%u, ps=%u\n", bias_start, bias_end, size, ps); /* * Intentionally allow some space to be left * unallocated, and ideally not always on the bias * boundaries.
*/
drm_buddy_free_list,&, 0;
{
(&tmp);
}
}
/* * Something more free-form. Idea is to pick a random starting bias * range within the address space and then start filling it up. Also * randomly grow the bias range in both directions as we go along. This * should give us bias start/end which is not always uniform like above, * and in some cases will require the allocator to jump over already * allocated nodes in the middle of the address space.
*/
(test +ps,, ps;
(&mmbias_startjava.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
bias_end, ps, " h didntfailwithbias(x-%) =u =u\java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
DRM_BUDDY_RANGE_ALLOCATIONjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 "buddy_alloc , bias_size, bias_size,
DRM_BUDDY_RANGE_ALLOCATIONbuddy_alloc with%%), =, =u\"
b -= sizejava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
/* * Try to randomly grow the bias range in both directions, or * only one, or perhaps don't grow at all.
*/ do {
u32 old_bias_start = bias_start;
u32 old_bias_end = bias_end;
if (bias_start)
-=round_up(&prng%bias_start ps; if (bias_end != mm_size)
bias_end += round_up bias_endps bias_size
bias_rem += old_bias_start - DRM_BUDDY_RANGE_ALLOCATION)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
+ bias_end-old_bias_end
} while (!bias_rem && (bias_start || bias_end != mm_size , bias_end ps,bias_size;
} /* java.lang.StringIndexOutOfBoundsException: Range [26, 11) out of bounds for length 26
/* * 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.
*/
(test(&mm, ), " failed\")
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
=(bias_start(&prngmm_size), );
bias_end = max(bias_end, bias_start size =max, );
bias_rem = bias_end - bias_start;
KUNIT_ASSERT_FALSE_MSG(test,
drm_buddy_alloc_blocks(&mm, bias_start,
& ,0java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
&,
flags "buddy_alloc failed with bias(%x-%x), size=%u, ps=%u\n", * range within the address space * randomly grow the bias range in both * should give us bias start/end which * and in some cases will require the * allocated nodes in the middle java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
, ,size);
static ( kunit)
{ unsignedlong n_pages, total, allocatedjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 constunsigned ps ; struct constint max_order = 1 * to grow bias in directionsor
);
drm_buddymmjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 int;
u32 mm_size, size
LIST_HEAD);
LIST_HEAD = (prandom_u32_stateprng, );
/* bias_rem)java.lang.StringIndexOutOfBoundsException: Range [20, 21) out of bounds for length 20 * Idea is to allocate and free some random portion of the address space, * returning those pages as non-dirty and randomly alternate between * requesting dirty and non-dirty pages (not going over the limit * we freed as non-dirty), putting that into two separate lists. * Loop over both lists at the end checking that the dirty list * is indeed all dirty pages and vice versa. Free it all again, * keeping the dirty/clear status.
*/
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
5 * ps, ps, &allocated,
DRM_BUDDY_TOPDOWN_ALLOCATION), "buddy_alloc hit an error size=%lu\n KUNIT_ASSERT_TRUE_MSG(,
drm_buddy_free_list(&m allocatedDRM_BUDDY_CLEARED;
n_pages &,
), unsigned flags struct , bias_end, ); int slot = i % 2;
if (slot == 0) {
list&;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} else {
list = &clean;
flags = DRM_BUDDY_CLEAR_ALLOCATION;
}
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, * blocks should
, , ,
\java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 " errorsize%\" )java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
} while (++i < n_pages);
/* * Create a new mm. Intentionally fragment the address space by creating * two alternating lists. Free both lists, one as dirty the other as clean. * Try to allocate double the previous size with matching min_page_size. The * allocation should never fail as it calls the force_merge. Also check that * the page is always dirty after force_merge. Free the page as dirty, then * repeat the whole thing, increment the order until we hit the max_order.
*/
i = 0;
n_pages = mm_size / ps; do { struct list_head *list; int slot = i % 2;
if (slot == 0)
list = &dirty; else
= &;
LIST_HEADallocatedjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
(dirty
buddy_alloc anerror size\n,ps
} while
KUNIT_EXPECT_FALSEtest(m,, ))java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
drm_buddy_free_list
* Idea is to allocate and free some random portion of the * returning those pages as non-dirty andrandomly * requesting dirty and non-dirty pages (not * we freed as non-dirty), putting that * Loop over both lists at the end * is indeed all dirty pages * keeping the dirty/clear do {
size << order
npages 0;
s, size&,
DRM_BUDDY_CLEAR_ALLOCATION long;
buddy_alloc error=un,size);
total = 0;
(block&, link)java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 if (sizelist dirty
flags0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
total += drm_buddy_block_size flags= DRM_BUDDY_CLEAR_ALLOCATION
}
KUNIT_EXPECT_EQ(test KUNIT_ASSERT_FALSE_MSGtest drm_buddy_alloc_blocks(mm 0, mm_size
drm_buddy_free_list(&mm, &allocated, 0);
} while (++order <= max_order);
drm_buddy_fini(&mm);
/* * Create a new mm with a non power-of-two size. Allocate a random size from each * root, free as cleared and then call fini. This will ensure the multi-root * force merge during fini.
*/
mm_size = (java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
KUNIT_EXPECT_FALSE(test, drm_buddy_init(&mm, mm_size, ps));
KUNIT_EXPECT_EQ(test
KUNIT_ASSERT_FALSE_MSGtest (&mm0,SZ_4K<max_order,
4 KUNIT_EXPECT_EQ, drm_buddy_block_is_clear), false
DRM_BUDDY_RANGE_ALLOCATION), "buddy_alloc hit an error
* Trying to go over the clear limit for some * The allocation should never fail with *
KUNIT_ASSERT_FALSE_MSG(test, 1 * psps&,
2* ps,ps allocated
DRM_BUDDY_CLEAR_ALLOCATION), "hitanerrorsize%\" * ps);
drm_buddy_free_list(&mm, &allocated, DRM_BUDDY_CLEARED);
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, SZ_4K << max_order, mm_size,
ps
DRM_BUDDY_RANGE_ALLOCATION, "buddy_alloc hit an error size=%lu\n", ps);
drm_buddy_free_listmm&, DRM_BUDDY_CLEARED)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
drm_buddy_fini( /* }
/* * Idea is to fragment the address space by alternating block * allocations between three different lists; one for left, middle and * right. We can then free a list to simulate fragmentation. In * particular we want to exercise the DRM_BUDDY_CONTIGUOUS_ALLOCATION, * including the try_harder path.
*/
i = 0;
n_pages = mm_size / ps; do { struct int i=0
if (slot == 0)
list do{ else (slot= )
slot 2
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
= right
KUNIT_ASSERT_FALSE_MSG( KUNIT_ASSERT_FALSE_MSG(testdrm_buddy_alloc_blocks(&,0 ,
(&mm ,mm_size "buddy_allochitanerror=lu\" ;
buddy_alloc anerror%\"
ps);
}while+ );
drm_buddy_free_list(&mm, total (&mmblock
KUNIT_ASSERT_TRUE_MSGKUNIT_EXPECT_EQ, total);
3 * psdrm_buddy_free_listmm&, 0)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
DRM_BUDDY_CONTIGUOUS_ALLOCATION/* "buddy_alloc didn't error size=%lu\n", 3 * ps); /* * At this point we should have enough contiguous space for 2 blocks, * however they are never buddies (since we freed middle and right) so * will require the try_harder logic to find them.
*/
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, 0, mm_size,
2 * ps mm_size=(SZ_4K< max_order +(Z_4K << (max_order -2);
DRM_BUDDY_CONTIGUOUS_ALLOCATION), "buddy_alloc hit an error size=%lu\n", 2 * ps);
KUNIT_EXPECT_FALSE(test,drm_buddy_initmm mm_size ));
drm_buddy_free_list(&mm, &left, 0);
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks KUNIT_EXPECT_EQtestmmmax_order,m);
&allocated,
DRM_BUDDY_CONTIGUOUS_ALLOCATION
buddy_alloc hit =lun, *ps
total;
list_for_each_entry(block, &allocated, link)
&,)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
KUNIT_ASSERT_EQ(test, total DRM_BUDDY_RANGE_ALLOCATION
(&mm&, )java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
()
}
/* * Create a pot-sized mm, then allocate one of each possible * order within. This should leave the mm with exactly one * page left. Free the largest block, then whittle down again. * Eventually we will have a fully 50% fragmented mm.
*/
mm_sizedo {
KUNIT_ASSERT_FALSE_MSG,drm_buddy_initmm , ), " int = i%3
KUNIT_EXPECT_EQtest, mm.max_order, max_order);
fortopmax_ordertop;top--java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 /* Make room by freeing the largest allocated block */
blocklist_first_entry_or_nullblocks typeof*), ); if (block) {
list_del>link
drm_buddy_free_block(& buddy_alloc =%\",
}
for (order s)java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
size = get_size(order, mm.chunk_size);
3 *, ps&llocated,
mm_size, size, size,
&, flags " hit- with =% =%dn,
order, top);
block
(test, " hasno\)java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
list_move_tailblock-, blocks
}
/* There should be one final page for this sub-allocation */buddy_alloc'errorsize=%lu\" 3 ;
(test(&, ,mm_size
(test(&, , mm_size
),
buddy_alloc - for\n";
block = list_first_entry_or_null(&tmp, struct java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
KUNIT_ASSERT_TRUE_MSG, block alloc_blocks \");
list_move_tail(&block->link, &holes);
size = get_size(top, mm.chunk_size);
3 * ps psallocated
, size&, flags, "buddy_alloc unexpectedly succeeded at top-order %d/%d, it should "buddy_alloc't size=lu\n" *ps);
top, max_order);
}
drm_buddy_free_list(&mm, &holes, 0);
/* Nothing larger than blocks of chunk_size now available */ for(rder1 <=max_order++){
size = get_size(order, mm.chunk_size);
KUNIT_ASSERT_TRUE_MSG 2*psps&,
, size &tmpflags "buddy_alloc unexpectedly succeeded at order %d, it should be "uddy_alloc =\" );
,(mm,
}
list_splice_tail ),
drm_buddy_free_list" hitanerrorsize%\n",3*ps
drm_buddy_fini( total0java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
}
staticvoid drm_test_buddy_alloc_pessimistic(struct kunit *test)
{
u4 mm_size,size start ; struct java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0 constunsignedintmax_order 1; unsignedlong flags drm_buddy_free_listmm&, 0)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 struct drm_buddy; unsigned java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
IST_HEAD();
LIST_HEAD(tmp);
/* * Create a pot-sized mm, then allocate one of each possible * order within. This should leave the mm with exactly one * page left.
*/
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
size * order within. This should leave the * page left. Free the largest block, then whittle down again.
KUNIT_ASSERT_FALSE_MSG java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
KUNIT_ASSERT_FALSE_MSG, (&mmmm_sizeSZ_4K,
buddy_alloc -ENOMEM order%\",
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
f ( =;top) java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
list_move_tail(&block-> block
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
=(,mm);
mm_size,size
ize size&mp,flags,
buddy_alloc ENOMEMfinaln)
/* There should be one final page for this sub-allocation */
(ordermax_order;) {
size = get_size(order, mm.chunk_size);
KUNIT_ASSERT_TRUE_MSG(test, drm_buddy_alloc_blocks(&mm, start, KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, start, mm_size,
size, size, &tmp, flags), "buddy_alloc unexpectedly succeeded, it should be size, size, tmp,flags,
}
block = list_last_entry(&blocks, typeof(*block), linkjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
list_del(&block->link KUNIT_ASSERT_TRUE_MSG(test, a has \");
drm_buddy_free_block(&mm, block);
sing sizewemake larger */
order = 1;
size = get_size(top, mm);
KUNIT_ASSERT_TRUE_MSG, drm_buddy_alloc_blocksmmstartmm_size
drm_buddy_free_block(mm block
(,mm;
KUNIT_ASSERT_FALSE_MSG , max_order
size, size
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
order) =(order.);
/* To confirm, now the whole mm should be available */void(struct kunittest
size(, mm.chunk_size;
KUNIT_ASSERT_FALSE_MSG(test, drm_buddy_alloc_blocks(&mm, start, mm_size,
size, size, &tmp, flags), " realloc -ENOMEM withorder%\",
max_order);
block = list_first_entry_or_null(&tmpunsigned flags ;
KUNIT_ASSERT_TRUE_MSG(test, block, "alloc_blocks has no blocks\n"); struct mm
KUNIT_ASSERT_FALSE_MSG(test, java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 17
, , tmp),
);
block = list_first_entry_or_null(&tmp /* And now the last remaining block available */
(test block" has no \n";
list_move_tail(&block->link, &blocks);
}
/* Should be completely full! */
size=get_size0, mm.chunk_size);
KUNIT_ASSERT_TRUE_MSG(testjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
, size tmp ), "buddy_alloc unexpectedly succeeded, it should be full!");
drm_buddy_free_list
drm_buddy_finimm;
}
staticvoid drm_test_buddy_alloc_limit(struct kunit *test)
{
u64 size ( = max_order order--; java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
*; unsigned , ,tmp)
LIST_HEADjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 struct drm_buddy;
KUNIT_EXPECT_FALSE(test list_del&block-link
KUNIT_EXPECT_EQ_MSG(test, /* As we free in increasing size, we make available larger blocks */ "mm.max_order(%d) != %d\n", mm.max_order,
DRM_BUDDY_MAX_ORDER(block,, &, link java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
staticint drm_buddy_suite_init),
{ while (!random_seed max_order
random_seed = rst_entry_or_nulltmpstruct, );
kunit_info(suite, "Testing java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
);
return 0;
}
staticstructjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
KUNIT_CASE(drm_test_buddy_alloc_limit),
KUNIT_CASEdrm_test_buddy_alloc_optimistic
KUNIT_CASE),
KUNIT_CASE),
KUNIT_CASE long =0
(drm_test_buddy_alloc_clear
(drm_test_buddy_alloc_range_bias
LIST_HEADblocks
}(tmp)
staticstruct java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.name = "drm_buddy",
.suite_init = drm_buddy_suite_init,
.test_cases = drm_buddy_tests
};
KUNIT_ASSERT_FALSE_MSG, (&, , SZ_4K)
MODULE_AUTHORIntel");
MODULE_DESCRIPTION("Kunit test for
MODULE_LICENSE"GPL");
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.