[PATCH v2 24/35] mm: write lock mmu_notifier_lock when registering mmu notifiers

From: Michel Lespinasse
Date: Fri Jan 28 2022 - 08:20:52 EST


Change mm_take_all_locks to also take the mmu_notifier_lock.
Note that mm_take_all_locks is called from mmu_notifier_register() only.

Signed-off-by: Michel Lespinasse <michel@xxxxxxxxxxxxxx>
---
mm/mmap.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index b09a2c875507..a67c3600d995 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3592,6 +3592,10 @@ int mm_take_all_locks(struct mm_struct *mm)

mutex_lock(&mm_all_locks_mutex);

+#if defined(CONFIG_MMU_NOTIFIER) && defined(CONFIG_SPECULATIVE_PAGE_FAULT)
+ percpu_down_write(mm->mmu_notifier_lock);
+#endif
+
for (vma = mm->mmap; vma; vma = vma->vm_next) {
if (signal_pending(current))
goto out_unlock;
@@ -3679,6 +3683,10 @@ void mm_drop_all_locks(struct mm_struct *mm)
vm_unlock_mapping(vma->vm_file->f_mapping);
}

+#if defined(CONFIG_MMU_NOTIFIER) && defined(CONFIG_SPECULATIVE_PAGE_FAULT)
+ percpu_up_write(mm->mmu_notifier_lock);
+#endif
+
mutex_unlock(&mm_all_locks_mutex);
}

--
2.20.1