mmap.c (13d77e0133908721f7da093ffd3169a92bae8b11) mmap.c (63fc66f5b6b18f39269a66cf34d8cb7a24fbfe88)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * mm/mmap.c
4 *
5 * Written by obz.
6 *
7 * Address space accounting code <alan@lxorguk.ukuu.org.uk>
8 */

--- 155 unchanged lines hidden (view full) ---

164 if (brk <= mm->brk) {
165 /* Search one past newbrk */
166 vma_iter_init(&vmi, mm, newbrk);
167 brkvma = vma_find(&vmi, oldbrk);
168 if (!brkvma || brkvma->vm_start >= oldbrk)
169 goto out; /* mapping intersects with an existing non-brk vma. */
170 /*
171 * mm->brk must be protected by write mmap_lock.
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * mm/mmap.c
4 *
5 * Written by obz.
6 *
7 * Address space accounting code <alan@lxorguk.ukuu.org.uk>
8 */

--- 155 unchanged lines hidden (view full) ---

164 if (brk <= mm->brk) {
165 /* Search one past newbrk */
166 vma_iter_init(&vmi, mm, newbrk);
167 brkvma = vma_find(&vmi, oldbrk);
168 if (!brkvma || brkvma->vm_start >= oldbrk)
169 goto out; /* mapping intersects with an existing non-brk vma. */
170 /*
171 * mm->brk must be protected by write mmap_lock.
172 * do_vma_munmap() will drop the lock on success, so update it
173 * before calling do_vma_munmap().
172 * do_vmi_align_munmap() will drop the lock on success, so
173 * update it before calling do_vma_munmap().
174 */
175 mm->brk = brk;
174 */
175 mm->brk = brk;
176 if (do_vma_munmap(&vmi, brkvma, newbrk, oldbrk, &uf, true))
176 if (do_vmi_align_munmap(&vmi, brkvma, mm, newbrk, oldbrk, &uf,
177 /* unlock = */ true))
177 goto out;
178
179 goto success_unlocked;
180 }
181
182 if (check_brk_limits(oldbrk, newbrk - oldbrk))
183 goto out;
184

--- 1289 unchanged lines hidden (view full) ---

1474 vma_set_range(vma, addr, end, pgoff);
1475 vm_flags_init(vma, vm_flags);
1476 vma->vm_page_prot = vm_get_page_prot(vm_flags);
1477
1478 if (file) {
1479 vma->vm_file = get_file(file);
1480 /*
1481 * call_mmap() may map PTE, so ensure there are no existing PTEs
178 goto out;
179
180 goto success_unlocked;
181 }
182
183 if (check_brk_limits(oldbrk, newbrk - oldbrk))
184 goto out;
185

--- 1289 unchanged lines hidden (view full) ---

1475 vma_set_range(vma, addr, end, pgoff);
1476 vm_flags_init(vma, vm_flags);
1477 vma->vm_page_prot = vm_get_page_prot(vm_flags);
1478
1479 if (file) {
1480 vma->vm_file = get_file(file);
1481 /*
1482 * call_mmap() may map PTE, so ensure there are no existing PTEs
1482 * call the vm_ops close function if one exists.
1483 * and call the vm_ops close function if one exists.
1483 */
1484 */
1484 vms_clean_up_area(&vms, &mas_detach, true);
1485 vms_clean_up_area(&vms, &mas_detach);
1485 error = call_mmap(file, vma);
1486 if (error)
1487 goto unmap_and_free_vma;
1488
1489 if (vma_is_shared_maywrite(vma)) {
1490 error = mapping_map_writable(file->f_mapping);
1491 if (error)
1492 goto close_and_free_vma;

--- 247 unchanged lines hidden (view full) ---

1740 if (populate)
1741 mm_populate(ret, populate);
1742 if (!IS_ERR_VALUE(ret))
1743 ret = 0;
1744 return ret;
1745}
1746
1747/*
1486 error = call_mmap(file, vma);
1487 if (error)
1488 goto unmap_and_free_vma;
1489
1490 if (vma_is_shared_maywrite(vma)) {
1491 error = mapping_map_writable(file->f_mapping);
1492 if (error)
1493 goto close_and_free_vma;

--- 247 unchanged lines hidden (view full) ---

1741 if (populate)
1742 mm_populate(ret, populate);
1743 if (!IS_ERR_VALUE(ret))
1744 ret = 0;
1745 return ret;
1746}
1747
1748/*
1748 * do_vma_munmap() - Unmap a full or partial vma.
1749 * @vmi: The vma iterator pointing at the vma
1750 * @vma: The first vma to be munmapped
1751 * @start: the start of the address to unmap
1752 * @end: The end of the address to unmap
1753 * @uf: The userfaultfd list_head
1754 * @unlock: Drop the lock on success
1755 *
1756 * unmaps a VMA mapping when the vma iterator is already in position.
1757 * Does not handle alignment.
1758 *
1759 * Return: 0 on success drops the lock of so directed, error on failure and will
1760 * still hold the lock.
1761 */
1762int do_vma_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma,
1763 unsigned long start, unsigned long end, struct list_head *uf,
1764 bool unlock)
1765{
1766 return do_vmi_align_munmap(vmi, vma, vma->vm_mm, start, end, uf, unlock);
1767}
1768
1769/*
1770 * do_brk_flags() - Increase the brk vma if the flags match.
1771 * @vmi: The vma iterator
1772 * @addr: The start address
1773 * @len: The length of the increase
1774 * @vma: The vma,
1775 * @flags: The VMA Flags
1776 *
1777 * Extend the brk VMA from addr to addr + len. If the VMA is NULL or the flags

--- 619 unchanged lines hidden ---
1749 * do_brk_flags() - Increase the brk vma if the flags match.
1750 * @vmi: The vma iterator
1751 * @addr: The start address
1752 * @len: The length of the increase
1753 * @vma: The vma,
1754 * @flags: The VMA Flags
1755 *
1756 * Extend the brk VMA from addr to addr + len. If the VMA is NULL or the flags

--- 619 unchanged lines hidden ---