[PATCH] mm: add mmap_write_trylock()
From: Lorenzo Stoakes
Date: Sat Jul 11 2026 - 03:07:27 EST
Commit cf95e337cb63 ("mm: delete mmap_write_trylock() and
vma_try_start_write()") removed mmap_write_trylock() as there were no
users.
Re-add this helper and update to have it update the mm's write lock
sequence count number as per the current VMA lock implementation.
The use cases for this function are very narrow - in the vast majority of
cases an inability to acquire the write lock is terminal so you want either
an unconditional or killable variant of the mmap write lock.
However this is being added so a subsequent patch can safely dump PTE
information when an unhandled fault arises in arm32.
Signed-off-by: Lorenzo Stoakes <ljs@xxxxxxxxxx>
---
include/linux/mmap_lock.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h
index 04b8f61ece5d..fe14d4babae9 100644
--- a/include/linux/mmap_lock.h
+++ b/include/linux/mmap_lock.h
@@ -546,6 +546,18 @@ static inline void mmap_write_lock_nested(struct mm_struct *mm, int subclass)
__mmap_lock_trace_acquire_returned(mm, true, true);
}
+static inline bool __must_check mmap_write_trylock(struct mm_struct *mm)
+{
+ bool ret;
+
+ __mmap_lock_trace_start_locking(mm, true);
+ ret = down_write_trylock(&mm->mmap_lock) != 0;
+ if (ret)
+ mm_lock_seqcount_begin(mm);
+ __mmap_lock_trace_acquire_returned(mm, true, ret);
+ return ret;
+}
+
static inline int __must_check mmap_write_lock_killable(struct mm_struct *mm)
{
int ret;
--
2.55.0