mm/cgroup/reclaim: fix dirty pages throttling on cgroup v1
[platform/kernel/linux-starfive.git] / mm / mmap.c
index e270057..74a84eb 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -456,7 +456,7 @@ void vma_mas_remove(struct vm_area_struct *vma, struct ma_state *mas)
  * vma_mas_szero() - Set a given range to zero.  Used when modifying a
  * vm_area_struct start or end.
  *
- * @mm: The struct_mm
+ * @mas: The maple tree ma_state
  * @start: The start address to zero
  * @end: The end address to zero.
  */
@@ -2674,6 +2674,8 @@ cannot_expand:
                error = -EINVAL;
                if (file)
                        goto close_and_free_vma;
+               else if (vma->vm_file)
+                       goto unmap_and_free_vma;
                else
                        goto free_vma;
        }
@@ -2682,6 +2684,8 @@ cannot_expand:
                error = -ENOMEM;
                if (file)
                        goto close_and_free_vma;
+               else if (vma->vm_file)
+                       goto unmap_and_free_vma;
                else
                        goto free_vma;
        }
@@ -2751,7 +2755,7 @@ unmap_and_free_vma:
 
        /* Undo any partial mapping done by a device driver. */
        unmap_region(mm, mas.tree, vma, prev, next, vma->vm_start, vma->vm_end);
-       if (vm_flags & VM_SHARED)
+       if (file && (vm_flags & VM_SHARED))
                mapping_unmap_writable(file->f_mapping);
 free_vma:
        vm_area_free(vma);
@@ -2852,6 +2856,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
                        if (next->vm_flags != vma->vm_flags)
                                goto out;
 
+                       if (start + size <= next->vm_end)
+                               break;
+
                        prev = next;
                }