]> www.infradead.org Git - users/willy/linux.git/commitdiff
maple-tree: Handle external locking in mt_set_in_rcu()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 20 Oct 2021 19:21:17 +0000 (15:21 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 20 Oct 2021 19:21:17 +0000 (15:21 -0400)
If the tree is marked as externally locked, we must not take the
ma_lock.  Instead, assert that the external lock is held.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
include/linux/maple_tree.h

index 91765810e5928fe042c21c8e0ee04854a223fdee..f94a8796d758f78cb1729a1ba108ff6a4c2d8781 100644 (file)
@@ -468,9 +468,14 @@ static inline void mt_clear_in_rcu(struct maple_tree *mt)
        if (!mt_in_rcu(mt))
                return;
 
-       mtree_lock(mt);
-       mt->ma_flags &= ~MT_FLAGS_USE_RCU;
-       mtree_unlock(mt);
+       if (mt_external_lock(mt)) {
+               BUG_ON(!lock_is_held(mt->ma_external_lock));
+               mt->ma_flags &= ~MT_FLAGS_USE_RCU;
+       } else {
+               mtree_lock(mt);
+               mt->ma_flags &= ~MT_FLAGS_USE_RCU;
+               mtree_unlock(mt);
+       }
 }
 
 /**
@@ -481,9 +486,14 @@ static inline void mt_set_in_rcu(struct maple_tree *mt)
        if (mt_in_rcu(mt))
                return;
 
-       mtree_lock(mt);
-       mt->ma_flags |= MT_FLAGS_USE_RCU;
-       mtree_unlock(mt);
+       if (mt_external_lock(mt)) {
+               BUG_ON(!lock_is_held(mt->ma_external_lock));
+               mt->ma_flags |= MT_FLAGS_USE_RCU;
+       } else {
+               mtree_lock(mt);
+               mt->ma_flags |= MT_FLAGS_USE_RCU;
+               mtree_unlock(mt);
+       }
 }
 
 void *mt_find(struct maple_tree *mt, unsigned long *index, unsigned long max);