mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 11:06:41 -05:00
mm/mremap: clean up mlock populate behaviour
When an mlock()'d VMA is expanded, we need to populate the expanded region to maintain the contract that all mlock()'d memory is present (albeit - with some period after mmap unlock where the expanded part of the mapping remains unfaulted). The current implementation is very unclear, so make it absolutely explicit under what circumstances we do this. Link: https://lkml.kernel.org/r/2358b0006baa9cab83db4259817794f16fe1992e.1752770784.git.lorenzo.stoakes@oracle.com Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Peter Xu <peterx@redhat.com> Cc: Rik van Riel <riel@surriel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
9b2301bf8d
commit
2cf442d742
13
mm/mremap.c
13
mm/mremap.c
@@ -65,7 +65,7 @@ struct vma_remap_struct {
|
||||
|
||||
/* Internal state, determined in do_mremap(). */
|
||||
unsigned long delta; /* Absolute delta of old_len,new_len. */
|
||||
bool mlocked; /* Was the VMA mlock()'d? */
|
||||
bool populate_expand; /* mlock()'d expanded, must populate. */
|
||||
enum mremap_type remap_type; /* expand, shrink, etc. */
|
||||
bool mmap_locked; /* Is mm currently write-locked? */
|
||||
unsigned long charged; /* If VM_ACCOUNT, # pages to account. */
|
||||
@@ -1010,10 +1010,8 @@ static void vrm_stat_account(struct vma_remap_struct *vrm,
|
||||
struct vm_area_struct *vma = vrm->vma;
|
||||
|
||||
vm_stat_account(mm, vma->vm_flags, pages);
|
||||
if (vma->vm_flags & VM_LOCKED) {
|
||||
if (vma->vm_flags & VM_LOCKED)
|
||||
mm->locked_vm += pages;
|
||||
vrm->mlocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1660,6 +1658,10 @@ static int check_prep_vma(struct vma_remap_struct *vrm)
|
||||
if (new_len == old_len)
|
||||
return 0;
|
||||
|
||||
/* We are expanding and the VMA is mlock()'d so we need to populate. */
|
||||
if (vma->vm_flags & VM_LOCKED)
|
||||
vrm->populate_expand = true;
|
||||
|
||||
/* Need to be careful about a growing mapping */
|
||||
pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
|
||||
pgoff += vma->vm_pgoff;
|
||||
@@ -1780,7 +1782,8 @@ static unsigned long do_mremap(struct vma_remap_struct *vrm)
|
||||
if (vrm->mmap_locked)
|
||||
mmap_write_unlock(mm);
|
||||
|
||||
if (!failed && vrm->mlocked && vrm->new_len > vrm->old_len)
|
||||
/* VMA mlock'd + was expanded, so populated expanded region. */
|
||||
if (!failed && vrm->populate_expand)
|
||||
mm_populate(vrm->new_addr + vrm->old_len, vrm->delta);
|
||||
|
||||
notify_uffd(vrm, failed);
|
||||
|
||||
Reference in New Issue
Block a user