vma.c (40b88644dd92d99e572063893c2a247598c238d6) | vma.c (df2a7df9a9aa32c3df227de346693e6e802c8591) |
---|---|
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" --- 698 unchanged lines hidden (view full) --- 707 /* 708 * Make sure that map_count on return from munmap() will 709 * not exceed its limit; but let map_count go just above 710 * its limit temporarily, to help free resources as expected. 711 */ 712 if (end < vma->vm_end && mm->map_count >= sysctl_max_map_count) 713 goto map_count_exceeded; 714 | 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" --- 698 unchanged lines hidden (view full) --- 707 /* 708 * Make sure that map_count on return from munmap() will 709 * not exceed its limit; but let map_count go just above 710 * its limit temporarily, to help free resources as expected. 711 */ 712 if (end < vma->vm_end && mm->map_count >= sysctl_max_map_count) 713 goto map_count_exceeded; 714 |
715 /* Don't bother splitting the VMA if we can't unmap it anyway */ 716 if (!can_modify_vma(vma)) { 717 error = -EPERM; 718 goto start_split_failed; 719 } 720 |
|
715 error = __split_vma(vmi, vma, start, 1); 716 if (error) 717 goto start_split_failed; 718 } 719 720 /* 721 * Detach a range of VMAs from the mm. Using next as a temp variable as 722 * it is always overwritten. 723 */ 724 next = vma; 725 do { | 721 error = __split_vma(vmi, vma, start, 1); 722 if (error) 723 goto start_split_failed; 724 } 725 726 /* 727 * Detach a range of VMAs from the mm. Using next as a temp variable as 728 * it is always overwritten. 729 */ 730 next = vma; 731 do { |
732 if (!can_modify_vma(next)) { 733 error = -EPERM; 734 goto modify_vma_failed; 735 } 736 |
|
726 /* Does it split the end? */ 727 if (next->vm_end > end) { 728 error = __split_vma(vmi, next, end, 0); 729 if (error) 730 goto end_split_failed; 731 } 732 vma_start_write(next); 733 mas_set(&mas_detach, count); --- 76 unchanged lines hidden (view full) --- 810 remove_mt(mm, &mas_detach); 811 validate_mm(mm); 812 if (unlock) 813 mmap_read_unlock(mm); 814 815 __mt_destroy(&mt_detach); 816 return 0; 817 | 737 /* Does it split the end? */ 738 if (next->vm_end > end) { 739 error = __split_vma(vmi, next, end, 0); 740 if (error) 741 goto end_split_failed; 742 } 743 vma_start_write(next); 744 mas_set(&mas_detach, count); --- 76 unchanged lines hidden (view full) --- 821 remove_mt(mm, &mas_detach); 822 validate_mm(mm); 823 if (unlock) 824 mmap_read_unlock(mm); 825 826 __mt_destroy(&mt_detach); 827 return 0; 828 |
829modify_vma_failed: |
|
818clear_tree_failed: 819userfaultfd_error: 820munmap_gather_failed: 821end_split_failed: 822 mas_set(&mas_detach, 0); 823 mas_for_each(&mas_detach, next, end) 824 vma_mark_detached(next, false); 825 --- 29 unchanged lines hidden (view full) --- 855 856 if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start) 857 return -EINVAL; 858 859 end = start + PAGE_ALIGN(len); 860 if (end == start) 861 return -EINVAL; 862 | 830clear_tree_failed: 831userfaultfd_error: 832munmap_gather_failed: 833end_split_failed: 834 mas_set(&mas_detach, 0); 835 mas_for_each(&mas_detach, next, end) 836 vma_mark_detached(next, false); 837 --- 29 unchanged lines hidden (view full) --- 867 868 if ((offset_in_page(start)) || start > TASK_SIZE || len > TASK_SIZE-start) 869 return -EINVAL; 870 871 end = start + PAGE_ALIGN(len); 872 if (end == start) 873 return -EINVAL; 874 |
863 /* 864 * Check if memory is sealed, prevent unmapping a sealed VMA. 865 * can_modify_mm assumes we have acquired the lock on MM. 866 */ 867 if (unlikely(!can_modify_mm(mm, start, end))) 868 return -EPERM; 869 | |
870 /* Find the first overlapping VMA */ 871 vma = vma_find(vmi, end); 872 if (!vma) { 873 if (unlock) 874 mmap_write_unlock(mm); 875 return 0; 876 } 877 --- 885 unchanged lines hidden --- | 875 /* Find the first overlapping VMA */ 876 vma = vma_find(vmi, end); 877 if (!vma) { 878 if (unlock) 879 mmap_write_unlock(mm); 880 return 0; 881 } 882 --- 885 unchanged lines hidden --- |