return 0;
}
+/*
+ * init_multi_vma_lock() - Initializer for struct vma_locking
+ * @vl: The vma_locking struct
+ * @vma: The vma that will be altered once locked
+ * @next: The next vma if it is to be adjusted
+ * @remove: The first vma to be removed
+ * @remove2: The second vma to be removed
+ */
+static inline void init_multi_vma_lock(struct vma_locking *vl,
+ struct vm_area_struct *vma, struct vm_area_struct *next,
+ struct vm_area_struct *remove, struct vm_area_struct *remove2)
+{
+
+ memset(vl, 0, sizeof(struct vma_locking));
+ vl->vma = vma;
+ vl->anon_vma = vma->anon_vma;
+ vl->remove = remove;
+ vl->remove2 = remove2;
+ vl->adj_next = next;
+ if (!vl->anon_vma && next)
+ vl->anon_vma = next->anon_vma;
+
+ vl->file = vma->vm_file;
+ if (vl->file)
+ vl->mapping = vma->vm_file->f_mapping;
+
+}
+
+static inline void init_vma_lock(struct vma_locking *vl,
+ struct vm_area_struct *vma)
+{
+ init_multi_vma_lock(vl, vma, NULL, NULL, NULL);
+}
+
/*
* lock_vma() - Helper function for locking VMAs prior to altering
* @vl: The initialized vma_locking struct
/*
* In mprotect's case 6 (see comments on vma_merge),
- * we must remove next_next too.
+ * we must remove the one after next too.
*/
if (vl->remove2) {
vl->remove = vl->remove2;
struct vm_area_struct *next)
{
+ bool remove_next = false;
struct vma_locking vma_lock;
- memset(&vma_lock, 0, sizeof(vma_lock));
- vma_lock.vma = vma;
- vma_lock.anon_vma = vma->anon_vma;
if (next && (vma != next) && (end == next->vm_end)) {
- vma_lock.remove = next;
+ remove_next = true;
if (next->anon_vma && !vma->anon_vma) {
int error;
- vma_lock.anon_vma = next->anon_vma;
vma->anon_vma = next->anon_vma;
error = anon_vma_clone(vma, next);
if (error)
}
}
+ init_multi_vma_lock(&vma_lock, vma, NULL, remove_next ? next : NULL,
+ NULL);
/* Not merging but overwriting any part of next is not handled. */
VM_BUG_ON(next && !vma_lock.remove &&
next != vma && end > next->vm_start);
goto nomem;
vma_adjust_trans_huge(vma, start, end, 0);
-
- vma_lock.file = vma->vm_file;
- if (vma_lock.file)
- vma_lock.mapping = vma_lock.file->f_mapping;
lock_vma(&vma_lock);
vma->vm_start = start;
nomem:
return -ENOMEM;
}
+
/*
* We cannot adjust vm_start, vm_end, vm_pgoff fields of a vma that
* is already present in an i_mmap tree without adjusting the tree.
struct vm_area_struct *expand)
{
struct mm_struct *mm = vma->vm_mm;
- struct vm_area_struct *next_next = NULL;
+ struct vm_area_struct *remove2 = NULL;
+ struct vm_area_struct *remove = NULL;
struct vm_area_struct *next = find_vma(mm, vma->vm_end);
struct vm_area_struct *orig_vma = vma;
- struct anon_vma *anon_vma = NULL;
struct file *file = vma->vm_file;
bool vma_changed = false;
long adjust_next = 0;
- int remove_next = 0;
MA_STATE(mas, &mm->mm_mt, 0, 0);
struct vm_area_struct *exporter = NULL, *importer = NULL;
struct vma_locking vma_lock;
* removing "vma" and that to do so we
* swapped "vma" and "next".
*/
- remove_next = 3;
VM_WARN_ON(file != next->vm_file);
swap(vma, next);
+ remove = next;
} else {
VM_WARN_ON(expand != vma);
/*
* case 1, 6, 7, remove_next == 2 is case 6,
* remove_next == 1 is case 1 or 7.
*/
- remove_next = 1 + (end > next->vm_end);
- if (remove_next == 2)
- next_next = find_vma(mm, next->vm_end);
+ remove = next;
+ if (end > next->vm_end);
+ remove2 = find_vma(mm, next->vm_end);
- VM_WARN_ON(remove_next == 2 &&
- end != next_next->vm_end);
+ VM_WARN_ON(remove2 != NULL &&
+ end != remove2->vm_end);
}
exporter = next;
* If next doesn't have anon_vma, import from vma after
* next, if the vma overlaps with it.
*/
- if (remove_next == 2 && !next->anon_vma)
- exporter = next_next;
+ if (remove2 != NULL && !next->anon_vma)
+ exporter = remove2;
} else if (end > next->vm_start) {
/*
if (mas_preallocate(&mas, vma, GFP_KERNEL))
return -ENOMEM;
- anon_vma = vma->anon_vma;
- if (!anon_vma && adjust_next)
- anon_vma = next->anon_vma;
-
- if (anon_vma)
- VM_WARN_ON(adjust_next && next->anon_vma &&
- anon_vma != next->anon_vma);
-
vma_adjust_trans_huge(orig_vma, start, end, adjust_next);
- memset(&vma_lock, 0, sizeof(vma_lock));
- vma_lock.vma = vma;
- vma_lock.anon_vma = anon_vma;
- vma_lock.file = file;
- if (adjust_next)
- vma_lock.adj_next = next;
- if (file)
- vma_lock.mapping = file->f_mapping;
- vma_lock.insert = insert;
- if (remove_next) {
- vma_lock.remove = next;
- vma_lock.remove2 = next_next;
- }
+ init_multi_vma_lock(&vma_lock, vma, adjust_next ? next : NULL, remove,
+ remove2);
+ VM_WARN_ON(vma_lock.anon_vma && adjust_next && next->anon_vma &&
+ vma_lock.anon_vma != next->anon_vma);
+ vma_lock.insert = insert;
lock_vma(&vma_lock);
if (start != vma->vm_start) {