hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/mips/mm/fault.c
....@@ -44,7 +44,7 @@
4444 const int field = sizeof(unsigned long) * 2;
4545 int si_code;
4646 vm_fault_t fault;
47
- unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
47
+ unsigned int flags = FAULT_FLAG_DEFAULT;
4848
4949 static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);
5050
....@@ -96,8 +96,10 @@
9696
9797 if (user_mode(regs))
9898 flags |= FAULT_FLAG_USER;
99
+
100
+ perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
99101 retry:
100
- down_read(&mm->mmap_sem);
102
+ mmap_read_lock(mm);
101103 vma = find_vma(mm, address);
102104 if (!vma)
103105 goto bad_area;
....@@ -142,7 +144,7 @@
142144 goto bad_area;
143145 }
144146 } else {
145
- if (!(vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)))
147
+ if (unlikely(!vma_is_accessible(vma)))
146148 goto bad_area;
147149 }
148150 }
....@@ -152,12 +154,11 @@
152154 * make sure we exit gracefully rather than endlessly redo
153155 * the fault.
154156 */
155
- fault = handle_mm_fault(vma, address, flags);
157
+ fault = handle_mm_fault(vma, address, flags, regs);
156158
157
- if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
159
+ if (fault_signal_pending(fault, regs))
158160 return;
159161
160
- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
161162 if (unlikely(fault & VM_FAULT_ERROR)) {
162163 if (fault & VM_FAULT_OOM)
163164 goto out_of_memory;
....@@ -168,21 +169,11 @@
168169 BUG();
169170 }
170171 if (flags & FAULT_FLAG_ALLOW_RETRY) {
171
- if (fault & VM_FAULT_MAJOR) {
172
- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
173
- regs, address);
174
- tsk->maj_flt++;
175
- } else {
176
- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
177
- regs, address);
178
- tsk->min_flt++;
179
- }
180172 if (fault & VM_FAULT_RETRY) {
181
- flags &= ~FAULT_FLAG_ALLOW_RETRY;
182173 flags |= FAULT_FLAG_TRIED;
183174
184175 /*
185
- * No need to up_read(&mm->mmap_sem) as we would
176
+ * No need to mmap_read_unlock(mm) as we would
186177 * have already released it in __lock_page_or_retry
187178 * in mm/filemap.c.
188179 */
....@@ -191,7 +182,7 @@
191182 }
192183 }
193184
194
- up_read(&mm->mmap_sem);
185
+ mmap_read_unlock(mm);
195186 return;
196187
197188 /*
....@@ -199,7 +190,7 @@
199190 * Fix it, but check if it's kernel or user first..
200191 */
201192 bad_area:
202
- up_read(&mm->mmap_sem);
193
+ mmap_read_unlock(mm);
203194
204195 bad_area_nosemaphore:
205196 /* User mode accesses just cause a SIGSEGV */
....@@ -223,7 +214,7 @@
223214 pr_cont("\n");
224215 }
225216 current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
226
- force_sig_fault(SIGSEGV, si_code, (void __user *)address, tsk);
217
+ force_sig_fault(SIGSEGV, si_code, (void __user *)address);
227218 return;
228219 }
229220
....@@ -251,14 +242,14 @@
251242 * We ran out of memory, call the OOM killer, and return the userspace
252243 * (which will retry the fault, or kill us if we got oom-killed).
253244 */
254
- up_read(&mm->mmap_sem);
245
+ mmap_read_unlock(mm);
255246 if (!user_mode(regs))
256247 goto no_context;
257248 pagefault_out_of_memory();
258249 return;
259250
260251 do_sigbus:
261
- up_read(&mm->mmap_sem);
252
+ mmap_read_unlock(mm);
262253
263254 /* Kernel mode? Handle exceptions or die */
264255 if (!user_mode(regs))
....@@ -279,7 +270,7 @@
279270 #endif
280271 current->thread.trap_nr = (regs->cp0_cause >> 2) & 0x1f;
281272 tsk->thread.cp0_badvaddr = address;
282
- force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, tsk);
273
+ force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address);
283274
284275 return;
285276 #ifndef CONFIG_64BIT
....@@ -292,8 +283,9 @@
292283 * Do _not_ use "tsk" here. We might be inside
293284 * an interrupt in the middle of a task switch..
294285 */
295
- int offset = __pgd_offset(address);
286
+ int offset = pgd_index(address);
296287 pgd_t *pgd, *pgd_k;
288
+ p4d_t *p4d, *p4d_k;
297289 pud_t *pud, *pud_k;
298290 pmd_t *pmd, *pmd_k;
299291 pte_t *pte_k;
....@@ -305,8 +297,13 @@
305297 goto no_context;
306298 set_pgd(pgd, *pgd_k);
307299
308
- pud = pud_offset(pgd, address);
309
- pud_k = pud_offset(pgd_k, address);
300
+ p4d = p4d_offset(pgd, address);
301
+ p4d_k = p4d_offset(pgd_k, address);
302
+ if (!p4d_present(*p4d_k))
303
+ goto no_context;
304
+
305
+ pud = pud_offset(p4d, address);
306
+ pud_k = pud_offset(p4d_k, address);
310307 if (!pud_present(*pud_k))
311308 goto no_context;
312309