Allow unmap to work with an mshare host mm. Signed-off-by: Anthony Yznaga <anthony.yznaga@xxxxxxxxxx> --- mm/vma.c | 10 ++++++---- mm/vma.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 28942701e301..60a37a9eb15e 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1174,7 +1174,7 @@ static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct vm_area_struct *vma; struct mm_struct *mm; - mm = current->mm; + mm = vms->mm; mm->map_count -= vms->vma_count; mm->locked_vm -= vms->locked_vm; if (vms->unlock) @@ -1382,13 +1382,15 @@ static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, * @start: The aligned start address to munmap * @end: The aligned end address to munmap * @uf: The userfaultfd list_head + * @mm: The mm struct * @unlock: Unlock after the operation. Only unlocked on success */ static void init_vma_munmap(struct vma_munmap_struct *vms, struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) + struct mm_struct *mm, bool unlock) { + vms->mm = mm; vms->vmi = vmi; vms->vma = vma; if (vma) { @@ -1432,7 +1434,7 @@ int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, struct vma_munmap_struct vms; int error; - init_vma_munmap(&vms, vmi, vma, start, end, uf, unlock); + init_vma_munmap(&vms, vmi, vma, start, end, uf, mm, unlock); error = vms_gather_munmap_vmas(&vms, &mas_detach); if (error) goto gather_failed; @@ -2229,7 +2231,7 @@ static int __mmap_prepare(struct mmap_state *map, struct list_head *uf) /* Find the first overlapping VMA and initialise unmap state. */ vms->vma = vma_find(vmi, map->end); - init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, + init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, map->mm, /* unlock = */ false); /* OK, we have overlapping VMAs - prepare to unmap them. */ diff --git a/mm/vma.h b/mm/vma.h index e704f56577f3..03d69321312d 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -49,6 +49,7 @@ struct vma_munmap_struct { unsigned long exec_vm; unsigned long stack_vm; unsigned long data_vm; + struct mm_struct *mm; }; enum vma_merge_state { -- 2.43.5