linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm: lock a vma before stack expansion
@ 2023-07-07  4:32 Suren Baghdasaryan
  2023-07-07  4:32 ` [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible Suren Baghdasaryan
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Suren Baghdasaryan @ 2023-07-07  4:32 UTC (permalink / raw)
  To: akpm
  Cc: willy, liam.howlett, david, peterx, vbabka, michel, jglisse,
	mhocko, hannes, dave, ldufour, hughd, punit.agrawal, lstoakes,
	rientjes, axelrasmussen, jannh, shakeelb, tatashin, gthelen,
	linux-mm, linux-kernel, stable, kernel-team, surenb

With recent changes necessitating mmap_lock to be held for write while
expanding a stack, per-VMA locks should follow the same rules and be
write-locked to prevent page faults into the VMA being expanded. Add
the necessary locking.

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
 mm/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index 204ddcd52625..c66e4622a557 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1977,6 +1977,8 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 		return -ENOMEM;
 	}
 
+	/* Lock the VMA before expanding to prevent concurrent page faults */
+	vma_start_write(vma);
 	/*
 	 * vma->vm_start/vm_end cannot change under us because the caller
 	 * is required to hold the mmap_lock in read mode.  We need the
@@ -2064,6 +2066,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address)
 		return -ENOMEM;
 	}
 
+	/* Lock the VMA before expanding to prevent concurrent page faults */
+	vma_start_write(vma);
 	/*
 	 * vma->vm_start/vm_end cannot change under us because the caller
 	 * is required to hold the mmap_lock in read mode.  We need the
-- 
2.41.0.255.g8b1d071c50-goog



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-08  6:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-07  4:32 [PATCH 1/2] mm: lock a vma before stack expansion Suren Baghdasaryan
2023-07-07  4:32 ` [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible Suren Baghdasaryan
2023-07-07 19:48   ` Liam R. Howlett
2023-07-07 20:15     ` Suren Baghdasaryan
2023-07-07 19:27 ` [PATCH 1/2] mm: lock a vma before stack expansion Andrew Morton
2023-07-07 20:03   ` Suren Baghdasaryan
2023-07-07 20:00 ` Markus Elfring
2023-07-07 20:03   ` Matthew Wilcox
2023-07-07 20:08     ` Suren Baghdasaryan
2023-07-08  5:55       ` [1/2] " Markus Elfring
2023-07-08  6:18         ` Suren Baghdasaryan
2023-07-08  6:33           ` Markus Elfring
2023-07-08  5:30     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox