diff options
Diffstat (limited to 'arch/x86/mm/fault.c')
-rw-r--r-- | arch/x86/mm/fault.c | 446 |
1 files changed, 263 insertions, 183 deletions
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 90dfae511a41..d3eee74f830a 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/kprobes.h> | 26 | #include <linux/kprobes.h> |
27 | #include <linux/uaccess.h> | 27 | #include <linux/uaccess.h> |
28 | #include <linux/kdebug.h> | 28 | #include <linux/kdebug.h> |
29 | #include <linux/magic.h> | ||
29 | 30 | ||
30 | #include <asm/system.h> | 31 | #include <asm/system.h> |
31 | #include <asm/desc.h> | 32 | #include <asm/desc.h> |
@@ -91,8 +92,8 @@ static inline int notify_page_fault(struct pt_regs *regs) | |||
91 | * | 92 | * |
92 | * Opcode checker based on code by Richard Brunner | 93 | * Opcode checker based on code by Richard Brunner |
93 | */ | 94 | */ |
94 | static int is_prefetch(struct pt_regs *regs, unsigned long addr, | 95 | static int is_prefetch(struct pt_regs *regs, unsigned long error_code, |
95 | unsigned long error_code) | 96 | unsigned long addr) |
96 | { | 97 | { |
97 | unsigned char *instr; | 98 | unsigned char *instr; |
98 | int scan_more = 1; | 99 | int scan_more = 1; |
@@ -409,17 +410,16 @@ static void show_fault_oops(struct pt_regs *regs, unsigned long error_code, | |||
409 | } | 410 | } |
410 | 411 | ||
411 | #ifdef CONFIG_X86_64 | 412 | #ifdef CONFIG_X86_64 |
412 | static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs, | 413 | static noinline void pgtable_bad(struct pt_regs *regs, |
413 | unsigned long error_code) | 414 | unsigned long error_code, unsigned long address) |
414 | { | 415 | { |
415 | unsigned long flags = oops_begin(); | 416 | unsigned long flags = oops_begin(); |
416 | int sig = SIGKILL; | 417 | int sig = SIGKILL; |
417 | struct task_struct *tsk; | 418 | struct task_struct *tsk = current; |
418 | 419 | ||
419 | printk(KERN_ALERT "%s: Corrupted page table at address %lx\n", | 420 | printk(KERN_ALERT "%s: Corrupted page table at address %lx\n", |
420 | current->comm, address); | 421 | tsk->comm, address); |
421 | dump_pagetable(address); | 422 | dump_pagetable(address); |
422 | tsk = current; | ||
423 | tsk->thread.cr2 = address; | 423 | tsk->thread.cr2 = address; |
424 | tsk->thread.trap_no = 14; | 424 | tsk->thread.trap_no = 14; |
425 | tsk->thread.error_code = error_code; | 425 | tsk->thread.error_code = error_code; |
@@ -429,6 +429,196 @@ static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs, | |||
429 | } | 429 | } |
430 | #endif | 430 | #endif |
431 | 431 | ||
432 | static noinline void no_context(struct pt_regs *regs, | ||
433 | unsigned long error_code, unsigned long address) | ||
434 | { | ||
435 | struct task_struct *tsk = current; | ||
436 | unsigned long *stackend; | ||
437 | |||
438 | #ifdef CONFIG_X86_64 | ||
439 | unsigned long flags; | ||
440 | int sig; | ||
441 | #endif | ||
442 | |||
443 | /* Are we prepared to handle this kernel fault? */ | ||
444 | if (fixup_exception(regs)) | ||
445 | return; | ||
446 | |||
447 | /* | ||
448 | * X86_32 | ||
449 | * Valid to do another page fault here, because if this fault | ||
450 | * had been triggered by is_prefetch fixup_exception would have | ||
451 | * handled it. | ||
452 | * | ||
453 | * X86_64 | ||
454 | * Hall of shame of CPU/BIOS bugs. | ||
455 | */ | ||
456 | if (is_prefetch(regs, error_code, address)) | ||
457 | return; | ||
458 | |||
459 | if (is_errata93(regs, address)) | ||
460 | return; | ||
461 | |||
462 | /* | ||
463 | * Oops. The kernel tried to access some bad page. We'll have to | ||
464 | * terminate things with extreme prejudice. | ||
465 | */ | ||
466 | #ifdef CONFIG_X86_32 | ||
467 | bust_spinlocks(1); | ||
468 | #else | ||
469 | flags = oops_begin(); | ||
470 | #endif | ||
471 | |||
472 | show_fault_oops(regs, error_code, address); | ||
473 | |||
474 | stackend = end_of_stack(tsk); | ||
475 | if (*stackend != STACK_END_MAGIC) | ||
476 | printk(KERN_ALERT "Thread overran stack, or stack corrupted\n"); | ||
477 | |||
478 | tsk->thread.cr2 = address; | ||
479 | tsk->thread.trap_no = 14; | ||
480 | tsk->thread.error_code = error_code; | ||
481 | |||
482 | #ifdef CONFIG_X86_32 | ||
483 | die("Oops", regs, error_code); | ||
484 | bust_spinlocks(0); | ||
485 | do_exit(SIGKILL); | ||
486 | #else | ||
487 | sig = SIGKILL; | ||
488 | if (__die("Oops", regs, error_code)) | ||
489 | sig = 0; | ||
490 | /* Executive summary in case the body of the oops scrolled away */ | ||
491 | printk(KERN_EMERG "CR2: %016lx\n", address); | ||
492 | oops_end(flags, regs, sig); | ||
493 | #endif | ||
494 | } | ||
495 | |||
496 | static void __bad_area_nosemaphore(struct pt_regs *regs, | ||
497 | unsigned long error_code, unsigned long address, | ||
498 | int si_code) | ||
499 | { | ||
500 | struct task_struct *tsk = current; | ||
501 | |||
502 | /* User mode accesses just cause a SIGSEGV */ | ||
503 | if (error_code & PF_USER) { | ||
504 | /* | ||
505 | * It's possible to have interrupts off here. | ||
506 | */ | ||
507 | local_irq_enable(); | ||
508 | |||
509 | /* | ||
510 | * Valid to do another page fault here because this one came | ||
511 | * from user space. | ||
512 | */ | ||
513 | if (is_prefetch(regs, error_code, address)) | ||
514 | return; | ||
515 | |||
516 | if (is_errata100(regs, address)) | ||
517 | return; | ||
518 | |||
519 | if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && | ||
520 | printk_ratelimit()) { | ||
521 | printk( | ||
522 | "%s%s[%d]: segfault at %lx ip %p sp %p error %lx", | ||
523 | task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, | ||
524 | tsk->comm, task_pid_nr(tsk), address, | ||
525 | (void *) regs->ip, (void *) regs->sp, error_code); | ||
526 | print_vma_addr(" in ", regs->ip); | ||
527 | printk("\n"); | ||
528 | } | ||
529 | |||
530 | tsk->thread.cr2 = address; | ||
531 | /* Kernel addresses are always protection faults */ | ||
532 | tsk->thread.error_code = error_code | (address >= TASK_SIZE); | ||
533 | tsk->thread.trap_no = 14; | ||
534 | force_sig_info_fault(SIGSEGV, si_code, address, tsk); | ||
535 | return; | ||
536 | } | ||
537 | |||
538 | if (is_f00f_bug(regs, address)) | ||
539 | return; | ||
540 | |||
541 | no_context(regs, error_code, address); | ||
542 | } | ||
543 | |||
544 | static noinline void bad_area_nosemaphore(struct pt_regs *regs, | ||
545 | unsigned long error_code, unsigned long address) | ||
546 | { | ||
547 | __bad_area_nosemaphore(regs, error_code, address, SEGV_MAPERR); | ||
548 | } | ||
549 | |||
550 | static void __bad_area(struct pt_regs *regs, | ||
551 | unsigned long error_code, unsigned long address, | ||
552 | int si_code) | ||
553 | { | ||
554 | struct mm_struct *mm = current->mm; | ||
555 | |||
556 | /* | ||
557 | * Something tried to access memory that isn't in our memory map.. | ||
558 | * Fix it, but check if it's kernel or user first.. | ||
559 | */ | ||
560 | up_read(&mm->mmap_sem); | ||
561 | |||
562 | __bad_area_nosemaphore(regs, error_code, address, si_code); | ||
563 | } | ||
564 | |||
565 | static noinline void bad_area(struct pt_regs *regs, | ||
566 | unsigned long error_code, unsigned long address) | ||
567 | { | ||
568 | __bad_area(regs, error_code, address, SEGV_MAPERR); | ||
569 | } | ||
570 | |||
571 | static noinline void bad_area_access_error(struct pt_regs *regs, | ||
572 | unsigned long error_code, unsigned long address) | ||
573 | { | ||
574 | __bad_area(regs, error_code, address, SEGV_ACCERR); | ||
575 | } | ||
576 | |||
577 | /* TODO: fixup for "mm-invoke-oom-killer-from-page-fault.patch" */ | ||
578 | static void out_of_memory(struct pt_regs *regs, | ||
579 | unsigned long error_code, unsigned long address) | ||
580 | { | ||
581 | /* | ||
582 | * We ran out of memory, call the OOM killer, and return the userspace | ||
583 | * (which will retry the fault, or kill us if we got oom-killed). | ||
584 | */ | ||
585 | up_read(¤t->mm->mmap_sem); | ||
586 | pagefault_out_of_memory(); | ||
587 | } | ||
588 | |||
589 | static void do_sigbus(struct pt_regs *regs, | ||
590 | unsigned long error_code, unsigned long address) | ||
591 | { | ||
592 | struct task_struct *tsk = current; | ||
593 | struct mm_struct *mm = tsk->mm; | ||
594 | |||
595 | up_read(&mm->mmap_sem); | ||
596 | |||
597 | /* Kernel mode? Handle exceptions or die */ | ||
598 | if (!(error_code & PF_USER)) | ||
599 | no_context(regs, error_code, address); | ||
600 | #ifdef CONFIG_X86_32 | ||
601 | /* User space => ok to do another page fault */ | ||
602 | if (is_prefetch(regs, error_code, address)) | ||
603 | return; | ||
604 | #endif | ||
605 | tsk->thread.cr2 = address; | ||
606 | tsk->thread.error_code = error_code; | ||
607 | tsk->thread.trap_no = 14; | ||
608 | force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk); | ||
609 | } | ||
610 | |||
611 | static noinline void mm_fault_error(struct pt_regs *regs, | ||
612 | unsigned long error_code, unsigned long address, unsigned int fault) | ||
613 | { | ||
614 | if (fault & VM_FAULT_OOM) | ||
615 | out_of_memory(regs, error_code, address); | ||
616 | else if (fault & VM_FAULT_SIGBUS) | ||
617 | do_sigbus(regs, error_code, address); | ||
618 | else | ||
619 | BUG(); | ||
620 | } | ||
621 | |||
432 | static int spurious_fault_check(unsigned long error_code, pte_t *pte) | 622 | static int spurious_fault_check(unsigned long error_code, pte_t *pte) |
433 | { | 623 | { |
434 | if ((error_code & PF_WRITE) && !pte_write(*pte)) | 624 | if ((error_code & PF_WRITE) && !pte_write(*pte)) |
@@ -448,8 +638,8 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte) | |||
448 | * There are no security implications to leaving a stale TLB when | 638 | * There are no security implications to leaving a stale TLB when |
449 | * increasing the permissions on a page. | 639 | * increasing the permissions on a page. |
450 | */ | 640 | */ |
451 | static int spurious_fault(unsigned long address, | 641 | static noinline int spurious_fault(unsigned long error_code, |
452 | unsigned long error_code) | 642 | unsigned long address) |
453 | { | 643 | { |
454 | pgd_t *pgd; | 644 | pgd_t *pgd; |
455 | pud_t *pud; | 645 | pud_t *pud; |
@@ -494,7 +684,7 @@ static int spurious_fault(unsigned long address, | |||
494 | * | 684 | * |
495 | * This assumes no large pages in there. | 685 | * This assumes no large pages in there. |
496 | */ | 686 | */ |
497 | static int vmalloc_fault(unsigned long address) | 687 | static noinline int vmalloc_fault(unsigned long address) |
498 | { | 688 | { |
499 | #ifdef CONFIG_X86_32 | 689 | #ifdef CONFIG_X86_32 |
500 | unsigned long pgd_paddr; | 690 | unsigned long pgd_paddr; |
@@ -573,6 +763,25 @@ static int vmalloc_fault(unsigned long address) | |||
573 | 763 | ||
574 | int show_unhandled_signals = 1; | 764 | int show_unhandled_signals = 1; |
575 | 765 | ||
766 | static inline int access_error(unsigned long error_code, int write, | ||
767 | struct vm_area_struct *vma) | ||
768 | { | ||
769 | if (write) { | ||
770 | /* write, present and write, not present */ | ||
771 | if (unlikely(!(vma->vm_flags & VM_WRITE))) | ||
772 | return 1; | ||
773 | } else if (unlikely(error_code & PF_PROT)) { | ||
774 | /* read, present */ | ||
775 | return 1; | ||
776 | } else { | ||
777 | /* read, not present */ | ||
778 | if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE)))) | ||
779 | return 1; | ||
780 | } | ||
781 | |||
782 | return 0; | ||
783 | } | ||
784 | |||
576 | /* | 785 | /* |
577 | * This routine handles page faults. It determines the address, | 786 | * This routine handles page faults. It determines the address, |
578 | * and the problem, and then passes it off to one of the appropriate | 787 | * and the problem, and then passes it off to one of the appropriate |
@@ -583,16 +792,12 @@ asmlinkage | |||
583 | #endif | 792 | #endif |
584 | void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | 793 | void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) |
585 | { | 794 | { |
795 | unsigned long address; | ||
586 | struct task_struct *tsk; | 796 | struct task_struct *tsk; |
587 | struct mm_struct *mm; | 797 | struct mm_struct *mm; |
588 | struct vm_area_struct *vma; | 798 | struct vm_area_struct *vma; |
589 | unsigned long address; | 799 | int write; |
590 | int write, si_code; | ||
591 | int fault; | 800 | int fault; |
592 | #ifdef CONFIG_X86_64 | ||
593 | unsigned long flags; | ||
594 | int sig; | ||
595 | #endif | ||
596 | 801 | ||
597 | tsk = current; | 802 | tsk = current; |
598 | mm = tsk->mm; | 803 | mm = tsk->mm; |
@@ -601,9 +806,7 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
601 | /* get the address */ | 806 | /* get the address */ |
602 | address = read_cr2(); | 807 | address = read_cr2(); |
603 | 808 | ||
604 | si_code = SEGV_MAPERR; | 809 | if (unlikely(notify_page_fault(regs))) |
605 | |||
606 | if (notify_page_fault(regs)) | ||
607 | return; | 810 | return; |
608 | if (unlikely(kmmio_fault(regs, address))) | 811 | if (unlikely(kmmio_fault(regs, address))) |
609 | return; | 812 | return; |
@@ -631,17 +834,17 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
631 | return; | 834 | return; |
632 | 835 | ||
633 | /* Can handle a stale RO->RW TLB */ | 836 | /* Can handle a stale RO->RW TLB */ |
634 | if (spurious_fault(address, error_code)) | 837 | if (spurious_fault(error_code, address)) |
635 | return; | 838 | return; |
636 | 839 | ||
637 | /* | 840 | /* |
638 | * Don't take the mm semaphore here. If we fixup a prefetch | 841 | * Don't take the mm semaphore here. If we fixup a prefetch |
639 | * fault we could otherwise deadlock. | 842 | * fault we could otherwise deadlock. |
640 | */ | 843 | */ |
641 | goto bad_area_nosemaphore; | 844 | bad_area_nosemaphore(regs, error_code, address); |
845 | return; | ||
642 | } | 846 | } |
643 | 847 | ||
644 | |||
645 | /* | 848 | /* |
646 | * It's safe to allow irq's after cr2 has been saved and the | 849 | * It's safe to allow irq's after cr2 has been saved and the |
647 | * vmalloc fault has been handled. | 850 | * vmalloc fault has been handled. |
@@ -657,15 +860,17 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
657 | 860 | ||
658 | #ifdef CONFIG_X86_64 | 861 | #ifdef CONFIG_X86_64 |
659 | if (unlikely(error_code & PF_RSVD)) | 862 | if (unlikely(error_code & PF_RSVD)) |
660 | pgtable_bad(address, regs, error_code); | 863 | pgtable_bad(regs, error_code, address); |
661 | #endif | 864 | #endif |
662 | 865 | ||
663 | /* | 866 | /* |
664 | * If we're in an interrupt, have no user context or are running in an | 867 | * If we're in an interrupt, have no user context or are running in an |
665 | * atomic region then we must not take the fault. | 868 | * atomic region then we must not take the fault. |
666 | */ | 869 | */ |
667 | if (unlikely(in_atomic() || !mm)) | 870 | if (unlikely(in_atomic() || !mm)) { |
668 | goto bad_area_nosemaphore; | 871 | bad_area_nosemaphore(regs, error_code, address); |
872 | return; | ||
873 | } | ||
669 | 874 | ||
670 | /* | 875 | /* |
671 | * When running in the kernel we expect faults to occur only to | 876 | * When running in the kernel we expect faults to occur only to |
@@ -683,20 +888,26 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
683 | * source. If this is invalid we can skip the address space check, | 888 | * source. If this is invalid we can skip the address space check, |
684 | * thus avoiding the deadlock. | 889 | * thus avoiding the deadlock. |
685 | */ | 890 | */ |
686 | if (!down_read_trylock(&mm->mmap_sem)) { | 891 | if (unlikely(!down_read_trylock(&mm->mmap_sem))) { |
687 | if ((error_code & PF_USER) == 0 && | 892 | if ((error_code & PF_USER) == 0 && |
688 | !search_exception_tables(regs->ip)) | 893 | !search_exception_tables(regs->ip)) { |
689 | goto bad_area_nosemaphore; | 894 | bad_area_nosemaphore(regs, error_code, address); |
895 | return; | ||
896 | } | ||
690 | down_read(&mm->mmap_sem); | 897 | down_read(&mm->mmap_sem); |
691 | } | 898 | } |
692 | 899 | ||
693 | vma = find_vma(mm, address); | 900 | vma = find_vma(mm, address); |
694 | if (!vma) | 901 | if (unlikely(!vma)) { |
695 | goto bad_area; | 902 | bad_area(regs, error_code, address); |
696 | if (vma->vm_start <= address) | 903 | return; |
904 | } | ||
905 | if (likely(vma->vm_start <= address)) | ||
697 | goto good_area; | 906 | goto good_area; |
698 | if (!(vma->vm_flags & VM_GROWSDOWN)) | 907 | if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) { |
699 | goto bad_area; | 908 | bad_area(regs, error_code, address); |
909 | return; | ||
910 | } | ||
700 | if (error_code & PF_USER) { | 911 | if (error_code & PF_USER) { |
701 | /* | 912 | /* |
702 | * Accessing the stack below %sp is always a bug. | 913 | * Accessing the stack below %sp is always a bug. |
@@ -704,31 +915,25 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
704 | * and pusha to work. ("enter $65535,$31" pushes | 915 | * and pusha to work. ("enter $65535,$31" pushes |
705 | * 32 pointers and then decrements %sp by 65535.) | 916 | * 32 pointers and then decrements %sp by 65535.) |
706 | */ | 917 | */ |
707 | if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp) | 918 | if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) { |
708 | goto bad_area; | 919 | bad_area(regs, error_code, address); |
920 | return; | ||
921 | } | ||
709 | } | 922 | } |
710 | if (expand_stack(vma, address)) | 923 | if (unlikely(expand_stack(vma, address))) { |
711 | goto bad_area; | 924 | bad_area(regs, error_code, address); |
712 | /* | 925 | return; |
713 | * Ok, we have a good vm_area for this memory access, so | 926 | } |
714 | * we can handle it.. | 927 | |
715 | */ | 928 | /* |
929 | * Ok, we have a good vm_area for this memory access, so | ||
930 | * we can handle it.. | ||
931 | */ | ||
716 | good_area: | 932 | good_area: |
717 | si_code = SEGV_ACCERR; | 933 | write = error_code & PF_WRITE; |
718 | write = 0; | 934 | if (unlikely(access_error(error_code, write, vma))) { |
719 | switch (error_code & (PF_PROT|PF_WRITE)) { | 935 | bad_area_access_error(regs, error_code, address); |
720 | default: /* 3: write, present */ | 936 | return; |
721 | /* fall through */ | ||
722 | case PF_WRITE: /* write, not present */ | ||
723 | if (!(vma->vm_flags & VM_WRITE)) | ||
724 | goto bad_area; | ||
725 | write++; | ||
726 | break; | ||
727 | case PF_PROT: /* read, present */ | ||
728 | goto bad_area; | ||
729 | case 0: /* read, not present */ | ||
730 | if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) | ||
731 | goto bad_area; | ||
732 | } | 937 | } |
733 | 938 | ||
734 | /* | 939 | /* |
@@ -738,11 +943,8 @@ good_area: | |||
738 | */ | 943 | */ |
739 | fault = handle_mm_fault(mm, vma, address, write); | 944 | fault = handle_mm_fault(mm, vma, address, write); |
740 | if (unlikely(fault & VM_FAULT_ERROR)) { | 945 | if (unlikely(fault & VM_FAULT_ERROR)) { |
741 | if (fault & VM_FAULT_OOM) | 946 | mm_fault_error(regs, error_code, address, fault); |
742 | goto out_of_memory; | 947 | return; |
743 | else if (fault & VM_FAULT_SIGBUS) | ||
744 | goto do_sigbus; | ||
745 | BUG(); | ||
746 | } | 948 | } |
747 | if (fault & VM_FAULT_MAJOR) | 949 | if (fault & VM_FAULT_MAJOR) |
748 | tsk->maj_flt++; | 950 | tsk->maj_flt++; |
@@ -760,128 +962,6 @@ good_area: | |||
760 | } | 962 | } |
761 | #endif | 963 | #endif |
762 | up_read(&mm->mmap_sem); | 964 | up_read(&mm->mmap_sem); |
763 | return; | ||
764 | |||
765 | /* | ||
766 | * Something tried to access memory that isn't in our memory map.. | ||
767 | * Fix it, but check if it's kernel or user first.. | ||
768 | */ | ||
769 | bad_area: | ||
770 | up_read(&mm->mmap_sem); | ||
771 | |||
772 | bad_area_nosemaphore: | ||
773 | /* User mode accesses just cause a SIGSEGV */ | ||
774 | if (error_code & PF_USER) { | ||
775 | /* | ||
776 | * It's possible to have interrupts off here. | ||
777 | */ | ||
778 | local_irq_enable(); | ||
779 | |||
780 | /* | ||
781 | * Valid to do another page fault here because this one came | ||
782 | * from user space. | ||
783 | */ | ||
784 | if (is_prefetch(regs, address, error_code)) | ||
785 | return; | ||
786 | |||
787 | if (is_errata100(regs, address)) | ||
788 | return; | ||
789 | |||
790 | if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV) && | ||
791 | printk_ratelimit()) { | ||
792 | printk( | ||
793 | "%s%s[%d]: segfault at %lx ip %p sp %p error %lx", | ||
794 | task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG, | ||
795 | tsk->comm, task_pid_nr(tsk), address, | ||
796 | (void *) regs->ip, (void *) regs->sp, error_code); | ||
797 | print_vma_addr(" in ", regs->ip); | ||
798 | printk("\n"); | ||
799 | } | ||
800 | |||
801 | tsk->thread.cr2 = address; | ||
802 | /* Kernel addresses are always protection faults */ | ||
803 | tsk->thread.error_code = error_code | (address >= TASK_SIZE); | ||
804 | tsk->thread.trap_no = 14; | ||
805 | force_sig_info_fault(SIGSEGV, si_code, address, tsk); | ||
806 | return; | ||
807 | } | ||
808 | |||
809 | if (is_f00f_bug(regs, address)) | ||
810 | return; | ||
811 | |||
812 | no_context: | ||
813 | /* Are we prepared to handle this kernel fault? */ | ||
814 | if (fixup_exception(regs)) | ||
815 | return; | ||
816 | |||
817 | /* | ||
818 | * X86_32 | ||
819 | * Valid to do another page fault here, because if this fault | ||
820 | * had been triggered by is_prefetch fixup_exception would have | ||
821 | * handled it. | ||
822 | * | ||
823 | * X86_64 | ||
824 | * Hall of shame of CPU/BIOS bugs. | ||
825 | */ | ||
826 | if (is_prefetch(regs, address, error_code)) | ||
827 | return; | ||
828 | |||
829 | if (is_errata93(regs, address)) | ||
830 | return; | ||
831 | |||
832 | /* | ||
833 | * Oops. The kernel tried to access some bad page. We'll have to | ||
834 | * terminate things with extreme prejudice. | ||
835 | */ | ||
836 | #ifdef CONFIG_X86_32 | ||
837 | bust_spinlocks(1); | ||
838 | #else | ||
839 | flags = oops_begin(); | ||
840 | #endif | ||
841 | |||
842 | show_fault_oops(regs, error_code, address); | ||
843 | |||
844 | tsk->thread.cr2 = address; | ||
845 | tsk->thread.trap_no = 14; | ||
846 | tsk->thread.error_code = error_code; | ||
847 | |||
848 | #ifdef CONFIG_X86_32 | ||
849 | die("Oops", regs, error_code); | ||
850 | bust_spinlocks(0); | ||
851 | do_exit(SIGKILL); | ||
852 | #else | ||
853 | sig = SIGKILL; | ||
854 | if (__die("Oops", regs, error_code)) | ||
855 | sig = 0; | ||
856 | /* Executive summary in case the body of the oops scrolled away */ | ||
857 | printk(KERN_EMERG "CR2: %016lx\n", address); | ||
858 | oops_end(flags, regs, sig); | ||
859 | #endif | ||
860 | |||
861 | out_of_memory: | ||
862 | /* | ||
863 | * We ran out of memory, call the OOM killer, and return the userspace | ||
864 | * (which will retry the fault, or kill us if we got oom-killed). | ||
865 | */ | ||
866 | up_read(&mm->mmap_sem); | ||
867 | pagefault_out_of_memory(); | ||
868 | return; | ||
869 | |||
870 | do_sigbus: | ||
871 | up_read(&mm->mmap_sem); | ||
872 | |||
873 | /* Kernel mode? Handle exceptions or die */ | ||
874 | if (!(error_code & PF_USER)) | ||
875 | goto no_context; | ||
876 | #ifdef CONFIG_X86_32 | ||
877 | /* User space => ok to do another page fault */ | ||
878 | if (is_prefetch(regs, address, error_code)) | ||
879 | return; | ||
880 | #endif | ||
881 | tsk->thread.cr2 = address; | ||
882 | tsk->thread.error_code = error_code; | ||
883 | tsk->thread.trap_no = 14; | ||
884 | force_sig_info_fault(SIGBUS, BUS_ADRERR, address, tsk); | ||
885 | } | 965 | } |
886 | 966 | ||
887 | DEFINE_SPINLOCK(pgd_lock); | 967 | DEFINE_SPINLOCK(pgd_lock); |