Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mremap: correctly account old mapping after MREMAP_DONTUNMAP remap

Commit b714ccb02a76 ("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: b714ccb02a76 ("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>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
0e59f47c 841a8bfc

+6 -9
+6 -9
mm/mremap.c
··· 1237 1237 } 1238 1238 1239 1239 /* 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. 1244 1244 */ 1245 1245 static void dontunmap_complete(struct vma_remap_struct *vrm, 1246 1246 struct vm_area_struct *new_vma) ··· 1250 1250 unsigned long old_start = vrm->vma->vm_start; 1251 1251 unsigned long old_end = vrm->vma->vm_end; 1252 1252 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); 1258 1255 1259 1256 /* 1260 1257 * anon_vma links of the old vma is no longer needed after its page