diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-10-12 05:32:17 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-10-12 05:32:17 -0400 |
commit | 206855c321adee56db3946ca09a5887cddb9d598 (patch) | |
tree | 13a2729d4d0e37170552bd9ad3c6bba71ba0c55c /arch/x86/kernel/ptrace.c | |
parent | e8d3f455de4f42d4bab2f6f1aeb2cf3bd18eb508 (diff) | |
parent | cb58ffc3889f0545628f138f849e759a331b8ddc (diff) |
Merge branch 'x86/urgent' into core/signal
Conflicts:
arch/x86/kernel/signal_64.c
Diffstat (limited to 'arch/x86/kernel/ptrace.c')
-rw-r--r-- | arch/x86/kernel/ptrace.c | 444 |
1 files changed, 269 insertions, 175 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index bf45cdf1aaca..42ec4421e10b 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
@@ -555,45 +555,115 @@ static int ptrace_set_debugreg(struct task_struct *child, | |||
555 | return 0; | 555 | return 0; |
556 | } | 556 | } |
557 | 557 | ||
558 | #ifdef X86_BTS | 558 | #ifdef CONFIG_X86_PTRACE_BTS |
559 | /* | ||
560 | * The configuration for a particular BTS hardware implementation. | ||
561 | */ | ||
562 | struct bts_configuration { | ||
563 | /* the size of a BTS record in bytes; at most BTS_MAX_RECORD_SIZE */ | ||
564 | unsigned char sizeof_bts; | ||
565 | /* the size of a field in the BTS record in bytes */ | ||
566 | unsigned char sizeof_field; | ||
567 | /* a bitmask to enable/disable BTS in DEBUGCTL MSR */ | ||
568 | unsigned long debugctl_mask; | ||
569 | }; | ||
570 | static struct bts_configuration bts_cfg; | ||
571 | |||
572 | #define BTS_MAX_RECORD_SIZE (8 * 3) | ||
573 | |||
574 | |||
575 | /* | ||
576 | * Branch Trace Store (BTS) uses the following format. Different | ||
577 | * architectures vary in the size of those fields. | ||
578 | * - source linear address | ||
579 | * - destination linear address | ||
580 | * - flags | ||
581 | * | ||
582 | * Later architectures use 64bit pointers throughout, whereas earlier | ||
583 | * architectures use 32bit pointers in 32bit mode. | ||
584 | * | ||
585 | * We compute the base address for the first 8 fields based on: | ||
586 | * - the field size stored in the DS configuration | ||
587 | * - the relative field position | ||
588 | * | ||
589 | * In order to store additional information in the BTS buffer, we use | ||
590 | * a special source address to indicate that the record requires | ||
591 | * special interpretation. | ||
592 | * | ||
593 | * Netburst indicated via a bit in the flags field whether the branch | ||
594 | * was predicted; this is ignored. | ||
595 | */ | ||
596 | |||
597 | enum bts_field { | ||
598 | bts_from = 0, | ||
599 | bts_to, | ||
600 | bts_flags, | ||
601 | |||
602 | bts_escape = (unsigned long)-1, | ||
603 | bts_qual = bts_to, | ||
604 | bts_jiffies = bts_flags | ||
605 | }; | ||
559 | 606 | ||
560 | static int ptrace_bts_get_size(struct task_struct *child) | 607 | static inline unsigned long bts_get(const char *base, enum bts_field field) |
561 | { | 608 | { |
562 | if (!child->thread.ds_area_msr) | 609 | base += (bts_cfg.sizeof_field * field); |
563 | return -ENXIO; | 610 | return *(unsigned long *)base; |
611 | } | ||
612 | |||
613 | static inline void bts_set(char *base, enum bts_field field, unsigned long val) | ||
614 | { | ||
615 | base += (bts_cfg.sizeof_field * field);; | ||
616 | (*(unsigned long *)base) = val; | ||
617 | } | ||
564 | 618 | ||
565 | return ds_get_bts_index((void *)child->thread.ds_area_msr); | 619 | /* |
620 | * Translate a BTS record from the raw format into the bts_struct format | ||
621 | * | ||
622 | * out (out): bts_struct interpretation | ||
623 | * raw: raw BTS record | ||
624 | */ | ||
625 | static void ptrace_bts_translate_record(struct bts_struct *out, const void *raw) | ||
626 | { | ||
627 | memset(out, 0, sizeof(*out)); | ||
628 | if (bts_get(raw, bts_from) == bts_escape) { | ||
629 | out->qualifier = bts_get(raw, bts_qual); | ||
630 | out->variant.jiffies = bts_get(raw, bts_jiffies); | ||
631 | } else { | ||
632 | out->qualifier = BTS_BRANCH; | ||
633 | out->variant.lbr.from_ip = bts_get(raw, bts_from); | ||
634 | out->variant.lbr.to_ip = bts_get(raw, bts_to); | ||
635 | } | ||
566 | } | 636 | } |
567 | 637 | ||
568 | static int ptrace_bts_read_record(struct task_struct *child, | 638 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, |
569 | long index, | ||
570 | struct bts_struct __user *out) | 639 | struct bts_struct __user *out) |
571 | { | 640 | { |
572 | struct bts_struct ret; | 641 | struct bts_struct ret; |
573 | int retval; | 642 | const void *bts_record; |
574 | int bts_end; | 643 | size_t bts_index, bts_end; |
575 | int bts_index; | 644 | int error; |
576 | 645 | ||
577 | if (!child->thread.ds_area_msr) | 646 | error = ds_get_bts_end(child, &bts_end); |
578 | return -ENXIO; | 647 | if (error < 0) |
648 | return error; | ||
579 | 649 | ||
580 | if (index < 0) | ||
581 | return -EINVAL; | ||
582 | |||
583 | bts_end = ds_get_bts_end((void *)child->thread.ds_area_msr); | ||
584 | if (bts_end <= index) | 650 | if (bts_end <= index) |
585 | return -EINVAL; | 651 | return -EINVAL; |
586 | 652 | ||
653 | error = ds_get_bts_index(child, &bts_index); | ||
654 | if (error < 0) | ||
655 | return error; | ||
656 | |||
587 | /* translate the ptrace bts index into the ds bts index */ | 657 | /* translate the ptrace bts index into the ds bts index */ |
588 | bts_index = ds_get_bts_index((void *)child->thread.ds_area_msr); | 658 | bts_index += bts_end - (index + 1); |
589 | bts_index -= (index + 1); | 659 | if (bts_end <= bts_index) |
590 | if (bts_index < 0) | 660 | bts_index -= bts_end; |
591 | bts_index += bts_end; | 661 | |
662 | error = ds_access_bts(child, bts_index, &bts_record); | ||
663 | if (error < 0) | ||
664 | return error; | ||
592 | 665 | ||
593 | retval = ds_read_bts((void *)child->thread.ds_area_msr, | 666 | ptrace_bts_translate_record(&ret, bts_record); |
594 | bts_index, &ret); | ||
595 | if (retval < 0) | ||
596 | return retval; | ||
597 | 667 | ||
598 | if (copy_to_user(out, &ret, sizeof(ret))) | 668 | if (copy_to_user(out, &ret, sizeof(ret))) |
599 | return -EFAULT; | 669 | return -EFAULT; |
@@ -601,101 +671,106 @@ static int ptrace_bts_read_record(struct task_struct *child, | |||
601 | return sizeof(ret); | 671 | return sizeof(ret); |
602 | } | 672 | } |
603 | 673 | ||
604 | static int ptrace_bts_clear(struct task_struct *child) | ||
605 | { | ||
606 | if (!child->thread.ds_area_msr) | ||
607 | return -ENXIO; | ||
608 | |||
609 | return ds_clear((void *)child->thread.ds_area_msr); | ||
610 | } | ||
611 | |||
612 | static int ptrace_bts_drain(struct task_struct *child, | 674 | static int ptrace_bts_drain(struct task_struct *child, |
613 | long size, | 675 | long size, |
614 | struct bts_struct __user *out) | 676 | struct bts_struct __user *out) |
615 | { | 677 | { |
616 | int end, i; | 678 | struct bts_struct ret; |
617 | void *ds = (void *)child->thread.ds_area_msr; | 679 | const unsigned char *raw; |
618 | 680 | size_t end, i; | |
619 | if (!ds) | 681 | int error; |
620 | return -ENXIO; | ||
621 | 682 | ||
622 | end = ds_get_bts_index(ds); | 683 | error = ds_get_bts_index(child, &end); |
623 | if (end <= 0) | 684 | if (error < 0) |
624 | return end; | 685 | return error; |
625 | 686 | ||
626 | if (size < (end * sizeof(struct bts_struct))) | 687 | if (size < (end * sizeof(struct bts_struct))) |
627 | return -EIO; | 688 | return -EIO; |
628 | 689 | ||
629 | for (i = 0; i < end; i++, out++) { | 690 | error = ds_access_bts(child, 0, (const void **)&raw); |
630 | struct bts_struct ret; | 691 | if (error < 0) |
631 | int retval; | 692 | return error; |
632 | 693 | ||
633 | retval = ds_read_bts(ds, i, &ret); | 694 | for (i = 0; i < end; i++, out++, raw += bts_cfg.sizeof_bts) { |
634 | if (retval < 0) | 695 | ptrace_bts_translate_record(&ret, raw); |
635 | return retval; | ||
636 | 696 | ||
637 | if (copy_to_user(out, &ret, sizeof(ret))) | 697 | if (copy_to_user(out, &ret, sizeof(ret))) |
638 | return -EFAULT; | 698 | return -EFAULT; |
639 | } | 699 | } |
640 | 700 | ||
641 | ds_clear(ds); | 701 | error = ds_clear_bts(child); |
702 | if (error < 0) | ||
703 | return error; | ||
642 | 704 | ||
643 | return end; | 705 | return end; |
644 | } | 706 | } |
645 | 707 | ||
708 | static void ptrace_bts_ovfl(struct task_struct *child) | ||
709 | { | ||
710 | send_sig(child->thread.bts_ovfl_signal, child, 0); | ||
711 | } | ||
712 | |||
646 | static int ptrace_bts_config(struct task_struct *child, | 713 | static int ptrace_bts_config(struct task_struct *child, |
647 | long cfg_size, | 714 | long cfg_size, |
648 | const struct ptrace_bts_config __user *ucfg) | 715 | const struct ptrace_bts_config __user *ucfg) |
649 | { | 716 | { |
650 | struct ptrace_bts_config cfg; | 717 | struct ptrace_bts_config cfg; |
651 | int bts_size, ret = 0; | 718 | int error = 0; |
652 | void *ds; | 719 | |
720 | error = -EOPNOTSUPP; | ||
721 | if (!bts_cfg.sizeof_bts) | ||
722 | goto errout; | ||
653 | 723 | ||
724 | error = -EIO; | ||
654 | if (cfg_size < sizeof(cfg)) | 725 | if (cfg_size < sizeof(cfg)) |
655 | return -EIO; | 726 | goto errout; |
656 | 727 | ||
728 | error = -EFAULT; | ||
657 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) | 729 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) |
658 | return -EFAULT; | 730 | goto errout; |
659 | 731 | ||
660 | if ((int)cfg.size < 0) | 732 | error = -EINVAL; |
661 | return -EINVAL; | 733 | if ((cfg.flags & PTRACE_BTS_O_SIGNAL) && |
734 | !(cfg.flags & PTRACE_BTS_O_ALLOC)) | ||
735 | goto errout; | ||
662 | 736 | ||
663 | bts_size = 0; | 737 | if (cfg.flags & PTRACE_BTS_O_ALLOC) { |
664 | ds = (void *)child->thread.ds_area_msr; | 738 | ds_ovfl_callback_t ovfl = NULL; |
665 | if (ds) { | 739 | unsigned int sig = 0; |
666 | bts_size = ds_get_bts_size(ds); | 740 | |
667 | if (bts_size < 0) | 741 | /* we ignore the error in case we were not tracing child */ |
668 | return bts_size; | 742 | (void)ds_release_bts(child); |
669 | } | 743 | |
670 | cfg.size = PAGE_ALIGN(cfg.size); | 744 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { |
745 | if (!cfg.signal) | ||
746 | goto errout; | ||
747 | |||
748 | sig = cfg.signal; | ||
749 | ovfl = ptrace_bts_ovfl; | ||
750 | } | ||
671 | 751 | ||
672 | if (bts_size != cfg.size) { | 752 | error = ds_request_bts(child, /* base = */ NULL, cfg.size, ovfl); |
673 | ret = ptrace_bts_realloc(child, cfg.size, | 753 | if (error < 0) |
674 | cfg.flags & PTRACE_BTS_O_CUT_SIZE); | ||
675 | if (ret < 0) | ||
676 | goto errout; | 754 | goto errout; |
677 | 755 | ||
678 | ds = (void *)child->thread.ds_area_msr; | 756 | child->thread.bts_ovfl_signal = sig; |
679 | } | 757 | } |
680 | 758 | ||
681 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) | 759 | error = -EINVAL; |
682 | ret = ds_set_overflow(ds, DS_O_SIGNAL); | 760 | if (!child->thread.ds_ctx && cfg.flags) |
683 | else | ||
684 | ret = ds_set_overflow(ds, DS_O_WRAP); | ||
685 | if (ret < 0) | ||
686 | goto errout; | 761 | goto errout; |
687 | 762 | ||
688 | if (cfg.flags & PTRACE_BTS_O_TRACE) | 763 | if (cfg.flags & PTRACE_BTS_O_TRACE) |
689 | child->thread.debugctlmsr |= ds_debugctl_mask(); | 764 | child->thread.debugctlmsr |= bts_cfg.debugctl_mask; |
690 | else | 765 | else |
691 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 766 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
692 | 767 | ||
693 | if (cfg.flags & PTRACE_BTS_O_SCHED) | 768 | if (cfg.flags & PTRACE_BTS_O_SCHED) |
694 | set_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 769 | set_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
695 | else | 770 | else |
696 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 771 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
697 | 772 | ||
698 | ret = sizeof(cfg); | 773 | error = sizeof(cfg); |
699 | 774 | ||
700 | out: | 775 | out: |
701 | if (child->thread.debugctlmsr) | 776 | if (child->thread.debugctlmsr) |
@@ -703,10 +778,10 @@ out: | |||
703 | else | 778 | else |
704 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 779 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); |
705 | 780 | ||
706 | return ret; | 781 | return error; |
707 | 782 | ||
708 | errout: | 783 | errout: |
709 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 784 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
710 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 785 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
711 | goto out; | 786 | goto out; |
712 | } | 787 | } |
@@ -715,29 +790,40 @@ static int ptrace_bts_status(struct task_struct *child, | |||
715 | long cfg_size, | 790 | long cfg_size, |
716 | struct ptrace_bts_config __user *ucfg) | 791 | struct ptrace_bts_config __user *ucfg) |
717 | { | 792 | { |
718 | void *ds = (void *)child->thread.ds_area_msr; | ||
719 | struct ptrace_bts_config cfg; | 793 | struct ptrace_bts_config cfg; |
794 | size_t end; | ||
795 | const void *base, *max; | ||
796 | int error; | ||
720 | 797 | ||
721 | if (cfg_size < sizeof(cfg)) | 798 | if (cfg_size < sizeof(cfg)) |
722 | return -EIO; | 799 | return -EIO; |
723 | 800 | ||
724 | memset(&cfg, 0, sizeof(cfg)); | 801 | error = ds_get_bts_end(child, &end); |
802 | if (error < 0) | ||
803 | return error; | ||
725 | 804 | ||
726 | if (ds) { | 805 | error = ds_access_bts(child, /* index = */ 0, &base); |
727 | cfg.size = ds_get_bts_size(ds); | 806 | if (error < 0) |
807 | return error; | ||
728 | 808 | ||
729 | if (ds_get_overflow(ds) == DS_O_SIGNAL) | 809 | error = ds_access_bts(child, /* index = */ end, &max); |
730 | cfg.flags |= PTRACE_BTS_O_SIGNAL; | 810 | if (error < 0) |
811 | return error; | ||
731 | 812 | ||
732 | if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) && | 813 | memset(&cfg, 0, sizeof(cfg)); |
733 | child->thread.debugctlmsr & ds_debugctl_mask()) | 814 | cfg.size = (max - base); |
734 | cfg.flags |= PTRACE_BTS_O_TRACE; | 815 | cfg.signal = child->thread.bts_ovfl_signal; |
816 | cfg.bts_size = sizeof(struct bts_struct); | ||
735 | 817 | ||
736 | if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS)) | 818 | if (cfg.signal) |
737 | cfg.flags |= PTRACE_BTS_O_SCHED; | 819 | cfg.flags |= PTRACE_BTS_O_SIGNAL; |
738 | } | ||
739 | 820 | ||
740 | cfg.bts_size = sizeof(struct bts_struct); | 821 | if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) && |
822 | child->thread.debugctlmsr & bts_cfg.debugctl_mask) | ||
823 | cfg.flags |= PTRACE_BTS_O_TRACE; | ||
824 | |||
825 | if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS)) | ||
826 | cfg.flags |= PTRACE_BTS_O_SCHED; | ||
741 | 827 | ||
742 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) | 828 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) |
743 | return -EFAULT; | 829 | return -EFAULT; |
@@ -745,89 +831,38 @@ static int ptrace_bts_status(struct task_struct *child, | |||
745 | return sizeof(cfg); | 831 | return sizeof(cfg); |
746 | } | 832 | } |
747 | 833 | ||
748 | |||
749 | static int ptrace_bts_write_record(struct task_struct *child, | 834 | static int ptrace_bts_write_record(struct task_struct *child, |
750 | const struct bts_struct *in) | 835 | const struct bts_struct *in) |
751 | { | 836 | { |
752 | int retval; | 837 | unsigned char bts_record[BTS_MAX_RECORD_SIZE]; |
753 | 838 | ||
754 | if (!child->thread.ds_area_msr) | 839 | BUG_ON(BTS_MAX_RECORD_SIZE < bts_cfg.sizeof_bts); |
755 | return -ENXIO; | ||
756 | 840 | ||
757 | retval = ds_write_bts((void *)child->thread.ds_area_msr, in); | 841 | memset(bts_record, 0, bts_cfg.sizeof_bts); |
758 | if (retval) | 842 | switch (in->qualifier) { |
759 | return retval; | 843 | case BTS_INVALID: |
844 | break; | ||
760 | 845 | ||
761 | return sizeof(*in); | 846 | case BTS_BRANCH: |
762 | } | 847 | bts_set(bts_record, bts_from, in->variant.lbr.from_ip); |
848 | bts_set(bts_record, bts_to, in->variant.lbr.to_ip); | ||
849 | break; | ||
763 | 850 | ||
764 | static int ptrace_bts_realloc(struct task_struct *child, | 851 | case BTS_TASK_ARRIVES: |
765 | int size, int reduce_size) | 852 | case BTS_TASK_DEPARTS: |
766 | { | 853 | bts_set(bts_record, bts_from, bts_escape); |
767 | unsigned long rlim, vm; | 854 | bts_set(bts_record, bts_qual, in->qualifier); |
768 | int ret, old_size; | 855 | bts_set(bts_record, bts_jiffies, in->variant.jiffies); |
856 | break; | ||
769 | 857 | ||
770 | if (size < 0) | 858 | default: |
771 | return -EINVAL; | 859 | return -EINVAL; |
772 | |||
773 | old_size = ds_get_bts_size((void *)child->thread.ds_area_msr); | ||
774 | if (old_size < 0) | ||
775 | return old_size; | ||
776 | |||
777 | ret = ds_free((void **)&child->thread.ds_area_msr); | ||
778 | if (ret < 0) | ||
779 | goto out; | ||
780 | |||
781 | size >>= PAGE_SHIFT; | ||
782 | old_size >>= PAGE_SHIFT; | ||
783 | |||
784 | current->mm->total_vm -= old_size; | ||
785 | current->mm->locked_vm -= old_size; | ||
786 | |||
787 | if (size == 0) | ||
788 | goto out; | ||
789 | |||
790 | rlim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT; | ||
791 | vm = current->mm->total_vm + size; | ||
792 | if (rlim < vm) { | ||
793 | ret = -ENOMEM; | ||
794 | |||
795 | if (!reduce_size) | ||
796 | goto out; | ||
797 | |||
798 | size = rlim - current->mm->total_vm; | ||
799 | if (size <= 0) | ||
800 | goto out; | ||
801 | } | 860 | } |
802 | 861 | ||
803 | rlim = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT; | 862 | /* The writing task will be the switched-to task on a context |
804 | vm = current->mm->locked_vm + size; | 863 | * switch. It needs to write into the switched-from task's BTS |
805 | if (rlim < vm) { | 864 | * buffer. */ |
806 | ret = -ENOMEM; | 865 | return ds_unchecked_write_bts(child, bts_record, bts_cfg.sizeof_bts); |
807 | |||
808 | if (!reduce_size) | ||
809 | goto out; | ||
810 | |||
811 | size = rlim - current->mm->locked_vm; | ||
812 | if (size <= 0) | ||
813 | goto out; | ||
814 | } | ||
815 | |||
816 | ret = ds_allocate((void **)&child->thread.ds_area_msr, | ||
817 | size << PAGE_SHIFT); | ||
818 | if (ret < 0) | ||
819 | goto out; | ||
820 | |||
821 | current->mm->total_vm += size; | ||
822 | current->mm->locked_vm += size; | ||
823 | |||
824 | out: | ||
825 | if (child->thread.ds_area_msr) | ||
826 | set_tsk_thread_flag(child, TIF_DS_AREA_MSR); | ||
827 | else | ||
828 | clear_tsk_thread_flag(child, TIF_DS_AREA_MSR); | ||
829 | |||
830 | return ret; | ||
831 | } | 866 | } |
832 | 867 | ||
833 | void ptrace_bts_take_timestamp(struct task_struct *tsk, | 868 | void ptrace_bts_take_timestamp(struct task_struct *tsk, |
@@ -840,7 +875,66 @@ void ptrace_bts_take_timestamp(struct task_struct *tsk, | |||
840 | 875 | ||
841 | ptrace_bts_write_record(tsk, &rec); | 876 | ptrace_bts_write_record(tsk, &rec); |
842 | } | 877 | } |
843 | #endif /* X86_BTS */ | 878 | |
879 | static const struct bts_configuration bts_cfg_netburst = { | ||
880 | .sizeof_bts = sizeof(long) * 3, | ||
881 | .sizeof_field = sizeof(long), | ||
882 | .debugctl_mask = (1<<2)|(1<<3)|(1<<5) | ||
883 | }; | ||
884 | |||
885 | static const struct bts_configuration bts_cfg_pentium_m = { | ||
886 | .sizeof_bts = sizeof(long) * 3, | ||
887 | .sizeof_field = sizeof(long), | ||
888 | .debugctl_mask = (1<<6)|(1<<7) | ||
889 | }; | ||
890 | |||
891 | static const struct bts_configuration bts_cfg_core2 = { | ||
892 | .sizeof_bts = 8 * 3, | ||
893 | .sizeof_field = 8, | ||
894 | .debugctl_mask = (1<<6)|(1<<7)|(1<<9) | ||
895 | }; | ||
896 | |||
897 | static inline void bts_configure(const struct bts_configuration *cfg) | ||
898 | { | ||
899 | bts_cfg = *cfg; | ||
900 | } | ||
901 | |||
902 | void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *c) | ||
903 | { | ||
904 | switch (c->x86) { | ||
905 | case 0x6: | ||
906 | switch (c->x86_model) { | ||
907 | case 0xD: | ||
908 | case 0xE: /* Pentium M */ | ||
909 | bts_configure(&bts_cfg_pentium_m); | ||
910 | break; | ||
911 | case 0xF: /* Core2 */ | ||
912 | case 0x1C: /* Atom */ | ||
913 | bts_configure(&bts_cfg_core2); | ||
914 | break; | ||
915 | default: | ||
916 | /* sorry, don't know about them */ | ||
917 | break; | ||
918 | } | ||
919 | break; | ||
920 | case 0xF: | ||
921 | switch (c->x86_model) { | ||
922 | case 0x0: | ||
923 | case 0x1: | ||
924 | case 0x2: /* Netburst */ | ||
925 | bts_configure(&bts_cfg_netburst); | ||
926 | break; | ||
927 | default: | ||
928 | /* sorry, don't know about them */ | ||
929 | break; | ||
930 | } | ||
931 | break; | ||
932 | default: | ||
933 | /* sorry, don't know about them */ | ||
934 | break; | ||
935 | } | ||
936 | } | ||
937 | #endif /* CONFIG_X86_PTRACE_BTS */ | ||
844 | 938 | ||
845 | /* | 939 | /* |
846 | * Called by kernel/ptrace.c when detaching.. | 940 | * Called by kernel/ptrace.c when detaching.. |
@@ -853,15 +947,15 @@ void ptrace_disable(struct task_struct *child) | |||
853 | #ifdef TIF_SYSCALL_EMU | 947 | #ifdef TIF_SYSCALL_EMU |
854 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | 948 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); |
855 | #endif | 949 | #endif |
856 | if (child->thread.ds_area_msr) { | 950 | #ifdef CONFIG_X86_PTRACE_BTS |
857 | #ifdef X86_BTS | 951 | (void)ds_release_bts(child); |
858 | ptrace_bts_realloc(child, 0, 0); | 952 | |
859 | #endif | 953 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
860 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 954 | if (!child->thread.debugctlmsr) |
861 | if (!child->thread.debugctlmsr) | 955 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); |
862 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 956 | |
863 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 957 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
864 | } | 958 | #endif /* CONFIG_X86_PTRACE_BTS */ |
865 | } | 959 | } |
866 | 960 | ||
867 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION | 961 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION |
@@ -981,7 +1075,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
981 | /* | 1075 | /* |
982 | * These bits need more cooking - not enabled yet: | 1076 | * These bits need more cooking - not enabled yet: |
983 | */ | 1077 | */ |
984 | #ifdef X86_BTS | 1078 | #ifdef CONFIG_X86_PTRACE_BTS |
985 | case PTRACE_BTS_CONFIG: | 1079 | case PTRACE_BTS_CONFIG: |
986 | ret = ptrace_bts_config | 1080 | ret = ptrace_bts_config |
987 | (child, data, (struct ptrace_bts_config __user *)addr); | 1081 | (child, data, (struct ptrace_bts_config __user *)addr); |
@@ -993,7 +1087,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
993 | break; | 1087 | break; |
994 | 1088 | ||
995 | case PTRACE_BTS_SIZE: | 1089 | case PTRACE_BTS_SIZE: |
996 | ret = ptrace_bts_get_size(child); | 1090 | ret = ds_get_bts_index(child, /* pos = */ NULL); |
997 | break; | 1091 | break; |
998 | 1092 | ||
999 | case PTRACE_BTS_GET: | 1093 | case PTRACE_BTS_GET: |
@@ -1002,14 +1096,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
1002 | break; | 1096 | break; |
1003 | 1097 | ||
1004 | case PTRACE_BTS_CLEAR: | 1098 | case PTRACE_BTS_CLEAR: |
1005 | ret = ptrace_bts_clear(child); | 1099 | ret = ds_clear_bts(child); |
1006 | break; | 1100 | break; |
1007 | 1101 | ||
1008 | case PTRACE_BTS_DRAIN: | 1102 | case PTRACE_BTS_DRAIN: |
1009 | ret = ptrace_bts_drain | 1103 | ret = ptrace_bts_drain |
1010 | (child, data, (struct bts_struct __user *) addr); | 1104 | (child, data, (struct bts_struct __user *) addr); |
1011 | break; | 1105 | break; |
1012 | #endif | 1106 | #endif /* CONFIG_X86_PTRACE_BTS */ |
1013 | 1107 | ||
1014 | default: | 1108 | default: |
1015 | ret = ptrace_request(child, request, addr, data); | 1109 | ret = ptrace_request(child, request, addr, data); |