Skip to contentSkip to conversation

mm/mmu_notifiers: use helper function mmu_notifier_synchronize()

PATCH In review Miaohe Lin 3 participants 5 messages Feb 17, 2022 – Feb 18, 2022

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm/mmu_notifiers: use helper function mmu_notifier_synchronize()

Use helper function mmu_notifier_synchronize() to ensure all mmu_notifiers are freed. Minor readability improvement.

---
 mm/mmu_notifier.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/mmu_notifier.c +6 -6
index 459d195d2ff6..159f70c20236 100644
@@ -334,15 +334,15 @@ static void mn_hlist_release(struct mmu_notifier_subscriptions *subscriptions,
 	srcu_read_unlock(&srcu, id);
 
 	/*
-	 * synchronize_srcu here prevents mmu_notifier_release from returning to
-	 * exit_mmap (which would proceed with freeing all pages in the mm)
-	 * until the ->release method returns, if it was invoked by
-	 * mmu_notifier_unregister.
+	 * mmu_notifier_synchronize here prevents mmu_notifier_release from
+	 * returning to exit_mmap (which would proceed with freeing all pages
+	 * in the mm) until the ->release method returns, if it was invoked
+	 * by mmu_notifier_unregister.
 	 *
 	 * The notifier_subscriptions can't go away from under us because
 	 * one mm_count is held by exit_mmap.
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();
 }
 
 void __mmu_notifier_release(struct mm_struct *mm)
@@ -851,7 +851,7 @@ void mmu_notifier_unregister(struct mmu_notifier *subscription,
 	 * Wait for any running method to finish, of course including
 	 * ->release if it was run by mmu_notifier_release instead of us.
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();
 
 	BUG_ON(atomic_read(&mm->mm_count) <= 0);
 
Signature · 1 line
2.23.0
#1 lore raw
Quoted 2 lines · Miaohe Lin

Use helper function mmu_notifier_synchronize() to ensure all mmu_notifiers are freed. Minor readability improvement.

Is it though?

Quoted 8 lines
mm/mmu_notifier.c +0 -4
@@ -334,15 +334,15 @@ static void mn_hlist_release(struct mmu_notifier_subscriptions *subscriptions,
 	srcu_read_unlock(&srcu, id);
 
 	/*
-	 * synchronize_srcu here prevents mmu_notifier_release from returning to
-	 * exit_mmap (which would proceed with freeing all pages in the mm)
-	 * until the ->release method returns, if it was invoked by
-	 * mmu_notifier_unregister.

mm/mmu_notifier.c static void mn_hlist_release(struct mmu_notifier_subscriptions *subscriptions, · line 345

Quoted 10 lines
mm/mmu_notifier.c +5 -1
+	 * mmu_notifier_synchronize here prevents mmu_notifier_release from
+	 * returning to exit_mmap (which would proceed with freeing all pages
+	 * in the mm) until the ->release method returns, if it was invoked
+	 * by mmu_notifier_unregister.
 	 *
 	 * The notifier_subscriptions can't go away from under us because
 	 * one mm_count is held by exit_mmap.
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();

We just read_unlocked the &srcu. Now I have to jump to the definition of mmu_notifier_synchronize() to find out that it's now waiting for the very same srcu. I think this abstraction makes the code harder to read, not easier.

mm/mmu_notifier.c void mmu_notifier_unregister(struct mmu_notifier *subscription, · line 854

Quoted 9 lines
mm/mmu_notifier.c +1 -1
 }
 
 void __mmu_notifier_release(struct mm_struct *mm)
@@ -851,7 +851,7 @@ void mmu_notifier_unregister(struct mmu_notifier *subscription,
 	 * Wait for any running method to finish, of course including
 	 * ->release if it was run by mmu_notifier_release instead of us.
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();

Same here.

author
#2 lore raw
Quoted 21 lines · Matthew Wilcox
Quoted 2 lines · Miaohe Lin

Use helper function mmu_notifier_synchronize() to ensure all mmu_notifiers are freed. Minor readability improvement.

Is it though?

Quoted 15 lines
mm/mmu_notifier.c +4 -4
@@ -334,15 +334,15 @@ static void mn_hlist_release(struct mmu_notifier_subscriptions *subscriptions,
 	srcu_read_unlock(&srcu, id);
 
 	/*
-	 * synchronize_srcu here prevents mmu_notifier_release from returning to
-	 * exit_mmap (which would proceed with freeing all pages in the mm)
-	 * until the ->release method returns, if it was invoked by
-	 * mmu_notifier_unregister.
+	 * mmu_notifier_synchronize here prevents mmu_notifier_release from
+	 * returning to exit_mmap (which would proceed with freeing all pages
+	 * in the mm) until the ->release method returns, if it was invoked
+	 * by mmu_notifier_unregister.
 	 *
 	 * The notifier_subscriptions can't go away from under us because
 	 * one mm_count is held by exit_mmap.
Quoted 9 lines

mm/mmu_notifier.c static void mn_hlist_release(struct mmu_notifier_subscriptions *subscriptions, · line 345

Quoted 3 lines
mm/mmu_notifier.c +1 -1
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();

We just read_unlocked the &srcu. Now I have to jump to the definition of mmu_notifier_synchronize() to find out that it's now waiting for the very same srcu. I think this abstraction makes the code harder to read, not easier.

From this point of view, this helper would disturb the understanding of the code. Many thanks for pointing this out. Sorry for my mindlessness.

Quoted 14 lines

mm/mmu_notifier.c void mmu_notifier_unregister(struct mmu_notifier *subscription, · line 854

Quoted 9 lines
mm/mmu_notifier.c +1 -1
 }
 
 void __mmu_notifier_release(struct mm_struct *mm)
@@ -851,7 +851,7 @@ void mmu_notifier_unregister(struct mmu_notifier *subscription,
 	 * Wait for any running method to finish, of course including
 	 * ->release if it was run by mmu_notifier_release instead of us.
 	 */
-	synchronize_srcu(&srcu);
+	mmu_notifier_synchronize();

Same here.

.

#3 lore raw
In reply to Miaohe Lin
Quoted 7 lines · Miaohe Lin

Use helper function mmu_notifier_synchronize() to ensure all mmu_notifiers are freed. Minor readability improvement.

---
 mm/mmu_notifier.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

I'm not keen on this, the internal synchronize_srcu's don't have the same usage model as described in the comment for mmu_notifier_synchronize(). Instead they are doing what their comments say.

Yes, it is the same code, but the purpose is different.

Jason

author
#4 lore raw
Quoted 9 lines · Jason Gunthorpe
Quoted 7 lines · Miaohe Lin

Use helper function mmu_notifier_synchronize() to ensure all mmu_notifiers are freed. Minor readability improvement.

---
 mm/mmu_notifier.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Quoted 7 lines

I'm not keen on this, the internal synchronize_srcu's don't have the same usage model as described in the comment for mmu_notifier_synchronize(). Instead they are doing what their comments say.

Yes, it is the same code, but the purpose is different.

Yep, this is my overlook. Many thanks for reply.

Quoted 3 lines

Jason
.