vma.c (4f87153e82c4906e917d273ab7accd0d540aab35) vma.c (63fc66f5b6b18f39269a66cf34d8cb7a24fbfe88)
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3/*
4 * VMA-specific functions.
5 */
6
7#include "vma_internal.h"
8#include "vma.h"

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

653 return;
654
655 /*
656 * We can free page tables without write-locking mmap_lock because VMAs
657 * were isolated before we downgraded mmap_lock.
658 */
659 mas_set(mas_detach, 1);
660 lru_add_drain();
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3/*
4 * VMA-specific functions.
5 */
6
7#include "vma_internal.h"
8#include "vma.h"

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

653 return;
654
655 /*
656 * We can free page tables without write-locking mmap_lock because VMAs
657 * were isolated before we downgraded mmap_lock.
658 */
659 mas_set(mas_detach, 1);
660 lru_add_drain();
661 tlb_gather_mmu(&tlb, vms->mm);
662 update_hiwater_rss(vms->mm);
661 tlb_gather_mmu(&tlb, vms->vma->vm_mm);
662 update_hiwater_rss(vms->vma->vm_mm);
663 unmap_vmas(&tlb, mas_detach, vms->vma, vms->start, vms->end,
664 vms->vma_count, mm_wr_locked);
665
666 mas_set(mas_detach, 1);
667 /* start and end may be different if there is no prev or next vma. */
668 free_pgtables(&tlb, mas_detach, vms->vma, vms->unmap_start,
669 vms->unmap_end, mm_wr_locked);
670 tlb_finish_mmu(&tlb);
671 vms->clear_ptes = false;
672}
673
674void vms_clean_up_area(struct vma_munmap_struct *vms,
663 unmap_vmas(&tlb, mas_detach, vms->vma, vms->start, vms->end,
664 vms->vma_count, mm_wr_locked);
665
666 mas_set(mas_detach, 1);
667 /* start and end may be different if there is no prev or next vma. */
668 free_pgtables(&tlb, mas_detach, vms->vma, vms->unmap_start,
669 vms->unmap_end, mm_wr_locked);
670 tlb_finish_mmu(&tlb);
671 vms->clear_ptes = false;
672}
673
674void vms_clean_up_area(struct vma_munmap_struct *vms,
675 struct ma_state *mas_detach, bool mm_wr_locked)
675 struct ma_state *mas_detach)
676{
677 struct vm_area_struct *vma;
678
679 if (!vms->nr_pages)
680 return;
681
676{
677 struct vm_area_struct *vma;
678
679 if (!vms->nr_pages)
680 return;
681
682 vms_clear_ptes(vms, mas_detach, mm_wr_locked);
682 vms_clear_ptes(vms, mas_detach, true);
683 mas_set(mas_detach, 0);
684 mas_for_each(mas_detach, vma, ULONG_MAX)
685 if (vma->vm_ops && vma->vm_ops->close)
686 vma->vm_ops->close(vma);
687 vms->closed_vm_ops = true;
688}
689
690/*

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

697 * needed to be done once the vma maple tree is updated.
698 */
699void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
700 struct ma_state *mas_detach)
701{
702 struct vm_area_struct *vma;
703 struct mm_struct *mm;
704
683 mas_set(mas_detach, 0);
684 mas_for_each(mas_detach, vma, ULONG_MAX)
685 if (vma->vm_ops && vma->vm_ops->close)
686 vma->vm_ops->close(vma);
687 vms->closed_vm_ops = true;
688}
689
690/*

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

697 * needed to be done once the vma maple tree is updated.
698 */
699void vms_complete_munmap_vmas(struct vma_munmap_struct *vms,
700 struct ma_state *mas_detach)
701{
702 struct vm_area_struct *vma;
703 struct mm_struct *mm;
704
705 mm = vms->mm;
705 mm = current->mm;
706 mm->map_count -= vms->vma_count;
707 mm->locked_vm -= vms->locked_vm;
708 if (vms->unlock)
709 mmap_write_downgrade(mm);
710
711 if (!vms->nr_pages)
712 return;
713

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

765 if (vms->start > vms->vma->vm_start) {
766
767 /*
768 * Make sure that map_count on return from munmap() will
769 * not exceed its limit; but let map_count go just above
770 * its limit temporarily, to help free resources as expected.
771 */
772 if (vms->end < vms->vma->vm_end &&
706 mm->map_count -= vms->vma_count;
707 mm->locked_vm -= vms->locked_vm;
708 if (vms->unlock)
709 mmap_write_downgrade(mm);
710
711 if (!vms->nr_pages)
712 return;
713

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

765 if (vms->start > vms->vma->vm_start) {
766
767 /*
768 * Make sure that map_count on return from munmap() will
769 * not exceed its limit; but let map_count go just above
770 * its limit temporarily, to help free resources as expected.
771 */
772 if (vms->end < vms->vma->vm_end &&
773 vms->mm->map_count >= sysctl_max_map_count)
773 vms->vma->vm_mm->map_count >= sysctl_max_map_count)
774 goto map_count_exceeded;
775
776 /* Don't bother splitting the VMA if we can't unmap it anyway */
777 if (!can_modify_vma(vms->vma)) {
778 error = -EPERM;
779 goto start_split_failed;
780 }
781

--- 1078 unchanged lines hidden ---
774 goto map_count_exceeded;
775
776 /* Don't bother splitting the VMA if we can't unmap it anyway */
777 if (!can_modify_vma(vms->vma)) {
778 error = -EPERM;
779 goto start_split_failed;
780 }
781

--- 1078 unchanged lines hidden ---