]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Alias rcu check to mas_slot() and mas_slot_protected
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 15 Sep 2020 16:13:12 +0000 (12:13 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:11:48 +0000 (15:11 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 045b47c10bb8801c460d72fd7b9445019adafa80..cbb813acdb699dc6678a5a409a1ebfc98364f52d 100644 (file)
@@ -540,7 +540,7 @@ static inline unsigned long _mas_safe_pivot(const struct ma_state *mas,
 }
 
 /*
- * mas_safe_pivot() - Return the pivot or the mas->max.
+ * mas_safe_pivot() - Return pivot, implied or otherwise.
  * @mas: The maple state.
  * @piv:  the pivot location.
  *
@@ -555,6 +555,10 @@ static inline unsigned long mas_safe_pivot(const struct ma_state *mas,
        return _mas_safe_pivot(mas, pivots, piv, type);
 }
 
+/*
+ * mas_safe_min() - Return the minimum for a given offset.
+ *
+ */
 static inline unsigned long mas_safe_min(struct ma_state *mas,
                                         unsigned long *pivots,
                                         unsigned char piv)
@@ -603,19 +607,28 @@ static inline void __rcu **ma_slots(struct maple_node *mn, enum maple_type mt)
        }
 }
 
-static inline void *ma_slot(struct ma_state *mas, void **slots,
-                           unsigned char offset)
+static inline void *mas_slot_protected(struct ma_state *mas, void **slots,
+                                      unsigned char offset)
+{
+       if (mt_in_rcu(mas->tree))
+               return rcu_dereference_protected(slots[offset],
+                                       lockdep_is_held(&mas->tree->ma_lock));
+       return slots[offset];
+}
+
+static inline void *mas_slot(struct ma_state *mas, void **slots,
+                            unsigned char offset)
 {
        if (mt_in_rcu(mas->tree))
                return rcu_dereference(slots[offset]);
-       else
-               return slots[offset];
+
+       return slots[offset];
 }
 
 static inline struct maple_enode *mas_get_slot(struct ma_state *mas,
                unsigned char offset)
 {
-       return ma_slot(mas, ma_slots(mas_mn(mas), mte_node_type(mas->node)),
+       return mas_slot(mas, ma_slots(mas_mn(mas), mte_node_type(mas->node)),
                       offset);
 }
 
@@ -1191,7 +1204,7 @@ static inline unsigned long mas_first_entry(struct ma_state *mas,
 
        while ((pivot < limit) && (offset < mt_slot_count(mas->node))) {
                pivot = mas_safe_pivot(mas, offset);
-               entry = rcu_dereference(slots[offset]);
+               entry = mas_slot(mas, slots, offset);
                if (entry) {
                        mas_set_offset(mas, offset);
                        return pivot;
@@ -1429,8 +1442,7 @@ static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start,
                gaps = ma_gaps(node, mt);
 
        for (i = mas_start, j = mab_start; i <= mas_end; i++, j++) {
-               b_node->slot[j] = rcu_dereference_protected(slots[i],
-                                       lockdep_is_held(&mas->tree->ma_lock));
+               b_node->slot[j] = mas_slot_protected(mas, slots, i);
 
                if (gaps)
                        b_node->gap[j] = gaps[i];
@@ -3160,7 +3172,7 @@ restart_prev_node:
        mas->max = mas_safe_pivot(mas, offset);
        while (level > 1) {
                level--;
-               mas->node = rcu_dereference(slots[offset]);
+               mas->node = mas_slot(mas, slots, offset);
                if (mas_dead_node(mas, start_piv))
                        goto restart_prev_node;
                mt = mte_node_type(mas->node);
@@ -3174,7 +3186,7 @@ restart_prev_node:
        mas->min = mas_safe_min(mas, ma_pivots(mas_mn(mas),
                                               mte_node_type(mas->node)),
                                offset);
-       mas->node = rcu_dereference(slots[offset]);
+       mas->node = mas_slot(mas, slots, offset);
        if (mas_dead_node(mas, start_piv))
                goto restart_prev_node;
        return;
@@ -3235,14 +3247,14 @@ restart_next_node:
        // Descend, if necessary.
        while (level > 1) {
                level--;
-               mas->node = rcu_dereference(slots[offset]);
+               mas->node = mas_slot(mas, slots, offset);
                mt = mte_node_type(mas->node);
                slots = ma_slots(mas_mn(mas), mt);
                offset = 0;
                pivot = mas_safe_pivot(mas, offset);
        }
 
-       mas->node = rcu_dereference(slots[offset]);
+       mas->node = mas_slot(mas, slots,offset);
        mas->min = prev_piv + 1;
        mas->max = pivot;
        return mas->max;
@@ -3314,7 +3326,7 @@ static inline bool mas_next_nentry(struct ma_state *mas, unsigned long max,
                if (r_start > mas->max)
                        goto no_entry;
 
-               entry = ma_slot(mas, slots, offset);
+               entry = mas_slot(mas, slots, offset);
                if (entry)
                        goto found;
 
@@ -3547,7 +3559,7 @@ bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
 
                if (!ma_is_leaf(type))
                        gap = gaps[offset];
-               else if (rcu_dereference(slots[offset]))
+               else if (mas_slot(mas, slots, offset))
                        continue; // no gap in leaf.
                else
                        gap = max - min + 1;
@@ -3573,7 +3585,7 @@ bool _mas_rev_awalk(struct ma_state *mas, unsigned long size)
        }
 
        //descend
-       mas->node = rcu_dereference(slots[offset]);
+       mas->node = mas_slot(mas, slots, offset);
        mas->min = min;
        mas->max = max;
        mas_set_offset(mas, mt_pivot_count(mas->node));