2020-06-09 12:33:14 +08:00
|
|
|
#ifndef _LINUX_MMAP_LOCK_H
|
|
|
|
#define _LINUX_MMAP_LOCK_H
|
|
|
|
|
2020-06-09 12:33:44 +08:00
|
|
|
#include <linux/mmdebug.h>
|
|
|
|
|
2020-06-09 12:33:40 +08:00
|
|
|
#define MMAP_LOCK_INITIALIZER(name) \
|
2020-06-09 12:33:47 +08:00
|
|
|
.mmap_lock = __RWSEM_INITIALIZER((name).mmap_lock),
|
2020-06-09 12:33:40 +08:00
|
|
|
|
2020-06-09 12:33:14 +08:00
|
|
|
static inline void mmap_init_lock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
init_rwsem(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_write_lock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
down_write(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 12:33:33 +08:00
|
|
|
static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
down_write_nested(&mm->mmap_lock, subclass);
|
2020-06-09 12:33:33 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 12:33:14 +08:00
|
|
|
static inline int mmap_write_lock_killable(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
return down_write_killable(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool mmap_write_trylock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
return down_write_trylock(&mm->mmap_lock) != 0;
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_write_unlock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
up_write(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_write_downgrade(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
downgrade_write(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_read_lock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
down_read(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mmap_read_lock_killable(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
return down_read_killable(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool mmap_read_trylock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
return down_read_trylock(&mm->mmap_lock) != 0;
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_read_unlock(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
up_read(&mm->mmap_lock);
|
2020-06-09 12:33:14 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 12:33:37 +08:00
|
|
|
static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
if (down_read_trylock(&mm->mmap_lock)) {
|
|
|
|
rwsem_release(&mm->mmap_lock.dep_map, _RET_IP_);
|
2020-06-09 12:33:37 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_read_unlock_non_owner(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
up_read_non_owner(&mm->mmap_lock);
|
2020-06-09 12:33:37 +08:00
|
|
|
}
|
|
|
|
|
2020-06-09 12:33:44 +08:00
|
|
|
static inline void mmap_assert_locked(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
lockdep_assert_held(&mm->mmap_lock);
|
|
|
|
VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
|
2020-06-09 12:33:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmap_assert_write_locked(struct mm_struct *mm)
|
|
|
|
{
|
2020-06-09 12:33:47 +08:00
|
|
|
lockdep_assert_held_write(&mm->mmap_lock);
|
|
|
|
VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_lock), mm);
|
2020-06-09 12:33:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 07:53:39 +08:00
|
|
|
static inline int mmap_lock_is_contended(struct mm_struct *mm)
|
|
|
|
{
|
|
|
|
return rwsem_is_contended(&mm->mmap_lock);
|
|
|
|
}
|
|
|
|
|
2020-06-09 12:33:14 +08:00
|
|
|
#endif /* _LINUX_MMAP_LOCK_H */
|