summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2025-11-19 04:26:35 +0000
committerAndrew Morton <akpm@linux-foundation.org>2025-11-24 15:08:55 -0800
commitecf371b2cabee6a2bfb61f87d71c9f02a9ff34d7 (patch)
tree2fb824b2c9c0ea1b01ed91d49ada55aac122ba0d
parent31807483d3952059d395c2a73b1fa9625db9b366 (diff)
mm: tweak __vma_enter_locked()
Move the commentary on how __vma_enter_locked() behaves from the body of __vma_start_write() to the head of __vma_enter_locked() and merge it with the existing documentation. Also add a call to mmap_assert_write_locked(). Link: https://lkml.kernel.org/r/20251119042639.3937024-1-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r--mm/mmap_lock.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/mm/mmap_lock.c b/mm/mmap_lock.c
index f2532af6208c..e6e5570d1ec7 100644
--- a/mm/mmap_lock.c
+++ b/mm/mmap_lock.c
@@ -46,9 +46,9 @@ EXPORT_SYMBOL(__mmap_lock_do_trace_released);
#ifdef CONFIG_MMU
#ifdef CONFIG_PER_VMA_LOCK
/*
- * Return value: 0 if vma detached,
- * 1 if vma attached with no readers,
- * -EINTR if signal received,
+ * __vma_enter_locked() returns 0 immediately if the vma is not
+ * attached, otherwise it waits for any current readers to finish and
+ * returns 1. Returns -EINTR if a signal is received while waiting.
*/
static inline int __vma_enter_locked(struct vm_area_struct *vma,
bool detaching, int state)
@@ -56,6 +56,8 @@ static inline int __vma_enter_locked(struct vm_area_struct *vma,
int err;
unsigned int tgt_refcnt = VMA_LOCK_OFFSET;
+ mmap_assert_write_locked(vma->vm_mm);
+
/* Additional refcnt if the vma is attached. */
if (!detaching)
tgt_refcnt++;
@@ -91,11 +93,6 @@ int __vma_start_write(struct vm_area_struct *vma, unsigned int mm_lock_seq,
{
int locked;
- /*
- * __vma_enter_locked() returns false immediately if the vma is not
- * attached, otherwise it waits until refcnt is indicating that vma
- * is attached with no readers.
- */
locked = __vma_enter_locked(vma, false, state);
if (locked < 0)
return locked;