diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2008-04-19 12:17:34 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2008-04-19 12:17:34 -0400 |
commit | cf816ecb533ab96b883dfdc0db174598b5b5c4d2 (patch) | |
tree | 1b7705db288ae2917105e624b01fdf81e0882bf1 /kernel | |
parent | adf6d34e460387ee3e8f1e1875d52bff51212c7d (diff) | |
parent | 15f7d677ccff6f0f5de8a1ee43a792567e9f9de9 (diff) |
Merge branch 'merge-fixes' into devel
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 3 | ||||
-rw-r--r-- | kernel/audit.c | 24 | ||||
-rw-r--r-- | kernel/audit.h | 25 | ||||
-rw-r--r-- | kernel/auditfilter.c | 99 | ||||
-rw-r--r-- | kernel/auditsc.c | 74 | ||||
-rw-r--r-- | kernel/cgroup.c | 7 | ||||
-rw-r--r-- | kernel/compat.c | 15 | ||||
-rw-r--r-- | kernel/hrtimer.c | 22 | ||||
-rw-r--r-- | kernel/kgdb.c | 1700 | ||||
-rw-r--r-- | kernel/posix-cpu-timers.c | 30 | ||||
-rw-r--r-- | kernel/printk.c | 17 | ||||
-rw-r--r-- | kernel/sched_fair.c | 6 | ||||
-rw-r--r-- | kernel/semaphore.c | 264 | ||||
-rw-r--r-- | kernel/signal.c | 71 | ||||
-rw-r--r-- | kernel/time/clocksource.c | 30 | ||||
-rw-r--r-- | kernel/time/tick-broadcast.c | 2 | ||||
-rw-r--r-- | kernel/time/tick-common.c | 4 | ||||
-rw-r--r-- | kernel/time/tick-oneshot.c | 2 | ||||
-rw-r--r-- | kernel/time/tick-sched.c | 6 | ||||
-rw-r--r-- | kernel/timer.c | 16 | ||||
-rw-r--r-- | kernel/workqueue.c | 2 |
21 files changed, 2187 insertions, 232 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index 6c584c55a6e9..6c5f081132a4 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -8,7 +8,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ | |||
8 | signal.o sys.o kmod.o workqueue.o pid.o \ | 8 | signal.o sys.o kmod.o workqueue.o pid.o \ |
9 | rcupdate.o extable.o params.o posix-timers.o \ | 9 | rcupdate.o extable.o params.o posix-timers.o \ |
10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ | 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ |
11 | hrtimer.o rwsem.o nsproxy.o srcu.o \ | 11 | hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ |
12 | notifier.o ksysfs.o pm_qos_params.o | 12 | notifier.o ksysfs.o pm_qos_params.o |
13 | 13 | ||
14 | obj-$(CONFIG_SYSCTL) += sysctl_check.o | 14 | obj-$(CONFIG_SYSCTL) += sysctl_check.o |
@@ -53,6 +53,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o | |||
53 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o | 53 | obj-$(CONFIG_AUDITSYSCALL) += auditsc.o |
54 | obj-$(CONFIG_AUDIT_TREE) += audit_tree.o | 54 | obj-$(CONFIG_AUDIT_TREE) += audit_tree.o |
55 | obj-$(CONFIG_KPROBES) += kprobes.o | 55 | obj-$(CONFIG_KPROBES) += kprobes.o |
56 | obj-$(CONFIG_KGDB) += kgdb.o | ||
56 | obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o | 57 | obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o |
57 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ | 58 | obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ |
58 | obj-$(CONFIG_SECCOMP) += seccomp.o | 59 | obj-$(CONFIG_SECCOMP) += seccomp.o |
diff --git a/kernel/audit.c b/kernel/audit.c index b782b046543d..a7b16086d36f 100644 --- a/kernel/audit.c +++ b/kernel/audit.c | |||
@@ -21,7 +21,7 @@ | |||
21 | * | 21 | * |
22 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> | 22 | * Written by Rickard E. (Rik) Faith <faith@redhat.com> |
23 | * | 23 | * |
24 | * Goals: 1) Integrate fully with SELinux. | 24 | * Goals: 1) Integrate fully with Security Modules. |
25 | * 2) Minimal run-time overhead: | 25 | * 2) Minimal run-time overhead: |
26 | * a) Minimal when syscall auditing is disabled (audit_enable=0). | 26 | * a) Minimal when syscall auditing is disabled (audit_enable=0). |
27 | * b) Small when syscall auditing is enabled and no audit record | 27 | * b) Small when syscall auditing is enabled and no audit record |
@@ -55,7 +55,6 @@ | |||
55 | #include <net/netlink.h> | 55 | #include <net/netlink.h> |
56 | #include <linux/skbuff.h> | 56 | #include <linux/skbuff.h> |
57 | #include <linux/netlink.h> | 57 | #include <linux/netlink.h> |
58 | #include <linux/selinux.h> | ||
59 | #include <linux/inotify.h> | 58 | #include <linux/inotify.h> |
60 | #include <linux/freezer.h> | 59 | #include <linux/freezer.h> |
61 | #include <linux/tty.h> | 60 | #include <linux/tty.h> |
@@ -265,13 +264,13 @@ static int audit_log_config_change(char *function_name, int new, int old, | |||
265 | char *ctx = NULL; | 264 | char *ctx = NULL; |
266 | u32 len; | 265 | u32 len; |
267 | 266 | ||
268 | rc = selinux_sid_to_string(sid, &ctx, &len); | 267 | rc = security_secid_to_secctx(sid, &ctx, &len); |
269 | if (rc) { | 268 | if (rc) { |
270 | audit_log_format(ab, " sid=%u", sid); | 269 | audit_log_format(ab, " sid=%u", sid); |
271 | allow_changes = 0; /* Something weird, deny request */ | 270 | allow_changes = 0; /* Something weird, deny request */ |
272 | } else { | 271 | } else { |
273 | audit_log_format(ab, " subj=%s", ctx); | 272 | audit_log_format(ab, " subj=%s", ctx); |
274 | kfree(ctx); | 273 | security_release_secctx(ctx, len); |
275 | } | 274 | } |
276 | } | 275 | } |
277 | audit_log_format(ab, " res=%d", allow_changes); | 276 | audit_log_format(ab, " res=%d", allow_changes); |
@@ -550,12 +549,13 @@ static int audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type, | |||
550 | audit_log_format(*ab, "user pid=%d uid=%u auid=%u", | 549 | audit_log_format(*ab, "user pid=%d uid=%u auid=%u", |
551 | pid, uid, auid); | 550 | pid, uid, auid); |
552 | if (sid) { | 551 | if (sid) { |
553 | rc = selinux_sid_to_string(sid, &ctx, &len); | 552 | rc = security_secid_to_secctx(sid, &ctx, &len); |
554 | if (rc) | 553 | if (rc) |
555 | audit_log_format(*ab, " ssid=%u", sid); | 554 | audit_log_format(*ab, " ssid=%u", sid); |
556 | else | 555 | else { |
557 | audit_log_format(*ab, " subj=%s", ctx); | 556 | audit_log_format(*ab, " subj=%s", ctx); |
558 | kfree(ctx); | 557 | security_release_secctx(ctx, len); |
558 | } | ||
559 | } | 559 | } |
560 | 560 | ||
561 | return rc; | 561 | return rc; |
@@ -758,18 +758,18 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
758 | break; | 758 | break; |
759 | } | 759 | } |
760 | case AUDIT_SIGNAL_INFO: | 760 | case AUDIT_SIGNAL_INFO: |
761 | err = selinux_sid_to_string(audit_sig_sid, &ctx, &len); | 761 | err = security_secid_to_secctx(audit_sig_sid, &ctx, &len); |
762 | if (err) | 762 | if (err) |
763 | return err; | 763 | return err; |
764 | sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL); | 764 | sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL); |
765 | if (!sig_data) { | 765 | if (!sig_data) { |
766 | kfree(ctx); | 766 | security_release_secctx(ctx, len); |
767 | return -ENOMEM; | 767 | return -ENOMEM; |
768 | } | 768 | } |
769 | sig_data->uid = audit_sig_uid; | 769 | sig_data->uid = audit_sig_uid; |
770 | sig_data->pid = audit_sig_pid; | 770 | sig_data->pid = audit_sig_pid; |
771 | memcpy(sig_data->ctx, ctx, len); | 771 | memcpy(sig_data->ctx, ctx, len); |
772 | kfree(ctx); | 772 | security_release_secctx(ctx, len); |
773 | audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_SIGNAL_INFO, | 773 | audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_SIGNAL_INFO, |
774 | 0, 0, sig_data, sizeof(*sig_data) + len); | 774 | 0, 0, sig_data, sizeof(*sig_data) + len); |
775 | kfree(sig_data); | 775 | kfree(sig_data); |
@@ -881,10 +881,6 @@ static int __init audit_init(void) | |||
881 | audit_enabled = audit_default; | 881 | audit_enabled = audit_default; |
882 | audit_ever_enabled |= !!audit_default; | 882 | audit_ever_enabled |= !!audit_default; |
883 | 883 | ||
884 | /* Register the callback with selinux. This callback will be invoked | ||
885 | * when a new policy is loaded. */ | ||
886 | selinux_audit_set_callback(&selinux_audit_rule_update); | ||
887 | |||
888 | audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized"); | 884 | audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized"); |
889 | 885 | ||
890 | #ifdef CONFIG_AUDITSYSCALL | 886 | #ifdef CONFIG_AUDITSYSCALL |
diff --git a/kernel/audit.h b/kernel/audit.h index 2554bd524fd1..3cfc54ee3e1f 100644 --- a/kernel/audit.h +++ b/kernel/audit.h | |||
@@ -65,34 +65,9 @@ struct audit_watch { | |||
65 | struct list_head rules; /* associated rules */ | 65 | struct list_head rules; /* associated rules */ |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct audit_field { | ||
69 | u32 type; | ||
70 | u32 val; | ||
71 | u32 op; | ||
72 | char *se_str; | ||
73 | struct selinux_audit_rule *se_rule; | ||
74 | }; | ||
75 | |||
76 | struct audit_tree; | 68 | struct audit_tree; |
77 | struct audit_chunk; | 69 | struct audit_chunk; |
78 | 70 | ||
79 | struct audit_krule { | ||
80 | int vers_ops; | ||
81 | u32 flags; | ||
82 | u32 listnr; | ||
83 | u32 action; | ||
84 | u32 mask[AUDIT_BITMASK_SIZE]; | ||
85 | u32 buflen; /* for data alloc on list rules */ | ||
86 | u32 field_count; | ||
87 | char *filterkey; /* ties events to rules */ | ||
88 | struct audit_field *fields; | ||
89 | struct audit_field *arch_f; /* quick access to arch field */ | ||
90 | struct audit_field *inode_f; /* quick access to an inode field */ | ||
91 | struct audit_watch *watch; /* associated watch */ | ||
92 | struct audit_tree *tree; /* associated watched tree */ | ||
93 | struct list_head rlist; /* entry in audit_{watch,tree}.rules list */ | ||
94 | }; | ||
95 | |||
96 | struct audit_entry { | 71 | struct audit_entry { |
97 | struct list_head list; | 72 | struct list_head list; |
98 | struct rcu_head rcu; | 73 | struct rcu_head rcu; |
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index 2f2914b7cc30..28fef6bf8534 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <linux/netlink.h> | 28 | #include <linux/netlink.h> |
29 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
30 | #include <linux/inotify.h> | 30 | #include <linux/inotify.h> |
31 | #include <linux/selinux.h> | 31 | #include <linux/security.h> |
32 | #include "audit.h" | 32 | #include "audit.h" |
33 | 33 | ||
34 | /* | 34 | /* |
@@ -38,7 +38,7 @@ | |||
38 | * Synchronizes writes and blocking reads of audit's filterlist | 38 | * Synchronizes writes and blocking reads of audit's filterlist |
39 | * data. Rcu is used to traverse the filterlist and access | 39 | * data. Rcu is used to traverse the filterlist and access |
40 | * contents of structs audit_entry, audit_watch and opaque | 40 | * contents of structs audit_entry, audit_watch and opaque |
41 | * selinux rules during filtering. If modified, these structures | 41 | * LSM rules during filtering. If modified, these structures |
42 | * must be copied and replace their counterparts in the filterlist. | 42 | * must be copied and replace their counterparts in the filterlist. |
43 | * An audit_parent struct is not accessed during filtering, so may | 43 | * An audit_parent struct is not accessed during filtering, so may |
44 | * be written directly provided audit_filter_mutex is held. | 44 | * be written directly provided audit_filter_mutex is held. |
@@ -139,8 +139,8 @@ static inline void audit_free_rule(struct audit_entry *e) | |||
139 | if (e->rule.fields) | 139 | if (e->rule.fields) |
140 | for (i = 0; i < e->rule.field_count; i++) { | 140 | for (i = 0; i < e->rule.field_count; i++) { |
141 | struct audit_field *f = &e->rule.fields[i]; | 141 | struct audit_field *f = &e->rule.fields[i]; |
142 | kfree(f->se_str); | 142 | kfree(f->lsm_str); |
143 | selinux_audit_rule_free(f->se_rule); | 143 | security_audit_rule_free(f->lsm_rule); |
144 | } | 144 | } |
145 | kfree(e->rule.fields); | 145 | kfree(e->rule.fields); |
146 | kfree(e->rule.filterkey); | 146 | kfree(e->rule.filterkey); |
@@ -554,8 +554,8 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data, | |||
554 | f->op = data->fieldflags[i] & AUDIT_OPERATORS; | 554 | f->op = data->fieldflags[i] & AUDIT_OPERATORS; |
555 | f->type = data->fields[i]; | 555 | f->type = data->fields[i]; |
556 | f->val = data->values[i]; | 556 | f->val = data->values[i]; |
557 | f->se_str = NULL; | 557 | f->lsm_str = NULL; |
558 | f->se_rule = NULL; | 558 | f->lsm_rule = NULL; |
559 | switch(f->type) { | 559 | switch(f->type) { |
560 | case AUDIT_PID: | 560 | case AUDIT_PID: |
561 | case AUDIT_UID: | 561 | case AUDIT_UID: |
@@ -597,12 +597,12 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data, | |||
597 | goto exit_free; | 597 | goto exit_free; |
598 | entry->rule.buflen += f->val; | 598 | entry->rule.buflen += f->val; |
599 | 599 | ||
600 | err = selinux_audit_rule_init(f->type, f->op, str, | 600 | err = security_audit_rule_init(f->type, f->op, str, |
601 | &f->se_rule); | 601 | (void **)&f->lsm_rule); |
602 | /* Keep currently invalid fields around in case they | 602 | /* Keep currently invalid fields around in case they |
603 | * become valid after a policy reload. */ | 603 | * become valid after a policy reload. */ |
604 | if (err == -EINVAL) { | 604 | if (err == -EINVAL) { |
605 | printk(KERN_WARNING "audit rule for selinux " | 605 | printk(KERN_WARNING "audit rule for LSM " |
606 | "\'%s\' is invalid\n", str); | 606 | "\'%s\' is invalid\n", str); |
607 | err = 0; | 607 | err = 0; |
608 | } | 608 | } |
@@ -610,7 +610,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data, | |||
610 | kfree(str); | 610 | kfree(str); |
611 | goto exit_free; | 611 | goto exit_free; |
612 | } else | 612 | } else |
613 | f->se_str = str; | 613 | f->lsm_str = str; |
614 | break; | 614 | break; |
615 | case AUDIT_WATCH: | 615 | case AUDIT_WATCH: |
616 | str = audit_unpack_string(&bufp, &remain, f->val); | 616 | str = audit_unpack_string(&bufp, &remain, f->val); |
@@ -754,7 +754,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule) | |||
754 | case AUDIT_OBJ_LEV_LOW: | 754 | case AUDIT_OBJ_LEV_LOW: |
755 | case AUDIT_OBJ_LEV_HIGH: | 755 | case AUDIT_OBJ_LEV_HIGH: |
756 | data->buflen += data->values[i] = | 756 | data->buflen += data->values[i] = |
757 | audit_pack_string(&bufp, f->se_str); | 757 | audit_pack_string(&bufp, f->lsm_str); |
758 | break; | 758 | break; |
759 | case AUDIT_WATCH: | 759 | case AUDIT_WATCH: |
760 | data->buflen += data->values[i] = | 760 | data->buflen += data->values[i] = |
@@ -806,7 +806,7 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b) | |||
806 | case AUDIT_OBJ_TYPE: | 806 | case AUDIT_OBJ_TYPE: |
807 | case AUDIT_OBJ_LEV_LOW: | 807 | case AUDIT_OBJ_LEV_LOW: |
808 | case AUDIT_OBJ_LEV_HIGH: | 808 | case AUDIT_OBJ_LEV_HIGH: |
809 | if (strcmp(a->fields[i].se_str, b->fields[i].se_str)) | 809 | if (strcmp(a->fields[i].lsm_str, b->fields[i].lsm_str)) |
810 | return 1; | 810 | return 1; |
811 | break; | 811 | break; |
812 | case AUDIT_WATCH: | 812 | case AUDIT_WATCH: |
@@ -862,28 +862,28 @@ out: | |||
862 | return new; | 862 | return new; |
863 | } | 863 | } |
864 | 864 | ||
865 | /* Duplicate selinux field information. The se_rule is opaque, so must be | 865 | /* Duplicate LSM field information. The lsm_rule is opaque, so must be |
866 | * re-initialized. */ | 866 | * re-initialized. */ |
867 | static inline int audit_dupe_selinux_field(struct audit_field *df, | 867 | static inline int audit_dupe_lsm_field(struct audit_field *df, |
868 | struct audit_field *sf) | 868 | struct audit_field *sf) |
869 | { | 869 | { |
870 | int ret = 0; | 870 | int ret = 0; |
871 | char *se_str; | 871 | char *lsm_str; |
872 | 872 | ||
873 | /* our own copy of se_str */ | 873 | /* our own copy of lsm_str */ |
874 | se_str = kstrdup(sf->se_str, GFP_KERNEL); | 874 | lsm_str = kstrdup(sf->lsm_str, GFP_KERNEL); |
875 | if (unlikely(!se_str)) | 875 | if (unlikely(!lsm_str)) |
876 | return -ENOMEM; | 876 | return -ENOMEM; |
877 | df->se_str = se_str; | 877 | df->lsm_str = lsm_str; |
878 | 878 | ||
879 | /* our own (refreshed) copy of se_rule */ | 879 | /* our own (refreshed) copy of lsm_rule */ |
880 | ret = selinux_audit_rule_init(df->type, df->op, df->se_str, | 880 | ret = security_audit_rule_init(df->type, df->op, df->lsm_str, |
881 | &df->se_rule); | 881 | (void **)&df->lsm_rule); |
882 | /* Keep currently invalid fields around in case they | 882 | /* Keep currently invalid fields around in case they |
883 | * become valid after a policy reload. */ | 883 | * become valid after a policy reload. */ |
884 | if (ret == -EINVAL) { | 884 | if (ret == -EINVAL) { |
885 | printk(KERN_WARNING "audit rule for selinux \'%s\' is " | 885 | printk(KERN_WARNING "audit rule for LSM \'%s\' is " |
886 | "invalid\n", df->se_str); | 886 | "invalid\n", df->lsm_str); |
887 | ret = 0; | 887 | ret = 0; |
888 | } | 888 | } |
889 | 889 | ||
@@ -891,7 +891,7 @@ static inline int audit_dupe_selinux_field(struct audit_field *df, | |||
891 | } | 891 | } |
892 | 892 | ||
893 | /* Duplicate an audit rule. This will be a deep copy with the exception | 893 | /* Duplicate an audit rule. This will be a deep copy with the exception |
894 | * of the watch - that pointer is carried over. The selinux specific fields | 894 | * of the watch - that pointer is carried over. The LSM specific fields |
895 | * will be updated in the copy. The point is to be able to replace the old | 895 | * will be updated in the copy. The point is to be able to replace the old |
896 | * rule with the new rule in the filterlist, then free the old rule. | 896 | * rule with the new rule in the filterlist, then free the old rule. |
897 | * The rlist element is undefined; list manipulations are handled apart from | 897 | * The rlist element is undefined; list manipulations are handled apart from |
@@ -930,7 +930,7 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old, | |||
930 | new->tree = old->tree; | 930 | new->tree = old->tree; |
931 | memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount); | 931 | memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount); |
932 | 932 | ||
933 | /* deep copy this information, updating the se_rule fields, because | 933 | /* deep copy this information, updating the lsm_rule fields, because |
934 | * the originals will all be freed when the old rule is freed. */ | 934 | * the originals will all be freed when the old rule is freed. */ |
935 | for (i = 0; i < fcount; i++) { | 935 | for (i = 0; i < fcount; i++) { |
936 | switch (new->fields[i].type) { | 936 | switch (new->fields[i].type) { |
@@ -944,7 +944,7 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old, | |||
944 | case AUDIT_OBJ_TYPE: | 944 | case AUDIT_OBJ_TYPE: |
945 | case AUDIT_OBJ_LEV_LOW: | 945 | case AUDIT_OBJ_LEV_LOW: |
946 | case AUDIT_OBJ_LEV_HIGH: | 946 | case AUDIT_OBJ_LEV_HIGH: |
947 | err = audit_dupe_selinux_field(&new->fields[i], | 947 | err = audit_dupe_lsm_field(&new->fields[i], |
948 | &old->fields[i]); | 948 | &old->fields[i]); |
949 | break; | 949 | break; |
950 | case AUDIT_FILTERKEY: | 950 | case AUDIT_FILTERKEY: |
@@ -1515,11 +1515,12 @@ static void audit_log_rule_change(uid_t loginuid, u32 sid, char *action, | |||
1515 | if (sid) { | 1515 | if (sid) { |
1516 | char *ctx = NULL; | 1516 | char *ctx = NULL; |
1517 | u32 len; | 1517 | u32 len; |
1518 | if (selinux_sid_to_string(sid, &ctx, &len)) | 1518 | if (security_secid_to_secctx(sid, &ctx, &len)) |
1519 | audit_log_format(ab, " ssid=%u", sid); | 1519 | audit_log_format(ab, " ssid=%u", sid); |
1520 | else | 1520 | else { |
1521 | audit_log_format(ab, " subj=%s", ctx); | 1521 | audit_log_format(ab, " subj=%s", ctx); |
1522 | kfree(ctx); | 1522 | security_release_secctx(ctx, len); |
1523 | } | ||
1523 | } | 1524 | } |
1524 | audit_log_format(ab, " op=%s rule key=", action); | 1525 | audit_log_format(ab, " op=%s rule key=", action); |
1525 | if (rule->filterkey) | 1526 | if (rule->filterkey) |
@@ -1761,38 +1762,12 @@ unlock_and_return: | |||
1761 | return result; | 1762 | return result; |
1762 | } | 1763 | } |
1763 | 1764 | ||
1764 | /* Check to see if the rule contains any selinux fields. Returns 1 if there | 1765 | /* This function will re-initialize the lsm_rule field of all applicable rules. |
1765 | are selinux fields specified in the rule, 0 otherwise. */ | 1766 | * It will traverse the filter lists serarching for rules that contain LSM |
1766 | static inline int audit_rule_has_selinux(struct audit_krule *rule) | ||
1767 | { | ||
1768 | int i; | ||
1769 | |||
1770 | for (i = 0; i < rule->field_count; i++) { | ||
1771 | struct audit_field *f = &rule->fields[i]; | ||
1772 | switch (f->type) { | ||
1773 | case AUDIT_SUBJ_USER: | ||
1774 | case AUDIT_SUBJ_ROLE: | ||
1775 | case AUDIT_SUBJ_TYPE: | ||
1776 | case AUDIT_SUBJ_SEN: | ||
1777 | case AUDIT_SUBJ_CLR: | ||
1778 | case AUDIT_OBJ_USER: | ||
1779 | case AUDIT_OBJ_ROLE: | ||
1780 | case AUDIT_OBJ_TYPE: | ||
1781 | case AUDIT_OBJ_LEV_LOW: | ||
1782 | case AUDIT_OBJ_LEV_HIGH: | ||
1783 | return 1; | ||
1784 | } | ||
1785 | } | ||
1786 | |||
1787 | return 0; | ||
1788 | } | ||
1789 | |||
1790 | /* This function will re-initialize the se_rule field of all applicable rules. | ||
1791 | * It will traverse the filter lists serarching for rules that contain selinux | ||
1792 | * specific filter fields. When such a rule is found, it is copied, the | 1767 | * specific filter fields. When such a rule is found, it is copied, the |
1793 | * selinux field is re-initialized, and the old rule is replaced with the | 1768 | * LSM field is re-initialized, and the old rule is replaced with the |
1794 | * updated rule. */ | 1769 | * updated rule. */ |
1795 | int selinux_audit_rule_update(void) | 1770 | int audit_update_lsm_rules(void) |
1796 | { | 1771 | { |
1797 | struct audit_entry *entry, *n, *nentry; | 1772 | struct audit_entry *entry, *n, *nentry; |
1798 | struct audit_watch *watch; | 1773 | struct audit_watch *watch; |
@@ -1804,7 +1779,7 @@ int selinux_audit_rule_update(void) | |||
1804 | 1779 | ||
1805 | for (i = 0; i < AUDIT_NR_FILTERS; i++) { | 1780 | for (i = 0; i < AUDIT_NR_FILTERS; i++) { |
1806 | list_for_each_entry_safe(entry, n, &audit_filter_list[i], list) { | 1781 | list_for_each_entry_safe(entry, n, &audit_filter_list[i], list) { |
1807 | if (!audit_rule_has_selinux(&entry->rule)) | 1782 | if (!security_audit_rule_known(&entry->rule)) |
1808 | continue; | 1783 | continue; |
1809 | 1784 | ||
1810 | watch = entry->rule.watch; | 1785 | watch = entry->rule.watch; |
@@ -1815,7 +1790,7 @@ int selinux_audit_rule_update(void) | |||
1815 | * return value */ | 1790 | * return value */ |
1816 | if (!err) | 1791 | if (!err) |
1817 | err = PTR_ERR(nentry); | 1792 | err = PTR_ERR(nentry); |
1818 | audit_panic("error updating selinux filters"); | 1793 | audit_panic("error updating LSM filters"); |
1819 | if (watch) | 1794 | if (watch) |
1820 | list_del(&entry->rule.rlist); | 1795 | list_del(&entry->rule.rlist); |
1821 | list_del_rcu(&entry->list); | 1796 | list_del_rcu(&entry->list); |
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 782262e4107d..56e56ed594a8 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -61,7 +61,6 @@ | |||
61 | #include <linux/security.h> | 61 | #include <linux/security.h> |
62 | #include <linux/list.h> | 62 | #include <linux/list.h> |
63 | #include <linux/tty.h> | 63 | #include <linux/tty.h> |
64 | #include <linux/selinux.h> | ||
65 | #include <linux/binfmts.h> | 64 | #include <linux/binfmts.h> |
66 | #include <linux/highmem.h> | 65 | #include <linux/highmem.h> |
67 | #include <linux/syscalls.h> | 66 | #include <linux/syscalls.h> |
@@ -528,14 +527,14 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
528 | match for now to avoid losing information that | 527 | match for now to avoid losing information that |
529 | may be wanted. An error message will also be | 528 | may be wanted. An error message will also be |
530 | logged upon error */ | 529 | logged upon error */ |
531 | if (f->se_rule) { | 530 | if (f->lsm_rule) { |
532 | if (need_sid) { | 531 | if (need_sid) { |
533 | selinux_get_task_sid(tsk, &sid); | 532 | security_task_getsecid(tsk, &sid); |
534 | need_sid = 0; | 533 | need_sid = 0; |
535 | } | 534 | } |
536 | result = selinux_audit_rule_match(sid, f->type, | 535 | result = security_audit_rule_match(sid, f->type, |
537 | f->op, | 536 | f->op, |
538 | f->se_rule, | 537 | f->lsm_rule, |
539 | ctx); | 538 | ctx); |
540 | } | 539 | } |
541 | break; | 540 | break; |
@@ -546,18 +545,18 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
546 | case AUDIT_OBJ_LEV_HIGH: | 545 | case AUDIT_OBJ_LEV_HIGH: |
547 | /* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR | 546 | /* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR |
548 | also applies here */ | 547 | also applies here */ |
549 | if (f->se_rule) { | 548 | if (f->lsm_rule) { |
550 | /* Find files that match */ | 549 | /* Find files that match */ |
551 | if (name) { | 550 | if (name) { |
552 | result = selinux_audit_rule_match( | 551 | result = security_audit_rule_match( |
553 | name->osid, f->type, f->op, | 552 | name->osid, f->type, f->op, |
554 | f->se_rule, ctx); | 553 | f->lsm_rule, ctx); |
555 | } else if (ctx) { | 554 | } else if (ctx) { |
556 | for (j = 0; j < ctx->name_count; j++) { | 555 | for (j = 0; j < ctx->name_count; j++) { |
557 | if (selinux_audit_rule_match( | 556 | if (security_audit_rule_match( |
558 | ctx->names[j].osid, | 557 | ctx->names[j].osid, |
559 | f->type, f->op, | 558 | f->type, f->op, |
560 | f->se_rule, ctx)) { | 559 | f->lsm_rule, ctx)) { |
561 | ++result; | 560 | ++result; |
562 | break; | 561 | break; |
563 | } | 562 | } |
@@ -570,7 +569,7 @@ static int audit_filter_rules(struct task_struct *tsk, | |||
570 | aux = aux->next) { | 569 | aux = aux->next) { |
571 | if (aux->type == AUDIT_IPC) { | 570 | if (aux->type == AUDIT_IPC) { |
572 | struct audit_aux_data_ipcctl *axi = (void *)aux; | 571 | struct audit_aux_data_ipcctl *axi = (void *)aux; |
573 | if (selinux_audit_rule_match(axi->osid, f->type, f->op, f->se_rule, ctx)) { | 572 | if (security_audit_rule_match(axi->osid, f->type, f->op, f->lsm_rule, ctx)) { |
574 | ++result; | 573 | ++result; |
575 | break; | 574 | break; |
576 | } | 575 | } |
@@ -885,11 +884,11 @@ void audit_log_task_context(struct audit_buffer *ab) | |||
885 | int error; | 884 | int error; |
886 | u32 sid; | 885 | u32 sid; |
887 | 886 | ||
888 | selinux_get_task_sid(current, &sid); | 887 | security_task_getsecid(current, &sid); |
889 | if (!sid) | 888 | if (!sid) |
890 | return; | 889 | return; |
891 | 890 | ||
892 | error = selinux_sid_to_string(sid, &ctx, &len); | 891 | error = security_secid_to_secctx(sid, &ctx, &len); |
893 | if (error) { | 892 | if (error) { |
894 | if (error != -EINVAL) | 893 | if (error != -EINVAL) |
895 | goto error_path; | 894 | goto error_path; |
@@ -897,7 +896,7 @@ void audit_log_task_context(struct audit_buffer *ab) | |||
897 | } | 896 | } |
898 | 897 | ||
899 | audit_log_format(ab, " subj=%s", ctx); | 898 | audit_log_format(ab, " subj=%s", ctx); |
900 | kfree(ctx); | 899 | security_release_secctx(ctx, len); |
901 | return; | 900 | return; |
902 | 901 | ||
903 | error_path: | 902 | error_path: |
@@ -941,7 +940,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, | |||
941 | u32 sid, char *comm) | 940 | u32 sid, char *comm) |
942 | { | 941 | { |
943 | struct audit_buffer *ab; | 942 | struct audit_buffer *ab; |
944 | char *s = NULL; | 943 | char *ctx = NULL; |
945 | u32 len; | 944 | u32 len; |
946 | int rc = 0; | 945 | int rc = 0; |
947 | 946 | ||
@@ -951,15 +950,16 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid, | |||
951 | 950 | ||
952 | audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid, | 951 | audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid, |
953 | uid, sessionid); | 952 | uid, sessionid); |
954 | if (selinux_sid_to_string(sid, &s, &len)) { | 953 | if (security_secid_to_secctx(sid, &ctx, &len)) { |
955 | audit_log_format(ab, " obj=(none)"); | 954 | audit_log_format(ab, " obj=(none)"); |
956 | rc = 1; | 955 | rc = 1; |
957 | } else | 956 | } else { |
958 | audit_log_format(ab, " obj=%s", s); | 957 | audit_log_format(ab, " obj=%s", ctx); |
958 | security_release_secctx(ctx, len); | ||
959 | } | ||
959 | audit_log_format(ab, " ocomm="); | 960 | audit_log_format(ab, " ocomm="); |
960 | audit_log_untrustedstring(ab, comm); | 961 | audit_log_untrustedstring(ab, comm); |
961 | audit_log_end(ab); | 962 | audit_log_end(ab); |
962 | kfree(s); | ||
963 | 963 | ||
964 | return rc; | 964 | return rc; |
965 | } | 965 | } |
@@ -1271,14 +1271,15 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1271 | if (axi->osid != 0) { | 1271 | if (axi->osid != 0) { |
1272 | char *ctx = NULL; | 1272 | char *ctx = NULL; |
1273 | u32 len; | 1273 | u32 len; |
1274 | if (selinux_sid_to_string( | 1274 | if (security_secid_to_secctx( |
1275 | axi->osid, &ctx, &len)) { | 1275 | axi->osid, &ctx, &len)) { |
1276 | audit_log_format(ab, " osid=%u", | 1276 | audit_log_format(ab, " osid=%u", |
1277 | axi->osid); | 1277 | axi->osid); |
1278 | call_panic = 1; | 1278 | call_panic = 1; |
1279 | } else | 1279 | } else { |
1280 | audit_log_format(ab, " obj=%s", ctx); | 1280 | audit_log_format(ab, " obj=%s", ctx); |
1281 | kfree(ctx); | 1281 | security_release_secctx(ctx, len); |
1282 | } | ||
1282 | } | 1283 | } |
1283 | break; } | 1284 | break; } |
1284 | 1285 | ||
@@ -1392,13 +1393,14 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts | |||
1392 | if (n->osid != 0) { | 1393 | if (n->osid != 0) { |
1393 | char *ctx = NULL; | 1394 | char *ctx = NULL; |
1394 | u32 len; | 1395 | u32 len; |
1395 | if (selinux_sid_to_string( | 1396 | if (security_secid_to_secctx( |
1396 | n->osid, &ctx, &len)) { | 1397 | n->osid, &ctx, &len)) { |
1397 | audit_log_format(ab, " osid=%u", n->osid); | 1398 | audit_log_format(ab, " osid=%u", n->osid); |
1398 | call_panic = 2; | 1399 | call_panic = 2; |
1399 | } else | 1400 | } else { |
1400 | audit_log_format(ab, " obj=%s", ctx); | 1401 | audit_log_format(ab, " obj=%s", ctx); |
1401 | kfree(ctx); | 1402 | security_release_secctx(ctx, len); |
1403 | } | ||
1402 | } | 1404 | } |
1403 | 1405 | ||
1404 | audit_log_end(ab); | 1406 | audit_log_end(ab); |
@@ -1775,7 +1777,7 @@ static void audit_copy_inode(struct audit_names *name, const struct inode *inode | |||
1775 | name->uid = inode->i_uid; | 1777 | name->uid = inode->i_uid; |
1776 | name->gid = inode->i_gid; | 1778 | name->gid = inode->i_gid; |
1777 | name->rdev = inode->i_rdev; | 1779 | name->rdev = inode->i_rdev; |
1778 | selinux_get_inode_sid(inode, &name->osid); | 1780 | security_inode_getsecid(inode, &name->osid); |
1779 | } | 1781 | } |
1780 | 1782 | ||
1781 | /** | 1783 | /** |
@@ -2190,8 +2192,7 @@ int __audit_ipc_obj(struct kern_ipc_perm *ipcp) | |||
2190 | ax->uid = ipcp->uid; | 2192 | ax->uid = ipcp->uid; |
2191 | ax->gid = ipcp->gid; | 2193 | ax->gid = ipcp->gid; |
2192 | ax->mode = ipcp->mode; | 2194 | ax->mode = ipcp->mode; |
2193 | selinux_get_ipc_sid(ipcp, &ax->osid); | 2195 | security_ipc_getsecid(ipcp, &ax->osid); |
2194 | |||
2195 | ax->d.type = AUDIT_IPC; | 2196 | ax->d.type = AUDIT_IPC; |
2196 | ax->d.next = context->aux; | 2197 | ax->d.next = context->aux; |
2197 | context->aux = (void *)ax; | 2198 | context->aux = (void *)ax; |
@@ -2343,7 +2344,7 @@ void __audit_ptrace(struct task_struct *t) | |||
2343 | context->target_auid = audit_get_loginuid(t); | 2344 | context->target_auid = audit_get_loginuid(t); |
2344 | context->target_uid = t->uid; | 2345 | context->target_uid = t->uid; |
2345 | context->target_sessionid = audit_get_sessionid(t); | 2346 | context->target_sessionid = audit_get_sessionid(t); |
2346 | selinux_get_task_sid(t, &context->target_sid); | 2347 | security_task_getsecid(t, &context->target_sid); |
2347 | memcpy(context->target_comm, t->comm, TASK_COMM_LEN); | 2348 | memcpy(context->target_comm, t->comm, TASK_COMM_LEN); |
2348 | } | 2349 | } |
2349 | 2350 | ||
@@ -2371,7 +2372,7 @@ int __audit_signal_info(int sig, struct task_struct *t) | |||
2371 | audit_sig_uid = tsk->loginuid; | 2372 | audit_sig_uid = tsk->loginuid; |
2372 | else | 2373 | else |
2373 | audit_sig_uid = tsk->uid; | 2374 | audit_sig_uid = tsk->uid; |
2374 | selinux_get_task_sid(tsk, &audit_sig_sid); | 2375 | security_task_getsecid(tsk, &audit_sig_sid); |
2375 | } | 2376 | } |
2376 | if (!audit_signals || audit_dummy_context()) | 2377 | if (!audit_signals || audit_dummy_context()) |
2377 | return 0; | 2378 | return 0; |
@@ -2384,7 +2385,7 @@ int __audit_signal_info(int sig, struct task_struct *t) | |||
2384 | ctx->target_auid = audit_get_loginuid(t); | 2385 | ctx->target_auid = audit_get_loginuid(t); |
2385 | ctx->target_uid = t->uid; | 2386 | ctx->target_uid = t->uid; |
2386 | ctx->target_sessionid = audit_get_sessionid(t); | 2387 | ctx->target_sessionid = audit_get_sessionid(t); |
2387 | selinux_get_task_sid(t, &ctx->target_sid); | 2388 | security_task_getsecid(t, &ctx->target_sid); |
2388 | memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); | 2389 | memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); |
2389 | return 0; | 2390 | return 0; |
2390 | } | 2391 | } |
@@ -2405,7 +2406,7 @@ int __audit_signal_info(int sig, struct task_struct *t) | |||
2405 | axp->target_auid[axp->pid_count] = audit_get_loginuid(t); | 2406 | axp->target_auid[axp->pid_count] = audit_get_loginuid(t); |
2406 | axp->target_uid[axp->pid_count] = t->uid; | 2407 | axp->target_uid[axp->pid_count] = t->uid; |
2407 | axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); | 2408 | axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); |
2408 | selinux_get_task_sid(t, &axp->target_sid[axp->pid_count]); | 2409 | security_task_getsecid(t, &axp->target_sid[axp->pid_count]); |
2409 | memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); | 2410 | memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); |
2410 | axp->pid_count++; | 2411 | axp->pid_count++; |
2411 | 2412 | ||
@@ -2435,16 +2436,17 @@ void audit_core_dumps(long signr) | |||
2435 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND); | 2436 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND); |
2436 | audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u", | 2437 | audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u", |
2437 | auid, current->uid, current->gid, sessionid); | 2438 | auid, current->uid, current->gid, sessionid); |
2438 | selinux_get_task_sid(current, &sid); | 2439 | security_task_getsecid(current, &sid); |
2439 | if (sid) { | 2440 | if (sid) { |
2440 | char *ctx = NULL; | 2441 | char *ctx = NULL; |
2441 | u32 len; | 2442 | u32 len; |
2442 | 2443 | ||
2443 | if (selinux_sid_to_string(sid, &ctx, &len)) | 2444 | if (security_secid_to_secctx(sid, &ctx, &len)) |
2444 | audit_log_format(ab, " ssid=%u", sid); | 2445 | audit_log_format(ab, " ssid=%u", sid); |
2445 | else | 2446 | else { |
2446 | audit_log_format(ab, " subj=%s", ctx); | 2447 | audit_log_format(ab, " subj=%s", ctx); |
2447 | kfree(ctx); | 2448 | security_release_secctx(ctx, len); |
2449 | } | ||
2448 | } | 2450 | } |
2449 | audit_log_format(ab, " pid=%d comm=", current->pid); | 2451 | audit_log_format(ab, " pid=%d comm=", current->pid); |
2450 | audit_log_untrustedstring(ab, current->comm); | 2452 | audit_log_untrustedstring(ab, current->comm); |
diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 2727f9238359..6d8de051382b 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c | |||
@@ -1722,7 +1722,12 @@ void cgroup_enable_task_cg_lists(void) | |||
1722 | use_task_css_set_links = 1; | 1722 | use_task_css_set_links = 1; |
1723 | do_each_thread(g, p) { | 1723 | do_each_thread(g, p) { |
1724 | task_lock(p); | 1724 | task_lock(p); |
1725 | if (list_empty(&p->cg_list)) | 1725 | /* |
1726 | * We should check if the process is exiting, otherwise | ||
1727 | * it will race with cgroup_exit() in that the list | ||
1728 | * entry won't be deleted though the process has exited. | ||
1729 | */ | ||
1730 | if (!(p->flags & PF_EXITING) && list_empty(&p->cg_list)) | ||
1726 | list_add(&p->cg_list, &p->cgroups->tasks); | 1731 | list_add(&p->cg_list, &p->cgroups->tasks); |
1727 | task_unlock(p); | 1732 | task_unlock(p); |
1728 | } while_each_thread(g, p); | 1733 | } while_each_thread(g, p); |
diff --git a/kernel/compat.c b/kernel/compat.c index 5f0e201bcfd3..9c48abfcd4a5 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -47,15 +47,14 @@ static long compat_nanosleep_restart(struct restart_block *restart) | |||
47 | mm_segment_t oldfs; | 47 | mm_segment_t oldfs; |
48 | long ret; | 48 | long ret; |
49 | 49 | ||
50 | rmtp = (struct compat_timespec __user *)(restart->arg1); | 50 | restart->nanosleep.rmtp = (struct timespec __user *) &rmt; |
51 | restart->arg1 = (unsigned long)&rmt; | ||
52 | oldfs = get_fs(); | 51 | oldfs = get_fs(); |
53 | set_fs(KERNEL_DS); | 52 | set_fs(KERNEL_DS); |
54 | ret = hrtimer_nanosleep_restart(restart); | 53 | ret = hrtimer_nanosleep_restart(restart); |
55 | set_fs(oldfs); | 54 | set_fs(oldfs); |
56 | 55 | ||
57 | if (ret) { | 56 | if (ret) { |
58 | restart->arg1 = (unsigned long)rmtp; | 57 | rmtp = restart->nanosleep.compat_rmtp; |
59 | 58 | ||
60 | if (rmtp && put_compat_timespec(&rmt, rmtp)) | 59 | if (rmtp && put_compat_timespec(&rmt, rmtp)) |
61 | return -EFAULT; | 60 | return -EFAULT; |
@@ -89,7 +88,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp, | |||
89 | = ¤t_thread_info()->restart_block; | 88 | = ¤t_thread_info()->restart_block; |
90 | 89 | ||
91 | restart->fn = compat_nanosleep_restart; | 90 | restart->fn = compat_nanosleep_restart; |
92 | restart->arg1 = (unsigned long)rmtp; | 91 | restart->nanosleep.compat_rmtp = rmtp; |
93 | 92 | ||
94 | if (rmtp && put_compat_timespec(&rmt, rmtp)) | 93 | if (rmtp && put_compat_timespec(&rmt, rmtp)) |
95 | return -EFAULT; | 94 | return -EFAULT; |
@@ -607,9 +606,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart) | |||
607 | long err; | 606 | long err; |
608 | mm_segment_t oldfs; | 607 | mm_segment_t oldfs; |
609 | struct timespec tu; | 608 | struct timespec tu; |
610 | struct compat_timespec *rmtp = (struct compat_timespec *)(restart->arg1); | 609 | struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp; |
611 | 610 | ||
612 | restart->arg1 = (unsigned long) &tu; | 611 | restart->nanosleep.rmtp = (struct timespec __user *) &tu; |
613 | oldfs = get_fs(); | 612 | oldfs = get_fs(); |
614 | set_fs(KERNEL_DS); | 613 | set_fs(KERNEL_DS); |
615 | err = clock_nanosleep_restart(restart); | 614 | err = clock_nanosleep_restart(restart); |
@@ -621,7 +620,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart) | |||
621 | 620 | ||
622 | if (err == -ERESTART_RESTARTBLOCK) { | 621 | if (err == -ERESTART_RESTARTBLOCK) { |
623 | restart->fn = compat_clock_nanosleep_restart; | 622 | restart->fn = compat_clock_nanosleep_restart; |
624 | restart->arg1 = (unsigned long) rmtp; | 623 | restart->nanosleep.compat_rmtp = rmtp; |
625 | } | 624 | } |
626 | return err; | 625 | return err; |
627 | } | 626 | } |
@@ -652,7 +651,7 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags, | |||
652 | if (err == -ERESTART_RESTARTBLOCK) { | 651 | if (err == -ERESTART_RESTARTBLOCK) { |
653 | restart = ¤t_thread_info()->restart_block; | 652 | restart = ¤t_thread_info()->restart_block; |
654 | restart->fn = compat_clock_nanosleep_restart; | 653 | restart->fn = compat_clock_nanosleep_restart; |
655 | restart->arg1 = (unsigned long) rmtp; | 654 | restart->nanosleep.compat_rmtp = rmtp; |
656 | } | 655 | } |
657 | return err; | 656 | return err; |
658 | } | 657 | } |
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 98bee013f71f..c642ef75069f 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -1354,13 +1354,13 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart) | |||
1354 | struct hrtimer_sleeper t; | 1354 | struct hrtimer_sleeper t; |
1355 | struct timespec __user *rmtp; | 1355 | struct timespec __user *rmtp; |
1356 | 1356 | ||
1357 | hrtimer_init(&t.timer, restart->arg0, HRTIMER_MODE_ABS); | 1357 | hrtimer_init(&t.timer, restart->nanosleep.index, HRTIMER_MODE_ABS); |
1358 | t.timer.expires.tv64 = ((u64)restart->arg3 << 32) | (u64) restart->arg2; | 1358 | t.timer.expires.tv64 = restart->nanosleep.expires; |
1359 | 1359 | ||
1360 | if (do_nanosleep(&t, HRTIMER_MODE_ABS)) | 1360 | if (do_nanosleep(&t, HRTIMER_MODE_ABS)) |
1361 | return 0; | 1361 | return 0; |
1362 | 1362 | ||
1363 | rmtp = (struct timespec __user *)restart->arg1; | 1363 | rmtp = restart->nanosleep.rmtp; |
1364 | if (rmtp) { | 1364 | if (rmtp) { |
1365 | int ret = update_rmtp(&t.timer, rmtp); | 1365 | int ret = update_rmtp(&t.timer, rmtp); |
1366 | if (ret <= 0) | 1366 | if (ret <= 0) |
@@ -1394,10 +1394,9 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, | |||
1394 | 1394 | ||
1395 | restart = ¤t_thread_info()->restart_block; | 1395 | restart = ¤t_thread_info()->restart_block; |
1396 | restart->fn = hrtimer_nanosleep_restart; | 1396 | restart->fn = hrtimer_nanosleep_restart; |
1397 | restart->arg0 = (unsigned long) t.timer.base->index; | 1397 | restart->nanosleep.index = t.timer.base->index; |
1398 | restart->arg1 = (unsigned long) rmtp; | 1398 | restart->nanosleep.rmtp = rmtp; |
1399 | restart->arg2 = t.timer.expires.tv64 & 0xFFFFFFFF; | 1399 | restart->nanosleep.expires = t.timer.expires.tv64; |
1400 | restart->arg3 = t.timer.expires.tv64 >> 32; | ||
1401 | 1400 | ||
1402 | return -ERESTART_RESTARTBLOCK; | 1401 | return -ERESTART_RESTARTBLOCK; |
1403 | } | 1402 | } |
@@ -1425,7 +1424,6 @@ static void __cpuinit init_hrtimers_cpu(int cpu) | |||
1425 | int i; | 1424 | int i; |
1426 | 1425 | ||
1427 | spin_lock_init(&cpu_base->lock); | 1426 | spin_lock_init(&cpu_base->lock); |
1428 | lockdep_set_class(&cpu_base->lock, &cpu_base->lock_key); | ||
1429 | 1427 | ||
1430 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) | 1428 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) |
1431 | cpu_base->clock_base[i].cpu_base = cpu_base; | 1429 | cpu_base->clock_base[i].cpu_base = cpu_base; |
@@ -1466,16 +1464,16 @@ static void migrate_hrtimers(int cpu) | |||
1466 | tick_cancel_sched_timer(cpu); | 1464 | tick_cancel_sched_timer(cpu); |
1467 | 1465 | ||
1468 | local_irq_disable(); | 1466 | local_irq_disable(); |
1469 | double_spin_lock(&new_base->lock, &old_base->lock, | 1467 | spin_lock(&new_base->lock); |
1470 | smp_processor_id() < cpu); | 1468 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1471 | 1469 | ||
1472 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { | 1470 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { |
1473 | migrate_hrtimer_list(&old_base->clock_base[i], | 1471 | migrate_hrtimer_list(&old_base->clock_base[i], |
1474 | &new_base->clock_base[i]); | 1472 | &new_base->clock_base[i]); |
1475 | } | 1473 | } |
1476 | 1474 | ||
1477 | double_spin_unlock(&new_base->lock, &old_base->lock, | 1475 | spin_unlock(&old_base->lock); |
1478 | smp_processor_id() < cpu); | 1476 | spin_unlock(&new_base->lock); |
1479 | local_irq_enable(); | 1477 | local_irq_enable(); |
1480 | put_cpu_var(hrtimer_bases); | 1478 | put_cpu_var(hrtimer_bases); |
1481 | } | 1479 | } |
diff --git a/kernel/kgdb.c b/kernel/kgdb.c new file mode 100644 index 000000000000..1bd0ec1c80b2 --- /dev/null +++ b/kernel/kgdb.c | |||
@@ -0,0 +1,1700 @@ | |||
1 | /* | ||
2 | * KGDB stub. | ||
3 | * | ||
4 | * Maintainer: Jason Wessel <jason.wessel@windriver.com> | ||
5 | * | ||
6 | * Copyright (C) 2000-2001 VERITAS Software Corporation. | ||
7 | * Copyright (C) 2002-2004 Timesys Corporation | ||
8 | * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com> | ||
9 | * Copyright (C) 2004 Pavel Machek <pavel@suse.cz> | ||
10 | * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org> | ||
11 | * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd. | ||
12 | * Copyright (C) 2005-2008 Wind River Systems, Inc. | ||
13 | * Copyright (C) 2007 MontaVista Software, Inc. | ||
14 | * Copyright (C) 2008 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> | ||
15 | * | ||
16 | * Contributors at various stages not listed above: | ||
17 | * Jason Wessel ( jason.wessel@windriver.com ) | ||
18 | * George Anzinger <george@mvista.com> | ||
19 | * Anurekh Saxena (anurekh.saxena@timesys.com) | ||
20 | * Lake Stevens Instrument Division (Glenn Engel) | ||
21 | * Jim Kingdon, Cygnus Support. | ||
22 | * | ||
23 | * Original KGDB stub: David Grothe <dave@gcom.com>, | ||
24 | * Tigran Aivazian <tigran@sco.com> | ||
25 | * | ||
26 | * This file is licensed under the terms of the GNU General Public License | ||
27 | * version 2. This program is licensed "as is" without any warranty of any | ||
28 | * kind, whether express or implied. | ||
29 | */ | ||
30 | #include <linux/pid_namespace.h> | ||
31 | #include <linux/clocksource.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/spinlock.h> | ||
34 | #include <linux/console.h> | ||
35 | #include <linux/threads.h> | ||
36 | #include <linux/uaccess.h> | ||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/ptrace.h> | ||
40 | #include <linux/reboot.h> | ||
41 | #include <linux/string.h> | ||
42 | #include <linux/delay.h> | ||
43 | #include <linux/sched.h> | ||
44 | #include <linux/sysrq.h> | ||
45 | #include <linux/init.h> | ||
46 | #include <linux/kgdb.h> | ||
47 | #include <linux/pid.h> | ||
48 | #include <linux/smp.h> | ||
49 | #include <linux/mm.h> | ||
50 | |||
51 | #include <asm/cacheflush.h> | ||
52 | #include <asm/byteorder.h> | ||
53 | #include <asm/atomic.h> | ||
54 | #include <asm/system.h> | ||
55 | |||
56 | static int kgdb_break_asap; | ||
57 | |||
58 | struct kgdb_state { | ||
59 | int ex_vector; | ||
60 | int signo; | ||
61 | int err_code; | ||
62 | int cpu; | ||
63 | int pass_exception; | ||
64 | long threadid; | ||
65 | long kgdb_usethreadid; | ||
66 | struct pt_regs *linux_regs; | ||
67 | }; | ||
68 | |||
69 | static struct debuggerinfo_struct { | ||
70 | void *debuggerinfo; | ||
71 | struct task_struct *task; | ||
72 | } kgdb_info[NR_CPUS]; | ||
73 | |||
74 | /** | ||
75 | * kgdb_connected - Is a host GDB connected to us? | ||
76 | */ | ||
77 | int kgdb_connected; | ||
78 | EXPORT_SYMBOL_GPL(kgdb_connected); | ||
79 | |||
80 | /* All the KGDB handlers are installed */ | ||
81 | static int kgdb_io_module_registered; | ||
82 | |||
83 | /* Guard for recursive entry */ | ||
84 | static int exception_level; | ||
85 | |||
86 | static struct kgdb_io *kgdb_io_ops; | ||
87 | static DEFINE_SPINLOCK(kgdb_registration_lock); | ||
88 | |||
89 | /* kgdb console driver is loaded */ | ||
90 | static int kgdb_con_registered; | ||
91 | /* determine if kgdb console output should be used */ | ||
92 | static int kgdb_use_con; | ||
93 | |||
94 | static int __init opt_kgdb_con(char *str) | ||
95 | { | ||
96 | kgdb_use_con = 1; | ||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | early_param("kgdbcon", opt_kgdb_con); | ||
101 | |||
102 | module_param(kgdb_use_con, int, 0644); | ||
103 | |||
104 | /* | ||
105 | * Holds information about breakpoints in a kernel. These breakpoints are | ||
106 | * added and removed by gdb. | ||
107 | */ | ||
108 | static struct kgdb_bkpt kgdb_break[KGDB_MAX_BREAKPOINTS] = { | ||
109 | [0 ... KGDB_MAX_BREAKPOINTS-1] = { .state = BP_UNDEFINED } | ||
110 | }; | ||
111 | |||
112 | /* | ||
113 | * The CPU# of the active CPU, or -1 if none: | ||
114 | */ | ||
115 | atomic_t kgdb_active = ATOMIC_INIT(-1); | ||
116 | |||
117 | /* | ||
118 | * We use NR_CPUs not PERCPU, in case kgdb is used to debug early | ||
119 | * bootup code (which might not have percpu set up yet): | ||
120 | */ | ||
121 | static atomic_t passive_cpu_wait[NR_CPUS]; | ||
122 | static atomic_t cpu_in_kgdb[NR_CPUS]; | ||
123 | atomic_t kgdb_setting_breakpoint; | ||
124 | |||
125 | struct task_struct *kgdb_usethread; | ||
126 | struct task_struct *kgdb_contthread; | ||
127 | |||
128 | int kgdb_single_step; | ||
129 | |||
130 | /* Our I/O buffers. */ | ||
131 | static char remcom_in_buffer[BUFMAX]; | ||
132 | static char remcom_out_buffer[BUFMAX]; | ||
133 | |||
134 | /* Storage for the registers, in GDB format. */ | ||
135 | static unsigned long gdb_regs[(NUMREGBYTES + | ||
136 | sizeof(unsigned long) - 1) / | ||
137 | sizeof(unsigned long)]; | ||
138 | |||
139 | /* to keep track of the CPU which is doing the single stepping*/ | ||
140 | atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1); | ||
141 | |||
142 | /* | ||
143 | * If you are debugging a problem where roundup (the collection of | ||
144 | * all other CPUs) is a problem [this should be extremely rare], | ||
145 | * then use the nokgdbroundup option to avoid roundup. In that case | ||
146 | * the other CPUs might interfere with your debugging context, so | ||
147 | * use this with care: | ||
148 | */ | ||
149 | int kgdb_do_roundup = 1; | ||
150 | |||
151 | static int __init opt_nokgdbroundup(char *str) | ||
152 | { | ||
153 | kgdb_do_roundup = 0; | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | early_param("nokgdbroundup", opt_nokgdbroundup); | ||
159 | |||
160 | /* | ||
161 | * Finally, some KGDB code :-) | ||
162 | */ | ||
163 | |||
164 | /* | ||
165 | * Weak aliases for breakpoint management, | ||
166 | * can be overriden by architectures when needed: | ||
167 | */ | ||
168 | int __weak kgdb_validate_break_address(unsigned long addr) | ||
169 | { | ||
170 | char tmp_variable[BREAK_INSTR_SIZE]; | ||
171 | |||
172 | return probe_kernel_read(tmp_variable, (char *)addr, BREAK_INSTR_SIZE); | ||
173 | } | ||
174 | |||
175 | int __weak kgdb_arch_set_breakpoint(unsigned long addr, char *saved_instr) | ||
176 | { | ||
177 | int err; | ||
178 | |||
179 | err = probe_kernel_read(saved_instr, (char *)addr, BREAK_INSTR_SIZE); | ||
180 | if (err) | ||
181 | return err; | ||
182 | |||
183 | return probe_kernel_write((char *)addr, arch_kgdb_ops.gdb_bpt_instr, | ||
184 | BREAK_INSTR_SIZE); | ||
185 | } | ||
186 | |||
187 | int __weak kgdb_arch_remove_breakpoint(unsigned long addr, char *bundle) | ||
188 | { | ||
189 | return probe_kernel_write((char *)addr, | ||
190 | (char *)bundle, BREAK_INSTR_SIZE); | ||
191 | } | ||
192 | |||
193 | unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) | ||
194 | { | ||
195 | return instruction_pointer(regs); | ||
196 | } | ||
197 | |||
198 | int __weak kgdb_arch_init(void) | ||
199 | { | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | int __weak kgdb_skipexception(int exception, struct pt_regs *regs) | ||
204 | { | ||
205 | return 0; | ||
206 | } | ||
207 | |||
208 | void __weak | ||
209 | kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code) | ||
210 | { | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | /** | ||
215 | * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb. | ||
216 | * @regs: Current &struct pt_regs. | ||
217 | * | ||
218 | * This function will be called if the particular architecture must | ||
219 | * disable hardware debugging while it is processing gdb packets or | ||
220 | * handling exception. | ||
221 | */ | ||
222 | void __weak kgdb_disable_hw_debug(struct pt_regs *regs) | ||
223 | { | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | * GDB remote protocol parser: | ||
228 | */ | ||
229 | |||
230 | static const char hexchars[] = "0123456789abcdef"; | ||
231 | |||
232 | static int hex(char ch) | ||
233 | { | ||
234 | if ((ch >= 'a') && (ch <= 'f')) | ||
235 | return ch - 'a' + 10; | ||
236 | if ((ch >= '0') && (ch <= '9')) | ||
237 | return ch - '0'; | ||
238 | if ((ch >= 'A') && (ch <= 'F')) | ||
239 | return ch - 'A' + 10; | ||
240 | return -1; | ||
241 | } | ||
242 | |||
243 | /* scan for the sequence $<data>#<checksum> */ | ||
244 | static void get_packet(char *buffer) | ||
245 | { | ||
246 | unsigned char checksum; | ||
247 | unsigned char xmitcsum; | ||
248 | int count; | ||
249 | char ch; | ||
250 | |||
251 | do { | ||
252 | /* | ||
253 | * Spin and wait around for the start character, ignore all | ||
254 | * other characters: | ||
255 | */ | ||
256 | while ((ch = (kgdb_io_ops->read_char())) != '$') | ||
257 | /* nothing */; | ||
258 | |||
259 | kgdb_connected = 1; | ||
260 | checksum = 0; | ||
261 | xmitcsum = -1; | ||
262 | |||
263 | count = 0; | ||
264 | |||
265 | /* | ||
266 | * now, read until a # or end of buffer is found: | ||
267 | */ | ||
268 | while (count < (BUFMAX - 1)) { | ||
269 | ch = kgdb_io_ops->read_char(); | ||
270 | if (ch == '#') | ||
271 | break; | ||
272 | checksum = checksum + ch; | ||
273 | buffer[count] = ch; | ||
274 | count = count + 1; | ||
275 | } | ||
276 | buffer[count] = 0; | ||
277 | |||
278 | if (ch == '#') { | ||
279 | xmitcsum = hex(kgdb_io_ops->read_char()) << 4; | ||
280 | xmitcsum += hex(kgdb_io_ops->read_char()); | ||
281 | |||
282 | if (checksum != xmitcsum) | ||
283 | /* failed checksum */ | ||
284 | kgdb_io_ops->write_char('-'); | ||
285 | else | ||
286 | /* successful transfer */ | ||
287 | kgdb_io_ops->write_char('+'); | ||
288 | if (kgdb_io_ops->flush) | ||
289 | kgdb_io_ops->flush(); | ||
290 | } | ||
291 | } while (checksum != xmitcsum); | ||
292 | } | ||
293 | |||
294 | /* | ||
295 | * Send the packet in buffer. | ||
296 | * Check for gdb connection if asked for. | ||
297 | */ | ||
298 | static void put_packet(char *buffer) | ||
299 | { | ||
300 | unsigned char checksum; | ||
301 | int count; | ||
302 | char ch; | ||
303 | |||
304 | /* | ||
305 | * $<packet info>#<checksum>. | ||
306 | */ | ||
307 | while (1) { | ||
308 | kgdb_io_ops->write_char('$'); | ||
309 | checksum = 0; | ||
310 | count = 0; | ||
311 | |||
312 | while ((ch = buffer[count])) { | ||
313 | kgdb_io_ops->write_char(ch); | ||
314 | checksum += ch; | ||
315 | count++; | ||
316 | } | ||
317 | |||
318 | kgdb_io_ops->write_char('#'); | ||
319 | kgdb_io_ops->write_char(hexchars[checksum >> 4]); | ||
320 | kgdb_io_ops->write_char(hexchars[checksum & 0xf]); | ||
321 | if (kgdb_io_ops->flush) | ||
322 | kgdb_io_ops->flush(); | ||
323 | |||
324 | /* Now see what we get in reply. */ | ||
325 | ch = kgdb_io_ops->read_char(); | ||
326 | |||
327 | if (ch == 3) | ||
328 | ch = kgdb_io_ops->read_char(); | ||
329 | |||
330 | /* If we get an ACK, we are done. */ | ||
331 | if (ch == '+') | ||
332 | return; | ||
333 | |||
334 | /* | ||
335 | * If we get the start of another packet, this means | ||
336 | * that GDB is attempting to reconnect. We will NAK | ||
337 | * the packet being sent, and stop trying to send this | ||
338 | * packet. | ||
339 | */ | ||
340 | if (ch == '$') { | ||
341 | kgdb_io_ops->write_char('-'); | ||
342 | if (kgdb_io_ops->flush) | ||
343 | kgdb_io_ops->flush(); | ||
344 | return; | ||
345 | } | ||
346 | } | ||
347 | } | ||
348 | |||
349 | static char *pack_hex_byte(char *pkt, u8 byte) | ||
350 | { | ||
351 | *pkt++ = hexchars[byte >> 4]; | ||
352 | *pkt++ = hexchars[byte & 0xf]; | ||
353 | |||
354 | return pkt; | ||
355 | } | ||
356 | |||
357 | /* | ||
358 | * Convert the memory pointed to by mem into hex, placing result in buf. | ||
359 | * Return a pointer to the last char put in buf (null). May return an error. | ||
360 | */ | ||
361 | int kgdb_mem2hex(char *mem, char *buf, int count) | ||
362 | { | ||
363 | char *tmp; | ||
364 | int err; | ||
365 | |||
366 | /* | ||
367 | * We use the upper half of buf as an intermediate buffer for the | ||
368 | * raw memory copy. Hex conversion will work against this one. | ||
369 | */ | ||
370 | tmp = buf + count; | ||
371 | |||
372 | err = probe_kernel_read(tmp, mem, count); | ||
373 | if (!err) { | ||
374 | while (count > 0) { | ||
375 | buf = pack_hex_byte(buf, *tmp); | ||
376 | tmp++; | ||
377 | count--; | ||
378 | } | ||
379 | |||
380 | *buf = 0; | ||
381 | } | ||
382 | |||
383 | return err; | ||
384 | } | ||
385 | |||
386 | /* | ||
387 | * Copy the binary array pointed to by buf into mem. Fix $, #, and | ||
388 | * 0x7d escaped with 0x7d. Return a pointer to the character after | ||
389 | * the last byte written. | ||
390 | */ | ||
391 | static int kgdb_ebin2mem(char *buf, char *mem, int count) | ||
392 | { | ||
393 | int err = 0; | ||
394 | char c; | ||
395 | |||
396 | while (count-- > 0) { | ||
397 | c = *buf++; | ||
398 | if (c == 0x7d) | ||
399 | c = *buf++ ^ 0x20; | ||
400 | |||
401 | err = probe_kernel_write(mem, &c, 1); | ||
402 | if (err) | ||
403 | break; | ||
404 | |||
405 | mem++; | ||
406 | } | ||
407 | |||
408 | return err; | ||
409 | } | ||
410 | |||
411 | /* | ||
412 | * Convert the hex array pointed to by buf into binary to be placed in mem. | ||
413 | * Return a pointer to the character AFTER the last byte written. | ||
414 | * May return an error. | ||
415 | */ | ||
416 | int kgdb_hex2mem(char *buf, char *mem, int count) | ||
417 | { | ||
418 | char *tmp_raw; | ||
419 | char *tmp_hex; | ||
420 | |||
421 | /* | ||
422 | * We use the upper half of buf as an intermediate buffer for the | ||
423 | * raw memory that is converted from hex. | ||
424 | */ | ||
425 | tmp_raw = buf + count * 2; | ||
426 | |||
427 | tmp_hex = tmp_raw - 1; | ||
428 | while (tmp_hex >= buf) { | ||
429 | tmp_raw--; | ||
430 | *tmp_raw = hex(*tmp_hex--); | ||
431 | *tmp_raw |= hex(*tmp_hex--) << 4; | ||
432 | } | ||
433 | |||
434 | return probe_kernel_write(mem, tmp_raw, count); | ||
435 | } | ||
436 | |||
437 | /* | ||
438 | * While we find nice hex chars, build a long_val. | ||
439 | * Return number of chars processed. | ||
440 | */ | ||
441 | int kgdb_hex2long(char **ptr, long *long_val) | ||
442 | { | ||
443 | int hex_val; | ||
444 | int num = 0; | ||
445 | |||
446 | *long_val = 0; | ||
447 | |||
448 | while (**ptr) { | ||
449 | hex_val = hex(**ptr); | ||
450 | if (hex_val < 0) | ||
451 | break; | ||
452 | |||
453 | *long_val = (*long_val << 4) | hex_val; | ||
454 | num++; | ||
455 | (*ptr)++; | ||
456 | } | ||
457 | |||
458 | return num; | ||
459 | } | ||
460 | |||
461 | /* Write memory due to an 'M' or 'X' packet. */ | ||
462 | static int write_mem_msg(int binary) | ||
463 | { | ||
464 | char *ptr = &remcom_in_buffer[1]; | ||
465 | unsigned long addr; | ||
466 | unsigned long length; | ||
467 | int err; | ||
468 | |||
469 | if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' && | ||
470 | kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') { | ||
471 | if (binary) | ||
472 | err = kgdb_ebin2mem(ptr, (char *)addr, length); | ||
473 | else | ||
474 | err = kgdb_hex2mem(ptr, (char *)addr, length); | ||
475 | if (err) | ||
476 | return err; | ||
477 | if (CACHE_FLUSH_IS_SAFE) | ||
478 | flush_icache_range(addr, addr + length + 1); | ||
479 | return 0; | ||
480 | } | ||
481 | |||
482 | return -EINVAL; | ||
483 | } | ||
484 | |||
485 | static void error_packet(char *pkt, int error) | ||
486 | { | ||
487 | error = -error; | ||
488 | pkt[0] = 'E'; | ||
489 | pkt[1] = hexchars[(error / 10)]; | ||
490 | pkt[2] = hexchars[(error % 10)]; | ||
491 | pkt[3] = '\0'; | ||
492 | } | ||
493 | |||
494 | /* | ||
495 | * Thread ID accessors. We represent a flat TID space to GDB, where | ||
496 | * the per CPU idle threads (which under Linux all have PID 0) are | ||
497 | * remapped to negative TIDs. | ||
498 | */ | ||
499 | |||
500 | #define BUF_THREAD_ID_SIZE 16 | ||
501 | |||
502 | static char *pack_threadid(char *pkt, unsigned char *id) | ||
503 | { | ||
504 | char *limit; | ||
505 | |||
506 | limit = pkt + BUF_THREAD_ID_SIZE; | ||
507 | while (pkt < limit) | ||
508 | pkt = pack_hex_byte(pkt, *id++); | ||
509 | |||
510 | return pkt; | ||
511 | } | ||
512 | |||
513 | static void int_to_threadref(unsigned char *id, int value) | ||
514 | { | ||
515 | unsigned char *scan; | ||
516 | int i = 4; | ||
517 | |||
518 | scan = (unsigned char *)id; | ||
519 | while (i--) | ||
520 | *scan++ = 0; | ||
521 | *scan++ = (value >> 24) & 0xff; | ||
522 | *scan++ = (value >> 16) & 0xff; | ||
523 | *scan++ = (value >> 8) & 0xff; | ||
524 | *scan++ = (value & 0xff); | ||
525 | } | ||
526 | |||
527 | static struct task_struct *getthread(struct pt_regs *regs, int tid) | ||
528 | { | ||
529 | /* | ||
530 | * Non-positive TIDs are remapped idle tasks: | ||
531 | */ | ||
532 | if (tid <= 0) | ||
533 | return idle_task(-tid); | ||
534 | |||
535 | /* | ||
536 | * find_task_by_pid_ns() does not take the tasklist lock anymore | ||
537 | * but is nicely RCU locked - hence is a pretty resilient | ||
538 | * thing to use: | ||
539 | */ | ||
540 | return find_task_by_pid_ns(tid, &init_pid_ns); | ||
541 | } | ||
542 | |||
543 | /* | ||
544 | * CPU debug state control: | ||
545 | */ | ||
546 | |||
547 | #ifdef CONFIG_SMP | ||
548 | static void kgdb_wait(struct pt_regs *regs) | ||
549 | { | ||
550 | unsigned long flags; | ||
551 | int cpu; | ||
552 | |||
553 | local_irq_save(flags); | ||
554 | cpu = raw_smp_processor_id(); | ||
555 | kgdb_info[cpu].debuggerinfo = regs; | ||
556 | kgdb_info[cpu].task = current; | ||
557 | /* | ||
558 | * Make sure the above info reaches the primary CPU before | ||
559 | * our cpu_in_kgdb[] flag setting does: | ||
560 | */ | ||
561 | smp_wmb(); | ||
562 | atomic_set(&cpu_in_kgdb[cpu], 1); | ||
563 | |||
564 | /* Wait till primary CPU is done with debugging */ | ||
565 | while (atomic_read(&passive_cpu_wait[cpu])) | ||
566 | cpu_relax(); | ||
567 | |||
568 | kgdb_info[cpu].debuggerinfo = NULL; | ||
569 | kgdb_info[cpu].task = NULL; | ||
570 | |||
571 | /* fix up hardware debug registers on local cpu */ | ||
572 | if (arch_kgdb_ops.correct_hw_break) | ||
573 | arch_kgdb_ops.correct_hw_break(); | ||
574 | |||
575 | /* Signal the primary CPU that we are done: */ | ||
576 | atomic_set(&cpu_in_kgdb[cpu], 0); | ||
577 | clocksource_touch_watchdog(); | ||
578 | local_irq_restore(flags); | ||
579 | } | ||
580 | #endif | ||
581 | |||
582 | /* | ||
583 | * Some architectures need cache flushes when we set/clear a | ||
584 | * breakpoint: | ||
585 | */ | ||
586 | static void kgdb_flush_swbreak_addr(unsigned long addr) | ||
587 | { | ||
588 | if (!CACHE_FLUSH_IS_SAFE) | ||
589 | return; | ||
590 | |||
591 | if (current->mm && current->mm->mmap_cache) { | ||
592 | flush_cache_range(current->mm->mmap_cache, | ||
593 | addr, addr + BREAK_INSTR_SIZE); | ||
594 | } | ||
595 | /* Force flush instruction cache if it was outside the mm */ | ||
596 | flush_icache_range(addr, addr + BREAK_INSTR_SIZE); | ||
597 | } | ||
598 | |||
599 | /* | ||
600 | * SW breakpoint management: | ||
601 | */ | ||
602 | static int kgdb_activate_sw_breakpoints(void) | ||
603 | { | ||
604 | unsigned long addr; | ||
605 | int error = 0; | ||
606 | int i; | ||
607 | |||
608 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
609 | if (kgdb_break[i].state != BP_SET) | ||
610 | continue; | ||
611 | |||
612 | addr = kgdb_break[i].bpt_addr; | ||
613 | error = kgdb_arch_set_breakpoint(addr, | ||
614 | kgdb_break[i].saved_instr); | ||
615 | if (error) | ||
616 | return error; | ||
617 | |||
618 | kgdb_flush_swbreak_addr(addr); | ||
619 | kgdb_break[i].state = BP_ACTIVE; | ||
620 | } | ||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | static int kgdb_set_sw_break(unsigned long addr) | ||
625 | { | ||
626 | int err = kgdb_validate_break_address(addr); | ||
627 | int breakno = -1; | ||
628 | int i; | ||
629 | |||
630 | if (err) | ||
631 | return err; | ||
632 | |||
633 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
634 | if ((kgdb_break[i].state == BP_SET) && | ||
635 | (kgdb_break[i].bpt_addr == addr)) | ||
636 | return -EEXIST; | ||
637 | } | ||
638 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
639 | if (kgdb_break[i].state == BP_REMOVED && | ||
640 | kgdb_break[i].bpt_addr == addr) { | ||
641 | breakno = i; | ||
642 | break; | ||
643 | } | ||
644 | } | ||
645 | |||
646 | if (breakno == -1) { | ||
647 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
648 | if (kgdb_break[i].state == BP_UNDEFINED) { | ||
649 | breakno = i; | ||
650 | break; | ||
651 | } | ||
652 | } | ||
653 | } | ||
654 | |||
655 | if (breakno == -1) | ||
656 | return -E2BIG; | ||
657 | |||
658 | kgdb_break[breakno].state = BP_SET; | ||
659 | kgdb_break[breakno].type = BP_BREAKPOINT; | ||
660 | kgdb_break[breakno].bpt_addr = addr; | ||
661 | |||
662 | return 0; | ||
663 | } | ||
664 | |||
665 | static int kgdb_deactivate_sw_breakpoints(void) | ||
666 | { | ||
667 | unsigned long addr; | ||
668 | int error = 0; | ||
669 | int i; | ||
670 | |||
671 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
672 | if (kgdb_break[i].state != BP_ACTIVE) | ||
673 | continue; | ||
674 | addr = kgdb_break[i].bpt_addr; | ||
675 | error = kgdb_arch_remove_breakpoint(addr, | ||
676 | kgdb_break[i].saved_instr); | ||
677 | if (error) | ||
678 | return error; | ||
679 | |||
680 | kgdb_flush_swbreak_addr(addr); | ||
681 | kgdb_break[i].state = BP_SET; | ||
682 | } | ||
683 | return 0; | ||
684 | } | ||
685 | |||
686 | static int kgdb_remove_sw_break(unsigned long addr) | ||
687 | { | ||
688 | int i; | ||
689 | |||
690 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
691 | if ((kgdb_break[i].state == BP_SET) && | ||
692 | (kgdb_break[i].bpt_addr == addr)) { | ||
693 | kgdb_break[i].state = BP_REMOVED; | ||
694 | return 0; | ||
695 | } | ||
696 | } | ||
697 | return -ENOENT; | ||
698 | } | ||
699 | |||
700 | int kgdb_isremovedbreak(unsigned long addr) | ||
701 | { | ||
702 | int i; | ||
703 | |||
704 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
705 | if ((kgdb_break[i].state == BP_REMOVED) && | ||
706 | (kgdb_break[i].bpt_addr == addr)) | ||
707 | return 1; | ||
708 | } | ||
709 | return 0; | ||
710 | } | ||
711 | |||
712 | int remove_all_break(void) | ||
713 | { | ||
714 | unsigned long addr; | ||
715 | int error; | ||
716 | int i; | ||
717 | |||
718 | /* Clear memory breakpoints. */ | ||
719 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | ||
720 | if (kgdb_break[i].state != BP_ACTIVE) | ||
721 | goto setundefined; | ||
722 | addr = kgdb_break[i].bpt_addr; | ||
723 | error = kgdb_arch_remove_breakpoint(addr, | ||
724 | kgdb_break[i].saved_instr); | ||
725 | if (error) | ||
726 | printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n", | ||
727 | addr); | ||
728 | setundefined: | ||
729 | kgdb_break[i].state = BP_UNDEFINED; | ||
730 | } | ||
731 | |||
732 | /* Clear hardware breakpoints. */ | ||
733 | if (arch_kgdb_ops.remove_all_hw_break) | ||
734 | arch_kgdb_ops.remove_all_hw_break(); | ||
735 | |||
736 | return 0; | ||
737 | } | ||
738 | |||
739 | /* | ||
740 | * Remap normal tasks to their real PID, idle tasks to -1 ... -NR_CPUs: | ||
741 | */ | ||
742 | static inline int shadow_pid(int realpid) | ||
743 | { | ||
744 | if (realpid) | ||
745 | return realpid; | ||
746 | |||
747 | return -1-raw_smp_processor_id(); | ||
748 | } | ||
749 | |||
750 | static char gdbmsgbuf[BUFMAX + 1]; | ||
751 | |||
752 | static void kgdb_msg_write(const char *s, int len) | ||
753 | { | ||
754 | char *bufptr; | ||
755 | int wcount; | ||
756 | int i; | ||
757 | |||
758 | /* 'O'utput */ | ||
759 | gdbmsgbuf[0] = 'O'; | ||
760 | |||
761 | /* Fill and send buffers... */ | ||
762 | while (len > 0) { | ||
763 | bufptr = gdbmsgbuf + 1; | ||
764 | |||
765 | /* Calculate how many this time */ | ||
766 | if ((len << 1) > (BUFMAX - 2)) | ||
767 | wcount = (BUFMAX - 2) >> 1; | ||
768 | else | ||
769 | wcount = len; | ||
770 | |||
771 | /* Pack in hex chars */ | ||
772 | for (i = 0; i < wcount; i++) | ||
773 | bufptr = pack_hex_byte(bufptr, s[i]); | ||
774 | *bufptr = '\0'; | ||
775 | |||
776 | /* Move up */ | ||
777 | s += wcount; | ||
778 | len -= wcount; | ||
779 | |||
780 | /* Write packet */ | ||
781 | put_packet(gdbmsgbuf); | ||
782 | } | ||
783 | } | ||
784 | |||
785 | /* | ||
786 | * Return true if there is a valid kgdb I/O module. Also if no | ||
787 | * debugger is attached a message can be printed to the console about | ||
788 | * waiting for the debugger to attach. | ||
789 | * | ||
790 | * The print_wait argument is only to be true when called from inside | ||
791 | * the core kgdb_handle_exception, because it will wait for the | ||
792 | * debugger to attach. | ||
793 | */ | ||
794 | static int kgdb_io_ready(int print_wait) | ||
795 | { | ||
796 | if (!kgdb_io_ops) | ||
797 | return 0; | ||
798 | if (kgdb_connected) | ||
799 | return 1; | ||
800 | if (atomic_read(&kgdb_setting_breakpoint)) | ||
801 | return 1; | ||
802 | if (print_wait) | ||
803 | printk(KERN_CRIT "KGDB: Waiting for remote debugger\n"); | ||
804 | return 1; | ||
805 | } | ||
806 | |||
807 | /* | ||
808 | * All the functions that start with gdb_cmd are the various | ||
809 | * operations to implement the handlers for the gdbserial protocol | ||
810 | * where KGDB is communicating with an external debugger | ||
811 | */ | ||
812 | |||
813 | /* Handle the '?' status packets */ | ||
814 | static void gdb_cmd_status(struct kgdb_state *ks) | ||
815 | { | ||
816 | /* | ||
817 | * We know that this packet is only sent | ||
818 | * during initial connect. So to be safe, | ||
819 | * we clear out our breakpoints now in case | ||
820 | * GDB is reconnecting. | ||
821 | */ | ||
822 | remove_all_break(); | ||
823 | |||
824 | remcom_out_buffer[0] = 'S'; | ||
825 | pack_hex_byte(&remcom_out_buffer[1], ks->signo); | ||
826 | } | ||
827 | |||
828 | /* Handle the 'g' get registers request */ | ||
829 | static void gdb_cmd_getregs(struct kgdb_state *ks) | ||
830 | { | ||
831 | struct task_struct *thread; | ||
832 | void *local_debuggerinfo; | ||
833 | int i; | ||
834 | |||
835 | thread = kgdb_usethread; | ||
836 | if (!thread) { | ||
837 | thread = kgdb_info[ks->cpu].task; | ||
838 | local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo; | ||
839 | } else { | ||
840 | local_debuggerinfo = NULL; | ||
841 | for (i = 0; i < NR_CPUS; i++) { | ||
842 | /* | ||
843 | * Try to find the task on some other | ||
844 | * or possibly this node if we do not | ||
845 | * find the matching task then we try | ||
846 | * to approximate the results. | ||
847 | */ | ||
848 | if (thread == kgdb_info[i].task) | ||
849 | local_debuggerinfo = kgdb_info[i].debuggerinfo; | ||
850 | } | ||
851 | } | ||
852 | |||
853 | /* | ||
854 | * All threads that don't have debuggerinfo should be | ||
855 | * in __schedule() sleeping, since all other CPUs | ||
856 | * are in kgdb_wait, and thus have debuggerinfo. | ||
857 | */ | ||
858 | if (local_debuggerinfo) { | ||
859 | pt_regs_to_gdb_regs(gdb_regs, local_debuggerinfo); | ||
860 | } else { | ||
861 | /* | ||
862 | * Pull stuff saved during switch_to; nothing | ||
863 | * else is accessible (or even particularly | ||
864 | * relevant). | ||
865 | * | ||
866 | * This should be enough for a stack trace. | ||
867 | */ | ||
868 | sleeping_thread_to_gdb_regs(gdb_regs, thread); | ||
869 | } | ||
870 | kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES); | ||
871 | } | ||
872 | |||
873 | /* Handle the 'G' set registers request */ | ||
874 | static void gdb_cmd_setregs(struct kgdb_state *ks) | ||
875 | { | ||
876 | kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES); | ||
877 | |||
878 | if (kgdb_usethread && kgdb_usethread != current) { | ||
879 | error_packet(remcom_out_buffer, -EINVAL); | ||
880 | } else { | ||
881 | gdb_regs_to_pt_regs(gdb_regs, ks->linux_regs); | ||
882 | strcpy(remcom_out_buffer, "OK"); | ||
883 | } | ||
884 | } | ||
885 | |||
886 | /* Handle the 'm' memory read bytes */ | ||
887 | static void gdb_cmd_memread(struct kgdb_state *ks) | ||
888 | { | ||
889 | char *ptr = &remcom_in_buffer[1]; | ||
890 | unsigned long length; | ||
891 | unsigned long addr; | ||
892 | int err; | ||
893 | |||
894 | if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' && | ||
895 | kgdb_hex2long(&ptr, &length) > 0) { | ||
896 | err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length); | ||
897 | if (err) | ||
898 | error_packet(remcom_out_buffer, err); | ||
899 | } else { | ||
900 | error_packet(remcom_out_buffer, -EINVAL); | ||
901 | } | ||
902 | } | ||
903 | |||
904 | /* Handle the 'M' memory write bytes */ | ||
905 | static void gdb_cmd_memwrite(struct kgdb_state *ks) | ||
906 | { | ||
907 | int err = write_mem_msg(0); | ||
908 | |||
909 | if (err) | ||
910 | error_packet(remcom_out_buffer, err); | ||
911 | else | ||
912 | strcpy(remcom_out_buffer, "OK"); | ||
913 | } | ||
914 | |||
915 | /* Handle the 'X' memory binary write bytes */ | ||
916 | static void gdb_cmd_binwrite(struct kgdb_state *ks) | ||
917 | { | ||
918 | int err = write_mem_msg(1); | ||
919 | |||
920 | if (err) | ||
921 | error_packet(remcom_out_buffer, err); | ||
922 | else | ||
923 | strcpy(remcom_out_buffer, "OK"); | ||
924 | } | ||
925 | |||
926 | /* Handle the 'D' or 'k', detach or kill packets */ | ||
927 | static void gdb_cmd_detachkill(struct kgdb_state *ks) | ||
928 | { | ||
929 | int error; | ||
930 | |||
931 | /* The detach case */ | ||
932 | if (remcom_in_buffer[0] == 'D') { | ||
933 | error = remove_all_break(); | ||
934 | if (error < 0) { | ||
935 | error_packet(remcom_out_buffer, error); | ||
936 | } else { | ||
937 | strcpy(remcom_out_buffer, "OK"); | ||
938 | kgdb_connected = 0; | ||
939 | } | ||
940 | put_packet(remcom_out_buffer); | ||
941 | } else { | ||
942 | /* | ||
943 | * Assume the kill case, with no exit code checking, | ||
944 | * trying to force detach the debugger: | ||
945 | */ | ||
946 | remove_all_break(); | ||
947 | kgdb_connected = 0; | ||
948 | } | ||
949 | } | ||
950 | |||
951 | /* Handle the 'R' reboot packets */ | ||
952 | static int gdb_cmd_reboot(struct kgdb_state *ks) | ||
953 | { | ||
954 | /* For now, only honor R0 */ | ||
955 | if (strcmp(remcom_in_buffer, "R0") == 0) { | ||
956 | printk(KERN_CRIT "Executing emergency reboot\n"); | ||
957 | strcpy(remcom_out_buffer, "OK"); | ||
958 | put_packet(remcom_out_buffer); | ||
959 | |||
960 | /* | ||
961 | * Execution should not return from | ||
962 | * machine_emergency_restart() | ||
963 | */ | ||
964 | machine_emergency_restart(); | ||
965 | kgdb_connected = 0; | ||
966 | |||
967 | return 1; | ||
968 | } | ||
969 | return 0; | ||
970 | } | ||
971 | |||
972 | /* Handle the 'q' query packets */ | ||
973 | static void gdb_cmd_query(struct kgdb_state *ks) | ||
974 | { | ||
975 | struct task_struct *thread; | ||
976 | unsigned char thref[8]; | ||
977 | char *ptr; | ||
978 | int i; | ||
979 | |||
980 | switch (remcom_in_buffer[1]) { | ||
981 | case 's': | ||
982 | case 'f': | ||
983 | if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10)) { | ||
984 | error_packet(remcom_out_buffer, -EINVAL); | ||
985 | break; | ||
986 | } | ||
987 | |||
988 | if (remcom_in_buffer[1] == 'f') | ||
989 | ks->threadid = 1; | ||
990 | |||
991 | remcom_out_buffer[0] = 'm'; | ||
992 | ptr = remcom_out_buffer + 1; | ||
993 | |||
994 | for (i = 0; i < 17; ks->threadid++) { | ||
995 | thread = getthread(ks->linux_regs, ks->threadid); | ||
996 | if (thread) { | ||
997 | int_to_threadref(thref, ks->threadid); | ||
998 | pack_threadid(ptr, thref); | ||
999 | ptr += BUF_THREAD_ID_SIZE; | ||
1000 | *(ptr++) = ','; | ||
1001 | i++; | ||
1002 | } | ||
1003 | } | ||
1004 | *(--ptr) = '\0'; | ||
1005 | break; | ||
1006 | |||
1007 | case 'C': | ||
1008 | /* Current thread id */ | ||
1009 | strcpy(remcom_out_buffer, "QC"); | ||
1010 | ks->threadid = shadow_pid(current->pid); | ||
1011 | int_to_threadref(thref, ks->threadid); | ||
1012 | pack_threadid(remcom_out_buffer + 2, thref); | ||
1013 | break; | ||
1014 | case 'T': | ||
1015 | if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16)) { | ||
1016 | error_packet(remcom_out_buffer, -EINVAL); | ||
1017 | break; | ||
1018 | } | ||
1019 | ks->threadid = 0; | ||
1020 | ptr = remcom_in_buffer + 17; | ||
1021 | kgdb_hex2long(&ptr, &ks->threadid); | ||
1022 | if (!getthread(ks->linux_regs, ks->threadid)) { | ||
1023 | error_packet(remcom_out_buffer, -EINVAL); | ||
1024 | break; | ||
1025 | } | ||
1026 | if (ks->threadid > 0) { | ||
1027 | kgdb_mem2hex(getthread(ks->linux_regs, | ||
1028 | ks->threadid)->comm, | ||
1029 | remcom_out_buffer, 16); | ||
1030 | } else { | ||
1031 | static char tmpstr[23 + BUF_THREAD_ID_SIZE]; | ||
1032 | |||
1033 | sprintf(tmpstr, "Shadow task %d for pid 0", | ||
1034 | (int)(-ks->threadid-1)); | ||
1035 | kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr)); | ||
1036 | } | ||
1037 | break; | ||
1038 | } | ||
1039 | } | ||
1040 | |||
1041 | /* Handle the 'H' task query packets */ | ||
1042 | static void gdb_cmd_task(struct kgdb_state *ks) | ||
1043 | { | ||
1044 | struct task_struct *thread; | ||
1045 | char *ptr; | ||
1046 | |||
1047 | switch (remcom_in_buffer[1]) { | ||
1048 | case 'g': | ||
1049 | ptr = &remcom_in_buffer[2]; | ||
1050 | kgdb_hex2long(&ptr, &ks->threadid); | ||
1051 | thread = getthread(ks->linux_regs, ks->threadid); | ||
1052 | if (!thread && ks->threadid > 0) { | ||
1053 | error_packet(remcom_out_buffer, -EINVAL); | ||
1054 | break; | ||
1055 | } | ||
1056 | kgdb_usethread = thread; | ||
1057 | ks->kgdb_usethreadid = ks->threadid; | ||
1058 | strcpy(remcom_out_buffer, "OK"); | ||
1059 | break; | ||
1060 | case 'c': | ||
1061 | ptr = &remcom_in_buffer[2]; | ||
1062 | kgdb_hex2long(&ptr, &ks->threadid); | ||
1063 | if (!ks->threadid) { | ||
1064 | kgdb_contthread = NULL; | ||
1065 | } else { | ||
1066 | thread = getthread(ks->linux_regs, ks->threadid); | ||
1067 | if (!thread && ks->threadid > 0) { | ||
1068 | error_packet(remcom_out_buffer, -EINVAL); | ||
1069 | break; | ||
1070 | } | ||
1071 | kgdb_contthread = thread; | ||
1072 | } | ||
1073 | strcpy(remcom_out_buffer, "OK"); | ||
1074 | break; | ||
1075 | } | ||
1076 | } | ||
1077 | |||
1078 | /* Handle the 'T' thread query packets */ | ||
1079 | static void gdb_cmd_thread(struct kgdb_state *ks) | ||
1080 | { | ||
1081 | char *ptr = &remcom_in_buffer[1]; | ||
1082 | struct task_struct *thread; | ||
1083 | |||
1084 | kgdb_hex2long(&ptr, &ks->threadid); | ||
1085 | thread = getthread(ks->linux_regs, ks->threadid); | ||
1086 | if (thread) | ||
1087 | strcpy(remcom_out_buffer, "OK"); | ||
1088 | else | ||
1089 | error_packet(remcom_out_buffer, -EINVAL); | ||
1090 | } | ||
1091 | |||
1092 | /* Handle the 'z' or 'Z' breakpoint remove or set packets */ | ||
1093 | static void gdb_cmd_break(struct kgdb_state *ks) | ||
1094 | { | ||
1095 | /* | ||
1096 | * Since GDB-5.3, it's been drafted that '0' is a software | ||
1097 | * breakpoint, '1' is a hardware breakpoint, so let's do that. | ||
1098 | */ | ||
1099 | char *bpt_type = &remcom_in_buffer[1]; | ||
1100 | char *ptr = &remcom_in_buffer[2]; | ||
1101 | unsigned long addr; | ||
1102 | unsigned long length; | ||
1103 | int error = 0; | ||
1104 | |||
1105 | if (arch_kgdb_ops.set_hw_breakpoint && *bpt_type >= '1') { | ||
1106 | /* Unsupported */ | ||
1107 | if (*bpt_type > '4') | ||
1108 | return; | ||
1109 | } else { | ||
1110 | if (*bpt_type != '0' && *bpt_type != '1') | ||
1111 | /* Unsupported. */ | ||
1112 | return; | ||
1113 | } | ||
1114 | |||
1115 | /* | ||
1116 | * Test if this is a hardware breakpoint, and | ||
1117 | * if we support it: | ||
1118 | */ | ||
1119 | if (*bpt_type == '1' && !(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT)) | ||
1120 | /* Unsupported. */ | ||
1121 | return; | ||
1122 | |||
1123 | if (*(ptr++) != ',') { | ||
1124 | error_packet(remcom_out_buffer, -EINVAL); | ||
1125 | return; | ||
1126 | } | ||
1127 | if (!kgdb_hex2long(&ptr, &addr)) { | ||
1128 | error_packet(remcom_out_buffer, -EINVAL); | ||
1129 | return; | ||
1130 | } | ||
1131 | if (*(ptr++) != ',' || | ||
1132 | !kgdb_hex2long(&ptr, &length)) { | ||
1133 | error_packet(remcom_out_buffer, -EINVAL); | ||
1134 | return; | ||
1135 | } | ||
1136 | |||
1137 | if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0') | ||
1138 | error = kgdb_set_sw_break(addr); | ||
1139 | else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0') | ||
1140 | error = kgdb_remove_sw_break(addr); | ||
1141 | else if (remcom_in_buffer[0] == 'Z') | ||
1142 | error = arch_kgdb_ops.set_hw_breakpoint(addr, | ||
1143 | (int)length, *bpt_type - '0'); | ||
1144 | else if (remcom_in_buffer[0] == 'z') | ||
1145 | error = arch_kgdb_ops.remove_hw_breakpoint(addr, | ||
1146 | (int) length, *bpt_type - '0'); | ||
1147 | |||
1148 | if (error == 0) | ||
1149 | strcpy(remcom_out_buffer, "OK"); | ||
1150 | else | ||
1151 | error_packet(remcom_out_buffer, error); | ||
1152 | } | ||
1153 | |||
1154 | /* Handle the 'C' signal / exception passing packets */ | ||
1155 | static int gdb_cmd_exception_pass(struct kgdb_state *ks) | ||
1156 | { | ||
1157 | /* C09 == pass exception | ||
1158 | * C15 == detach kgdb, pass exception | ||
1159 | */ | ||
1160 | if (remcom_in_buffer[1] == '0' && remcom_in_buffer[2] == '9') { | ||
1161 | |||
1162 | ks->pass_exception = 1; | ||
1163 | remcom_in_buffer[0] = 'c'; | ||
1164 | |||
1165 | } else if (remcom_in_buffer[1] == '1' && remcom_in_buffer[2] == '5') { | ||
1166 | |||
1167 | ks->pass_exception = 1; | ||
1168 | remcom_in_buffer[0] = 'D'; | ||
1169 | remove_all_break(); | ||
1170 | kgdb_connected = 0; | ||
1171 | return 1; | ||
1172 | |||
1173 | } else { | ||
1174 | error_packet(remcom_out_buffer, -EINVAL); | ||
1175 | return 0; | ||
1176 | } | ||
1177 | |||
1178 | /* Indicate fall through */ | ||
1179 | return -1; | ||
1180 | } | ||
1181 | |||
1182 | /* | ||
1183 | * This function performs all gdbserial command procesing | ||
1184 | */ | ||
1185 | static int gdb_serial_stub(struct kgdb_state *ks) | ||
1186 | { | ||
1187 | int error = 0; | ||
1188 | int tmp; | ||
1189 | |||
1190 | /* Clear the out buffer. */ | ||
1191 | memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); | ||
1192 | |||
1193 | if (kgdb_connected) { | ||
1194 | unsigned char thref[8]; | ||
1195 | char *ptr; | ||
1196 | |||
1197 | /* Reply to host that an exception has occurred */ | ||
1198 | ptr = remcom_out_buffer; | ||
1199 | *ptr++ = 'T'; | ||
1200 | ptr = pack_hex_byte(ptr, ks->signo); | ||
1201 | ptr += strlen(strcpy(ptr, "thread:")); | ||
1202 | int_to_threadref(thref, shadow_pid(current->pid)); | ||
1203 | ptr = pack_threadid(ptr, thref); | ||
1204 | *ptr++ = ';'; | ||
1205 | put_packet(remcom_out_buffer); | ||
1206 | } | ||
1207 | |||
1208 | kgdb_usethread = kgdb_info[ks->cpu].task; | ||
1209 | ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid); | ||
1210 | ks->pass_exception = 0; | ||
1211 | |||
1212 | while (1) { | ||
1213 | error = 0; | ||
1214 | |||
1215 | /* Clear the out buffer. */ | ||
1216 | memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer)); | ||
1217 | |||
1218 | get_packet(remcom_in_buffer); | ||
1219 | |||
1220 | switch (remcom_in_buffer[0]) { | ||
1221 | case '?': /* gdbserial status */ | ||
1222 | gdb_cmd_status(ks); | ||
1223 | break; | ||
1224 | case 'g': /* return the value of the CPU registers */ | ||
1225 | gdb_cmd_getregs(ks); | ||
1226 | break; | ||
1227 | case 'G': /* set the value of the CPU registers - return OK */ | ||
1228 | gdb_cmd_setregs(ks); | ||
1229 | break; | ||
1230 | case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */ | ||
1231 | gdb_cmd_memread(ks); | ||
1232 | break; | ||
1233 | case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */ | ||
1234 | gdb_cmd_memwrite(ks); | ||
1235 | break; | ||
1236 | case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */ | ||
1237 | gdb_cmd_binwrite(ks); | ||
1238 | break; | ||
1239 | /* kill or detach. KGDB should treat this like a | ||
1240 | * continue. | ||
1241 | */ | ||
1242 | case 'D': /* Debugger detach */ | ||
1243 | case 'k': /* Debugger detach via kill */ | ||
1244 | gdb_cmd_detachkill(ks); | ||
1245 | goto default_handle; | ||
1246 | case 'R': /* Reboot */ | ||
1247 | if (gdb_cmd_reboot(ks)) | ||
1248 | goto default_handle; | ||
1249 | break; | ||
1250 | case 'q': /* query command */ | ||
1251 | gdb_cmd_query(ks); | ||
1252 | break; | ||
1253 | case 'H': /* task related */ | ||
1254 | gdb_cmd_task(ks); | ||
1255 | break; | ||
1256 | case 'T': /* Query thread status */ | ||
1257 | gdb_cmd_thread(ks); | ||
1258 | break; | ||
1259 | case 'z': /* Break point remove */ | ||
1260 | case 'Z': /* Break point set */ | ||
1261 | gdb_cmd_break(ks); | ||
1262 | break; | ||
1263 | case 'C': /* Exception passing */ | ||
1264 | tmp = gdb_cmd_exception_pass(ks); | ||
1265 | if (tmp > 0) | ||
1266 | goto default_handle; | ||
1267 | if (tmp == 0) | ||
1268 | break; | ||
1269 | /* Fall through on tmp < 0 */ | ||
1270 | case 'c': /* Continue packet */ | ||
1271 | case 's': /* Single step packet */ | ||
1272 | if (kgdb_contthread && kgdb_contthread != current) { | ||
1273 | /* Can't switch threads in kgdb */ | ||
1274 | error_packet(remcom_out_buffer, -EINVAL); | ||
1275 | break; | ||
1276 | } | ||
1277 | kgdb_activate_sw_breakpoints(); | ||
1278 | /* Fall through to default processing */ | ||
1279 | default: | ||
1280 | default_handle: | ||
1281 | error = kgdb_arch_handle_exception(ks->ex_vector, | ||
1282 | ks->signo, | ||
1283 | ks->err_code, | ||
1284 | remcom_in_buffer, | ||
1285 | remcom_out_buffer, | ||
1286 | ks->linux_regs); | ||
1287 | /* | ||
1288 | * Leave cmd processing on error, detach, | ||
1289 | * kill, continue, or single step. | ||
1290 | */ | ||
1291 | if (error >= 0 || remcom_in_buffer[0] == 'D' || | ||
1292 | remcom_in_buffer[0] == 'k') { | ||
1293 | error = 0; | ||
1294 | goto kgdb_exit; | ||
1295 | } | ||
1296 | |||
1297 | } | ||
1298 | |||
1299 | /* reply to the request */ | ||
1300 | put_packet(remcom_out_buffer); | ||
1301 | } | ||
1302 | |||
1303 | kgdb_exit: | ||
1304 | if (ks->pass_exception) | ||
1305 | error = 1; | ||
1306 | return error; | ||
1307 | } | ||
1308 | |||
1309 | static int kgdb_reenter_check(struct kgdb_state *ks) | ||
1310 | { | ||
1311 | unsigned long addr; | ||
1312 | |||
1313 | if (atomic_read(&kgdb_active) != raw_smp_processor_id()) | ||
1314 | return 0; | ||
1315 | |||
1316 | /* Panic on recursive debugger calls: */ | ||
1317 | exception_level++; | ||
1318 | addr = kgdb_arch_pc(ks->ex_vector, ks->linux_regs); | ||
1319 | kgdb_deactivate_sw_breakpoints(); | ||
1320 | |||
1321 | /* | ||
1322 | * If the break point removed ok at the place exception | ||
1323 | * occurred, try to recover and print a warning to the end | ||
1324 | * user because the user planted a breakpoint in a place that | ||
1325 | * KGDB needs in order to function. | ||
1326 | */ | ||
1327 | if (kgdb_remove_sw_break(addr) == 0) { | ||
1328 | exception_level = 0; | ||
1329 | kgdb_skipexception(ks->ex_vector, ks->linux_regs); | ||
1330 | kgdb_activate_sw_breakpoints(); | ||
1331 | printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n", | ||
1332 | addr); | ||
1333 | WARN_ON_ONCE(1); | ||
1334 | |||
1335 | return 1; | ||
1336 | } | ||
1337 | remove_all_break(); | ||
1338 | kgdb_skipexception(ks->ex_vector, ks->linux_regs); | ||
1339 | |||
1340 | if (exception_level > 1) { | ||
1341 | dump_stack(); | ||
1342 | panic("Recursive entry to debugger"); | ||
1343 | } | ||
1344 | |||
1345 | printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n"); | ||
1346 | dump_stack(); | ||
1347 | panic("Recursive entry to debugger"); | ||
1348 | |||
1349 | return 1; | ||
1350 | } | ||
1351 | |||
1352 | /* | ||
1353 | * kgdb_handle_exception() - main entry point from a kernel exception | ||
1354 | * | ||
1355 | * Locking hierarchy: | ||
1356 | * interface locks, if any (begin_session) | ||
1357 | * kgdb lock (kgdb_active) | ||
1358 | */ | ||
1359 | int | ||
1360 | kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) | ||
1361 | { | ||
1362 | struct kgdb_state kgdb_var; | ||
1363 | struct kgdb_state *ks = &kgdb_var; | ||
1364 | unsigned long flags; | ||
1365 | int error = 0; | ||
1366 | int i, cpu; | ||
1367 | |||
1368 | ks->cpu = raw_smp_processor_id(); | ||
1369 | ks->ex_vector = evector; | ||
1370 | ks->signo = signo; | ||
1371 | ks->ex_vector = evector; | ||
1372 | ks->err_code = ecode; | ||
1373 | ks->kgdb_usethreadid = 0; | ||
1374 | ks->linux_regs = regs; | ||
1375 | |||
1376 | if (kgdb_reenter_check(ks)) | ||
1377 | return 0; /* Ouch, double exception ! */ | ||
1378 | |||
1379 | acquirelock: | ||
1380 | /* | ||
1381 | * Interrupts will be restored by the 'trap return' code, except when | ||
1382 | * single stepping. | ||
1383 | */ | ||
1384 | local_irq_save(flags); | ||
1385 | |||
1386 | cpu = raw_smp_processor_id(); | ||
1387 | |||
1388 | /* | ||
1389 | * Acquire the kgdb_active lock: | ||
1390 | */ | ||
1391 | while (atomic_cmpxchg(&kgdb_active, -1, cpu) != -1) | ||
1392 | cpu_relax(); | ||
1393 | |||
1394 | /* | ||
1395 | * Do not start the debugger connection on this CPU if the last | ||
1396 | * instance of the exception handler wanted to come into the | ||
1397 | * debugger on a different CPU via a single step | ||
1398 | */ | ||
1399 | if (atomic_read(&kgdb_cpu_doing_single_step) != -1 && | ||
1400 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { | ||
1401 | |||
1402 | atomic_set(&kgdb_active, -1); | ||
1403 | clocksource_touch_watchdog(); | ||
1404 | local_irq_restore(flags); | ||
1405 | |||
1406 | goto acquirelock; | ||
1407 | } | ||
1408 | |||
1409 | if (!kgdb_io_ready(1)) { | ||
1410 | error = 1; | ||
1411 | goto kgdb_restore; /* No I/O connection, so resume the system */ | ||
1412 | } | ||
1413 | |||
1414 | /* | ||
1415 | * Don't enter if we have hit a removed breakpoint. | ||
1416 | */ | ||
1417 | if (kgdb_skipexception(ks->ex_vector, ks->linux_regs)) | ||
1418 | goto kgdb_restore; | ||
1419 | |||
1420 | /* Call the I/O driver's pre_exception routine */ | ||
1421 | if (kgdb_io_ops->pre_exception) | ||
1422 | kgdb_io_ops->pre_exception(); | ||
1423 | |||
1424 | kgdb_info[ks->cpu].debuggerinfo = ks->linux_regs; | ||
1425 | kgdb_info[ks->cpu].task = current; | ||
1426 | |||
1427 | kgdb_disable_hw_debug(ks->linux_regs); | ||
1428 | |||
1429 | /* | ||
1430 | * Get the passive CPU lock which will hold all the non-primary | ||
1431 | * CPU in a spin state while the debugger is active | ||
1432 | */ | ||
1433 | if (!kgdb_single_step || !kgdb_contthread) { | ||
1434 | for (i = 0; i < NR_CPUS; i++) | ||
1435 | atomic_set(&passive_cpu_wait[i], 1); | ||
1436 | } | ||
1437 | |||
1438 | /* | ||
1439 | * spin_lock code is good enough as a barrier so we don't | ||
1440 | * need one here: | ||
1441 | */ | ||
1442 | atomic_set(&cpu_in_kgdb[ks->cpu], 1); | ||
1443 | |||
1444 | #ifdef CONFIG_SMP | ||
1445 | /* Signal the other CPUs to enter kgdb_wait() */ | ||
1446 | if ((!kgdb_single_step || !kgdb_contthread) && kgdb_do_roundup) | ||
1447 | kgdb_roundup_cpus(flags); | ||
1448 | #endif | ||
1449 | |||
1450 | /* | ||
1451 | * Wait for the other CPUs to be notified and be waiting for us: | ||
1452 | */ | ||
1453 | for_each_online_cpu(i) { | ||
1454 | while (!atomic_read(&cpu_in_kgdb[i])) | ||
1455 | cpu_relax(); | ||
1456 | } | ||
1457 | |||
1458 | /* | ||
1459 | * At this point the primary processor is completely | ||
1460 | * in the debugger and all secondary CPUs are quiescent | ||
1461 | */ | ||
1462 | kgdb_post_primary_code(ks->linux_regs, ks->ex_vector, ks->err_code); | ||
1463 | kgdb_deactivate_sw_breakpoints(); | ||
1464 | kgdb_single_step = 0; | ||
1465 | kgdb_contthread = NULL; | ||
1466 | exception_level = 0; | ||
1467 | |||
1468 | /* Talk to debugger with gdbserial protocol */ | ||
1469 | error = gdb_serial_stub(ks); | ||
1470 | |||
1471 | /* Call the I/O driver's post_exception routine */ | ||
1472 | if (kgdb_io_ops->post_exception) | ||
1473 | kgdb_io_ops->post_exception(); | ||
1474 | |||
1475 | kgdb_info[ks->cpu].debuggerinfo = NULL; | ||
1476 | kgdb_info[ks->cpu].task = NULL; | ||
1477 | atomic_set(&cpu_in_kgdb[ks->cpu], 0); | ||
1478 | |||
1479 | if (!kgdb_single_step || !kgdb_contthread) { | ||
1480 | for (i = NR_CPUS-1; i >= 0; i--) | ||
1481 | atomic_set(&passive_cpu_wait[i], 0); | ||
1482 | /* | ||
1483 | * Wait till all the CPUs have quit | ||
1484 | * from the debugger. | ||
1485 | */ | ||
1486 | for_each_online_cpu(i) { | ||
1487 | while (atomic_read(&cpu_in_kgdb[i])) | ||
1488 | cpu_relax(); | ||
1489 | } | ||
1490 | } | ||
1491 | |||
1492 | kgdb_restore: | ||
1493 | /* Free kgdb_active */ | ||
1494 | atomic_set(&kgdb_active, -1); | ||
1495 | clocksource_touch_watchdog(); | ||
1496 | local_irq_restore(flags); | ||
1497 | |||
1498 | return error; | ||
1499 | } | ||
1500 | |||
1501 | int kgdb_nmicallback(int cpu, void *regs) | ||
1502 | { | ||
1503 | #ifdef CONFIG_SMP | ||
1504 | if (!atomic_read(&cpu_in_kgdb[cpu]) && | ||
1505 | atomic_read(&kgdb_active) != cpu && | ||
1506 | atomic_read(&cpu_in_kgdb[atomic_read(&kgdb_active)])) { | ||
1507 | kgdb_wait((struct pt_regs *)regs); | ||
1508 | return 0; | ||
1509 | } | ||
1510 | #endif | ||
1511 | return 1; | ||
1512 | } | ||
1513 | |||
1514 | void kgdb_console_write(struct console *co, const char *s, unsigned count) | ||
1515 | { | ||
1516 | unsigned long flags; | ||
1517 | |||
1518 | /* If we're debugging, or KGDB has not connected, don't try | ||
1519 | * and print. */ | ||
1520 | if (!kgdb_connected || atomic_read(&kgdb_active) != -1) | ||
1521 | return; | ||
1522 | |||
1523 | local_irq_save(flags); | ||
1524 | kgdb_msg_write(s, count); | ||
1525 | local_irq_restore(flags); | ||
1526 | } | ||
1527 | |||
1528 | static struct console kgdbcons = { | ||
1529 | .name = "kgdb", | ||
1530 | .write = kgdb_console_write, | ||
1531 | .flags = CON_PRINTBUFFER | CON_ENABLED, | ||
1532 | .index = -1, | ||
1533 | }; | ||
1534 | |||
1535 | #ifdef CONFIG_MAGIC_SYSRQ | ||
1536 | static void sysrq_handle_gdb(int key, struct tty_struct *tty) | ||
1537 | { | ||
1538 | if (!kgdb_io_ops) { | ||
1539 | printk(KERN_CRIT "ERROR: No KGDB I/O module available\n"); | ||
1540 | return; | ||
1541 | } | ||
1542 | if (!kgdb_connected) | ||
1543 | printk(KERN_CRIT "Entering KGDB\n"); | ||
1544 | |||
1545 | kgdb_breakpoint(); | ||
1546 | } | ||
1547 | |||
1548 | static struct sysrq_key_op sysrq_gdb_op = { | ||
1549 | .handler = sysrq_handle_gdb, | ||
1550 | .help_msg = "Gdb", | ||
1551 | .action_msg = "GDB", | ||
1552 | }; | ||
1553 | #endif | ||
1554 | |||
1555 | static void kgdb_register_callbacks(void) | ||
1556 | { | ||
1557 | if (!kgdb_io_module_registered) { | ||
1558 | kgdb_io_module_registered = 1; | ||
1559 | kgdb_arch_init(); | ||
1560 | #ifdef CONFIG_MAGIC_SYSRQ | ||
1561 | register_sysrq_key('g', &sysrq_gdb_op); | ||
1562 | #endif | ||
1563 | if (kgdb_use_con && !kgdb_con_registered) { | ||
1564 | register_console(&kgdbcons); | ||
1565 | kgdb_con_registered = 1; | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | |||
1570 | static void kgdb_unregister_callbacks(void) | ||
1571 | { | ||
1572 | /* | ||
1573 | * When this routine is called KGDB should unregister from the | ||
1574 | * panic handler and clean up, making sure it is not handling any | ||
1575 | * break exceptions at the time. | ||
1576 | */ | ||
1577 | if (kgdb_io_module_registered) { | ||
1578 | kgdb_io_module_registered = 0; | ||
1579 | kgdb_arch_exit(); | ||
1580 | #ifdef CONFIG_MAGIC_SYSRQ | ||
1581 | unregister_sysrq_key('g', &sysrq_gdb_op); | ||
1582 | #endif | ||
1583 | if (kgdb_con_registered) { | ||
1584 | unregister_console(&kgdbcons); | ||
1585 | kgdb_con_registered = 0; | ||
1586 | } | ||
1587 | } | ||
1588 | } | ||
1589 | |||
1590 | static void kgdb_initial_breakpoint(void) | ||
1591 | { | ||
1592 | kgdb_break_asap = 0; | ||
1593 | |||
1594 | printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n"); | ||
1595 | kgdb_breakpoint(); | ||
1596 | } | ||
1597 | |||
1598 | /** | ||
1599 | * kgdb_register_io_module - register KGDB IO module | ||
1600 | * @new_kgdb_io_ops: the io ops vector | ||
1601 | * | ||
1602 | * Register it with the KGDB core. | ||
1603 | */ | ||
1604 | int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops) | ||
1605 | { | ||
1606 | int err; | ||
1607 | |||
1608 | spin_lock(&kgdb_registration_lock); | ||
1609 | |||
1610 | if (kgdb_io_ops) { | ||
1611 | spin_unlock(&kgdb_registration_lock); | ||
1612 | |||
1613 | printk(KERN_ERR "kgdb: Another I/O driver is already " | ||
1614 | "registered with KGDB.\n"); | ||
1615 | return -EBUSY; | ||
1616 | } | ||
1617 | |||
1618 | if (new_kgdb_io_ops->init) { | ||
1619 | err = new_kgdb_io_ops->init(); | ||
1620 | if (err) { | ||
1621 | spin_unlock(&kgdb_registration_lock); | ||
1622 | return err; | ||
1623 | } | ||
1624 | } | ||
1625 | |||
1626 | kgdb_io_ops = new_kgdb_io_ops; | ||
1627 | |||
1628 | spin_unlock(&kgdb_registration_lock); | ||
1629 | |||
1630 | printk(KERN_INFO "kgdb: Registered I/O driver %s.\n", | ||
1631 | new_kgdb_io_ops->name); | ||
1632 | |||
1633 | /* Arm KGDB now. */ | ||
1634 | kgdb_register_callbacks(); | ||
1635 | |||
1636 | if (kgdb_break_asap) | ||
1637 | kgdb_initial_breakpoint(); | ||
1638 | |||
1639 | return 0; | ||
1640 | } | ||
1641 | EXPORT_SYMBOL_GPL(kgdb_register_io_module); | ||
1642 | |||
1643 | /** | ||
1644 | * kkgdb_unregister_io_module - unregister KGDB IO module | ||
1645 | * @old_kgdb_io_ops: the io ops vector | ||
1646 | * | ||
1647 | * Unregister it with the KGDB core. | ||
1648 | */ | ||
1649 | void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops) | ||
1650 | { | ||
1651 | BUG_ON(kgdb_connected); | ||
1652 | |||
1653 | /* | ||
1654 | * KGDB is no longer able to communicate out, so | ||
1655 | * unregister our callbacks and reset state. | ||
1656 | */ | ||
1657 | kgdb_unregister_callbacks(); | ||
1658 | |||
1659 | spin_lock(&kgdb_registration_lock); | ||
1660 | |||
1661 | WARN_ON_ONCE(kgdb_io_ops != old_kgdb_io_ops); | ||
1662 | kgdb_io_ops = NULL; | ||
1663 | |||
1664 | spin_unlock(&kgdb_registration_lock); | ||
1665 | |||
1666 | printk(KERN_INFO | ||
1667 | "kgdb: Unregistered I/O driver %s, debugger disabled.\n", | ||
1668 | old_kgdb_io_ops->name); | ||
1669 | } | ||
1670 | EXPORT_SYMBOL_GPL(kgdb_unregister_io_module); | ||
1671 | |||
1672 | /** | ||
1673 | * kgdb_breakpoint - generate breakpoint exception | ||
1674 | * | ||
1675 | * This function will generate a breakpoint exception. It is used at the | ||
1676 | * beginning of a program to sync up with a debugger and can be used | ||
1677 | * otherwise as a quick means to stop program execution and "break" into | ||
1678 | * the debugger. | ||
1679 | */ | ||
1680 | void kgdb_breakpoint(void) | ||
1681 | { | ||
1682 | atomic_set(&kgdb_setting_breakpoint, 1); | ||
1683 | wmb(); /* Sync point before breakpoint */ | ||
1684 | arch_kgdb_breakpoint(); | ||
1685 | wmb(); /* Sync point after breakpoint */ | ||
1686 | atomic_set(&kgdb_setting_breakpoint, 0); | ||
1687 | } | ||
1688 | EXPORT_SYMBOL_GPL(kgdb_breakpoint); | ||
1689 | |||
1690 | static int __init opt_kgdb_wait(char *str) | ||
1691 | { | ||
1692 | kgdb_break_asap = 1; | ||
1693 | |||
1694 | if (kgdb_io_module_registered) | ||
1695 | kgdb_initial_breakpoint(); | ||
1696 | |||
1697 | return 0; | ||
1698 | } | ||
1699 | |||
1700 | early_param("kgdbwait", opt_kgdb_wait); | ||
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index 2eae91f954ca..ae5c6c147c4b 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -1087,45 +1087,45 @@ static void check_process_timers(struct task_struct *tsk, | |||
1087 | maxfire = 20; | 1087 | maxfire = 20; |
1088 | prof_expires = cputime_zero; | 1088 | prof_expires = cputime_zero; |
1089 | while (!list_empty(timers)) { | 1089 | while (!list_empty(timers)) { |
1090 | struct cpu_timer_list *t = list_first_entry(timers, | 1090 | struct cpu_timer_list *tl = list_first_entry(timers, |
1091 | struct cpu_timer_list, | 1091 | struct cpu_timer_list, |
1092 | entry); | 1092 | entry); |
1093 | if (!--maxfire || cputime_lt(ptime, t->expires.cpu)) { | 1093 | if (!--maxfire || cputime_lt(ptime, tl->expires.cpu)) { |
1094 | prof_expires = t->expires.cpu; | 1094 | prof_expires = tl->expires.cpu; |
1095 | break; | 1095 | break; |
1096 | } | 1096 | } |
1097 | t->firing = 1; | 1097 | tl->firing = 1; |
1098 | list_move_tail(&t->entry, firing); | 1098 | list_move_tail(&tl->entry, firing); |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | ++timers; | 1101 | ++timers; |
1102 | maxfire = 20; | 1102 | maxfire = 20; |
1103 | virt_expires = cputime_zero; | 1103 | virt_expires = cputime_zero; |
1104 | while (!list_empty(timers)) { | 1104 | while (!list_empty(timers)) { |
1105 | struct cpu_timer_list *t = list_first_entry(timers, | 1105 | struct cpu_timer_list *tl = list_first_entry(timers, |
1106 | struct cpu_timer_list, | 1106 | struct cpu_timer_list, |
1107 | entry); | 1107 | entry); |
1108 | if (!--maxfire || cputime_lt(utime, t->expires.cpu)) { | 1108 | if (!--maxfire || cputime_lt(utime, tl->expires.cpu)) { |
1109 | virt_expires = t->expires.cpu; | 1109 | virt_expires = tl->expires.cpu; |
1110 | break; | 1110 | break; |
1111 | } | 1111 | } |
1112 | t->firing = 1; | 1112 | tl->firing = 1; |
1113 | list_move_tail(&t->entry, firing); | 1113 | list_move_tail(&tl->entry, firing); |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | ++timers; | 1116 | ++timers; |
1117 | maxfire = 20; | 1117 | maxfire = 20; |
1118 | sched_expires = 0; | 1118 | sched_expires = 0; |
1119 | while (!list_empty(timers)) { | 1119 | while (!list_empty(timers)) { |
1120 | struct cpu_timer_list *t = list_first_entry(timers, | 1120 | struct cpu_timer_list *tl = list_first_entry(timers, |
1121 | struct cpu_timer_list, | 1121 | struct cpu_timer_list, |
1122 | entry); | 1122 | entry); |
1123 | if (!--maxfire || sum_sched_runtime < t->expires.sched) { | 1123 | if (!--maxfire || sum_sched_runtime < tl->expires.sched) { |
1124 | sched_expires = t->expires.sched; | 1124 | sched_expires = tl->expires.sched; |
1125 | break; | 1125 | break; |
1126 | } | 1126 | } |
1127 | t->firing = 1; | 1127 | tl->firing = 1; |
1128 | list_move_tail(&t->entry, firing); | 1128 | list_move_tail(&tl->entry, firing); |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | /* | 1131 | /* |
diff --git a/kernel/printk.c b/kernel/printk.c index c46a20a19a15..bdd4ea8c3f2b 100644 --- a/kernel/printk.c +++ b/kernel/printk.c | |||
@@ -643,8 +643,21 @@ static int acquire_console_semaphore_for_printk(unsigned int cpu) | |||
643 | { | 643 | { |
644 | int retval = 0; | 644 | int retval = 0; |
645 | 645 | ||
646 | if (can_use_console(cpu)) | 646 | if (!try_acquire_console_sem()) { |
647 | retval = !try_acquire_console_sem(); | 647 | retval = 1; |
648 | |||
649 | /* | ||
650 | * If we can't use the console, we need to release | ||
651 | * the console semaphore by hand to avoid flushing | ||
652 | * the buffer. We need to hold the console semaphore | ||
653 | * in order to do this test safely. | ||
654 | */ | ||
655 | if (!can_use_console(cpu)) { | ||
656 | console_locked = 0; | ||
657 | up(&console_sem); | ||
658 | retval = 0; | ||
659 | } | ||
660 | } | ||
648 | printk_cpu = UINT_MAX; | 661 | printk_cpu = UINT_MAX; |
649 | spin_unlock(&logbuf_lock); | 662 | spin_unlock(&logbuf_lock); |
650 | return retval; | 663 | return retval; |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 86a93376282c..0080968d3e4a 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -510,10 +510,8 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial) | |||
510 | 510 | ||
511 | if (!initial) { | 511 | if (!initial) { |
512 | /* sleeps upto a single latency don't count. */ | 512 | /* sleeps upto a single latency don't count. */ |
513 | if (sched_feat(NEW_FAIR_SLEEPERS)) { | 513 | if (sched_feat(NEW_FAIR_SLEEPERS)) |
514 | vruntime -= calc_delta_fair(sysctl_sched_latency, | 514 | vruntime -= sysctl_sched_latency; |
515 | &cfs_rq->load); | ||
516 | } | ||
517 | 515 | ||
518 | /* ensure we never gain time by being placed backwards. */ | 516 | /* ensure we never gain time by being placed backwards. */ |
519 | vruntime = max_vruntime(se->vruntime, vruntime); | 517 | vruntime = max_vruntime(se->vruntime, vruntime); |
diff --git a/kernel/semaphore.c b/kernel/semaphore.c new file mode 100644 index 000000000000..5c2942e768cd --- /dev/null +++ b/kernel/semaphore.c | |||
@@ -0,0 +1,264 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Intel Corporation | ||
3 | * Author: Matthew Wilcox <willy@linux.intel.com> | ||
4 | * | ||
5 | * Distributed under the terms of the GNU GPL, version 2 | ||
6 | * | ||
7 | * This file implements counting semaphores. | ||
8 | * A counting semaphore may be acquired 'n' times before sleeping. | ||
9 | * See mutex.c for single-acquisition sleeping locks which enforce | ||
10 | * rules which allow code to be debugged more easily. | ||
11 | */ | ||
12 | |||
13 | /* | ||
14 | * Some notes on the implementation: | ||
15 | * | ||
16 | * The spinlock controls access to the other members of the semaphore. | ||
17 | * down_trylock() and up() can be called from interrupt context, so we | ||
18 | * have to disable interrupts when taking the lock. It turns out various | ||
19 | * parts of the kernel expect to be able to use down() on a semaphore in | ||
20 | * interrupt context when they know it will succeed, so we have to use | ||
21 | * irqsave variants for down(), down_interruptible() and down_killable() | ||
22 | * too. | ||
23 | * | ||
24 | * The ->count variable represents how many more tasks can acquire this | ||
25 | * semaphore. If it's zero, there may be tasks waiting on the wait_list. | ||
26 | */ | ||
27 | |||
28 | #include <linux/compiler.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/sched.h> | ||
32 | #include <linux/semaphore.h> | ||
33 | #include <linux/spinlock.h> | ||
34 | |||
35 | static noinline void __down(struct semaphore *sem); | ||
36 | static noinline int __down_interruptible(struct semaphore *sem); | ||
37 | static noinline int __down_killable(struct semaphore *sem); | ||
38 | static noinline int __down_timeout(struct semaphore *sem, long jiffies); | ||
39 | static noinline void __up(struct semaphore *sem); | ||
40 | |||
41 | /** | ||
42 | * down - acquire the semaphore | ||
43 | * @sem: the semaphore to be acquired | ||
44 | * | ||
45 | * Acquires the semaphore. If no more tasks are allowed to acquire the | ||
46 | * semaphore, calling this function will put the task to sleep until the | ||
47 | * semaphore is released. | ||
48 | * | ||
49 | * Use of this function is deprecated, please use down_interruptible() or | ||
50 | * down_killable() instead. | ||
51 | */ | ||
52 | void down(struct semaphore *sem) | ||
53 | { | ||
54 | unsigned long flags; | ||
55 | |||
56 | spin_lock_irqsave(&sem->lock, flags); | ||
57 | if (likely(sem->count > 0)) | ||
58 | sem->count--; | ||
59 | else | ||
60 | __down(sem); | ||
61 | spin_unlock_irqrestore(&sem->lock, flags); | ||
62 | } | ||
63 | EXPORT_SYMBOL(down); | ||
64 | |||
65 | /** | ||
66 | * down_interruptible - acquire the semaphore unless interrupted | ||
67 | * @sem: the semaphore to be acquired | ||
68 | * | ||
69 | * Attempts to acquire the semaphore. If no more tasks are allowed to | ||
70 | * acquire the semaphore, calling this function will put the task to sleep. | ||
71 | * If the sleep is interrupted by a signal, this function will return -EINTR. | ||
72 | * If the semaphore is successfully acquired, this function returns 0. | ||
73 | */ | ||
74 | int down_interruptible(struct semaphore *sem) | ||
75 | { | ||
76 | unsigned long flags; | ||
77 | int result = 0; | ||
78 | |||
79 | spin_lock_irqsave(&sem->lock, flags); | ||
80 | if (likely(sem->count > 0)) | ||
81 | sem->count--; | ||
82 | else | ||
83 | result = __down_interruptible(sem); | ||
84 | spin_unlock_irqrestore(&sem->lock, flags); | ||
85 | |||
86 | return result; | ||
87 | } | ||
88 | EXPORT_SYMBOL(down_interruptible); | ||
89 | |||
90 | /** | ||
91 | * down_killable - acquire the semaphore unless killed | ||
92 | * @sem: the semaphore to be acquired | ||
93 | * | ||
94 | * Attempts to acquire the semaphore. If no more tasks are allowed to | ||
95 | * acquire the semaphore, calling this function will put the task to sleep. | ||
96 | * If the sleep is interrupted by a fatal signal, this function will return | ||
97 | * -EINTR. If the semaphore is successfully acquired, this function returns | ||
98 | * 0. | ||
99 | */ | ||
100 | int down_killable(struct semaphore *sem) | ||
101 | { | ||
102 | unsigned long flags; | ||
103 | int result = 0; | ||
104 | |||
105 | spin_lock_irqsave(&sem->lock, flags); | ||
106 | if (likely(sem->count > 0)) | ||
107 | sem->count--; | ||
108 | else | ||
109 | result = __down_killable(sem); | ||
110 | spin_unlock_irqrestore(&sem->lock, flags); | ||
111 | |||
112 | return result; | ||
113 | } | ||
114 | EXPORT_SYMBOL(down_killable); | ||
115 | |||
116 | /** | ||
117 | * down_trylock - try to acquire the semaphore, without waiting | ||
118 | * @sem: the semaphore to be acquired | ||
119 | * | ||
120 | * Try to acquire the semaphore atomically. Returns 0 if the mutex has | ||
121 | * been acquired successfully or 1 if it it cannot be acquired. | ||
122 | * | ||
123 | * NOTE: This return value is inverted from both spin_trylock and | ||
124 | * mutex_trylock! Be careful about this when converting code. | ||
125 | * | ||
126 | * Unlike mutex_trylock, this function can be used from interrupt context, | ||
127 | * and the semaphore can be released by any task or interrupt. | ||
128 | */ | ||
129 | int down_trylock(struct semaphore *sem) | ||
130 | { | ||
131 | unsigned long flags; | ||
132 | int count; | ||
133 | |||
134 | spin_lock_irqsave(&sem->lock, flags); | ||
135 | count = sem->count - 1; | ||
136 | if (likely(count >= 0)) | ||
137 | sem->count = count; | ||
138 | spin_unlock_irqrestore(&sem->lock, flags); | ||
139 | |||
140 | return (count < 0); | ||
141 | } | ||
142 | EXPORT_SYMBOL(down_trylock); | ||
143 | |||
144 | /** | ||
145 | * down_timeout - acquire the semaphore within a specified time | ||
146 | * @sem: the semaphore to be acquired | ||
147 | * @jiffies: how long to wait before failing | ||
148 | * | ||
149 | * Attempts to acquire the semaphore. If no more tasks are allowed to | ||
150 | * acquire the semaphore, calling this function will put the task to sleep. | ||
151 | * If the semaphore is not released within the specified number of jiffies, | ||
152 | * this function returns -ETIME. It returns 0 if the semaphore was acquired. | ||
153 | */ | ||
154 | int down_timeout(struct semaphore *sem, long jiffies) | ||
155 | { | ||
156 | unsigned long flags; | ||
157 | int result = 0; | ||
158 | |||
159 | spin_lock_irqsave(&sem->lock, flags); | ||
160 | if (likely(sem->count > 0)) | ||
161 | sem->count--; | ||
162 | else | ||
163 | result = __down_timeout(sem, jiffies); | ||
164 | spin_unlock_irqrestore(&sem->lock, flags); | ||
165 | |||
166 | return result; | ||
167 | } | ||
168 | EXPORT_SYMBOL(down_timeout); | ||
169 | |||
170 | /** | ||
171 | * up - release the semaphore | ||
172 | * @sem: the semaphore to release | ||
173 | * | ||
174 | * Release the semaphore. Unlike mutexes, up() may be called from any | ||
175 | * context and even by tasks which have never called down(). | ||
176 | */ | ||
177 | void up(struct semaphore *sem) | ||
178 | { | ||
179 | unsigned long flags; | ||
180 | |||
181 | spin_lock_irqsave(&sem->lock, flags); | ||
182 | if (likely(list_empty(&sem->wait_list))) | ||
183 | sem->count++; | ||
184 | else | ||
185 | __up(sem); | ||
186 | spin_unlock_irqrestore(&sem->lock, flags); | ||
187 | } | ||
188 | EXPORT_SYMBOL(up); | ||
189 | |||
190 | /* Functions for the contended case */ | ||
191 | |||
192 | struct semaphore_waiter { | ||
193 | struct list_head list; | ||
194 | struct task_struct *task; | ||
195 | int up; | ||
196 | }; | ||
197 | |||
198 | /* | ||
199 | * Because this function is inlined, the 'state' parameter will be | ||
200 | * constant, and thus optimised away by the compiler. Likewise the | ||
201 | * 'timeout' parameter for the cases without timeouts. | ||
202 | */ | ||
203 | static inline int __sched __down_common(struct semaphore *sem, long state, | ||
204 | long timeout) | ||
205 | { | ||
206 | struct task_struct *task = current; | ||
207 | struct semaphore_waiter waiter; | ||
208 | |||
209 | list_add_tail(&waiter.list, &sem->wait_list); | ||
210 | waiter.task = task; | ||
211 | waiter.up = 0; | ||
212 | |||
213 | for (;;) { | ||
214 | if (state == TASK_INTERRUPTIBLE && signal_pending(task)) | ||
215 | goto interrupted; | ||
216 | if (state == TASK_KILLABLE && fatal_signal_pending(task)) | ||
217 | goto interrupted; | ||
218 | if (timeout <= 0) | ||
219 | goto timed_out; | ||
220 | __set_task_state(task, state); | ||
221 | spin_unlock_irq(&sem->lock); | ||
222 | timeout = schedule_timeout(timeout); | ||
223 | spin_lock_irq(&sem->lock); | ||
224 | if (waiter.up) | ||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | timed_out: | ||
229 | list_del(&waiter.list); | ||
230 | return -ETIME; | ||
231 | |||
232 | interrupted: | ||
233 | list_del(&waiter.list); | ||
234 | return -EINTR; | ||
235 | } | ||
236 | |||
237 | static noinline void __sched __down(struct semaphore *sem) | ||
238 | { | ||
239 | __down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); | ||
240 | } | ||
241 | |||
242 | static noinline int __sched __down_interruptible(struct semaphore *sem) | ||
243 | { | ||
244 | return __down_common(sem, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); | ||
245 | } | ||
246 | |||
247 | static noinline int __sched __down_killable(struct semaphore *sem) | ||
248 | { | ||
249 | return __down_common(sem, TASK_KILLABLE, MAX_SCHEDULE_TIMEOUT); | ||
250 | } | ||
251 | |||
252 | static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies) | ||
253 | { | ||
254 | return __down_common(sem, TASK_UNINTERRUPTIBLE, jiffies); | ||
255 | } | ||
256 | |||
257 | static noinline void __sched __up(struct semaphore *sem) | ||
258 | { | ||
259 | struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list, | ||
260 | struct semaphore_waiter, list); | ||
261 | list_del(&waiter->list); | ||
262 | waiter->up = 1; | ||
263 | wake_up_process(waiter->task); | ||
264 | } | ||
diff --git a/kernel/signal.c b/kernel/signal.c index 6af1210092c3..cc8303cd093d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
@@ -1757,6 +1757,45 @@ static int do_signal_stop(int signr) | |||
1757 | return 1; | 1757 | return 1; |
1758 | } | 1758 | } |
1759 | 1759 | ||
1760 | static int ptrace_signal(int signr, siginfo_t *info, | ||
1761 | struct pt_regs *regs, void *cookie) | ||
1762 | { | ||
1763 | if (!(current->ptrace & PT_PTRACED)) | ||
1764 | return signr; | ||
1765 | |||
1766 | ptrace_signal_deliver(regs, cookie); | ||
1767 | |||
1768 | /* Let the debugger run. */ | ||
1769 | ptrace_stop(signr, 0, info); | ||
1770 | |||
1771 | /* We're back. Did the debugger cancel the sig? */ | ||
1772 | signr = current->exit_code; | ||
1773 | if (signr == 0) | ||
1774 | return signr; | ||
1775 | |||
1776 | current->exit_code = 0; | ||
1777 | |||
1778 | /* Update the siginfo structure if the signal has | ||
1779 | changed. If the debugger wanted something | ||
1780 | specific in the siginfo structure then it should | ||
1781 | have updated *info via PTRACE_SETSIGINFO. */ | ||
1782 | if (signr != info->si_signo) { | ||
1783 | info->si_signo = signr; | ||
1784 | info->si_errno = 0; | ||
1785 | info->si_code = SI_USER; | ||
1786 | info->si_pid = task_pid_vnr(current->parent); | ||
1787 | info->si_uid = current->parent->uid; | ||
1788 | } | ||
1789 | |||
1790 | /* If the (new) signal is now blocked, requeue it. */ | ||
1791 | if (sigismember(¤t->blocked, signr)) { | ||
1792 | specific_send_sig_info(signr, info, current); | ||
1793 | signr = 0; | ||
1794 | } | ||
1795 | |||
1796 | return signr; | ||
1797 | } | ||
1798 | |||
1760 | int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, | 1799 | int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, |
1761 | struct pt_regs *regs, void *cookie) | 1800 | struct pt_regs *regs, void *cookie) |
1762 | { | 1801 | { |
@@ -1785,36 +1824,10 @@ relock: | |||
1785 | if (!signr) | 1824 | if (!signr) |
1786 | break; /* will return 0 */ | 1825 | break; /* will return 0 */ |
1787 | 1826 | ||
1788 | if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) { | 1827 | if (signr != SIGKILL) { |
1789 | ptrace_signal_deliver(regs, cookie); | 1828 | signr = ptrace_signal(signr, info, regs, cookie); |
1790 | 1829 | if (!signr) | |
1791 | /* Let the debugger run. */ | ||
1792 | ptrace_stop(signr, 0, info); | ||
1793 | |||
1794 | /* We're back. Did the debugger cancel the sig? */ | ||
1795 | signr = current->exit_code; | ||
1796 | if (signr == 0) | ||
1797 | continue; | ||
1798 | |||
1799 | current->exit_code = 0; | ||
1800 | |||
1801 | /* Update the siginfo structure if the signal has | ||
1802 | changed. If the debugger wanted something | ||
1803 | specific in the siginfo structure then it should | ||
1804 | have updated *info via PTRACE_SETSIGINFO. */ | ||
1805 | if (signr != info->si_signo) { | ||
1806 | info->si_signo = signr; | ||
1807 | info->si_errno = 0; | ||
1808 | info->si_code = SI_USER; | ||
1809 | info->si_pid = task_pid_vnr(current->parent); | ||
1810 | info->si_uid = current->parent->uid; | ||
1811 | } | ||
1812 | |||
1813 | /* If the (new) signal is now blocked, requeue it. */ | ||
1814 | if (sigismember(¤t->blocked, signr)) { | ||
1815 | specific_send_sig_info(signr, info, current); | ||
1816 | continue; | 1830 | continue; |
1817 | } | ||
1818 | } | 1831 | } |
1819 | 1832 | ||
1820 | ka = ¤t->sighand->action[signr-1]; | 1833 | ka = ¤t->sighand->action[signr-1]; |
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c index 7f60097d443a..73961f35fdc8 100644 --- a/kernel/time/clocksource.c +++ b/kernel/time/clocksource.c | |||
@@ -141,8 +141,16 @@ static void clocksource_watchdog(unsigned long data) | |||
141 | } | 141 | } |
142 | 142 | ||
143 | if (!list_empty(&watchdog_list)) { | 143 | if (!list_empty(&watchdog_list)) { |
144 | __mod_timer(&watchdog_timer, | 144 | /* |
145 | watchdog_timer.expires + WATCHDOG_INTERVAL); | 145 | * Cycle through CPUs to check if the CPUs stay |
146 | * synchronized to each other. | ||
147 | */ | ||
148 | int next_cpu = next_cpu(raw_smp_processor_id(), cpu_online_map); | ||
149 | |||
150 | if (next_cpu >= NR_CPUS) | ||
151 | next_cpu = first_cpu(cpu_online_map); | ||
152 | watchdog_timer.expires += WATCHDOG_INTERVAL; | ||
153 | add_timer_on(&watchdog_timer, next_cpu); | ||
146 | } | 154 | } |
147 | spin_unlock(&watchdog_lock); | 155 | spin_unlock(&watchdog_lock); |
148 | } | 156 | } |
@@ -164,7 +172,8 @@ static void clocksource_check_watchdog(struct clocksource *cs) | |||
164 | if (!started && watchdog) { | 172 | if (!started && watchdog) { |
165 | watchdog_last = watchdog->read(); | 173 | watchdog_last = watchdog->read(); |
166 | watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL; | 174 | watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL; |
167 | add_timer(&watchdog_timer); | 175 | add_timer_on(&watchdog_timer, |
176 | first_cpu(cpu_online_map)); | ||
168 | } | 177 | } |
169 | } else { | 178 | } else { |
170 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) | 179 | if (cs->flags & CLOCK_SOURCE_IS_CONTINUOUS) |
@@ -185,7 +194,8 @@ static void clocksource_check_watchdog(struct clocksource *cs) | |||
185 | watchdog_last = watchdog->read(); | 194 | watchdog_last = watchdog->read(); |
186 | watchdog_timer.expires = | 195 | watchdog_timer.expires = |
187 | jiffies + WATCHDOG_INTERVAL; | 196 | jiffies + WATCHDOG_INTERVAL; |
188 | add_timer(&watchdog_timer); | 197 | add_timer_on(&watchdog_timer, |
198 | first_cpu(cpu_online_map)); | ||
189 | } | 199 | } |
190 | } | 200 | } |
191 | } | 201 | } |
@@ -222,6 +232,18 @@ void clocksource_resume(void) | |||
222 | } | 232 | } |
223 | 233 | ||
224 | /** | 234 | /** |
235 | * clocksource_touch_watchdog - Update watchdog | ||
236 | * | ||
237 | * Update the watchdog after exception contexts such as kgdb so as not | ||
238 | * to incorrectly trip the watchdog. | ||
239 | * | ||
240 | */ | ||
241 | void clocksource_touch_watchdog(void) | ||
242 | { | ||
243 | clocksource_resume_watchdog(); | ||
244 | } | ||
245 | |||
246 | /** | ||
225 | * clocksource_get_next - Returns the selected clocksource | 247 | * clocksource_get_next - Returns the selected clocksource |
226 | * | 248 | * |
227 | */ | 249 | */ |
diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c index e1bd50cbbf5d..fdfa0c745bb6 100644 --- a/kernel/time/tick-broadcast.c +++ b/kernel/time/tick-broadcast.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #include <linux/cpu.h> | 14 | #include <linux/cpu.h> |
15 | #include <linux/err.h> | 15 | #include <linux/err.h> |
16 | #include <linux/hrtimer.h> | 16 | #include <linux/hrtimer.h> |
17 | #include <linux/irq.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/profile.h> | 19 | #include <linux/profile.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c index 1bea399a9ef0..4f3886562b8c 100644 --- a/kernel/time/tick-common.c +++ b/kernel/time/tick-common.c | |||
@@ -14,12 +14,14 @@ | |||
14 | #include <linux/cpu.h> | 14 | #include <linux/cpu.h> |
15 | #include <linux/err.h> | 15 | #include <linux/err.h> |
16 | #include <linux/hrtimer.h> | 16 | #include <linux/hrtimer.h> |
17 | #include <linux/irq.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/profile.h> | 19 | #include <linux/profile.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/tick.h> | 21 | #include <linux/tick.h> |
22 | 22 | ||
23 | #include <asm/irq_regs.h> | ||
24 | |||
23 | #include "tick-internal.h" | 25 | #include "tick-internal.h" |
24 | 26 | ||
25 | /* | 27 | /* |
diff --git a/kernel/time/tick-oneshot.c b/kernel/time/tick-oneshot.c index 0258d3115d54..450c04935b66 100644 --- a/kernel/time/tick-oneshot.c +++ b/kernel/time/tick-oneshot.c | |||
@@ -14,7 +14,7 @@ | |||
14 | #include <linux/cpu.h> | 14 | #include <linux/cpu.h> |
15 | #include <linux/err.h> | 15 | #include <linux/err.h> |
16 | #include <linux/hrtimer.h> | 16 | #include <linux/hrtimer.h> |
17 | #include <linux/irq.h> | 17 | #include <linux/interrupt.h> |
18 | #include <linux/percpu.h> | 18 | #include <linux/percpu.h> |
19 | #include <linux/profile.h> | 19 | #include <linux/profile.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 686da821d376..69dba0c71727 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c | |||
@@ -158,9 +158,8 @@ void tick_nohz_stop_idle(int cpu) | |||
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | static ktime_t tick_nohz_start_idle(int cpu) | 161 | static ktime_t tick_nohz_start_idle(struct tick_sched *ts) |
162 | { | 162 | { |
163 | struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); | ||
164 | ktime_t now, delta; | 163 | ktime_t now, delta; |
165 | 164 | ||
166 | now = ktime_get(); | 165 | now = ktime_get(); |
@@ -201,8 +200,8 @@ void tick_nohz_stop_sched_tick(void) | |||
201 | local_irq_save(flags); | 200 | local_irq_save(flags); |
202 | 201 | ||
203 | cpu = smp_processor_id(); | 202 | cpu = smp_processor_id(); |
204 | now = tick_nohz_start_idle(cpu); | ||
205 | ts = &per_cpu(tick_cpu_sched, cpu); | 203 | ts = &per_cpu(tick_cpu_sched, cpu); |
204 | now = tick_nohz_start_idle(ts); | ||
206 | 205 | ||
207 | /* | 206 | /* |
208 | * If this cpu is offline and it is the one which updates | 207 | * If this cpu is offline and it is the one which updates |
@@ -222,7 +221,6 @@ void tick_nohz_stop_sched_tick(void) | |||
222 | if (need_resched()) | 221 | if (need_resched()) |
223 | goto end; | 222 | goto end; |
224 | 223 | ||
225 | cpu = smp_processor_id(); | ||
226 | if (unlikely(local_softirq_pending())) { | 224 | if (unlikely(local_softirq_pending())) { |
227 | static int ratelimit; | 225 | static int ratelimit; |
228 | 226 | ||
diff --git a/kernel/timer.c b/kernel/timer.c index b024106daa70..f3d35d4ea42e 100644 --- a/kernel/timer.c +++ b/kernel/timer.c | |||
@@ -1228,13 +1228,6 @@ asmlinkage long sys_sysinfo(struct sysinfo __user *info) | |||
1228 | return 0; | 1228 | return 0; |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | /* | ||
1232 | * lockdep: we want to track each per-CPU base as a separate lock-class, | ||
1233 | * but timer-bases are kmalloc()-ed, so we need to attach separate | ||
1234 | * keys to them: | ||
1235 | */ | ||
1236 | static struct lock_class_key base_lock_keys[NR_CPUS]; | ||
1237 | |||
1238 | static int __cpuinit init_timers_cpu(int cpu) | 1231 | static int __cpuinit init_timers_cpu(int cpu) |
1239 | { | 1232 | { |
1240 | int j; | 1233 | int j; |
@@ -1277,7 +1270,6 @@ static int __cpuinit init_timers_cpu(int cpu) | |||
1277 | } | 1270 | } |
1278 | 1271 | ||
1279 | spin_lock_init(&base->lock); | 1272 | spin_lock_init(&base->lock); |
1280 | lockdep_set_class(&base->lock, base_lock_keys + cpu); | ||
1281 | 1273 | ||
1282 | for (j = 0; j < TVN_SIZE; j++) { | 1274 | for (j = 0; j < TVN_SIZE; j++) { |
1283 | INIT_LIST_HEAD(base->tv5.vec + j); | 1275 | INIT_LIST_HEAD(base->tv5.vec + j); |
@@ -1316,8 +1308,8 @@ static void __cpuinit migrate_timers(int cpu) | |||
1316 | new_base = get_cpu_var(tvec_bases); | 1308 | new_base = get_cpu_var(tvec_bases); |
1317 | 1309 | ||
1318 | local_irq_disable(); | 1310 | local_irq_disable(); |
1319 | double_spin_lock(&new_base->lock, &old_base->lock, | 1311 | spin_lock(&new_base->lock); |
1320 | smp_processor_id() < cpu); | 1312 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1321 | 1313 | ||
1322 | BUG_ON(old_base->running_timer); | 1314 | BUG_ON(old_base->running_timer); |
1323 | 1315 | ||
@@ -1330,8 +1322,8 @@ static void __cpuinit migrate_timers(int cpu) | |||
1330 | migrate_timer_list(new_base, old_base->tv5.vec + i); | 1322 | migrate_timer_list(new_base, old_base->tv5.vec + i); |
1331 | } | 1323 | } |
1332 | 1324 | ||
1333 | double_spin_unlock(&new_base->lock, &old_base->lock, | 1325 | spin_unlock(&old_base->lock); |
1334 | smp_processor_id() < cpu); | 1326 | spin_unlock(&new_base->lock); |
1335 | local_irq_enable(); | 1327 | local_irq_enable(); |
1336 | put_cpu_var(tvec_bases); | 1328 | put_cpu_var(tvec_bases); |
1337 | } | 1329 | } |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index ff06611655af..00ff4d08e370 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -219,6 +219,7 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, | |||
219 | struct timer_list *timer = &dwork->timer; | 219 | struct timer_list *timer = &dwork->timer; |
220 | struct work_struct *work = &dwork->work; | 220 | struct work_struct *work = &dwork->work; |
221 | 221 | ||
222 | timer_stats_timer_set_start_info(&dwork->timer); | ||
222 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { | 223 | if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { |
223 | BUG_ON(timer_pending(timer)); | 224 | BUG_ON(timer_pending(timer)); |
224 | BUG_ON(!list_empty(&work->entry)); | 225 | BUG_ON(!list_empty(&work->entry)); |
@@ -580,6 +581,7 @@ EXPORT_SYMBOL(schedule_delayed_work); | |||
580 | int schedule_delayed_work_on(int cpu, | 581 | int schedule_delayed_work_on(int cpu, |
581 | struct delayed_work *dwork, unsigned long delay) | 582 | struct delayed_work *dwork, unsigned long delay) |
582 | { | 583 | { |
584 | timer_stats_timer_set_start_info(&dwork->timer); | ||
583 | return queue_delayed_work_on(cpu, keventd_wq, dwork, delay); | 585 | return queue_delayed_work_on(cpu, keventd_wq, dwork, delay); |
584 | } | 586 | } |
585 | EXPORT_SYMBOL(schedule_delayed_work_on); | 587 | EXPORT_SYMBOL(schedule_delayed_work_on); |