Skip to content

Commit

Permalink
test_maple_tree: test exhausted upper limit of mtree_alloc_cyclic()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
howlett authored and akpm00 committed Jan 26, 2025
1 parent e2c9e61 commit b02fcc0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/test_maple_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3738,6 +3738,34 @@ static noinline void __init alloc_cyclic_testing(struct maple_tree *mt)
}

mtree_destroy(mt);

/*
* Issue with reverse search was discovered
* https://lore.kernel.org/all/[email protected]/
* Exhausting the allocation area and forcing the search to wrap needs a
* mas_reset() in mas_alloc_cyclic().
*/
next = 0;
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
for (int i = 0; i < 1023; i++) {
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
MT_BUG_ON(mt, i != location - 2);
MT_BUG_ON(mt, i != next - 3);
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
}
mtree_erase(mt, 123);
MT_BUG_ON(mt, mtree_load(mt, 123) != NULL);
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
MT_BUG_ON(mt, 123 != location);
MT_BUG_ON(mt, 124 != next);
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
mtree_erase(mt, 100);
mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
MT_BUG_ON(mt, 100 != location);
MT_BUG_ON(mt, 101 != next);
MT_BUG_ON(mt, mtree_load(mt, location) != mt);
mtree_destroy(mt);

/* Overflow test */
next = ULONG_MAX - 1;
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
Expand Down

0 comments on commit b02fcc0

Please sign in to comment.