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 @@
1#ifndef _LINUX_MMAP_LOCK_H1#ifndef _LINUX_MMAP_LOCK_H
2#define _LINUX_MMAP_LOCK_H2#define _LINUX_MMAP_LOCK_H
3 3
4#include <linux/mmdebug.h>
5
4#define MMAP_LOCK_INITIALIZER(name) \6#define MMAP_LOCK_INITIALIZER(name) \
5 .mmap_sem = __RWSEM_INITIALIZER((name).mmap_sem),7 .mmap_sem = __RWSEM_INITIALIZER((name).mmap_sem),
6 8
@@ -73,4 +75,16 @@ static inline void mmap_read_unlock_non_owner(struct mm_struct *mm) · 66 unmodified lines
73 up_read_non_owner(&mm->mmap_sem);75 up_read_non_owner(&mm->mmap_sem);
74}76}
75 77
78static 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
84static 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
76#endif /* _LINUX_MMAP_LOCK_H */90#endif /* _LINUX_MMAP_LOCK_H */