]> www.infradead.org Git - users/willy/linux.git/commitdiff
maple tree: Add mt_locked()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 19 Oct 2021 18:38:26 +0000 (14:38 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 19 Oct 2021 18:38:26 +0000 (14:38 -0400)
This predicate asks whether the maple tree is locked.  For externally
locked trees, we always return true as we don't know what locking they
might have.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
lib/maple_tree.c

index da3d4488821add6ff16a663dce7206ded3f2bff7..d104f2a34458a46916eb39ecc1bf6162df54c598 100644 (file)
@@ -747,11 +747,16 @@ static inline void __rcu **ma_slots(struct maple_node *mn, enum maple_type mt)
        }
 }
 
+static inline bool mt_locked(const struct maple_tree *mt)
+{
+       return ((mt->ma_flags & MT_FLAGS_LOCK_MASK) == MT_FLAGS_LOCK_EXTERN) ||
+               lockdep_is_held(&mt->ma_lock);
+}
+
 static inline void *mt_slot(const struct maple_tree *mt,
                void __rcu **slots, unsigned char offset)
 {
-       return rcu_dereference_check(slots[offset],
-                       lockdep_is_held(&mt->ma_lock));
+       return rcu_dereference_check(slots[offset], mt_locked(mt));
 }
 
 /*
@@ -765,8 +770,7 @@ static inline void *mt_slot(const struct maple_tree *mt,
 static inline void *mas_slot_locked(struct ma_state *mas, void __rcu **slots,
                                       unsigned char offset)
 {
-       return rcu_dereference_protected(slots[offset],
-                       lockdep_is_held(&mas->tree->ma_lock));
+       return rcu_dereference_protected(slots[offset], mt_locked(mas->tree));
 }
 
 /*
@@ -805,14 +809,12 @@ static inline struct maple_enode *mas_get_slot(struct ma_state *mas,
  */
 static inline void *mas_root(struct ma_state *mas)
 {
-       return rcu_dereference_check(mas->tree->ma_root,
-                       lockdep_is_held(&mas->tree->ma_lock));
+       return rcu_dereference_check(mas->tree->ma_root, mt_locked(mas->tree));
 }
 
 static inline void *mt_root_locked(const struct maple_tree *mt)
 {
-       return rcu_dereference_protected(mt->ma_root,
-                       lockdep_is_held(&mt->ma_lock));
+       return rcu_dereference_protected(mt->ma_root, mt_locked(mt));
 }
 
 /*
@@ -6511,8 +6513,7 @@ void mt_dump_node(const struct maple_tree *mt, void *entry, unsigned long min,
 
 void mt_dump(const struct maple_tree *mt)
 {
-       void *entry = rcu_dereference_check(mt->ma_root,
-                       lockdep_is_held(&mt->ma_lock));
+       void *entry = rcu_dereference_check(mt->ma_root, mt_locked(mt));
 
        pr_info("maple_tree("MA_PTR") flags %X, height %u root "MA_PTR"\n",
                 mt, mt->ma_flags, mt_height(mt), entry);