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.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -56,4 +56,18 @@ static inline void mmap_read_unlock(struct mm_struct *mm) · 55 unmodified lines | |||
| 56 | up_read(&mm->mmap_sem); | 56 | up_read(&mm->mmap_sem); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 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 | |||
| 59 | #endif /* _LINUX_MMAP_LOCK_H */ | 73 | #endif /* _LINUX_MMAP_LOCK_H */ |