Skip to content

Commit 0e59f47

Browse files
ljskernelakpm00
authored andcommitted
mm/mremap: correctly account old mapping after MREMAP_DONTUNMAP remap
Commit b714ccb ("mm/mremap: complete refactor of move_vma()") mistakenly introduced a new behaviour - clearing the VM_ACCOUNT flag of the old mapping when a mapping is mremap()'d with the MREMAP_DONTUNMAP flag set. While we always clear the VM_LOCKED and VM_LOCKONFAULT flags for the old mapping (the page tables have been moved, so there is no data that could possibly be locked in memory), there is no reason to touch any other VMA flags. This is because after the move the old mapping is in a state as if it were freshly mapped. This implies that the attributes of the mapping ought to remain the same, including whether or not the mapping is accounted. Link: https://lkml.kernel.org/r/20251013165836.273113-1-lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Fixes: b714ccb ("mm/mremap: complete refactor of move_vma()") Reviewed-by: Pedro Falcato <pfalcato@suse.de> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 841a8bf commit 0e59f47

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

mm/mremap.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,10 +1237,10 @@ static int copy_vma_and_data(struct vma_remap_struct *vrm,
12371237
}
12381238

12391239
/*
1240-
* Perform final tasks for MADV_DONTUNMAP operation, clearing mlock() and
1241-
* account flags on remaining VMA by convention (it cannot be mlock()'d any
1242-
* longer, as pages in range are no longer mapped), and removing anon_vma_chain
1243-
* links from it (if the entire VMA was copied over).
1240+
* Perform final tasks for MADV_DONTUNMAP operation, clearing mlock() flag on
1241+
* remaining VMA by convention (it cannot be mlock()'d any longer, as pages in
1242+
* range are no longer mapped), and removing anon_vma_chain links from it if the
1243+
* entire VMA was copied over.
12441244
*/
12451245
static void dontunmap_complete(struct vma_remap_struct *vrm,
12461246
struct vm_area_struct *new_vma)
@@ -1250,11 +1250,8 @@ static void dontunmap_complete(struct vma_remap_struct *vrm,
12501250
unsigned long old_start = vrm->vma->vm_start;
12511251
unsigned long old_end = vrm->vma->vm_end;
12521252

1253-
/*
1254-
* We always clear VM_LOCKED[ONFAULT] | VM_ACCOUNT on the old
1255-
* vma.
1256-
*/
1257-
vm_flags_clear(vrm->vma, VM_LOCKED_MASK | VM_ACCOUNT);
1253+
/* We always clear VM_LOCKED[ONFAULT] on the old VMA. */
1254+
vm_flags_clear(vrm->vma, VM_LOCKED_MASK);
12581255

12591256
/*
12601257
* anon_vma links of the old vma is no longer needed after its page

0 commit comments

Comments
 (0)