From 89338ffb4e173b2ab787c5f9e985ad2743897b5c Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Tue, 15 Sep 2020 12:13:12 -0400 Subject: [PATCH] maple_tree: Alias rcu check to mas_slot() and mas_slot_protected Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 045b47c10bb8..cbb813acdb69 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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)); -- 2.50.1