History

mmap locking API: add mmap_assert_locked() and mmap_assert_write_locked()

Add new APIs to assert that mmap_sem is held. Using this instead of rwsem_is_locked and lockdep_assert_held[_write] makes the assertions more tolerant of future changes to the lock type.

Michel Lespinasse committed 6 years ago

Commit 42fc5411 parent 14c36569 files · +28 −14Browse files

Showing the changes to include/linux (1 of 9 files). Show all

Unified · Split

include/linux/mmap_lock.h+14−0
@@ -1,6 +1,8 @@
11 #ifndef _LINUX_MMAP_LOCK_H
22 #define _LINUX_MMAP_LOCK_H
33
4+#include <linux/mmdebug.h>
5+
46 #define MMAP_LOCK_INITIALIZER(name) \
57 .mmap_sem = __RWSEM_INITIALIZER((name).mmap_sem),
68
@@ -73,4 +75,16 @@ static inline void mmap_read_unlock_non_owner(struct mm_struct *mm) · 66 unmodified lines
7375 up_read_non_owner(&mm->mmap_sem);
7476 }
7577
78+static inline void mmap_assert_locked(struct mm_struct *mm)
79+{
80+ lockdep_assert_held(&mm->mmap_sem);
81+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
82+}
83+
84+static inline void mmap_assert_write_locked(struct mm_struct *mm)
85+{
86+ lockdep_assert_held_write(&mm->mmap_sem);
87+ VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
88+}
89+
7690 #endif /* _LINUX_MMAP_LOCK_H */