]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: add test case to model vma expansion
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Thu, 25 Jan 2024 01:50:44 +0000 (17:50 -0800)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Sat, 20 Apr 2024 01:40:09 +0000 (21:40 -0400)
During testing, despite userspace tests passing, a vm was unable to
boot after a crash when expanding a shrinking a vma. Simulate this
operation as a userspace test case to expand test coverage.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
tools/testing/radix-tree/maple.c

index 194da3341a25689a9f9ee4dcf1be5f7e36b695c7..c834e91e68107ff31816d263c58d5ddb0c512cfa 100644 (file)
@@ -36224,6 +36224,37 @@ static noinline void __init check_mtree_dup(struct maple_tree *mt)
 
 extern void test_kmem_cache_bulk(void);
 
+
+ /* test to simulate expanding a vma from [0x7fffffffe000, 0x7ffffffff000)
+  * to [0x7ffde4ca1000, 0x7ffffffff000) and then shrinking the vma to
+  * [0x7ffde4ca1000, 0x7ffde4ca2000)
+  */
+static inline int check_vma_modification(struct maple_tree *mt)
+{
+       MA_STATE(mas, mt, 0, 0);
+
+       /* vma with old start and old end */
+       __mas_set_range(&mas, 0x7fffffffe000, 0x7ffffffff000 - 1);
+       mas_preallocate(&mas, xa_mk_value(1), GFP_KERNEL);
+       mas_store_prealloc(&mas, xa_mk_value(1));
+
+       /* next write occurs partly in previous range [0, 0x7fffffffe000)*/
+       mas_prev_range(&mas, 0);
+       /* expand vma to {0x7ffde4ca1000, 0x7ffffffff000) */
+       __mas_set_range(&mas, 0x7ffde4ca1000, 0x7ffffffff000 - 1);
+       mas_preallocate(&mas, xa_mk_value(1), GFP_KERNEL);
+       mas_store_prealloc(&mas, xa_mk_value(1));
+
+       /* shrink vma to [0x7ffde4ca1000, 7ffde4ca2000) */
+       __mas_set_range(&mas, 0x7ffde4ca2000, 0x7ffffffff000 - 1);
+       mas_preallocate(&mas, NULL, GFP_KERNEL);
+       mas_store_prealloc(&mas, NULL);
+       mt_dump(mt, mt_dump_hex);
+
+       return 0;
+}
+
+
 void farmer_tests(void)
 {
        struct maple_node *node;
@@ -36231,6 +36262,10 @@ void farmer_tests(void)
 
        mt_dump(&tree, mt_dump_dec);
 
+       mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | MT_FLAGS_USE_RCU);
+       check_vma_modification(&tree);
+       mtree_destroy(&tree);
+
        tree.ma_root = xa_mk_value(0);
        mt_dump(&tree, mt_dump_dec);