Skip to contentSkip to conversation

maple_tree: Remove rcu_read_lock() from mt_validate()

PATCH Applied Liam R. Howlett 2 participants 2 messages Aug 20, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 maple_tree: Remove rcu_read_lock() from mt_validate()

From: "Liam R. Howlett" <[email protected]>

The write lock should be held when validating the tree to avoid updates racing with checks. Holding the rcu read lock during a large tree validation may also cause a prolonged rcu read window.

Fixes 54a611b60590 ("Maple Tree: add new data structure")
Reported-by [email protected]
---
 lib/maple_tree.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/maple_tree.c +2 -5
index 755ba8b18e14..fe1b01b29201 100644
@@ -7588,14 +7588,14 @@ static void mt_validate_nulls(struct maple_tree *mt)
  * 2. The gap is correctly set in the parents
  */
 void mt_validate(struct maple_tree *mt)
+	__must_hold(mas->tree->ma_lock)
 {
 	unsigned char end;
 
 	MA_STATE(mas, mt, 0, 0);
-	rcu_read_lock();
 	mas_start(&mas);
 	if (!mas_is_active(&mas))
-		goto done;
+		return;
 
 	while (!mte_is_leaf(mas.node))
 		mas_descend(&mas);
@@ -7616,9 +7616,6 @@ void mt_validate(struct maple_tree *mt)
 		mas_dfs_postorder(&mas, ULONG_MAX);
 	}
 	mt_validate_nulls(mt);
-done:
-	rcu_read_unlock();
-
 }
 EXPORT_SYMBOL_GPL(mt_validate);
 
Signature · 1 line
2.43.0
#1 lore raw

On Wed, Aug 21, 2024 at 06:38:45AM +0800, Hillf Danton wrote:

Hillf, your email client is STILL broken. It's using the same message ID as the email it's replying to, which causes all kinds of problems. Please fix it or change to a different client.

Quoted 8 lines

On Tue, 20 Aug 2024 13:54:17 -0400 "Liam R. Howlett" <[email protected]>

Quoted 6 lines

The write lock should be held when validating the tree to avoid updates racing with checks. Holding the rcu read lock during a large tree validation may also cause a prolonged rcu read window.

From the rcu stall's view, holding spin lock plays the same role of rcu

read lock, so what are you fixing by simply dropping rcu read lock?

He's not holding a spinlock, he's holding a mutex, which has very different properties.