]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: Change find_vma_intersection to maple tree and make find_vma to
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 28 Sep 2020 19:50:19 +0000 (15:50 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 29 Jan 2021 16:07:54 +0000 (11:07 -0500)
inline.

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().  Exported for kvm module.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
include/linux/mm.h
mm/mmap.c

index 2e3151fdb8cc60e5c113ed4f160e7a7a1d1e6cf7..0f970ed0a61915a7a8bdf41634e43e0760c28a4c 100644 (file)
@@ -2652,14 +2652,8 @@ 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)
 {
index f3dd55683b5a1438889da631372b4cf4967ccfc2..236754f0016a825a1a05806e2bcc0fb23951b4ae 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2083,32 +2083,50 @@ 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 associated 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.
+ * May return %NULL in the case of no 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 start_addr,
+                                            unsigned long end_addr)
 {
        struct vm_area_struct *vma;
-       MA_STATE(mas, &mm->mm_mt, addr, addr);
+       MA_STATE(mas, &mm->mm_mt, start_addr, start_addr);
 
        /* Check the cache first. */
-       vma = vmacache_find(mm, addr);
+       vma = vmacache_find(mm, start_addr);
        if (likely(vma))
                return vma;
 
        rcu_read_lock();
-       vma = mas_find(&mas, -1);
+       vma = mas_find(&mas, end_addr - 1);
        rcu_read_unlock();
        if (vma)
-               vmacache_update(addr, vma);
+               vmacache_update(mas.index, vma);
 
        return vma;
 }
+EXPORT_SYMBOL(find_vma_intersection);
+
+/**
+ * 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.
+ */
+inline 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);
 
 /**