OSDN Git Service

riscv/mm/fault: Move access error check to function
authorPekka Enberg <penberg@kernel.org>
Tue, 25 Aug 2020 16:41:17 +0000 (19:41 +0300)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Wed, 16 Sep 2020 01:46:05 +0000 (18:46 -0700)
Move the access error check into a access_error() function to simplify
the control flow in do_page_fault().

Signed-off-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/mm/fault.c

index bdc70d3..a23eaf5 100644 (file)
@@ -156,6 +156,30 @@ static void inline vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
        local_flush_tlb_page(addr);
 }
 
+static inline bool access_error(unsigned long cause, struct vm_area_struct *vma)
+{
+       switch (cause) {
+       case EXC_INST_PAGE_FAULT:
+               if (!(vma->vm_flags & VM_EXEC)) {
+                       return true;
+               }
+               break;
+       case EXC_LOAD_PAGE_FAULT:
+               if (!(vma->vm_flags & VM_READ)) {
+                       return true;
+               }
+               break;
+       case EXC_STORE_PAGE_FAULT:
+               if (!(vma->vm_flags & VM_WRITE)) {
+                       return true;
+               }
+               break;
+       default:
+               panic("%s: unhandled cause %lu", __func__, cause);
+       }
+       return false;
+}
+
 /*
  * This routine handles page faults.  It determines the address and the
  * problem, and then passes it off to one of the appropriate routines.
@@ -236,27 +260,9 @@ retry:
 good_area:
        code = SEGV_ACCERR;
 
-       switch (cause) {
-       case EXC_INST_PAGE_FAULT:
-               if (!(vma->vm_flags & VM_EXEC)) {
-                       bad_area(regs, mm, code, addr);
-                       return;
-               }
-               break;
-       case EXC_LOAD_PAGE_FAULT:
-               if (!(vma->vm_flags & VM_READ)) {
-                       bad_area(regs, mm, code, addr);
-                       return;
-               }
-               break;
-       case EXC_STORE_PAGE_FAULT:
-               if (!(vma->vm_flags & VM_WRITE)) {
-                       bad_area(regs, mm, code, addr);
-                       return;
-               }
-               break;
-       default:
-               panic("%s: unhandled cause %lu", __func__, cause);
+       if (unlikely(access_error(cause, vma))) {
+               bad_area(regs, mm, code, addr);
+               return;
        }
 
        /*