]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ipc/shm: Use VMA iterator instead of linked list
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 4 Jan 2021 19:51:19 +0000 (14:51 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 1 Nov 2021 14:43:49 +0000 (10:43 -0400)
The VMA iterator is faster than the linked llist, and it can be walked
even when VMAs are being removed from the address space, so there's no
need to keep track of 'next'.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
ipc/shm.c

index ab749be6d8b71ffc351a0a6fa92b5027593966b6..363ea4889aaa97b3675538724aa954b14149d56d 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1630,7 +1630,7 @@ long ksys_shmdt(char __user *shmaddr)
 #ifdef CONFIG_MMU
        loff_t size = 0;
        struct file *file;
-       struct vm_area_struct *next;
+       VMA_ITERATOR(vmi, mm, addr);
 #endif
 
        if (addr & ~PAGE_MASK)
@@ -1660,12 +1660,9 @@ long ksys_shmdt(char __user *shmaddr)
         * match the usual checks anyway. So assume all vma's are
         * above the starting address given.
         */
-       vma = find_vma(mm, addr);
 
 #ifdef CONFIG_MMU
-       while (vma) {
-               next = vma->vm_next;
-
+       for_each_vma(vmi, vma) {
                /*
                 * Check if the starting address would match, i.e. it's
                 * a fragment created by mprotect() and/or munmap(), or it
@@ -1683,6 +1680,7 @@ long ksys_shmdt(char __user *shmaddr)
                        file = vma->vm_file;
                        size = i_size_read(file_inode(vma->vm_file));
                        do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start, NULL);
+                       mas_pause(&vmi.mas);
                        /*
                         * We discovered the size of the shm segment, so
                         * break out of here and fall through to the next
@@ -1690,10 +1688,9 @@ long ksys_shmdt(char __user *shmaddr)
                         * searching for matching vma's.
                         */
                        retval = 0;
-                       vma = next;
+                       vma = vma_next(&vmi);
                        break;
                }
-               vma = next;
        }
 
        /*
@@ -1703,17 +1700,19 @@ long ksys_shmdt(char __user *shmaddr)
         */
        size = PAGE_ALIGN(size);
        while (vma && (loff_t)(vma->vm_end - addr) <= size) {
-               next = vma->vm_next;
-
                /* finding a matching vma now does not alter retval */
                if ((vma->vm_ops == &shm_vm_ops) &&
                    ((vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) &&
-                   (vma->vm_file == file))
+                   (vma->vm_file == file)) {
                        do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start, NULL);
-               vma = next;
+                       mas_pause(&vmi.mas);
+               }
+
+               vma = vma_next(&vmi);
        }
 
 #else  /* CONFIG_MMU */
+       vma = vma_lookup(mm, addr);
        /* under NOMMU conditions, the exact address to be destroyed must be
         * given
         */