History

mmap locking API: add mmap_read_trylock_non_owner()

Add a couple APIs used by kernel/bpf/stackmap.c only: - mmap_read_trylock_non_owner() - mmap_read_unlock_non_owner() (may be called from a work queue). It's still not ideal that bpf/stackmap subverts the lock ownership in this way. Thanks to Peter Zijlstra for suggesting this API as the least-ugly way of addressing this in the short term.

Michel Lespinasse committed 6 years ago

Commit 0cc55a01 parent aaa2cc52 files · +19 −12Browse files

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

Unified · Split

include/linux/mmap_lock.h+14−0
@@ -56,4 +56,18 @@ static inline void mmap_read_unlock(struct mm_struct *mm) · 55 unmodified lines
5656 up_read(&mm->mmap_sem);
5757 }
5858
59+static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm)
60+{
61+ if (down_read_trylock(&mm->mmap_sem)) {
62+ rwsem_release(&mm->mmap_sem.dep_map, _RET_IP_);
63+ return true;
64+ }
65+ return false;
66+}
67+
68+static inline void mmap_read_unlock_non_owner(struct mm_struct *mm)
69+{
70+ up_read_non_owner(&mm->mmap_sem);
71+}
72+
5973 #endif /* _LINUX_MMAP_LOCK_H */