Skip to content

Commit b02fcc0

Browse files
howlettakpm00
authored andcommitted
test_maple_tree: test exhausted upper limit of mtree_alloc_cyclic()
When the upper bound of the search is exhausted, the maple state may be returned in an error state of -EBUSY. This means maple state needs to be reset before the second search in mas_alloc_cylic() to ensure the search happens. This test ensures the issue is not recreated. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Liam R. Howlett <[email protected]> Reviewed-by: Yang Erkun <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Chuck Lever <[email protected]> says: Signed-off-by: Andrew Morton <[email protected]>
1 parent e2c9e61 commit b02fcc0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/test_maple_tree.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,6 +3738,34 @@ static noinline void __init alloc_cyclic_testing(struct maple_tree *mt)
37383738
}
37393739

37403740
mtree_destroy(mt);
3741+
3742+
/*
3743+
* Issue with reverse search was discovered
3744+
* https://lore.kernel.org/all/[email protected]/
3745+
* Exhausting the allocation area and forcing the search to wrap needs a
3746+
* mas_reset() in mas_alloc_cyclic().
3747+
*/
3748+
next = 0;
3749+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
3750+
for (int i = 0; i < 1023; i++) {
3751+
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
3752+
MT_BUG_ON(mt, i != location - 2);
3753+
MT_BUG_ON(mt, i != next - 3);
3754+
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
3755+
}
3756+
mtree_erase(mt, 123);
3757+
MT_BUG_ON(mt, mtree_load(mt, 123) != NULL);
3758+
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
3759+
MT_BUG_ON(mt, 123 != location);
3760+
MT_BUG_ON(mt, 124 != next);
3761+
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
3762+
mtree_erase(mt, 100);
3763+
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
3764+
MT_BUG_ON(mt, 100 != location);
3765+
MT_BUG_ON(mt, 101 != next);
3766+
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
3767+
mtree_destroy(mt);
3768+
37413769
/* Overflow test */
37423770
next = ULONG_MAX - 1;
37433771
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);

0 commit comments

Comments
 (0)