2 * Copyright (C) 1995 Linus Torvalds
3 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs.
6 #include <linux/signal.h>
7 #include <linux/sched.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/string.h>
11 #include <linux/types.h>
12 #include <linux/ptrace.h>
13 #include <linux/mman.h>
15 #include <linux/smp.h>
16 #include <linux/interrupt.h>
17 #include <linux/init.h>
18 #include <linux/tty.h>
19 #include <linux/vt_kern.h> /* For unblank_screen() */
20 #include <linux/compiler.h>
21 #include <linux/highmem.h>
22 #include <linux/bootmem.h> /* for max_low_pfn */
23 #include <linux/vmalloc.h>
24 #include <linux/module.h>
25 #include <linux/kprobes.h>
26 #include <linux/uaccess.h>
27 #include <linux/kdebug.h>
29 #include <asm/system.h>
31 #include <asm/segment.h>
32 #include <asm/pgalloc.h>
34 #include <asm/tlbflush.h>
35 #include <asm/proto.h>
36 #include <asm-generic/sections.h>
39 * Page fault error code bits
40 * bit 0 == 0 means no page found, 1 means protection fault
41 * bit 1 == 0 means read, 1 means write
42 * bit 2 == 0 means kernel, 1 means user-mode
43 * bit 3 == 1 means use of reserved bit detected
44 * bit 4 == 1 means fault was an instruction fetch
46 #define PF_PROT (1<<0)
47 #define PF_WRITE (1<<1)
48 #define PF_USER (1<<2)
49 #define PF_RSVD (1<<3)
50 #define PF_INSTR (1<<4)
52 #ifdef CONFIG_MMIOTRACE_HOOKS
53 static pf_handler_func mmiotrace_pf_handler
; /* protected by RCU */
54 static DEFINE_SPINLOCK(mmiotrace_handler_lock
);
56 int mmiotrace_register_pf(pf_handler_func new_pfh
)
60 spin_lock_irqsave(&mmiotrace_handler_lock
, flags
);
61 if (mmiotrace_pf_handler
)
64 mmiotrace_pf_handler
= new_pfh
;
65 spin_unlock_irqrestore(&mmiotrace_handler_lock
, flags
);
68 EXPORT_SYMBOL_GPL(mmiotrace_register_pf
);
71 * mmiotrace_unregister_pf:
72 * The caller must ensure @old_pfh is not in use anymore before freeing it.
73 * This function does not guarantee it. The handler function pointer is
74 * protected by RCU, so you can do this by e.g. calling synchronize_rcu().
76 int mmiotrace_unregister_pf(pf_handler_func old_pfh
)
80 spin_lock_irqsave(&mmiotrace_handler_lock
, flags
);
81 if (mmiotrace_pf_handler
!= old_pfh
)
84 mmiotrace_pf_handler
= NULL
;
85 spin_unlock_irqrestore(&mmiotrace_handler_lock
, flags
);
88 EXPORT_SYMBOL_GPL(mmiotrace_unregister_pf
);
89 #endif /* CONFIG_MMIOTRACE_HOOKS */
91 /* returns non-zero if do_page_fault() should return */
92 static inline int call_mmiotrace(struct pt_regs
*regs
,
93 unsigned long error_code
,
94 unsigned long address
)
96 #ifdef CONFIG_MMIOTRACE_HOOKS
99 if (mmiotrace_pf_handler
)
100 ret
= mmiotrace_pf_handler(regs
, error_code
, address
);
108 static inline int notify_page_fault(struct pt_regs
*regs
)
110 #ifdef CONFIG_KPROBES
113 /* kprobe_running() needs smp_processor_id() */
115 if (!user_mode_vm(regs
)) {
117 if (!user_mode(regs
)) {
120 if (kprobe_running() && kprobe_fault_handler(regs
, 14))
133 * Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
134 * Check that here and ignore it.
137 * Sometimes the CPU reports invalid exceptions on prefetch.
138 * Check that here and ignore it.
140 * Opcode checker based on code by Richard Brunner
142 static int is_prefetch(struct pt_regs
*regs
, unsigned long addr
,
143 unsigned long error_code
)
145 unsigned char *instr
;
148 unsigned char *max_instr
;
151 * If it was a exec (instruction fetch) fault on NX page, then
152 * do not ignore the fault:
154 if (error_code
& PF_INSTR
)
157 instr
= (unsigned char *)convert_ip_to_linear(current
, regs
);
158 max_instr
= instr
+ 15;
160 if (user_mode(regs
) && instr
>= (unsigned char *)TASK_SIZE
)
163 while (scan_more
&& instr
< max_instr
) {
164 unsigned char opcode
;
165 unsigned char instr_hi
;
166 unsigned char instr_lo
;
168 if (probe_kernel_address(instr
, opcode
))
171 instr_hi
= opcode
& 0xf0;
172 instr_lo
= opcode
& 0x0f;
179 * Values 0x26,0x2E,0x36,0x3E are valid x86 prefixes.
180 * In X86_64 long mode, the CPU will signal invalid
181 * opcode if some of these prefixes are present so
182 * X86_64 will never get here anyway
184 scan_more
= ((instr_lo
& 7) == 0x6);
189 * In AMD64 long mode 0x40..0x4F are valid REX prefixes
190 * Need to figure out under what instruction mode the
191 * instruction was issued. Could check the LDT for lm,
192 * but for now it's good enough to assume that long
193 * mode only uses well known segments or kernel.
195 scan_more
= (!user_mode(regs
)) || (regs
->cs
== __USER_CS
);
199 /* 0x64 thru 0x67 are valid prefixes in all modes. */
200 scan_more
= (instr_lo
& 0xC) == 0x4;
203 /* 0xF0, 0xF2, 0xF3 are valid prefixes in all modes. */
204 scan_more
= !instr_lo
|| (instr_lo
>>1) == 1;
207 /* Prefetch instruction is 0x0F0D or 0x0F18 */
210 if (probe_kernel_address(instr
, opcode
))
212 prefetch
= (instr_lo
== 0xF) &&
213 (opcode
== 0x0D || opcode
== 0x18);
223 static void force_sig_info_fault(int si_signo
, int si_code
,
224 unsigned long address
, struct task_struct
*tsk
)
228 info
.si_signo
= si_signo
;
230 info
.si_code
= si_code
;
231 info
.si_addr
= (void __user
*)address
;
232 force_sig_info(si_signo
, &info
, tsk
);
236 static int bad_address(void *p
)
239 return probe_kernel_address((unsigned long *)p
, dummy
);
243 static void dump_pagetable(unsigned long address
)
246 __typeof__(pte_val(__pte(0))) page
;
249 page
= ((__typeof__(page
) *) __va(page
))[address
>> PGDIR_SHIFT
];
250 #ifdef CONFIG_X86_PAE
251 printk("*pdpt = %016Lx ", page
);
252 if ((page
>> PAGE_SHIFT
) < max_low_pfn
253 && page
& _PAGE_PRESENT
) {
255 page
= ((__typeof__(page
) *) __va(page
))[(address
>> PMD_SHIFT
)
256 & (PTRS_PER_PMD
- 1)];
257 printk(KERN_CONT
"*pde = %016Lx ", page
);
261 printk("*pde = %08lx ", page
);
265 * We must not directly access the pte in the highpte
266 * case if the page table is located in highmem.
267 * And let's rather not kmap-atomic the pte, just in case
268 * it's allocated already.
270 if ((page
>> PAGE_SHIFT
) < max_low_pfn
271 && (page
& _PAGE_PRESENT
)
272 && !(page
& _PAGE_PSE
)) {
274 page
= ((__typeof__(page
) *) __va(page
))[(address
>> PAGE_SHIFT
)
275 & (PTRS_PER_PTE
- 1)];
276 printk("*pte = %0*Lx ", sizeof(page
)*2, (u64
)page
);
280 #else /* CONFIG_X86_64 */
286 pgd
= (pgd_t
*)read_cr3();
288 pgd
= __va((unsigned long)pgd
& PHYSICAL_PAGE_MASK
);
289 pgd
+= pgd_index(address
);
290 if (bad_address(pgd
)) goto bad
;
291 printk("PGD %lx ", pgd_val(*pgd
));
292 if (!pgd_present(*pgd
)) goto ret
;
294 pud
= pud_offset(pgd
, address
);
295 if (bad_address(pud
)) goto bad
;
296 printk("PUD %lx ", pud_val(*pud
));
297 if (!pud_present(*pud
) || pud_large(*pud
))
300 pmd
= pmd_offset(pud
, address
);
301 if (bad_address(pmd
)) goto bad
;
302 printk("PMD %lx ", pmd_val(*pmd
));
303 if (!pmd_present(*pmd
) || pmd_large(*pmd
)) goto ret
;
305 pte
= pte_offset_kernel(pmd
, address
);
306 if (bad_address(pte
)) goto bad
;
307 printk("PTE %lx", pte_val(*pte
));
317 static inline pmd_t
*vmalloc_sync_one(pgd_t
*pgd
, unsigned long address
)
319 unsigned index
= pgd_index(address
);
325 pgd_k
= init_mm
.pgd
+ index
;
327 if (!pgd_present(*pgd_k
))
331 * set_pgd(pgd, *pgd_k); here would be useless on PAE
332 * and redundant with the set_pmd() on non-PAE. As would
336 pud
= pud_offset(pgd
, address
);
337 pud_k
= pud_offset(pgd_k
, address
);
338 if (!pud_present(*pud_k
))
341 pmd
= pmd_offset(pud
, address
);
342 pmd_k
= pmd_offset(pud_k
, address
);
343 if (!pmd_present(*pmd_k
))
345 if (!pmd_present(*pmd
)) {
346 set_pmd(pmd
, *pmd_k
);
347 arch_flush_lazy_mmu_mode();
349 BUG_ON(pmd_page(*pmd
) != pmd_page(*pmd_k
));
355 static const char errata93_warning
[] =
356 KERN_ERR
"******* Your BIOS seems to not contain a fix for K8 errata #93\n"
357 KERN_ERR
"******* Working around it, but it may cause SEGVs or burn power.\n"
358 KERN_ERR
"******* Please consider a BIOS update.\n"
359 KERN_ERR
"******* Disabling USB legacy in the BIOS may also help.\n";
362 /* Workaround for K8 erratum #93 & buggy BIOS.
363 BIOS SMM functions are required to use a specific workaround
364 to avoid corruption of the 64bit RIP register on C stepping K8.
365 A lot of BIOS that didn't get tested properly miss this.
366 The OS sees this as a page fault with the upper 32bits of RIP cleared.
367 Try to work around it here.
368 Note we only handle faults in kernel here.
369 Does nothing for X86_32
371 static int is_errata93(struct pt_regs
*regs
, unsigned long address
)
375 if (address
!= regs
->ip
)
377 if ((address
>> 32) != 0)
379 address
|= 0xffffffffUL
<< 32;
380 if ((address
>= (u64
)_stext
&& address
<= (u64
)_etext
) ||
381 (address
>= MODULES_VADDR
&& address
<= MODULES_END
)) {
383 printk(errata93_warning
);
394 * Work around K8 erratum #100 K8 in compat mode occasionally jumps to illegal
395 * addresses >4GB. We catch this in the page fault handler because these
396 * addresses are not reachable. Just detect this case and return. Any code
397 * segment in LDT is compatibility mode.
399 static int is_errata100(struct pt_regs
*regs
, unsigned long address
)
402 if ((regs
->cs
== __USER32_CS
|| (regs
->cs
& (1<<2))) &&
409 void do_invalid_op(struct pt_regs
*, unsigned long);
411 static int is_f00f_bug(struct pt_regs
*regs
, unsigned long address
)
413 #ifdef CONFIG_X86_F00F_BUG
416 * Pentium F0 0F C7 C8 bug workaround.
418 if (boot_cpu_data
.f00f_bug
) {
419 nr
= (address
- idt_descr
.address
) >> 3;
422 do_invalid_op(regs
, 0);
430 static void show_fault_oops(struct pt_regs
*regs
, unsigned long error_code
,
431 unsigned long address
)
434 if (!oops_may_print())
438 #ifdef CONFIG_X86_PAE
439 if (error_code
& PF_INSTR
) {
441 pte_t
*pte
= lookup_address(address
, &level
);
443 if (pte
&& pte_present(*pte
) && !pte_exec(*pte
))
444 printk(KERN_CRIT
"kernel tried to execute "
445 "NX-protected page - exploit attempt? "
446 "(uid: %d)\n", current
->uid
);
450 printk(KERN_ALERT
"BUG: unable to handle kernel ");
451 if (address
< PAGE_SIZE
)
452 printk(KERN_CONT
"NULL pointer dereference");
454 printk(KERN_CONT
"paging request");
456 printk(KERN_CONT
" at %08lx\n", address
);
458 printk(KERN_CONT
" at %016lx\n", address
);
460 printk(KERN_ALERT
"IP:");
461 printk_address(regs
->ip
, 1);
462 dump_pagetable(address
);
466 static noinline
void pgtable_bad(unsigned long address
, struct pt_regs
*regs
,
467 unsigned long error_code
)
469 unsigned long flags
= oops_begin();
470 struct task_struct
*tsk
;
472 printk(KERN_ALERT
"%s: Corrupted page table at address %lx\n",
473 current
->comm
, address
);
474 dump_pagetable(address
);
476 tsk
->thread
.cr2
= address
;
477 tsk
->thread
.trap_no
= 14;
478 tsk
->thread
.error_code
= error_code
;
479 if (__die("Bad pagetable", regs
, error_code
))
481 oops_end(flags
, regs
, SIGKILL
);
485 static int spurious_fault_check(unsigned long error_code
, pte_t
*pte
)
487 if ((error_code
& PF_WRITE
) && !pte_write(*pte
))
489 if ((error_code
& PF_INSTR
) && !pte_exec(*pte
))
496 * Handle a spurious fault caused by a stale TLB entry. This allows
497 * us to lazily refresh the TLB when increasing the permissions of a
498 * kernel page (RO -> RW or NX -> X). Doing it eagerly is very
499 * expensive since that implies doing a full cross-processor TLB
500 * flush, even if no stale TLB entries exist on other processors.
501 * There are no security implications to leaving a stale TLB when
502 * increasing the permissions on a page.
504 static int spurious_fault(unsigned long address
,
505 unsigned long error_code
)
512 /* Reserved-bit violation or user access to kernel space? */
513 if (error_code
& (PF_USER
| PF_RSVD
))
516 pgd
= init_mm
.pgd
+ pgd_index(address
);
517 if (!pgd_present(*pgd
))
520 pud
= pud_offset(pgd
, address
);
521 if (!pud_present(*pud
))
525 return spurious_fault_check(error_code
, (pte_t
*) pud
);
527 pmd
= pmd_offset(pud
, address
);
528 if (!pmd_present(*pmd
))
532 return spurious_fault_check(error_code
, (pte_t
*) pmd
);
534 pte
= pte_offset_kernel(pmd
, address
);
535 if (!pte_present(*pte
))
538 return spurious_fault_check(error_code
, pte
);
543 * Handle a fault on the vmalloc or module mapping area
546 * Handle a fault on the vmalloc area
548 * This assumes no large pages in there.
550 static int vmalloc_fault(unsigned long address
)
553 unsigned long pgd_paddr
;
557 * Synchronize this task's top level page-table
558 * with the 'reference' page table.
560 * Do _not_ use "current" here. We might be inside
561 * an interrupt in the middle of a task switch..
563 pgd_paddr
= read_cr3();
564 pmd_k
= vmalloc_sync_one(__va(pgd_paddr
), address
);
567 pte_k
= pte_offset_kernel(pmd_k
, address
);
568 if (!pte_present(*pte_k
))
572 pgd_t
*pgd
, *pgd_ref
;
573 pud_t
*pud
, *pud_ref
;
574 pmd_t
*pmd
, *pmd_ref
;
575 pte_t
*pte
, *pte_ref
;
577 /* Make sure we are in vmalloc area */
578 if (!(address
>= VMALLOC_START
&& address
< VMALLOC_END
))
581 /* Copy kernel mappings over when needed. This can also
582 happen within a race in page table update. In the later
585 pgd
= pgd_offset(current
->mm
?: &init_mm
, address
);
586 pgd_ref
= pgd_offset_k(address
);
587 if (pgd_none(*pgd_ref
))
590 set_pgd(pgd
, *pgd_ref
);
592 BUG_ON(pgd_page_vaddr(*pgd
) != pgd_page_vaddr(*pgd_ref
));
594 /* Below here mismatches are bugs because these lower tables
597 pud
= pud_offset(pgd
, address
);
598 pud_ref
= pud_offset(pgd_ref
, address
);
599 if (pud_none(*pud_ref
))
601 if (pud_none(*pud
) || pud_page_vaddr(*pud
) != pud_page_vaddr(*pud_ref
))
603 pmd
= pmd_offset(pud
, address
);
604 pmd_ref
= pmd_offset(pud_ref
, address
);
605 if (pmd_none(*pmd_ref
))
607 if (pmd_none(*pmd
) || pmd_page(*pmd
) != pmd_page(*pmd_ref
))
609 pte_ref
= pte_offset_kernel(pmd_ref
, address
);
610 if (!pte_present(*pte_ref
))
612 pte
= pte_offset_kernel(pmd
, address
);
613 /* Don't use pte_page here, because the mappings can point
614 outside mem_map, and the NUMA hash lookup cannot handle
616 if (!pte_present(*pte
) || pte_pfn(*pte
) != pte_pfn(*pte_ref
))
622 int show_unhandled_signals
= 1;
625 * This routine handles page faults. It determines the address,
626 * and the problem, and then passes it off to one of the appropriate
632 void __kprobes
do_page_fault(struct pt_regs
*regs
, unsigned long error_code
)
634 struct task_struct
*tsk
;
635 struct mm_struct
*mm
;
636 struct vm_area_struct
*vma
;
637 unsigned long address
;
645 * We can fault from pretty much anywhere, with unknown IRQ state.
647 trace_hardirqs_fixup();
651 prefetchw(&mm
->mmap_sem
);
653 /* get the address */
654 address
= read_cr2();
656 si_code
= SEGV_MAPERR
;
658 if (notify_page_fault(regs
))
660 if (call_mmiotrace(regs
, error_code
, address
))
664 * We fault-in kernel-space virtual memory on-demand. The
665 * 'reference' page table is init_mm.pgd.
667 * NOTE! We MUST NOT take any locks for this case. We may
668 * be in an interrupt or a critical region, and should
669 * only copy the information from the master page table,
672 * This verifies that the fault happens in kernel space
673 * (error_code & 4) == 0, and that the fault was not a
674 * protection error (error_code & 9) == 0.
677 if (unlikely(address
>= TASK_SIZE
)) {
679 if (unlikely(address
>= TASK_SIZE64
)) {
681 if (!(error_code
& (PF_RSVD
|PF_USER
|PF_PROT
)) &&
682 vmalloc_fault(address
) >= 0)
685 /* Can handle a stale RO->RW TLB */
686 if (spurious_fault(address
, error_code
))
690 * Don't take the mm semaphore here. If we fixup a prefetch
691 * fault we could otherwise deadlock.
693 goto bad_area_nosemaphore
;
698 /* It's safe to allow irq's after cr2 has been saved and the vmalloc
699 fault has been handled. */
700 if (regs
->flags
& (X86_EFLAGS_IF
| X86_VM_MASK
))
704 * If we're in an interrupt, have no user context or are running in an
705 * atomic region then we must not take the fault.
707 if (in_atomic() || !mm
)
708 goto bad_area_nosemaphore
;
709 #else /* CONFIG_X86_64 */
710 if (likely(regs
->flags
& X86_EFLAGS_IF
))
713 if (unlikely(error_code
& PF_RSVD
))
714 pgtable_bad(address
, regs
, error_code
);
717 * If we're in an interrupt, have no user context or are running in an
718 * atomic region then we must not take the fault.
720 if (unlikely(in_atomic() || !mm
))
721 goto bad_area_nosemaphore
;
724 * User-mode registers count as a user access even for any
725 * potential system fault or CPU buglet.
727 if (user_mode_vm(regs
))
728 error_code
|= PF_USER
;
731 /* When running in the kernel we expect faults to occur only to
732 * addresses in user space. All other faults represent errors in the
733 * kernel and should generate an OOPS. Unfortunately, in the case of an
734 * erroneous fault occurring in a code path which already holds mmap_sem
735 * we will deadlock attempting to validate the fault against the
736 * address space. Luckily the kernel only validly references user
737 * space from well defined areas of code, which are listed in the
740 * As the vast majority of faults will be valid we will only perform
741 * the source reference check when there is a possibility of a deadlock.
742 * Attempt to lock the address space, if we cannot we then validate the
743 * source. If this is invalid we can skip the address space check,
744 * thus avoiding the deadlock.
746 if (!down_read_trylock(&mm
->mmap_sem
)) {
747 if ((error_code
& PF_USER
) == 0 &&
748 !search_exception_tables(regs
->ip
))
749 goto bad_area_nosemaphore
;
750 down_read(&mm
->mmap_sem
);
753 vma
= find_vma(mm
, address
);
756 if (vma
->vm_start
<= address
)
758 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
760 if (error_code
& PF_USER
) {
762 * Accessing the stack below %sp is always a bug.
763 * The large cushion allows instructions like enter
764 * and pusha to work. ("enter $65535,$31" pushes
765 * 32 pointers and then decrements %sp by 65535.)
767 if (address
+ 65536 + 32 * sizeof(unsigned long) < regs
->sp
)
770 if (expand_stack(vma
, address
))
773 * Ok, we have a good vm_area for this memory access, so
777 si_code
= SEGV_ACCERR
;
779 switch (error_code
& (PF_PROT
|PF_WRITE
)) {
780 default: /* 3: write, present */
782 case PF_WRITE
: /* write, not present */
783 if (!(vma
->vm_flags
& VM_WRITE
))
787 case PF_PROT
: /* read, present */
789 case 0: /* read, not present */
790 if (!(vma
->vm_flags
& (VM_READ
| VM_EXEC
| VM_WRITE
)))
798 * If for any reason at all we couldn't handle the fault,
799 * make sure we exit gracefully rather than endlessly redo
802 fault
= handle_mm_fault(mm
, vma
, address
, write
);
803 if (unlikely(fault
& VM_FAULT_ERROR
)) {
804 if (fault
& VM_FAULT_OOM
)
806 else if (fault
& VM_FAULT_SIGBUS
)
810 if (fault
& VM_FAULT_MAJOR
)
817 * Did it hit the DOS screen memory VA from vm86 mode?
819 if (v8086_mode(regs
)) {
820 unsigned long bit
= (address
- 0xA0000) >> PAGE_SHIFT
;
822 tsk
->thread
.screen_bitmap
|= 1 << bit
;
825 up_read(&mm
->mmap_sem
);
829 * Something tried to access memory that isn't in our memory map..
830 * Fix it, but check if it's kernel or user first..
833 up_read(&mm
->mmap_sem
);
835 bad_area_nosemaphore
:
836 /* User mode accesses just cause a SIGSEGV */
837 if (error_code
& PF_USER
) {
839 * It's possible to have interrupts off here.
844 * Valid to do another page fault here because this one came
847 if (is_prefetch(regs
, address
, error_code
))
850 if (is_errata100(regs
, address
))
853 if (show_unhandled_signals
&& unhandled_signal(tsk
, SIGSEGV
) &&
854 printk_ratelimit()) {
857 "%s%s[%d]: segfault at %lx ip %08lx sp %08lx error %lx",
859 "%s%s[%d]: segfault at %lx ip %lx sp %lx error %lx",
861 task_pid_nr(tsk
) > 1 ? KERN_INFO
: KERN_EMERG
,
862 tsk
->comm
, task_pid_nr(tsk
), address
, regs
->ip
,
863 regs
->sp
, error_code
);
864 print_vma_addr(" in ", regs
->ip
);
868 tsk
->thread
.cr2
= address
;
869 /* Kernel addresses are always protection faults */
870 tsk
->thread
.error_code
= error_code
| (address
>= TASK_SIZE
);
871 tsk
->thread
.trap_no
= 14;
872 force_sig_info_fault(SIGSEGV
, si_code
, address
, tsk
);
876 if (is_f00f_bug(regs
, address
))
880 /* Are we prepared to handle this kernel fault? */
881 if (fixup_exception(regs
))
886 * Valid to do another page fault here, because if this fault
887 * had been triggered by is_prefetch fixup_exception would have
891 * Hall of shame of CPU/BIOS bugs.
893 if (is_prefetch(regs
, address
, error_code
))
896 if (is_errata93(regs
, address
))
900 * Oops. The kernel tried to access some bad page. We'll have to
901 * terminate things with extreme prejudice.
906 flags
= oops_begin();
909 show_fault_oops(regs
, error_code
, address
);
911 tsk
->thread
.cr2
= address
;
912 tsk
->thread
.trap_no
= 14;
913 tsk
->thread
.error_code
= error_code
;
916 die("Oops", regs
, error_code
);
920 if (__die("Oops", regs
, error_code
))
922 /* Executive summary in case the body of the oops scrolled away */
923 printk(KERN_EMERG
"CR2: %016lx\n", address
);
924 oops_end(flags
, regs
, SIGKILL
);
928 * We ran out of memory, or some other thing happened to us that made
929 * us unable to handle the page fault gracefully.
932 up_read(&mm
->mmap_sem
);
933 if (is_global_init(tsk
)) {
936 down_read(&mm
->mmap_sem
);
943 printk("VM: killing process %s\n", tsk
->comm
);
944 if (error_code
& PF_USER
)
945 do_group_exit(SIGKILL
);
949 up_read(&mm
->mmap_sem
);
951 /* Kernel mode? Handle exceptions or die */
952 if (!(error_code
& PF_USER
))
955 /* User space => ok to do another page fault */
956 if (is_prefetch(regs
, address
, error_code
))
959 tsk
->thread
.cr2
= address
;
960 tsk
->thread
.error_code
= error_code
;
961 tsk
->thread
.trap_no
= 14;
962 force_sig_info_fault(SIGBUS
, BUS_ADRERR
, address
, tsk
);
965 DEFINE_SPINLOCK(pgd_lock
);
968 void vmalloc_sync_all(void)
972 * Note that races in the updates of insync and start aren't
973 * problematic: insync can only get set bits added, and updates to
974 * start are only improving performance (without affecting correctness
977 static DECLARE_BITMAP(insync
, PTRS_PER_PGD
);
978 static unsigned long start
= TASK_SIZE
;
979 unsigned long address
;
981 if (SHARED_KERNEL_PMD
)
984 BUILD_BUG_ON(TASK_SIZE
& ~PGDIR_MASK
);
985 for (address
= start
; address
>= TASK_SIZE
; address
+= PGDIR_SIZE
) {
986 if (!test_bit(pgd_index(address
), insync
)) {
990 spin_lock_irqsave(&pgd_lock
, flags
);
991 list_for_each_entry(page
, &pgd_list
, lru
) {
992 if (!vmalloc_sync_one(page_address(page
),
996 spin_unlock_irqrestore(&pgd_lock
, flags
);
998 set_bit(pgd_index(address
), insync
);
1000 if (address
== start
&& test_bit(pgd_index(address
), insync
))
1001 start
= address
+ PGDIR_SIZE
;
1003 #else /* CONFIG_X86_64 */
1005 * Note that races in the updates of insync and start aren't
1006 * problematic: insync can only get set bits added, and updates to
1007 * start are only improving performance (without affecting correctness
1010 static DECLARE_BITMAP(insync
, PTRS_PER_PGD
);
1011 static unsigned long start
= VMALLOC_START
& PGDIR_MASK
;
1012 unsigned long address
;
1014 for (address
= start
; address
<= VMALLOC_END
; address
+= PGDIR_SIZE
) {
1015 if (!test_bit(pgd_index(address
), insync
)) {
1016 const pgd_t
*pgd_ref
= pgd_offset_k(address
);
1017 unsigned long flags
;
1020 if (pgd_none(*pgd_ref
))
1022 spin_lock_irqsave(&pgd_lock
, flags
);
1023 list_for_each_entry(page
, &pgd_list
, lru
) {
1025 pgd
= (pgd_t
*)page_address(page
) + pgd_index(address
);
1027 set_pgd(pgd
, *pgd_ref
);
1029 BUG_ON(pgd_page_vaddr(*pgd
) != pgd_page_vaddr(*pgd_ref
));
1031 spin_unlock_irqrestore(&pgd_lock
, flags
);
1032 set_bit(pgd_index(address
), insync
);
1034 if (address
== start
)
1035 start
= address
+ PGDIR_SIZE
;