Skip to contentSkip to conversation

mmap_lock: Change trace and locking order

PATCH Superseded Liam Howlett 2 participants 3 messages Sep 3, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmap_lock: Change trace and locking order

Print to the trace log before releasing the lock to avoid racing with other trace log printers of the same lock type.

---
 include/linux/mmap_lock.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/mmap_lock.h +3 -3
index 0540f0156f58..5d2b343e39e7 100644
@@ -101,14 +101,14 @@ static inline bool mmap_write_trylock(struct mm_struct *mm)
 
 static inline void mmap_write_unlock(struct mm_struct *mm)
 {
-	up_write(&mm->mmap_lock);
 	__mmap_lock_trace_released(mm, true);
+	up_write(&mm->mmap_lock);
 }
 
 static inline void mmap_write_downgrade(struct mm_struct *mm)
 {
-	downgrade_write(&mm->mmap_lock);
 	__mmap_lock_trace_acquire_returned(mm, false, true);
+	downgrade_write(&mm->mmap_lock);
 }
 
 static inline void mmap_read_lock(struct mm_struct *mm)
@@ -140,8 +140,8 @@ static inline bool mmap_read_trylock(struct mm_struct *mm)
 
 static inline void mmap_read_unlock(struct mm_struct *mm)
 {
-	up_read(&mm->mmap_lock);
 	__mmap_lock_trace_released(mm, false);
+	up_read(&mm->mmap_lock);
 }
 
 static inline bool mmap_read_trylock_non_owner(struct mm_struct *mm)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 2 lines · Liam Howlett

Print to the trace log before releasing the lock to avoid racing with other trace log printers of the same lock type.

Aren't you missing mmap_read_unlock_non_owner()?

#2 lore raw
Quoted 5 lines · Matthew Wilcox
Quoted 2 lines · Liam Howlett

Print to the trace log before releasing the lock to avoid racing with other trace log printers of the same lock type.

Aren't you missing mmap_read_unlock_non_owner()?

Yes I am. I'll send out v2 shortly.