]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Drop mas.last setting in mt_find and add tests.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 5 Dec 2019 04:46:21 +0000 (23:46 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:28:16 +0000 (12:28 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c
lib/test_maple_tree.c

index 60e529b5b249e258230976521a6a85994a9472b0..ab799b36e629e3e63df15aa21687aa85cf9cd1e0 100644 (file)
@@ -2050,12 +2050,12 @@ static inline int _mas_add(struct ma_state *mas, void *entry, bool overwrite,
                                ret--;
                }
                if (slot > 0) {
-               slot_val = mte_get_rcu_slot(mas->node, slot - 1);
-               if (mt_is_empty(slot_val)) {
-                       slot--;
-                       if (ret)
-                               ret--;
-               }
+                       slot_val = mte_get_rcu_slot(mas->node, slot - 1);
+                       if (mt_is_empty(slot_val)) {
+                               slot--;
+                               if (ret)
+                                       ret--;
+                       }
                }
        }
        /* Check for splitting */
@@ -3788,7 +3788,6 @@ void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max,
                entry = NULL;
 
        while (mas_search_cont(&mas, range_start, max, entry)) {
-               mas.last = range_start;
                entry = _mas_next(&mas, max, &range_start);
                if (mt_is_empty(entry) || xa_is_zero(entry))
                        entry = NULL;
index a02415647e442d825d6636a223767b6f66967e52..172ab8f760068ddc1d5c6144527479b232b298e5 100644 (file)
@@ -831,35 +831,18 @@ static noinline void check_erase_testset(struct maple_tree *mt)
 
 #define erase_check_store_range(mt, a, i, ptr) mtree_test_store_range(mt, a[i],\
                                         a[i + 1], ptr)
-static noinline void check_erase2_testset(struct maple_tree *mt)
-{
 #define STORE 1
 #define ERASE 2
-       unsigned long set[] = {
-STORE, 140737488347136, 140737488351231,
-STORE, 140721266458624, 140737488351231,
-ERASE, 140721266458624, 140737488351231,
-STORE, 140721266458624, 140721266462719,
-STORE, 94735788949504, 94735789121535,
-ERASE, 94735788949504, 94735789121535,
-STORE, 94735788949504, 94735788965887,
-STORE, 94735788965888, 94735789121535,
-ERASE, 94735788965888, 94735789121535,
-STORE, 94735788965888, 94735789068287,
-STORE, 94735789068288, 94735789109247,
-STORE, 94735789109248, 94735789121535,
-STORE, 140253902692352, 140253902864383,
-ERASE, 140253902692352, 140253902864383,
-STORE, 140253902692352, 140253902696447,
-STORE, 140253902696448, 140253902864383,
-       };
+static noinline void check_erase2_testset(struct maple_tree *mt,
+               unsigned long *set, unsigned long size)
+{
        int entry_cnt = 0;
        int check = 0;
        void *foo;
        unsigned long addr = 0;
 
        mt_dump(mt);
-       for (int i = 0; i < ARRAY_SIZE(set); i+=3){
+       for (int i = 0; i < size; i+=3){
                switch(set[i]) {
                        case STORE:
                                if (!mtree_test_insert_range(mt, set[i + 1],
@@ -877,11 +860,70 @@ STORE, 140253902696448, 140253902864383,
        }
 
        mt_for_each(mt, foo, addr, ULONG_MAX) {
+               printk("addr %lu -> %p\n", addr, foo);
                check++;
        }
 
+       printk("test %d != %d\n", check, entry_cnt);
        MT_BUG_ON(mt, check != entry_cnt);
 }
+
+
+// These tests were pulled from kvm tests.
+static noinline void check_erase2_sets(struct maple_tree *mt)
+{
+       unsigned long start = 0;
+       unsigned long set[] = {
+STORE, 140737488347136, 140737488351231,
+STORE, 140721266458624, 140737488351231,
+ERASE, 140721266458624, 140737488351231,
+STORE, 140721266458624, 140721266462719,
+STORE, 94735788949504, 94735789121535,
+ERASE, 94735788949504, 94735789121535,
+STORE, 94735788949504, 94735788965887,
+STORE, 94735788965888, 94735789121535,
+ERASE, 94735788965888, 94735789121535,
+STORE, 94735788965888, 94735789068287,
+STORE, 94735789068288, 94735789109247,
+STORE, 94735789109248, 94735789121535,
+STORE, 140253902692352, 140253902864383,
+ERASE, 140253902692352, 140253902864383,
+STORE, 140253902692352, 140253902696447,
+STORE, 140253902696448, 140253902864383,
+               };
+       unsigned long set2[] = {
+STORE, 140737488347136, 140737488351232,
+STORE, 140735933583360, 140737488351232,
+ERASE, 140735933583360, 140737488351232,
+STORE, 140735933583360, 140735933587456,
+STORE, 94811003260928, 94811003432960,
+ERASE, 94811003260928, 94811003432960,
+STORE, 94811003260928, 94811003277312,
+STORE, 94811003277312, 94811003432960,
+ERASE, 94811003277312, 94811003432960,
+STORE, 94811003277312, 94811003379712,
+STORE, 94811003379712, 94811003420672,
+STORE, 94811003420672, 94811003432960,
+STORE, 140277094653952, 140277094825984,
+ERASE, 140277094653952, 140277094825984,
+STORE, 140277094653952, 140277094658048,
+STORE, 140277094658048, 140277094825984,
+ERASE, 140277094658048, 140277094825984,
+STORE, 140277094658048, 140277094780928,
+STORE, 140277094780928, 140277094813696,
+STORE, 140277094813696, 140277094821888,
+STORE, 140277094821888, 140277094825984,
+STORE, 140735933906944, 140735933911040,
+       };
+       check_erase2_testset(mt, set, ARRAY_SIZE(set));
+       mtree_destroy(mt);
+       mtree_init(mt, 0);
+       check_erase2_testset(mt, set2, ARRAY_SIZE(set2));
+       start = 140735933894656;
+       printk("mt_find check %lu-%lu\n", start, 140735933906943UL);
+       MT_BUG_ON(mt, mt_find(mt, &start, 140735933906943UL, true));
+
+}
 static noinline void check_alloc_rev_range(struct maple_tree *mt)
 {
        /* Generated by:
@@ -1315,7 +1357,7 @@ static int maple_tree_seed(void)
        check_erase_testset(&tree);
        mtree_destroy(&tree);
        mtree_init(&tree, 0);
-       check_erase2_testset(&tree);
+       check_erase2_sets(&tree);
        mtree_destroy(&tree);
 
        mtree_init(&tree, 0);