]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
arm64: mm: Update perf accounting to handle poison faults
authorPunit Agrawal <punit.agrawal@arm.com>
Thu, 8 Jun 2017 17:25:28 +0000 (18:25 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 9 Aug 2017 14:23:28 +0000 (16:23 +0200)
Re-organise the perf accounting for fault handling in preparation for
enabling handling of hardware poison faults in subsequent commits. The
change updates perf accounting to be inline with the behaviour on
x86.

With this update, the perf fault accounting -

  * Always report PERF_COUNT_SW_PAGE_FAULTS

  * Doesn't report anything else for VM_FAULT_ERROR (which includes
    hwpoison faults)

  * Reports PERF_COUNT_SW_PAGE_FAULTS_MAJ if it's a major
    fault (indicated by VM_FAULT_MAJOR)

  * Otherwise, reports PERF_COUNT_SW_PAGE_FAULTS_MIN

BugLink: http://launchpad.net/bugs/1696852
Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 0e3a9026396cd7d0eb5777ba923a8f30a3d9db19)
Signed-off-by: Manoj Iyer <manoj.iyer@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
arch/arm64/mm/fault.c

index d60f29e19809e1680b1cd046639f103bb263526a..14213c5f5c491f76e3b1637a5505bf712a7a6754 100644 (file)
@@ -313,7 +313,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
 {
        struct task_struct *tsk;
        struct mm_struct *mm;
-       int fault, sig, code;
+       int fault, sig, code, major = 0;
        unsigned long vm_flags = VM_READ | VM_WRITE;
        unsigned int mm_flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
 
@@ -352,6 +352,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,
                        die("Accessing user space memory outside uaccess.h routines", regs, esr);
        }
 
+       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
+
        /*
         * As per x86, we may deadlock here. However, since the kernel only
         * validly references user space from well defined areas of the code,
@@ -375,24 +377,42 @@ retry:
        }
 
        fault = __do_page_fault(mm, addr, mm_flags, vm_flags, tsk);
+       major |= fault & VM_FAULT_MAJOR;
 
-       /*
-        * If we need to retry but a fatal signal is pending, handle the
-        * signal first. We do not need to release the mmap_sem because it
-        * would already be released in __lock_page_or_retry in mm/filemap.c.
-        */
-       if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
-               return 0;
+       if (fault & VM_FAULT_RETRY) {
+               /*
+                * If we need to retry but a fatal signal is pending,
+                * handle the signal first. We do not need to release
+                * the mmap_sem because it would already be released
+                * in __lock_page_or_retry in mm/filemap.c.
+                */
+               if (fatal_signal_pending(current))
+                       return 0;
+
+               /*
+                * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of
+                * starvation.
+                */
+               if (mm_flags & FAULT_FLAG_ALLOW_RETRY) {
+                       mm_flags &= ~FAULT_FLAG_ALLOW_RETRY;
+                       mm_flags |= FAULT_FLAG_TRIED;
+                       goto retry;
+               }
+       }
+       up_read(&mm->mmap_sem);
 
        /*
-        * Major/minor page fault accounting is only done on the initial
-        * attempt. If we go through a retry, it is extremely likely that the
-        * page will be found in page cache at that point.
+        * Handle the "normal" (no error) case first.
         */
-
-       perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
-       if (mm_flags & FAULT_FLAG_ALLOW_RETRY) {
-               if (fault & VM_FAULT_MAJOR) {
+       if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP |
+                             VM_FAULT_BADACCESS)))) {
+               /*
+                * Major/minor page fault accounting is only done
+                * once. If we go through a retry, it is extremely
+                * likely that the page will be found in page cache at
+                * that point.
+                */
+               if (major) {
                        tsk->maj_flt++;
                        perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs,
                                      addr);
@@ -401,25 +421,9 @@ retry:
                        perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs,
                                      addr);
                }
-               if (fault & VM_FAULT_RETRY) {
-                       /*
-                        * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk of
-                        * starvation.
-                        */
-                       mm_flags &= ~FAULT_FLAG_ALLOW_RETRY;
-                       mm_flags |= FAULT_FLAG_TRIED;
-                       goto retry;
-               }
-       }
-
-       up_read(&mm->mmap_sem);
 
-       /*
-        * Handle the "normal" case first - VM_FAULT_MAJOR
-        */
-       if (likely(!(fault & (VM_FAULT_ERROR | VM_FAULT_BADMAP |
-                             VM_FAULT_BADACCESS))))
                return 0;
+       }
 
        /*
         * If we are in kernel mode at this point, we have no context to