Skip to contentSkip to conversation

mm: use mmap_assert_write_locked() instead of open coding it

PATCH Rolf Eike Beer 3 participants 4 messages Mar 28, 2022 – Apr 1, 2022

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

In case the lock is actually not held at this point this also avoids a stale lock reference if built with NDEBUG.

---
 mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/mmap.c +2 -2
index 3aa839f81e63..d62598dc2fdd 100644
@@ -3561,7 +3561,7 @@ int mm_take_all_locks(struct mm_struct *mm)
 	struct vm_area_struct *vma;
 	struct anon_vma_chain *avc;
 
-	BUG_ON(mmap_read_trylock(mm));
+	mmap_assert_write_locked(mm);
 
 	mutex_lock(&mm_all_locks_mutex);
 
@@ -3641,7 +3641,7 @@ void mm_drop_all_locks(struct mm_struct *mm)
 	struct vm_area_struct *vma;
 	struct anon_vma_chain *avc;
 
-	BUG_ON(mmap_read_trylock(mm));
+	mmap_assert_write_locked(mm);
 	BUG_ON(!mutex_is_locked(&mm_all_locks_mutex));
 
 	for (vma = mm->mmap; vma; vma = vma->vm_next) {
Signature · 11 lines
2.35.1


-- 
Rolf Eike Beer, emlix GmbH, https://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix - smart embedded open source
Reviewed-by
#1 lore raw
Quoted 2 lines · Rolf Eike Beer

In case the lock is actually not held at this point this also avoids a stale lock reference if built with NDEBUG.

The change looks good:

But I don't think NDEBUG is a thing in the kernel.

#2 lore raw

Am Dienstag, 29. März 2022, 08:36:39 CEST schrieb Christoph Hellwig:

Quoted 9 lines · Rolf Eike Beer
Quoted 2 lines

In case the lock is actually not held at this point this also avoids a stale lock reference if built with NDEBUG.

The change looks good:

But I don't think NDEBUG is a thing in the kernel.

You are right, it was in tools/include/linux/kernel.h and I didn't spot the prefix. Andrew, maybe you could just delete the sentence when you add the Reviewed-by?

Eike

Signature · 7 lines
Rolf Eike Beer, emlix GmbH, https://www.emlix.com
Fon +49 551 30664-0, Fax +49 551 30664-11
Gothaer Platz 3, 37083 Göttingen, Germany
Sitz der Gesellschaft: Göttingen, Amtsgericht Göttingen HR B 3160
Geschäftsführung: Heike Jordan, Dr. Uwe Kracke – Ust-IdNr.: DE 205 198 055

emlix - smart embedded open source
maintainer
#3 lore raw
Quoted 3 lines · On Tue, 29 Mar 2022 08:45:37 +0200 Rolf Eike Beer <[email protected]> wrote:

You are right, it was in tools/include/linux/kernel.h and I didn't spot the prefix. Andrew, maybe you could just delete the sentence when you add the Reviewed-by?

Did that. I used simply "In case the lock is actually not held at this point."