hc
2024-10-16 50a212ec906f7524620675f0c57357691c26c81f
kernel/arch/sh/mm/fault.c
....@@ -24,25 +24,10 @@
2424 #include <asm/tlbflush.h>
2525 #include <asm/traps.h>
2626
27
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
28
-{
29
- int ret = 0;
30
-
31
- if (kprobes_built_in() && !user_mode(regs)) {
32
- preempt_disable();
33
- if (kprobe_running() && kprobe_fault_handler(regs, trap))
34
- ret = 1;
35
- preempt_enable();
36
- }
37
-
38
- return ret;
39
-}
40
-
4127 static void
42
-force_sig_info_fault(int si_signo, int si_code, unsigned long address,
43
- struct task_struct *tsk)
28
+force_sig_info_fault(int si_signo, int si_code, unsigned long address)
4429 {
45
- force_sig_fault(si_signo, si_code, (void __user *)address, tsk);
30
+ force_sig_fault(si_signo, si_code, (void __user *)address);
4631 }
4732
4833 /*
....@@ -62,12 +47,13 @@
6247 pgd = swapper_pg_dir;
6348 }
6449
65
- printk(KERN_ALERT "pgd = %p\n", pgd);
50
+ pr_alert("pgd = %p\n", pgd);
6651 pgd += pgd_index(addr);
67
- printk(KERN_ALERT "[%08lx] *pgd=%0*Lx", addr,
68
- (u32)(sizeof(*pgd) * 2), (u64)pgd_val(*pgd));
52
+ pr_alert("[%08lx] *pgd=%0*llx", addr, (u32)(sizeof(*pgd) * 2),
53
+ (u64)pgd_val(*pgd));
6954
7055 do {
56
+ p4d_t *p4d;
7157 pud_t *pud;
7258 pmd_t *pmd;
7359 pte_t *pte;
....@@ -76,33 +62,46 @@
7662 break;
7763
7864 if (pgd_bad(*pgd)) {
79
- printk("(bad)");
65
+ pr_cont("(bad)");
8066 break;
8167 }
8268
83
- pud = pud_offset(pgd, addr);
69
+ p4d = p4d_offset(pgd, addr);
70
+ if (PTRS_PER_P4D != 1)
71
+ pr_cont(", *p4d=%0*Lx", (u32)(sizeof(*p4d) * 2),
72
+ (u64)p4d_val(*p4d));
73
+
74
+ if (p4d_none(*p4d))
75
+ break;
76
+
77
+ if (p4d_bad(*p4d)) {
78
+ pr_cont("(bad)");
79
+ break;
80
+ }
81
+
82
+ pud = pud_offset(p4d, addr);
8483 if (PTRS_PER_PUD != 1)
85
- printk(", *pud=%0*Lx", (u32)(sizeof(*pud) * 2),
86
- (u64)pud_val(*pud));
84
+ pr_cont(", *pud=%0*llx", (u32)(sizeof(*pud) * 2),
85
+ (u64)pud_val(*pud));
8786
8887 if (pud_none(*pud))
8988 break;
9089
9190 if (pud_bad(*pud)) {
92
- printk("(bad)");
91
+ pr_cont("(bad)");
9392 break;
9493 }
9594
9695 pmd = pmd_offset(pud, addr);
9796 if (PTRS_PER_PMD != 1)
98
- printk(", *pmd=%0*Lx", (u32)(sizeof(*pmd) * 2),
99
- (u64)pmd_val(*pmd));
97
+ pr_cont(", *pmd=%0*llx", (u32)(sizeof(*pmd) * 2),
98
+ (u64)pmd_val(*pmd));
10099
101100 if (pmd_none(*pmd))
102101 break;
103102
104103 if (pmd_bad(*pmd)) {
105
- printk("(bad)");
104
+ pr_cont("(bad)");
106105 break;
107106 }
108107
....@@ -111,17 +110,18 @@
111110 break;
112111
113112 pte = pte_offset_kernel(pmd, addr);
114
- printk(", *pte=%0*Lx", (u32)(sizeof(*pte) * 2),
115
- (u64)pte_val(*pte));
113
+ pr_cont(", *pte=%0*llx", (u32)(sizeof(*pte) * 2),
114
+ (u64)pte_val(*pte));
116115 } while (0);
117116
118
- printk("\n");
117
+ pr_cont("\n");
119118 }
120119
121120 static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
122121 {
123122 unsigned index = pgd_index(address);
124123 pgd_t *pgd_k;
124
+ p4d_t *p4d, *p4d_k;
125125 pud_t *pud, *pud_k;
126126 pmd_t *pmd, *pmd_k;
127127
....@@ -131,8 +131,13 @@
131131 if (!pgd_present(*pgd_k))
132132 return NULL;
133133
134
- pud = pud_offset(pgd, address);
135
- pud_k = pud_offset(pgd_k, address);
134
+ p4d = p4d_offset(pgd, address);
135
+ p4d_k = p4d_offset(pgd_k, address);
136
+ if (!p4d_present(*p4d_k))
137
+ return NULL;
138
+
139
+ pud = pud_offset(p4d, address);
140
+ pud_k = pud_offset(p4d_k, address);
136141 if (!pud_present(*pud_k))
137142 return NULL;
138143
....@@ -203,14 +208,11 @@
203208 if (!oops_may_print())
204209 return;
205210
206
- printk(KERN_ALERT "BUG: unable to handle kernel ");
207
- if (address < PAGE_SIZE)
208
- printk(KERN_CONT "NULL pointer dereference");
209
- else
210
- printk(KERN_CONT "paging request");
211
-
212
- printk(KERN_CONT " at %08lx\n", address);
213
- printk(KERN_ALERT "PC:");
211
+ pr_alert("BUG: unable to handle kernel %s at %08lx\n",
212
+ address < PAGE_SIZE ? "NULL pointer dereference"
213
+ : "paging request",
214
+ address);
215
+ pr_alert("PC:");
214216 printk_address(regs->pc, 1);
215217
216218 show_pte(NULL, address);
....@@ -244,8 +246,6 @@
244246 __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
245247 unsigned long address, int si_code)
246248 {
247
- struct task_struct *tsk = current;
248
-
249249 /* User mode accesses just cause a SIGSEGV */
250250 if (user_mode(regs)) {
251251 /*
....@@ -253,7 +253,7 @@
253253 */
254254 local_irq_enable();
255255
256
- force_sig_info_fault(SIGSEGV, si_code, address, tsk);
256
+ force_sig_info_fault(SIGSEGV, si_code, address);
257257
258258 return;
259259 }
....@@ -278,7 +278,7 @@
278278 * Something tried to access memory that isn't in our memory map..
279279 * Fix it, but check if it's kernel or user first..
280280 */
281
- up_read(&mm->mmap_sem);
281
+ mmap_read_unlock(mm);
282282
283283 __bad_area_nosemaphore(regs, error_code, address, si_code);
284284 }
....@@ -302,13 +302,13 @@
302302 struct task_struct *tsk = current;
303303 struct mm_struct *mm = tsk->mm;
304304
305
- up_read(&mm->mmap_sem);
305
+ mmap_read_unlock(mm);
306306
307307 /* Kernel mode? Handle exceptions or die: */
308308 if (!user_mode(regs))
309309 no_context(regs, error_code, address);
310310
311
- force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk);
311
+ force_sig_info_fault(SIGBUS, BUS_ADRERR, address);
312312 }
313313
314314 static noinline int
....@@ -319,13 +319,15 @@
319319 * Pagefault was interrupted by SIGKILL. We have no reason to
320320 * continue pagefault.
321321 */
322
- if (fatal_signal_pending(current)) {
323
- if (!(fault & VM_FAULT_RETRY))
324
- up_read(&current->mm->mmap_sem);
322
+ if (fault_signal_pending(fault, regs)) {
325323 if (!user_mode(regs))
326324 no_context(regs, error_code, address);
327325 return 1;
328326 }
327
+
328
+ /* Release mmap_lock first if necessary */
329
+ if (!(fault & VM_FAULT_RETRY))
330
+ mmap_read_unlock(current->mm);
329331
330332 if (!(fault & VM_FAULT_ERROR))
331333 return 0;
....@@ -333,11 +335,9 @@
333335 if (fault & VM_FAULT_OOM) {
334336 /* Kernel mode? Handle exceptions or die: */
335337 if (!user_mode(regs)) {
336
- up_read(&current->mm->mmap_sem);
337338 no_context(regs, error_code, address);
338339 return 1;
339340 }
340
- up_read(&current->mm->mmap_sem);
341341
342342 /*
343343 * We ran out of memory, call the OOM killer, and return the
....@@ -372,7 +372,7 @@
372372 return 1;
373373
374374 /* read, not present: */
375
- if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))))
375
+ if (unlikely(!vma_is_accessible(vma)))
376376 return 1;
377377
378378 return 0;
....@@ -397,7 +397,7 @@
397397 struct mm_struct *mm;
398398 struct vm_area_struct * vma;
399399 vm_fault_t fault;
400
- unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
400
+ unsigned int flags = FAULT_FLAG_DEFAULT;
401401
402402 tsk = current;
403403 mm = tsk->mm;
....@@ -415,14 +415,14 @@
415415 if (unlikely(fault_in_kernel_space(address))) {
416416 if (vmalloc_fault(address) >= 0)
417417 return;
418
- if (notify_page_fault(regs, vec))
418
+ if (kprobe_page_fault(regs, vec))
419419 return;
420420
421421 bad_area_nosemaphore(regs, error_code, address);
422422 return;
423423 }
424424
425
- if (unlikely(notify_page_fault(regs, vec)))
425
+ if (unlikely(kprobe_page_fault(regs, vec)))
426426 return;
427427
428428 /* Only enable interrupts if they were on before the fault */
....@@ -441,7 +441,7 @@
441441 }
442442
443443 retry:
444
- down_read(&mm->mmap_sem);
444
+ mmap_read_lock(mm);
445445
446446 vma = find_vma(mm, address);
447447 if (unlikely(!vma)) {
....@@ -481,28 +481,18 @@
481481 * make sure we exit gracefully rather than endlessly redo
482482 * the fault.
483483 */
484
- fault = handle_mm_fault(vma, address, flags);
484
+ fault = handle_mm_fault(vma, address, flags, regs);
485485
486486 if (unlikely(fault & (VM_FAULT_RETRY | VM_FAULT_ERROR)))
487487 if (mm_fault_error(regs, error_code, address, fault))
488488 return;
489489
490490 if (flags & FAULT_FLAG_ALLOW_RETRY) {
491
- if (fault & VM_FAULT_MAJOR) {
492
- tsk->maj_flt++;
493
- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1,
494
- regs, address);
495
- } else {
496
- tsk->min_flt++;
497
- perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1,
498
- regs, address);
499
- }
500491 if (fault & VM_FAULT_RETRY) {
501
- flags &= ~FAULT_FLAG_ALLOW_RETRY;
502492 flags |= FAULT_FLAG_TRIED;
503493
504494 /*
505
- * No need to up_read(&mm->mmap_sem) as we would
495
+ * No need to mmap_read_unlock(mm) as we would
506496 * have already released it in __lock_page_or_retry
507497 * in mm/filemap.c.
508498 */
....@@ -510,5 +500,5 @@
510500 }
511501 }
512502
513
- up_read(&mm->mmap_sem);
503
+ mmap_read_unlock(mm);
514504 }