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.
Showing the changes to include/linux (1 of 9 files). Show all
Unified · Split
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | #ifndef _LINUX_MMAP_LOCK_H |
| 2 | 2 | #define _LINUX_MMAP_LOCK_H |
| 3 | 3 | |
| 4 | +#include <linux/mmdebug.h> | |
| 5 | + | |
| 4 | 6 | #define MMAP_LOCK_INITIALIZER(name) \ |
| 5 | 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 | 75 | up_read_non_owner(&mm->mmap_sem); |
| 74 | 76 | } |
| 75 | 77 | |
| 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 | + | |
| 76 | 90 | #endif /* _LINUX_MMAP_LOCK_H */ |