Skip to content

Commit ecf371b

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
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>
1 parent 3180748 commit ecf371b

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

mm/mmap_lock.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ EXPORT_SYMBOL(__mmap_lock_do_trace_released);
4646
#ifdef CONFIG_MMU
4747
#ifdef CONFIG_PER_VMA_LOCK
4848
/*
49-
* Return value: 0 if vma detached,
50-
* 1 if vma attached with no readers,
51-
* -EINTR if signal received,
49+
* __vma_enter_locked() returns 0 immediately if the vma is not
50+
* attached, otherwise it waits for any current readers to finish and
51+
* returns 1. Returns -EINTR if a signal is received while waiting.
5252
*/
5353
static inline int __vma_enter_locked(struct vm_area_struct *vma,
5454
bool detaching, int state)
5555
{
5656
int err;
5757
unsigned int tgt_refcnt = VMA_LOCK_OFFSET;
5858

59+
mmap_assert_write_locked(vma->vm_mm);
60+
5961
/* Additional refcnt if the vma is attached. */
6062
if (!detaching)
6163
tgt_refcnt++;
@@ -91,11 +93,6 @@ int __vma_start_write(struct vm_area_struct *vma, unsigned int mm_lock_seq,
9193
{
9294
int locked;
9395

94-
/*
95-
* __vma_enter_locked() returns false immediately if the vma is not
96-
* attached, otherwise it waits until refcnt is indicating that vma
97-
* is attached with no readers.
98-
*/
9996
locked = __vma_enter_locked(vma, false, state);
10097
if (locked < 0)
10198
return locked;

0 commit comments

Comments
 (0)