From 0a6468d0bbcff51e1a570d5b4ccff3ff5b5c46bb Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 28 Sep 2020 15:50:19 -0400 Subject: [PATCH] mm: Move find_vma_intersection to mmap.c and change implementation to maple tree. When searching for a vma within a range, it is easier to use the maple tree interface. This means the find_vma() call changes to a special case of the find_vma_intersection() Signed-off-by: Liam R. Howlett --- include/linux/mm.h | 11 +++-------- mm/mmap.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index dbb83118eba0..4d82d0ef6df0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2647,14 +2647,9 @@ extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned lon /* Look up the first VMA which intersects the interval start_addr..end_addr-1, NULL if none. Assume start_addr < end_addr. */ -static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr) -{ - struct vm_area_struct * vma = find_vma(mm,start_addr); - - if (vma && end_addr <= vma->vm_start) - vma = NULL; - return vma; -} +extern struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, + unsigned long start_addr, + unsigned long end_addr); static inline unsigned long vm_start_gap(struct vm_area_struct *vma) { diff --git a/mm/mmap.c b/mm/mmap.c index a2bae6b7a608..e53535d98580 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2088,15 +2088,17 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, EXPORT_SYMBOL(get_unmapped_area); -/** - * find_vma() - Find the VMA for a given address, or the next vma. - * @mm The mm_struct to check - * @addr: The address +/* + * find_vma_intersection - Find the first vma between [@start, @end) + * @mm: The mm_struct to use. + * @start: The start address + * @end: The end address * - * Returns: The VMA assoicated with addr, or the next vma. - * May return NULL in the case of no vma at addr or above. + * Returns: The VMA associated with the @start or the next VMA within the range. */ -struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) +struct vm_area_struct *find_vma_intersection(struct mm_struct *mm, + unsigned long addr, + unsigned long end) { struct vm_area_struct *vma; @@ -2105,12 +2107,26 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) if (likely(vma)) return vma; - vma = mt_find(&mm->mm_mt, &addr, ULONG_MAX); + vma = mt_find(&mm->mm_mt, &addr, end - 1); if (vma) vmacache_update(addr, vma); return vma; } + +/** + * find_vma() - Find the VMA for a given address, or the next vma. + * @mm: The mm_struct to check + * @addr: The address + * + * Returns: The VMA associated with addr, or the next vma. + * May return NULL in the case of no vma at addr or above. + */ +struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) +{ + // Note find_vma_intersection will decrease 0 to underflow to ULONG_MAX + return find_vma_intersection(mm, addr, 0); +} EXPORT_SYMBOL(find_vma); /** -- 2.50.1