diff options
Diffstat (limited to 'arch/x86/kernel/ptrace.c')
| -rw-r--r-- | arch/x86/kernel/ptrace.c | 478 |
1 files changed, 275 insertions, 203 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index fc3e8dcd9da6..e375b658efc3 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
| 15 | #include <linux/ptrace.h> | 15 | #include <linux/ptrace.h> |
| 16 | #include <linux/regset.h> | 16 | #include <linux/regset.h> |
| 17 | #include <linux/tracehook.h> | ||
| 17 | #include <linux/user.h> | 18 | #include <linux/user.h> |
| 18 | #include <linux/elf.h> | 19 | #include <linux/elf.h> |
| 19 | #include <linux/security.h> | 20 | #include <linux/security.h> |
| @@ -554,45 +555,115 @@ static int ptrace_set_debugreg(struct task_struct *child, | |||
| 554 | return 0; | 555 | return 0; |
| 555 | } | 556 | } |
| 556 | 557 | ||
| 557 | #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 | }; | ||
| 606 | |||
| 607 | static inline unsigned long bts_get(const char *base, enum bts_field field) | ||
| 608 | { | ||
| 609 | base += (bts_cfg.sizeof_field * field); | ||
| 610 | return *(unsigned long *)base; | ||
| 611 | } | ||
| 558 | 612 | ||
| 559 | static int ptrace_bts_get_size(struct task_struct *child) | 613 | static inline void bts_set(char *base, enum bts_field field, unsigned long val) |
| 560 | { | 614 | { |
| 561 | if (!child->thread.ds_area_msr) | 615 | base += (bts_cfg.sizeof_field * field);; |
| 562 | return -ENXIO; | 616 | (*(unsigned long *)base) = val; |
| 617 | } | ||
| 563 | 618 | ||
| 564 | 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 | } | ||
| 565 | } | 636 | } |
| 566 | 637 | ||
| 567 | static int ptrace_bts_read_record(struct task_struct *child, | 638 | static int ptrace_bts_read_record(struct task_struct *child, size_t index, |
| 568 | long index, | ||
| 569 | struct bts_struct __user *out) | 639 | struct bts_struct __user *out) |
| 570 | { | 640 | { |
| 571 | struct bts_struct ret; | 641 | struct bts_struct ret; |
| 572 | int retval; | 642 | const void *bts_record; |
| 573 | int bts_end; | 643 | size_t bts_index, bts_end; |
| 574 | int bts_index; | 644 | int error; |
| 575 | |||
| 576 | if (!child->thread.ds_area_msr) | ||
| 577 | return -ENXIO; | ||
| 578 | 645 | ||
| 579 | if (index < 0) | 646 | error = ds_get_bts_end(child, &bts_end); |
| 580 | return -EINVAL; | 647 | if (error < 0) |
| 648 | return error; | ||
| 581 | 649 | ||
| 582 | bts_end = ds_get_bts_end((void *)child->thread.ds_area_msr); | ||
| 583 | if (bts_end <= index) | 650 | if (bts_end <= index) |
| 584 | return -EINVAL; | 651 | return -EINVAL; |
| 585 | 652 | ||
| 653 | error = ds_get_bts_index(child, &bts_index); | ||
| 654 | if (error < 0) | ||
| 655 | return error; | ||
| 656 | |||
| 586 | /* translate the ptrace bts index into the ds bts index */ | 657 | /* translate the ptrace bts index into the ds bts index */ |
| 587 | bts_index = ds_get_bts_index((void *)child->thread.ds_area_msr); | 658 | bts_index += bts_end - (index + 1); |
| 588 | bts_index -= (index + 1); | 659 | if (bts_end <= bts_index) |
| 589 | if (bts_index < 0) | 660 | bts_index -= bts_end; |
| 590 | bts_index += bts_end; | ||
| 591 | 661 | ||
| 592 | retval = ds_read_bts((void *)child->thread.ds_area_msr, | 662 | error = ds_access_bts(child, bts_index, &bts_record); |
| 593 | bts_index, &ret); | 663 | if (error < 0) |
| 594 | if (retval < 0) | 664 | return error; |
| 595 | return retval; | 665 | |
| 666 | ptrace_bts_translate_record(&ret, bts_record); | ||
| 596 | 667 | ||
| 597 | if (copy_to_user(out, &ret, sizeof(ret))) | 668 | if (copy_to_user(out, &ret, sizeof(ret))) |
| 598 | return -EFAULT; | 669 | return -EFAULT; |
| @@ -600,101 +671,106 @@ static int ptrace_bts_read_record(struct task_struct *child, | |||
| 600 | return sizeof(ret); | 671 | return sizeof(ret); |
| 601 | } | 672 | } |
| 602 | 673 | ||
| 603 | static int ptrace_bts_clear(struct task_struct *child) | ||
| 604 | { | ||
| 605 | if (!child->thread.ds_area_msr) | ||
| 606 | return -ENXIO; | ||
| 607 | |||
| 608 | return ds_clear((void *)child->thread.ds_area_msr); | ||
| 609 | } | ||
| 610 | |||
| 611 | static int ptrace_bts_drain(struct task_struct *child, | 674 | static int ptrace_bts_drain(struct task_struct *child, |
| 612 | long size, | 675 | long size, |
| 613 | struct bts_struct __user *out) | 676 | struct bts_struct __user *out) |
| 614 | { | 677 | { |
| 615 | int end, i; | 678 | struct bts_struct ret; |
| 616 | void *ds = (void *)child->thread.ds_area_msr; | 679 | const unsigned char *raw; |
| 617 | 680 | size_t end, i; | |
| 618 | if (!ds) | 681 | int error; |
| 619 | return -ENXIO; | ||
| 620 | 682 | ||
| 621 | end = ds_get_bts_index(ds); | 683 | error = ds_get_bts_index(child, &end); |
| 622 | if (end <= 0) | 684 | if (error < 0) |
| 623 | return end; | 685 | return error; |
| 624 | 686 | ||
| 625 | if (size < (end * sizeof(struct bts_struct))) | 687 | if (size < (end * sizeof(struct bts_struct))) |
| 626 | return -EIO; | 688 | return -EIO; |
| 627 | 689 | ||
| 628 | for (i = 0; i < end; i++, out++) { | 690 | error = ds_access_bts(child, 0, (const void **)&raw); |
| 629 | struct bts_struct ret; | 691 | if (error < 0) |
| 630 | int retval; | 692 | return error; |
| 631 | 693 | ||
| 632 | retval = ds_read_bts(ds, i, &ret); | 694 | for (i = 0; i < end; i++, out++, raw += bts_cfg.sizeof_bts) { |
| 633 | if (retval < 0) | 695 | ptrace_bts_translate_record(&ret, raw); |
| 634 | return retval; | ||
| 635 | 696 | ||
| 636 | if (copy_to_user(out, &ret, sizeof(ret))) | 697 | if (copy_to_user(out, &ret, sizeof(ret))) |
| 637 | return -EFAULT; | 698 | return -EFAULT; |
| 638 | } | 699 | } |
| 639 | 700 | ||
| 640 | ds_clear(ds); | 701 | error = ds_clear_bts(child); |
| 702 | if (error < 0) | ||
| 703 | return error; | ||
| 641 | 704 | ||
| 642 | return end; | 705 | return end; |
| 643 | } | 706 | } |
| 644 | 707 | ||
| 708 | static void ptrace_bts_ovfl(struct task_struct *child) | ||
| 709 | { | ||
| 710 | send_sig(child->thread.bts_ovfl_signal, child, 0); | ||
| 711 | } | ||
| 712 | |||
| 645 | static int ptrace_bts_config(struct task_struct *child, | 713 | static int ptrace_bts_config(struct task_struct *child, |
| 646 | long cfg_size, | 714 | long cfg_size, |
| 647 | const struct ptrace_bts_config __user *ucfg) | 715 | const struct ptrace_bts_config __user *ucfg) |
| 648 | { | 716 | { |
| 649 | struct ptrace_bts_config cfg; | 717 | struct ptrace_bts_config cfg; |
| 650 | int bts_size, ret = 0; | 718 | int error = 0; |
| 651 | void *ds; | 719 | |
| 720 | error = -EOPNOTSUPP; | ||
| 721 | if (!bts_cfg.sizeof_bts) | ||
| 722 | goto errout; | ||
| 652 | 723 | ||
| 724 | error = -EIO; | ||
| 653 | if (cfg_size < sizeof(cfg)) | 725 | if (cfg_size < sizeof(cfg)) |
| 654 | return -EIO; | 726 | goto errout; |
| 655 | 727 | ||
| 728 | error = -EFAULT; | ||
| 656 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) | 729 | if (copy_from_user(&cfg, ucfg, sizeof(cfg))) |
| 657 | return -EFAULT; | 730 | goto errout; |
| 658 | 731 | ||
| 659 | if ((int)cfg.size < 0) | 732 | error = -EINVAL; |
| 660 | return -EINVAL; | 733 | if ((cfg.flags & PTRACE_BTS_O_SIGNAL) && |
| 734 | !(cfg.flags & PTRACE_BTS_O_ALLOC)) | ||
| 735 | goto errout; | ||
| 661 | 736 | ||
| 662 | bts_size = 0; | 737 | if (cfg.flags & PTRACE_BTS_O_ALLOC) { |
| 663 | ds = (void *)child->thread.ds_area_msr; | 738 | ds_ovfl_callback_t ovfl = NULL; |
| 664 | if (ds) { | 739 | unsigned int sig = 0; |
| 665 | bts_size = ds_get_bts_size(ds); | 740 | |
| 666 | if (bts_size < 0) | 741 | /* we ignore the error in case we were not tracing child */ |
| 667 | return bts_size; | 742 | (void)ds_release_bts(child); |
| 668 | } | ||
| 669 | cfg.size = PAGE_ALIGN(cfg.size); | ||
| 670 | 743 | ||
| 671 | if (bts_size != cfg.size) { | 744 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) { |
| 672 | ret = ptrace_bts_realloc(child, cfg.size, | 745 | if (!cfg.signal) |
| 673 | cfg.flags & PTRACE_BTS_O_CUT_SIZE); | 746 | goto errout; |
| 674 | if (ret < 0) | 747 | |
| 748 | sig = cfg.signal; | ||
| 749 | ovfl = ptrace_bts_ovfl; | ||
| 750 | } | ||
| 751 | |||
| 752 | error = ds_request_bts(child, /* base = */ NULL, cfg.size, ovfl); | ||
| 753 | if (error < 0) | ||
| 675 | goto errout; | 754 | goto errout; |
| 676 | 755 | ||
| 677 | ds = (void *)child->thread.ds_area_msr; | 756 | child->thread.bts_ovfl_signal = sig; |
| 678 | } | 757 | } |
| 679 | 758 | ||
| 680 | if (cfg.flags & PTRACE_BTS_O_SIGNAL) | 759 | error = -EINVAL; |
| 681 | ret = ds_set_overflow(ds, DS_O_SIGNAL); | 760 | if (!child->thread.ds_ctx && cfg.flags) |
| 682 | else | ||
| 683 | ret = ds_set_overflow(ds, DS_O_WRAP); | ||
| 684 | if (ret < 0) | ||
| 685 | goto errout; | 761 | goto errout; |
| 686 | 762 | ||
| 687 | if (cfg.flags & PTRACE_BTS_O_TRACE) | 763 | if (cfg.flags & PTRACE_BTS_O_TRACE) |
| 688 | child->thread.debugctlmsr |= ds_debugctl_mask(); | 764 | child->thread.debugctlmsr |= bts_cfg.debugctl_mask; |
| 689 | else | 765 | else |
| 690 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 766 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
| 691 | 767 | ||
| 692 | if (cfg.flags & PTRACE_BTS_O_SCHED) | 768 | if (cfg.flags & PTRACE_BTS_O_SCHED) |
| 693 | set_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 769 | set_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
| 694 | else | 770 | else |
| 695 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 771 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
| 696 | 772 | ||
| 697 | ret = sizeof(cfg); | 773 | error = sizeof(cfg); |
| 698 | 774 | ||
| 699 | out: | 775 | out: |
| 700 | if (child->thread.debugctlmsr) | 776 | if (child->thread.debugctlmsr) |
| @@ -702,10 +778,10 @@ out: | |||
| 702 | else | 778 | else |
| 703 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 779 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); |
| 704 | 780 | ||
| 705 | return ret; | 781 | return error; |
| 706 | 782 | ||
| 707 | errout: | 783 | errout: |
| 708 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 784 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
| 709 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 785 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
| 710 | goto out; | 786 | goto out; |
| 711 | } | 787 | } |
| @@ -714,29 +790,40 @@ static int ptrace_bts_status(struct task_struct *child, | |||
| 714 | long cfg_size, | 790 | long cfg_size, |
| 715 | struct ptrace_bts_config __user *ucfg) | 791 | struct ptrace_bts_config __user *ucfg) |
| 716 | { | 792 | { |
| 717 | void *ds = (void *)child->thread.ds_area_msr; | ||
| 718 | struct ptrace_bts_config cfg; | 793 | struct ptrace_bts_config cfg; |
| 794 | size_t end; | ||
| 795 | const void *base, *max; | ||
| 796 | int error; | ||
| 719 | 797 | ||
| 720 | if (cfg_size < sizeof(cfg)) | 798 | if (cfg_size < sizeof(cfg)) |
| 721 | return -EIO; | 799 | return -EIO; |
| 722 | 800 | ||
| 723 | memset(&cfg, 0, sizeof(cfg)); | 801 | error = ds_get_bts_end(child, &end); |
| 802 | if (error < 0) | ||
| 803 | return error; | ||
| 724 | 804 | ||
| 725 | if (ds) { | 805 | error = ds_access_bts(child, /* index = */ 0, &base); |
| 726 | cfg.size = ds_get_bts_size(ds); | 806 | if (error < 0) |
| 807 | return error; | ||
| 727 | 808 | ||
| 728 | if (ds_get_overflow(ds) == DS_O_SIGNAL) | 809 | error = ds_access_bts(child, /* index = */ end, &max); |
| 729 | cfg.flags |= PTRACE_BTS_O_SIGNAL; | 810 | if (error < 0) |
| 811 | return error; | ||
| 730 | 812 | ||
| 731 | if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) && | 813 | memset(&cfg, 0, sizeof(cfg)); |
| 732 | child->thread.debugctlmsr & ds_debugctl_mask()) | 814 | cfg.size = (max - base); |
| 733 | cfg.flags |= PTRACE_BTS_O_TRACE; | 815 | cfg.signal = child->thread.bts_ovfl_signal; |
| 816 | cfg.bts_size = sizeof(struct bts_struct); | ||
| 734 | 817 | ||
| 735 | if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS)) | 818 | if (cfg.signal) |
| 736 | cfg.flags |= PTRACE_BTS_O_SCHED; | 819 | cfg.flags |= PTRACE_BTS_O_SIGNAL; |
| 737 | } | ||
| 738 | 820 | ||
| 739 | 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; | ||
| 740 | 827 | ||
| 741 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) | 828 | if (copy_to_user(ucfg, &cfg, sizeof(cfg))) |
| 742 | return -EFAULT; | 829 | return -EFAULT; |
| @@ -744,89 +831,38 @@ static int ptrace_bts_status(struct task_struct *child, | |||
| 744 | return sizeof(cfg); | 831 | return sizeof(cfg); |
| 745 | } | 832 | } |
| 746 | 833 | ||
| 747 | |||
| 748 | static int ptrace_bts_write_record(struct task_struct *child, | 834 | static int ptrace_bts_write_record(struct task_struct *child, |
| 749 | const struct bts_struct *in) | 835 | const struct bts_struct *in) |
| 750 | { | 836 | { |
| 751 | int retval; | 837 | unsigned char bts_record[BTS_MAX_RECORD_SIZE]; |
| 752 | 838 | ||
| 753 | if (!child->thread.ds_area_msr) | 839 | BUG_ON(BTS_MAX_RECORD_SIZE < bts_cfg.sizeof_bts); |
| 754 | return -ENXIO; | ||
| 755 | 840 | ||
| 756 | retval = ds_write_bts((void *)child->thread.ds_area_msr, in); | 841 | memset(bts_record, 0, bts_cfg.sizeof_bts); |
| 757 | if (retval) | 842 | switch (in->qualifier) { |
| 758 | return retval; | 843 | case BTS_INVALID: |
| 844 | break; | ||
| 759 | 845 | ||
| 760 | return sizeof(*in); | 846 | case BTS_BRANCH: |
| 761 | } | 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; | ||
| 762 | 850 | ||
| 763 | static int ptrace_bts_realloc(struct task_struct *child, | 851 | case BTS_TASK_ARRIVES: |
| 764 | int size, int reduce_size) | 852 | case BTS_TASK_DEPARTS: |
| 765 | { | 853 | bts_set(bts_record, bts_from, bts_escape); |
| 766 | unsigned long rlim, vm; | 854 | bts_set(bts_record, bts_qual, in->qualifier); |
| 767 | int ret, old_size; | 855 | bts_set(bts_record, bts_jiffies, in->variant.jiffies); |
| 856 | break; | ||
| 768 | 857 | ||
| 769 | if (size < 0) | 858 | default: |
| 770 | return -EINVAL; | 859 | return -EINVAL; |
| 771 | |||
| 772 | old_size = ds_get_bts_size((void *)child->thread.ds_area_msr); | ||
| 773 | if (old_size < 0) | ||
| 774 | return old_size; | ||
| 775 | |||
| 776 | ret = ds_free((void **)&child->thread.ds_area_msr); | ||
| 777 | if (ret < 0) | ||
| 778 | goto out; | ||
| 779 | |||
| 780 | size >>= PAGE_SHIFT; | ||
| 781 | old_size >>= PAGE_SHIFT; | ||
| 782 | |||
| 783 | current->mm->total_vm -= old_size; | ||
| 784 | current->mm->locked_vm -= old_size; | ||
| 785 | |||
| 786 | if (size == 0) | ||
| 787 | goto out; | ||
| 788 | |||
| 789 | rlim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT; | ||
| 790 | vm = current->mm->total_vm + size; | ||
| 791 | if (rlim < vm) { | ||
| 792 | ret = -ENOMEM; | ||
| 793 | |||
| 794 | if (!reduce_size) | ||
| 795 | goto out; | ||
| 796 | |||
| 797 | size = rlim - current->mm->total_vm; | ||
| 798 | if (size <= 0) | ||
| 799 | goto out; | ||
| 800 | } | ||
| 801 | |||
| 802 | rlim = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT; | ||
| 803 | vm = current->mm->locked_vm + size; | ||
| 804 | if (rlim < vm) { | ||
| 805 | ret = -ENOMEM; | ||
| 806 | |||
| 807 | if (!reduce_size) | ||
| 808 | goto out; | ||
| 809 | |||
| 810 | size = rlim - current->mm->locked_vm; | ||
| 811 | if (size <= 0) | ||
| 812 | goto out; | ||
| 813 | } | 860 | } |
| 814 | 861 | ||
| 815 | ret = ds_allocate((void **)&child->thread.ds_area_msr, | 862 | /* The writing task will be the switched-to task on a context |
| 816 | size << PAGE_SHIFT); | 863 | * switch. It needs to write into the switched-from task's BTS |
| 817 | if (ret < 0) | 864 | * buffer. */ |
| 818 | goto out; | 865 | return ds_unchecked_write_bts(child, bts_record, bts_cfg.sizeof_bts); |
| 819 | |||
| 820 | current->mm->total_vm += size; | ||
| 821 | current->mm->locked_vm += size; | ||
| 822 | |||
| 823 | out: | ||
| 824 | if (child->thread.ds_area_msr) | ||
| 825 | set_tsk_thread_flag(child, TIF_DS_AREA_MSR); | ||
| 826 | else | ||
| 827 | clear_tsk_thread_flag(child, TIF_DS_AREA_MSR); | ||
| 828 | |||
| 829 | return ret; | ||
| 830 | } | 866 | } |
| 831 | 867 | ||
| 832 | void ptrace_bts_take_timestamp(struct task_struct *tsk, | 868 | void ptrace_bts_take_timestamp(struct task_struct *tsk, |
| @@ -839,7 +875,66 @@ void ptrace_bts_take_timestamp(struct task_struct *tsk, | |||
| 839 | 875 | ||
| 840 | ptrace_bts_write_record(tsk, &rec); | 876 | ptrace_bts_write_record(tsk, &rec); |
| 841 | } | 877 | } |
| 842 | #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 */ | ||
| 843 | 938 | ||
| 844 | /* | 939 | /* |
| 845 | * Called by kernel/ptrace.c when detaching.. | 940 | * Called by kernel/ptrace.c when detaching.. |
| @@ -852,15 +947,15 @@ void ptrace_disable(struct task_struct *child) | |||
| 852 | #ifdef TIF_SYSCALL_EMU | 947 | #ifdef TIF_SYSCALL_EMU |
| 853 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); | 948 | clear_tsk_thread_flag(child, TIF_SYSCALL_EMU); |
| 854 | #endif | 949 | #endif |
| 855 | if (child->thread.ds_area_msr) { | 950 | #ifdef CONFIG_X86_PTRACE_BTS |
| 856 | #ifdef X86_BTS | 951 | (void)ds_release_bts(child); |
| 857 | ptrace_bts_realloc(child, 0, 0); | 952 | |
| 858 | #endif | 953 | child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask; |
| 859 | child->thread.debugctlmsr &= ~ds_debugctl_mask(); | 954 | if (!child->thread.debugctlmsr) |
| 860 | if (!child->thread.debugctlmsr) | 955 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); |
| 861 | clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR); | 956 | |
| 862 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); | 957 | clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS); |
| 863 | } | 958 | #endif /* CONFIG_X86_PTRACE_BTS */ |
| 864 | } | 959 | } |
| 865 | 960 | ||
| 866 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION | 961 | #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION |
| @@ -980,7 +1075,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
| 980 | /* | 1075 | /* |
| 981 | * These bits need more cooking - not enabled yet: | 1076 | * These bits need more cooking - not enabled yet: |
| 982 | */ | 1077 | */ |
| 983 | #ifdef X86_BTS | 1078 | #ifdef CONFIG_X86_PTRACE_BTS |
| 984 | case PTRACE_BTS_CONFIG: | 1079 | case PTRACE_BTS_CONFIG: |
| 985 | ret = ptrace_bts_config | 1080 | ret = ptrace_bts_config |
| 986 | (child, data, (struct ptrace_bts_config __user *)addr); | 1081 | (child, data, (struct ptrace_bts_config __user *)addr); |
| @@ -992,7 +1087,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
| 992 | break; | 1087 | break; |
| 993 | 1088 | ||
| 994 | case PTRACE_BTS_SIZE: | 1089 | case PTRACE_BTS_SIZE: |
| 995 | ret = ptrace_bts_get_size(child); | 1090 | ret = ds_get_bts_index(child, /* pos = */ NULL); |
| 996 | break; | 1091 | break; |
| 997 | 1092 | ||
| 998 | case PTRACE_BTS_GET: | 1093 | case PTRACE_BTS_GET: |
| @@ -1001,14 +1096,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) | |||
| 1001 | break; | 1096 | break; |
| 1002 | 1097 | ||
| 1003 | case PTRACE_BTS_CLEAR: | 1098 | case PTRACE_BTS_CLEAR: |
| 1004 | ret = ptrace_bts_clear(child); | 1099 | ret = ds_clear_bts(child); |
| 1005 | break; | 1100 | break; |
| 1006 | 1101 | ||
| 1007 | case PTRACE_BTS_DRAIN: | 1102 | case PTRACE_BTS_DRAIN: |
| 1008 | ret = ptrace_bts_drain | 1103 | ret = ptrace_bts_drain |
| 1009 | (child, data, (struct bts_struct __user *) addr); | 1104 | (child, data, (struct bts_struct __user *) addr); |
| 1010 | break; | 1105 | break; |
| 1011 | #endif | 1106 | #endif /* CONFIG_X86_PTRACE_BTS */ |
| 1012 | 1107 | ||
| 1013 | default: | 1108 | default: |
| 1014 | ret = ptrace_request(child, request, addr, data); | 1109 | ret = ptrace_request(child, request, addr, data); |
| @@ -1375,30 +1470,6 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code) | |||
| 1375 | force_sig_info(SIGTRAP, &info, tsk); | 1470 | force_sig_info(SIGTRAP, &info, tsk); |
| 1376 | } | 1471 | } |
| 1377 | 1472 | ||
| 1378 | static void syscall_trace(struct pt_regs *regs) | ||
| 1379 | { | ||
| 1380 | if (!(current->ptrace & PT_PTRACED)) | ||
| 1381 | return; | ||
| 1382 | |||
| 1383 | #if 0 | ||
| 1384 | printk("trace %s ip %lx sp %lx ax %d origrax %d caller %lx tiflags %x ptrace %x\n", | ||
| 1385 | current->comm, | ||
| 1386 | regs->ip, regs->sp, regs->ax, regs->orig_ax, __builtin_return_address(0), | ||
| 1387 | current_thread_info()->flags, current->ptrace); | ||
| 1388 | #endif | ||
| 1389 | |||
| 1390 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) | ||
| 1391 | ? 0x80 : 0)); | ||
| 1392 | /* | ||
| 1393 | * this isn't the same as continuing with a signal, but it will do | ||
| 1394 | * for normal use. strace only continues with a signal if the | ||
| 1395 | * stopping signal is not SIGTRAP. -brl | ||
| 1396 | */ | ||
| 1397 | if (current->exit_code) { | ||
| 1398 | send_sig(current->exit_code, current, 1); | ||
| 1399 | current->exit_code = 0; | ||
| 1400 | } | ||
| 1401 | } | ||
| 1402 | 1473 | ||
| 1403 | #ifdef CONFIG_X86_32 | 1474 | #ifdef CONFIG_X86_32 |
| 1404 | # define IS_IA32 1 | 1475 | # define IS_IA32 1 |
| @@ -1432,8 +1503,9 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs) | |||
| 1432 | if (unlikely(test_thread_flag(TIF_SYSCALL_EMU))) | 1503 | if (unlikely(test_thread_flag(TIF_SYSCALL_EMU))) |
| 1433 | ret = -1L; | 1504 | ret = -1L; |
| 1434 | 1505 | ||
| 1435 | if (ret || test_thread_flag(TIF_SYSCALL_TRACE)) | 1506 | if ((ret || test_thread_flag(TIF_SYSCALL_TRACE)) && |
| 1436 | syscall_trace(regs); | 1507 | tracehook_report_syscall_entry(regs)) |
| 1508 | ret = -1L; | ||
| 1437 | 1509 | ||
| 1438 | if (unlikely(current->audit_context)) { | 1510 | if (unlikely(current->audit_context)) { |
| 1439 | if (IS_IA32) | 1511 | if (IS_IA32) |
| @@ -1459,7 +1531,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs) | |||
| 1459 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); | 1531 | audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax); |
| 1460 | 1532 | ||
| 1461 | if (test_thread_flag(TIF_SYSCALL_TRACE)) | 1533 | if (test_thread_flag(TIF_SYSCALL_TRACE)) |
| 1462 | syscall_trace(regs); | 1534 | tracehook_report_syscall_exit(regs, 0); |
| 1463 | 1535 | ||
| 1464 | /* | 1536 | /* |
| 1465 | * If TIF_SYSCALL_EMU is set, we only get here because of | 1537 | * If TIF_SYSCALL_EMU is set, we only get here because of |
| @@ -1475,6 +1547,6 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs) | |||
| 1475 | * system call instruction. | 1547 | * system call instruction. |
| 1476 | */ | 1548 | */ |
| 1477 | if (test_thread_flag(TIF_SINGLESTEP) && | 1549 | if (test_thread_flag(TIF_SINGLESTEP) && |
| 1478 | (current->ptrace & PT_PTRACED)) | 1550 | tracehook_consider_fatal_signal(current, SIGTRAP, SIG_DFL)) |
| 1479 | send_sigtrap(current, regs, 0); | 1551 | send_sigtrap(current, regs, 0); |
| 1480 | } | 1552 | } |
