]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: Use maple tree operations for find_vma_intersection()
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>
Mon, 14 Mar 2022 18:49:45 +0000 (14:49 -0400)
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.

Exported find_vma_intersection() for kvm module.

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

index 965298bba99527c11fd96aa20dd5ba705a8ad9ca..1d37cc4ff87107c9e0b011278433b4e33d72e124 100644 (file)
@@ -2784,26 +2784,12 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
                                             struct vm_area_struct **pprev);
 
-/**
- * find_vma_intersection() - Look up the first VMA which intersects the interval
- * @mm: The process address space.
- * @start_addr: The inclusive start user address.
- * @end_addr: The exclusive end user address.
- *
- * Returns: The first VMA within the provided range, %NULL otherwise.  Assumes
- * start_addr < end_addr.
+/*
+ * Look up the first VMA which intersects the interval [start_addr, end_addr)
+ * 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;
-}
+                       unsigned long start_addr, unsigned long end_addr);
 
 /**
  * vma_lookup() - Find a VMA at a specific address
index 4ab29e2c66becf36948725d30b49ca1d06e151cb..f51df67e50f8343825ccfac5c7b74065d57a4a6c 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2030,6 +2030,35 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
 
 EXPORT_SYMBOL(get_unmapped_area);
 
+/**
+ * find_vma_intersection() - Look up the first VMA which intersects the interval
+ * @mm: The process address space.
+ * @start_addr: The inclusive start user address.
+ * @end_addr: The exclusive end user address.
+ *
+ * Returns: The first VMA within the provided range, %NULL otherwise.  Assumes
+ * start_addr < end_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;
+       unsigned long index = start_addr;
+
+       mmap_assert_locked(mm);
+       /* Check the cache first. */
+       vma = vmacache_find(mm, start_addr);
+       if (likely(vma))
+               return vma;
+
+       vma = mt_find(&mm->mm_mt, &index, end_addr - 1);
+       if (vma)
+               vmacache_update(start_addr, 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
index 9b8c033ef99730e42158512fa85511cf13743dd8..7d8f756f13f36ee6440c3fd1e17a2d76e13abbc3 100644 (file)
@@ -627,6 +627,17 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
        vm_area_free(vma);
 }
 
+struct vm_area_struct *find_vma_intersection(struct mm_struct *mm,
+                                            unsigned long start_addr,
+                                            unsigned long end_addr)
+{
+       unsigned long index = start_addr;
+
+       mmap_assert_locked(mm);
+       return mt_find(&mm->mm_mt, &index, end_addr - 1);
+}
+EXPORT_SYMBOL(find_vma_intersection);
+
 /*
  * look up the first VMA in which addr resides, NULL if none
  * - should be called with mm->mmap_lock at least held readlocked