aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm/fault.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/mm/fault.c')
-rw-r--r--arch/x86/mm/fault.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 852b319edbdc..7d90ceb882a4 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -919,9 +919,9 @@ spurious_fault(unsigned long error_code, unsigned long address)
919int show_unhandled_signals = 1; 919int show_unhandled_signals = 1;
920 920
921static inline int 921static inline int
922access_error(unsigned long error_code, int write, struct vm_area_struct *vma) 922access_error(unsigned long error_code, struct vm_area_struct *vma)
923{ 923{
924 if (write) { 924 if (error_code & PF_WRITE) {
925 /* write, present and write, not present: */ 925 /* write, present and write, not present: */
926 if (unlikely(!(vma->vm_flags & VM_WRITE))) 926 if (unlikely(!(vma->vm_flags & VM_WRITE)))
927 return 1; 927 return 1;
@@ -956,8 +956,10 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
956 struct task_struct *tsk; 956 struct task_struct *tsk;
957 unsigned long address; 957 unsigned long address;
958 struct mm_struct *mm; 958 struct mm_struct *mm;
959 int write;
960 int fault; 959 int fault;
960 int write = error_code & PF_WRITE;
961 unsigned int flags = FAULT_FLAG_ALLOW_RETRY |
962 (write ? FAULT_FLAG_WRITE : 0);
961 963
962 tsk = current; 964 tsk = current;
963 mm = tsk->mm; 965 mm = tsk->mm;
@@ -1068,6 +1070,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
1068 bad_area_nosemaphore(regs, error_code, address); 1070 bad_area_nosemaphore(regs, error_code, address);
1069 return; 1071 return;
1070 } 1072 }
1073retry:
1071 down_read(&mm->mmap_sem); 1074 down_read(&mm->mmap_sem);
1072 } else { 1075 } else {
1073 /* 1076 /*
@@ -1111,9 +1114,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
1111 * we can handle it.. 1114 * we can handle it..
1112 */ 1115 */
1113good_area: 1116good_area:
1114 write = error_code & PF_WRITE; 1117 if (unlikely(access_error(error_code, vma))) {
1115
1116 if (unlikely(access_error(error_code, write, vma))) {
1117 bad_area_access_error(regs, error_code, address); 1118 bad_area_access_error(regs, error_code, address);
1118 return; 1119 return;
1119 } 1120 }
@@ -1123,21 +1124,34 @@ good_area:
1123 * make sure we exit gracefully rather than endlessly redo 1124 * make sure we exit gracefully rather than endlessly redo
1124 * the fault: 1125 * the fault:
1125 */ 1126 */
1126 fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0); 1127 fault = handle_mm_fault(mm, vma, address, flags);
1127 1128
1128 if (unlikely(fault & VM_FAULT_ERROR)) { 1129 if (unlikely(fault & VM_FAULT_ERROR)) {
1129 mm_fault_error(regs, error_code, address, fault); 1130 mm_fault_error(regs, error_code, address, fault);
1130 return; 1131 return;
1131 } 1132 }
1132 1133
1133 if (fault & VM_FAULT_MAJOR) { 1134 /*
1134 tsk->maj_flt++; 1135 * Major/minor page fault accounting is only done on the
1135 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0, 1136 * initial attempt. If we go through a retry, it is extremely
1136 regs, address); 1137 * likely that the page will be found in page cache at that point.
1137 } else { 1138 */
1138 tsk->min_flt++; 1139 if (flags & FAULT_FLAG_ALLOW_RETRY) {
1139 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0, 1140 if (fault & VM_FAULT_MAJOR) {
1140 regs, address); 1141 tsk->maj_flt++;
1142 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, 0,
1143 regs, address);
1144 } else {
1145 tsk->min_flt++;
1146 perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, 0,
1147 regs, address);
1148 }
1149 if (fault & VM_FAULT_RETRY) {
1150 /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
1151 * of starvation. */
1152 flags &= ~FAULT_FLAG_ALLOW_RETRY;
1153 goto retry;
1154 }
1141 } 1155 }
1142 1156
1143 check_v8086_mode(regs, address, tsk); 1157 check_v8086_mode(regs, address, tsk);