hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/m68k/mm/fault.c
....@@ -12,10 +12,10 @@
1212 #include <linux/interrupt.h>
1313 #include <linux/module.h>
1414 #include <linux/uaccess.h>
15
+#include <linux/perf_event.h>
1516
1617 #include <asm/setup.h>
1718 #include <asm/traps.h>
18
-#include <asm/pgalloc.h>
1919
2020 extern void die_if_kernel(char *, struct pt_regs *, long);
2121
....@@ -30,13 +30,13 @@
3030 pr_debug("send_fault_sig: %p,%d,%d\n", addr, signo, si_code);
3131
3232 if (user_mode(regs)) {
33
- force_sig_fault(signo, si_code, addr, current);
33
+ force_sig_fault(signo, si_code, addr);
3434 } else {
3535 if (fixup_exception(regs))
3636 return -1;
3737
3838 //if (signo == SIGBUS)
39
- // force_sig_fault(si_signo, si_code, addr, current);
39
+ // force_sig_fault(si_signo, si_code, addr);
4040
4141 /*
4242 * Oops. The kernel tried to access some bad page. We'll have to
....@@ -48,7 +48,7 @@
4848 pr_alert("Unable to handle kernel access");
4949 pr_cont(" at virtual address %p\n", addr);
5050 die_if_kernel("Oops", regs, 0 /*error_code*/);
51
- do_exit(SIGKILL);
51
+ make_task_dead(SIGKILL);
5252 }
5353
5454 return 1;
....@@ -71,7 +71,7 @@
7171 struct mm_struct *mm = current->mm;
7272 struct vm_area_struct * vma;
7373 vm_fault_t fault;
74
- unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
74
+ unsigned int flags = FAULT_FLAG_DEFAULT;
7575
7676 pr_debug("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n",
7777 regs->sr, regs->pc, address, error_code, mm ? mm->pgd : NULL);
....@@ -85,8 +85,10 @@
8585
8686 if (user_mode(regs))
8787 flags |= FAULT_FLAG_USER;
88
+
89
+ perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
8890 retry:
89
- down_read(&mm->mmap_sem);
91
+ mmap_read_lock(mm);
9092
9193 vma = find_vma(mm, address);
9294 if (!vma)
....@@ -116,7 +118,7 @@
116118 pr_debug("do_page_fault: good_area\n");
117119 switch (error_code & 3) {
118120 default: /* 3: write, present */
119
- /* fall through */
121
+ fallthrough;
120122 case 2: /* write, not present */
121123 if (!(vma->vm_flags & VM_WRITE))
122124 goto acc_err;
....@@ -125,7 +127,7 @@
125127 case 1: /* read, present */
126128 goto acc_err;
127129 case 0: /* read, not present */
128
- if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))
130
+ if (unlikely(!vma_is_accessible(vma)))
129131 goto acc_err;
130132 }
131133
....@@ -135,10 +137,10 @@
135137 * the fault.
136138 */
137139
138
- fault = handle_mm_fault(vma, address, flags);
140
+ fault = handle_mm_fault(vma, address, flags, regs);
139141 pr_debug("handle_mm_fault returns %x\n", fault);
140142
141
- if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
143
+ if (fault_signal_pending(fault, regs))
142144 return 0;
143145
144146 if (unlikely(fault & VM_FAULT_ERROR)) {
....@@ -151,24 +153,12 @@
151153 BUG();
152154 }
153155
154
- /*
155
- * Major/minor page fault accounting is only done on the
156
- * initial attempt. If we go through a retry, it is extremely
157
- * likely that the page will be found in page cache at that point.
158
- */
159156 if (flags & FAULT_FLAG_ALLOW_RETRY) {
160
- if (fault & VM_FAULT_MAJOR)
161
- current->maj_flt++;
162
- else
163
- current->min_flt++;
164157 if (fault & VM_FAULT_RETRY) {
165
- /* Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
166
- * of starvation. */
167
- flags &= ~FAULT_FLAG_ALLOW_RETRY;
168158 flags |= FAULT_FLAG_TRIED;
169159
170160 /*
171
- * No need to up_read(&mm->mmap_sem) as we would
161
+ * No need to mmap_read_unlock(mm) as we would
172162 * have already released it in __lock_page_or_retry
173163 * in mm/filemap.c.
174164 */
....@@ -177,7 +167,7 @@
177167 }
178168 }
179169
180
- up_read(&mm->mmap_sem);
170
+ mmap_read_unlock(mm);
181171 return 0;
182172
183173 /*
....@@ -185,7 +175,7 @@
185175 * us unable to handle the page fault gracefully.
186176 */
187177 out_of_memory:
188
- up_read(&mm->mmap_sem);
178
+ mmap_read_unlock(mm);
189179 if (!user_mode(regs))
190180 goto no_context;
191181 pagefault_out_of_memory();
....@@ -214,6 +204,6 @@
214204 current->thread.faddr = address;
215205
216206 send_sig:
217
- up_read(&mm->mmap_sem);
207
+ mmap_read_unlock(mm);
218208 return send_fault_sig(regs);
219209 }