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. Signed-off-by: Michel Lespinasse <walken@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: David Rientjes <rientjes@google.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jerome Glisse <jglisse@redhat.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Laurent Dufour <ldufour@linux.ibm.com> Cc: Liam Howlett <Liam.Howlett@oracle.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ying Han <yinghan@google.com> Link: http://lkml.kernel.org/r/20200520052908.204642-10-walken@google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
14c3656b72
commit
42fc541404
@@ -1,6 +1,8 @@
|
||||
#ifndef _LINUX_MMAP_LOCK_H
|
||||
#define _LINUX_MMAP_LOCK_H
|
||||
|
||||
#include <linux/mmdebug.h>
|
||||
|
||||
#define MMAP_LOCK_INITIALIZER(name) \
|
||||
.mmap_sem = __RWSEM_INITIALIZER((name).mmap_sem),
|
||||
|
||||
@@ -73,4 +75,16 @@ static inline void mmap_read_unlock_non_owner(struct mm_struct *mm)
|
||||
up_read_non_owner(&mm->mmap_sem);
|
||||
}
|
||||
|
||||
static inline void mmap_assert_locked(struct mm_struct *mm)
|
||||
{
|
||||
lockdep_assert_held(&mm->mmap_sem);
|
||||
VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
|
||||
}
|
||||
|
||||
static inline void mmap_assert_write_locked(struct mm_struct *mm)
|
||||
{
|
||||
lockdep_assert_held_write(&mm->mmap_sem);
|
||||
VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
|
||||
}
|
||||
|
||||
#endif /* _LINUX_MMAP_LOCK_H */
|
||||
|
Reference in New Issue
Block a user