OSDN Git Service

mm/damon/paddr: minor refactor of damon_pa_mark_accessed_or_deactivate()
[tomoyo/tomoyo-test1.git] / mm / mremap.c
index 411a856..b11ce6c 100644 (file)
@@ -623,6 +623,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
                        return -ENOMEM;
        }
 
+       vma_start_write(vma);
        new_pgoff = vma->vm_pgoff + ((old_addr - vma->vm_start) >> PAGE_SHIFT);
        new_vma = copy_vma(&vma, new_addr, new_len, new_pgoff,
                           &need_rmap_locks);
@@ -683,7 +684,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
 
        /* Tell pfnmap has moved from this vma */
        if (unlikely(vma->vm_flags & VM_PFNMAP))
-               untrack_pfn_moved(vma);
+               untrack_pfn_clear(vma);
 
        if (unlikely(!err && (flags & MREMAP_DONTUNMAP))) {
                /* We always clear VM_LOCKED[ONFAULT] on the old vma */
@@ -1040,23 +1041,11 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
                         * vma (expand operation itself) and possibly also with
                         * the next vma if it becomes adjacent to the expanded
                         * vma and  otherwise compatible.
-                        *
-                        * However, vma_merge() can currently fail due to
-                        * is_mergeable_vma() check for vm_ops->close (see the
-                        * comment there). Yet this should not prevent vma
-                        * expanding, so perform a simple expand for such vma.
-                        * Ideally the check for close op should be only done
-                        * when a vma would be actually removed due to a merge.
                         */
-                       if (!vma->vm_ops || !vma->vm_ops->close) {
-                               vma = vma_merge(&vmi, mm, vma, extension_start,
-                                       extension_end, vma->vm_flags, vma->anon_vma,
-                                       vma->vm_file, extension_pgoff, vma_policy(vma),
-                                       vma->vm_userfaultfd_ctx, anon_vma_name(vma));
-                       } else if (vma_expand(&vmi, vma, vma->vm_start,
-                                       addr + new_len, vma->vm_pgoff, NULL)) {
-                               vma = NULL;
-                       }
+                       vma = vma_merge(&vmi, mm, vma, extension_start,
+                               extension_end, vma->vm_flags, vma->anon_vma,
+                               vma->vm_file, extension_pgoff, vma_policy(vma),
+                               vma->vm_userfaultfd_ctx, anon_vma_name(vma));
                        if (!vma) {
                                vm_unacct_memory(pages);
                                ret = -ENOMEM;