linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mmap/vma_merge: always check invariants
@ 2023-04-30 20:19 Lorenzo Stoakes
  2023-05-02  9:51 ` Vlastimil Babka
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Lorenzo Stoakes @ 2023-04-30 20:19 UTC (permalink / raw)
  To: linux-mm, linux-kernel, Andrew Morton
  Cc: Liam R . Howlett, Vlastimil Babka, Lorenzo Stoakes

We may still have inconsistent input parameters even if we choose not to
merge and the vma_merge() invariant checks are useful for checking this
with no production runtime cost (these are only relevant when
CONFIG_DEBUG_VM is specified).

Therefore, perform these checks regardless of whether we merge.

This is relevant, as a recent issue (addressed in commit "mm/mempolicy:
Correctly update prev when policy is equal on mbind") in the mbind logic
was only picked up in the 6.2.y stable branch where these assertions are
performed prior to determining mergeability.

Had this remained the same in mainline this issue may have been picked up
faster, so moving forward let's always check them.

Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
---
 mm/mmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 5522130ae606..13678edaa22c 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -960,17 +960,17 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm,
 		merge_next = true;
 	}
 
+	/* Verify some invariant that must be enforced by the caller. */
+	VM_WARN_ON(prev && addr <= prev->vm_start);
+	VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end));
+	VM_WARN_ON(addr >= end);
+
 	if (!merge_prev && !merge_next)
 		return NULL; /* Not mergeable. */
 
 	res = vma = prev;
 	remove = remove2 = adjust = NULL;
 
-	/* Verify some invariant that must be enforced by the caller. */
-	VM_WARN_ON(prev && addr <= prev->vm_start);
-	VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end));
-	VM_WARN_ON(addr >= end);
-
 	/* Can we merge both the predecessor and the successor? */
 	if (merge_prev && merge_next &&
 	    is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) {
-- 
2.40.1



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

end of thread, other threads:[~2023-05-14 17:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 20:19 [PATCH] mm/mmap/vma_merge: always check invariants Lorenzo Stoakes
2023-05-02  9:51 ` Vlastimil Babka
2023-05-02 11:29 ` David Hildenbrand
2023-05-02 13:13 ` Liam R. Howlett
2023-05-02 19:15 ` Andrew Morton
2023-05-10 14:15 ` Mark Rutland
2023-05-10 16:04   ` Lorenzo Stoakes
2023-05-10 16:17     ` Mark Rutland
2023-05-10 16:26       ` Lorenzo Stoakes
2023-05-11 18:08         ` Mike Rapoport
2023-05-12  1:22           ` Lorenzo Stoakes
2023-05-14 17:33           ` Lorenzo Stoakes

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