]> git.baikalelectronics.ru Git - kernel.git/commitdiff
cxl: remove vma linked list walk
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 6 Sep 2022 19:48:55 +0000 (19:48 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Sep 2022 02:46:20 +0000 (19:46 -0700)
Use the VMA iterator instead.  This requires a little restructuring of the
surrounding code to hoist the mm to the caller.  That turns
cxl_prefault_one() into a trivial function, so call cxl_fault_segment()
directly.

Link: https://lkml.kernel.org/r/20220906194824.2110408-38-Liam.Howlett@oracle.com
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Yu Zhao <yuzhao@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/misc/cxl/fault.c

index 60c829113299bd771580030b1d616cf272d1daf3..2c64f55cf01f8db08cc5a88a7da47bf5a32d3b53 100644 (file)
@@ -280,22 +280,6 @@ void cxl_handle_fault(struct work_struct *fault_work)
                mmput(mm);
 }
 
-static void cxl_prefault_one(struct cxl_context *ctx, u64 ea)
-{
-       struct mm_struct *mm;
-
-       mm = get_mem_context(ctx);
-       if (mm == NULL) {
-               pr_devel("cxl_prefault_one unable to get mm %i\n",
-                        pid_nr(ctx->pid));
-               return;
-       }
-
-       cxl_fault_segment(ctx, mm, ea);
-
-       mmput(mm);
-}
-
 static u64 next_segment(u64 ea, u64 vsid)
 {
        if (vsid & SLB_VSID_B_1T)
@@ -306,23 +290,16 @@ static u64 next_segment(u64 ea, u64 vsid)
        return ea + 1;
 }
 
-static void cxl_prefault_vma(struct cxl_context *ctx)
+static void cxl_prefault_vma(struct cxl_context *ctx, struct mm_struct *mm)
 {
        u64 ea, last_esid = 0;
        struct copro_slb slb;
+       VMA_ITERATOR(vmi, mm, 0);
        struct vm_area_struct *vma;
        int rc;
-       struct mm_struct *mm;
-
-       mm = get_mem_context(ctx);
-       if (mm == NULL) {
-               pr_devel("cxl_prefault_vm unable to get mm %i\n",
-                        pid_nr(ctx->pid));
-               return;
-       }
 
        mmap_read_lock(mm);
-       for (vma = mm->mmap; vma; vma = vma->vm_next) {
+       for_each_vma(vmi, vma) {
                for (ea = vma->vm_start; ea < vma->vm_end;
                                ea = next_segment(ea, slb.vsid)) {
                        rc = copro_calculate_slb(mm, ea, &slb);
@@ -337,20 +314,28 @@ static void cxl_prefault_vma(struct cxl_context *ctx)
                }
        }
        mmap_read_unlock(mm);
-
-       mmput(mm);
 }
 
 void cxl_prefault(struct cxl_context *ctx, u64 wed)
 {
+       struct mm_struct *mm = get_mem_context(ctx);
+
+       if (mm == NULL) {
+               pr_devel("cxl_prefault unable to get mm %i\n",
+                        pid_nr(ctx->pid));
+               return;
+       }
+
        switch (ctx->afu->prefault_mode) {
        case CXL_PREFAULT_WED:
-               cxl_prefault_one(ctx, wed);
+               cxl_fault_segment(ctx, mm, wed);
                break;
        case CXL_PREFAULT_ALL:
-               cxl_prefault_vma(ctx);
+               cxl_prefault_vma(ctx, mm);
                break;
        default:
                break;
        }
+
+       mmput(mm);
 }