diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-11 18:19:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-11 18:19:56 -0500 |
commit | 880188b2433c3af51fa006207d9b13c70d2e5938 (patch) | |
tree | 77376c0270e4e36f73a80856de798c6a89eeb96c | |
parent | 9764757932ce26f139332f89d1d3b815e4cc56ab (diff) | |
parent | 7f8b7ed6f825c729332b8190aca55c6bf95b158e (diff) |
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb:
kgdb: Always process the whole breakpoint list on activate or deactivate
kgdb: continue and warn on signal passing from gdb
kgdb,x86: do not set kgdb_single_step on x86
kgdb: allow for cpu switch when single stepping
kgdb,i386: Fix corner case access to ss with NMI watch dog exception
kgdb: Replace strstr() by strchr() for single-character needles
kgdbts: Read buffer overflow
kgdb: Read buffer overflow
kgdb,x86: remove redundant test
-rw-r--r-- | arch/x86/kernel/kgdb.c | 14 | ||||
-rw-r--r-- | drivers/misc/kgdbts.c | 14 | ||||
-rw-r--r-- | kernel/kgdb.c | 56 |
3 files changed, 59 insertions, 25 deletions
diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c index 20a5b3689463..dd74fe7273b1 100644 --- a/arch/x86/kernel/kgdb.c +++ b/arch/x86/kernel/kgdb.c | |||
@@ -86,9 +86,15 @@ void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) | |||
86 | gdb_regs[GDB_DS] = regs->ds; | 86 | gdb_regs[GDB_DS] = regs->ds; |
87 | gdb_regs[GDB_ES] = regs->es; | 87 | gdb_regs[GDB_ES] = regs->es; |
88 | gdb_regs[GDB_CS] = regs->cs; | 88 | gdb_regs[GDB_CS] = regs->cs; |
89 | gdb_regs[GDB_SS] = __KERNEL_DS; | ||
90 | gdb_regs[GDB_FS] = 0xFFFF; | 89 | gdb_regs[GDB_FS] = 0xFFFF; |
91 | gdb_regs[GDB_GS] = 0xFFFF; | 90 | gdb_regs[GDB_GS] = 0xFFFF; |
91 | if (user_mode_vm(regs)) { | ||
92 | gdb_regs[GDB_SS] = regs->ss; | ||
93 | gdb_regs[GDB_SP] = regs->sp; | ||
94 | } else { | ||
95 | gdb_regs[GDB_SS] = __KERNEL_DS; | ||
96 | gdb_regs[GDB_SP] = kernel_stack_pointer(regs); | ||
97 | } | ||
92 | #else | 98 | #else |
93 | gdb_regs[GDB_R8] = regs->r8; | 99 | gdb_regs[GDB_R8] = regs->r8; |
94 | gdb_regs[GDB_R9] = regs->r9; | 100 | gdb_regs[GDB_R9] = regs->r9; |
@@ -101,8 +107,8 @@ void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs) | |||
101 | gdb_regs32[GDB_PS] = regs->flags; | 107 | gdb_regs32[GDB_PS] = regs->flags; |
102 | gdb_regs32[GDB_CS] = regs->cs; | 108 | gdb_regs32[GDB_CS] = regs->cs; |
103 | gdb_regs32[GDB_SS] = regs->ss; | 109 | gdb_regs32[GDB_SS] = regs->ss; |
104 | #endif | ||
105 | gdb_regs[GDB_SP] = kernel_stack_pointer(regs); | 110 | gdb_regs[GDB_SP] = kernel_stack_pointer(regs); |
111 | #endif | ||
106 | } | 112 | } |
107 | 113 | ||
108 | /** | 114 | /** |
@@ -220,8 +226,7 @@ static void kgdb_correct_hw_break(void) | |||
220 | dr7 |= ((breakinfo[breakno].len << 2) | | 226 | dr7 |= ((breakinfo[breakno].len << 2) | |
221 | breakinfo[breakno].type) << | 227 | breakinfo[breakno].type) << |
222 | ((breakno << 2) + 16); | 228 | ((breakno << 2) + 16); |
223 | if (breakno >= 0 && breakno <= 3) | 229 | set_debugreg(breakinfo[breakno].addr, breakno); |
224 | set_debugreg(breakinfo[breakno].addr, breakno); | ||
225 | 230 | ||
226 | } else { | 231 | } else { |
227 | if ((dr7 & breakbit) && !breakinfo[breakno].enabled) { | 232 | if ((dr7 & breakbit) && !breakinfo[breakno].enabled) { |
@@ -395,7 +400,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code, | |||
395 | /* set the trace bit if we're stepping */ | 400 | /* set the trace bit if we're stepping */ |
396 | if (remcomInBuffer[0] == 's') { | 401 | if (remcomInBuffer[0] == 's') { |
397 | linux_regs->flags |= X86_EFLAGS_TF; | 402 | linux_regs->flags |= X86_EFLAGS_TF; |
398 | kgdb_single_step = 1; | ||
399 | atomic_set(&kgdb_cpu_doing_single_step, | 403 | atomic_set(&kgdb_cpu_doing_single_step, |
400 | raw_smp_processor_id()); | 404 | raw_smp_processor_id()); |
401 | } | 405 | } |
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c index e4ff50b95a5e..fcb6ec1af173 100644 --- a/drivers/misc/kgdbts.c +++ b/drivers/misc/kgdbts.c | |||
@@ -712,6 +712,12 @@ static int run_simple_test(int is_get_char, int chr) | |||
712 | 712 | ||
713 | /* End of packet == #XX so look for the '#' */ | 713 | /* End of packet == #XX so look for the '#' */ |
714 | if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') { | 714 | if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') { |
715 | if (put_buf_cnt >= BUFMAX) { | ||
716 | eprintk("kgdbts: ERROR: put buffer overflow on" | ||
717 | " '%s' line %i\n", ts.name, ts.idx); | ||
718 | put_buf_cnt = 0; | ||
719 | return 0; | ||
720 | } | ||
715 | put_buf[put_buf_cnt] = '\0'; | 721 | put_buf[put_buf_cnt] = '\0'; |
716 | v2printk("put%i: %s\n", ts.idx, put_buf); | 722 | v2printk("put%i: %s\n", ts.idx, put_buf); |
717 | /* Trigger check here */ | 723 | /* Trigger check here */ |
@@ -885,16 +891,16 @@ static void kgdbts_run_tests(void) | |||
885 | int nmi_sleep = 0; | 891 | int nmi_sleep = 0; |
886 | int i; | 892 | int i; |
887 | 893 | ||
888 | ptr = strstr(config, "F"); | 894 | ptr = strchr(config, 'F'); |
889 | if (ptr) | 895 | if (ptr) |
890 | fork_test = simple_strtol(ptr + 1, NULL, 10); | 896 | fork_test = simple_strtol(ptr + 1, NULL, 10); |
891 | ptr = strstr(config, "S"); | 897 | ptr = strchr(config, 'S'); |
892 | if (ptr) | 898 | if (ptr) |
893 | do_sys_open_test = simple_strtol(ptr + 1, NULL, 10); | 899 | do_sys_open_test = simple_strtol(ptr + 1, NULL, 10); |
894 | ptr = strstr(config, "N"); | 900 | ptr = strchr(config, 'N'); |
895 | if (ptr) | 901 | if (ptr) |
896 | nmi_sleep = simple_strtol(ptr+1, NULL, 10); | 902 | nmi_sleep = simple_strtol(ptr+1, NULL, 10); |
897 | ptr = strstr(config, "I"); | 903 | ptr = strchr(config, 'I'); |
898 | if (ptr) | 904 | if (ptr) |
899 | sstep_test = simple_strtol(ptr+1, NULL, 10); | 905 | sstep_test = simple_strtol(ptr+1, NULL, 10); |
900 | 906 | ||
diff --git a/kernel/kgdb.c b/kernel/kgdb.c index 7d7014634022..2eb517e23514 100644 --- a/kernel/kgdb.c +++ b/kernel/kgdb.c | |||
@@ -129,6 +129,7 @@ struct task_struct *kgdb_usethread; | |||
129 | struct task_struct *kgdb_contthread; | 129 | struct task_struct *kgdb_contthread; |
130 | 130 | ||
131 | int kgdb_single_step; | 131 | int kgdb_single_step; |
132 | pid_t kgdb_sstep_pid; | ||
132 | 133 | ||
133 | /* Our I/O buffers. */ | 134 | /* Our I/O buffers. */ |
134 | static char remcom_in_buffer[BUFMAX]; | 135 | static char remcom_in_buffer[BUFMAX]; |
@@ -541,12 +542,17 @@ static struct task_struct *getthread(struct pt_regs *regs, int tid) | |||
541 | */ | 542 | */ |
542 | if (tid == 0 || tid == -1) | 543 | if (tid == 0 || tid == -1) |
543 | tid = -atomic_read(&kgdb_active) - 2; | 544 | tid = -atomic_read(&kgdb_active) - 2; |
544 | if (tid < 0) { | 545 | if (tid < -1 && tid > -NR_CPUS - 2) { |
545 | if (kgdb_info[-tid - 2].task) | 546 | if (kgdb_info[-tid - 2].task) |
546 | return kgdb_info[-tid - 2].task; | 547 | return kgdb_info[-tid - 2].task; |
547 | else | 548 | else |
548 | return idle_task(-tid - 2); | 549 | return idle_task(-tid - 2); |
549 | } | 550 | } |
551 | if (tid <= 0) { | ||
552 | printk(KERN_ERR "KGDB: Internal thread select error\n"); | ||
553 | dump_stack(); | ||
554 | return NULL; | ||
555 | } | ||
550 | 556 | ||
551 | /* | 557 | /* |
552 | * find_task_by_pid_ns() does not take the tasklist lock anymore | 558 | * find_task_by_pid_ns() does not take the tasklist lock anymore |
@@ -619,7 +625,8 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) | |||
619 | static int kgdb_activate_sw_breakpoints(void) | 625 | static int kgdb_activate_sw_breakpoints(void) |
620 | { | 626 | { |
621 | unsigned long addr; | 627 | unsigned long addr; |
622 | int error = 0; | 628 | int error; |
629 | int ret = 0; | ||
623 | int i; | 630 | int i; |
624 | 631 | ||
625 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | 632 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { |
@@ -629,13 +636,16 @@ static int kgdb_activate_sw_breakpoints(void) | |||
629 | addr = kgdb_break[i].bpt_addr; | 636 | addr = kgdb_break[i].bpt_addr; |
630 | error = kgdb_arch_set_breakpoint(addr, | 637 | error = kgdb_arch_set_breakpoint(addr, |
631 | kgdb_break[i].saved_instr); | 638 | kgdb_break[i].saved_instr); |
632 | if (error) | 639 | if (error) { |
633 | return error; | 640 | ret = error; |
641 | printk(KERN_INFO "KGDB: BP install failed: %lx", addr); | ||
642 | continue; | ||
643 | } | ||
634 | 644 | ||
635 | kgdb_flush_swbreak_addr(addr); | 645 | kgdb_flush_swbreak_addr(addr); |
636 | kgdb_break[i].state = BP_ACTIVE; | 646 | kgdb_break[i].state = BP_ACTIVE; |
637 | } | 647 | } |
638 | return 0; | 648 | return ret; |
639 | } | 649 | } |
640 | 650 | ||
641 | static int kgdb_set_sw_break(unsigned long addr) | 651 | static int kgdb_set_sw_break(unsigned long addr) |
@@ -682,7 +692,8 @@ static int kgdb_set_sw_break(unsigned long addr) | |||
682 | static int kgdb_deactivate_sw_breakpoints(void) | 692 | static int kgdb_deactivate_sw_breakpoints(void) |
683 | { | 693 | { |
684 | unsigned long addr; | 694 | unsigned long addr; |
685 | int error = 0; | 695 | int error; |
696 | int ret = 0; | ||
686 | int i; | 697 | int i; |
687 | 698 | ||
688 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { | 699 | for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) { |
@@ -691,13 +702,15 @@ static int kgdb_deactivate_sw_breakpoints(void) | |||
691 | addr = kgdb_break[i].bpt_addr; | 702 | addr = kgdb_break[i].bpt_addr; |
692 | error = kgdb_arch_remove_breakpoint(addr, | 703 | error = kgdb_arch_remove_breakpoint(addr, |
693 | kgdb_break[i].saved_instr); | 704 | kgdb_break[i].saved_instr); |
694 | if (error) | 705 | if (error) { |
695 | return error; | 706 | printk(KERN_INFO "KGDB: BP remove failed: %lx\n", addr); |
707 | ret = error; | ||
708 | } | ||
696 | 709 | ||
697 | kgdb_flush_swbreak_addr(addr); | 710 | kgdb_flush_swbreak_addr(addr); |
698 | kgdb_break[i].state = BP_SET; | 711 | kgdb_break[i].state = BP_SET; |
699 | } | 712 | } |
700 | return 0; | 713 | return ret; |
701 | } | 714 | } |
702 | 715 | ||
703 | static int kgdb_remove_sw_break(unsigned long addr) | 716 | static int kgdb_remove_sw_break(unsigned long addr) |
@@ -1204,8 +1217,10 @@ static int gdb_cmd_exception_pass(struct kgdb_state *ks) | |||
1204 | return 1; | 1217 | return 1; |
1205 | 1218 | ||
1206 | } else { | 1219 | } else { |
1207 | error_packet(remcom_out_buffer, -EINVAL); | 1220 | kgdb_msg_write("KGDB only knows signal 9 (pass)" |
1208 | return 0; | 1221 | " and 15 (pass and disconnect)\n" |
1222 | "Executing a continue without signal passing\n", 0); | ||
1223 | remcom_in_buffer[0] = 'c'; | ||
1209 | } | 1224 | } |
1210 | 1225 | ||
1211 | /* Indicate fall through */ | 1226 | /* Indicate fall through */ |
@@ -1395,6 +1410,7 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) | |||
1395 | struct kgdb_state kgdb_var; | 1410 | struct kgdb_state kgdb_var; |
1396 | struct kgdb_state *ks = &kgdb_var; | 1411 | struct kgdb_state *ks = &kgdb_var; |
1397 | unsigned long flags; | 1412 | unsigned long flags; |
1413 | int sstep_tries = 100; | ||
1398 | int error = 0; | 1414 | int error = 0; |
1399 | int i, cpu; | 1415 | int i, cpu; |
1400 | 1416 | ||
@@ -1425,13 +1441,14 @@ acquirelock: | |||
1425 | cpu_relax(); | 1441 | cpu_relax(); |
1426 | 1442 | ||
1427 | /* | 1443 | /* |
1428 | * Do not start the debugger connection on this CPU if the last | 1444 | * For single stepping, try to only enter on the processor |
1429 | * instance of the exception handler wanted to come into the | 1445 | * that was single stepping. To gaurd against a deadlock, the |
1430 | * debugger on a different CPU via a single step | 1446 | * kernel will only try for the value of sstep_tries before |
1447 | * giving up and continuing on. | ||
1431 | */ | 1448 | */ |
1432 | if (atomic_read(&kgdb_cpu_doing_single_step) != -1 && | 1449 | if (atomic_read(&kgdb_cpu_doing_single_step) != -1 && |
1433 | atomic_read(&kgdb_cpu_doing_single_step) != cpu) { | 1450 | (kgdb_info[cpu].task && |
1434 | 1451 | kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) { | |
1435 | atomic_set(&kgdb_active, -1); | 1452 | atomic_set(&kgdb_active, -1); |
1436 | touch_softlockup_watchdog(); | 1453 | touch_softlockup_watchdog(); |
1437 | clocksource_touch_watchdog(); | 1454 | clocksource_touch_watchdog(); |
@@ -1524,6 +1541,13 @@ acquirelock: | |||
1524 | } | 1541 | } |
1525 | 1542 | ||
1526 | kgdb_restore: | 1543 | kgdb_restore: |
1544 | if (atomic_read(&kgdb_cpu_doing_single_step) != -1) { | ||
1545 | int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step); | ||
1546 | if (kgdb_info[sstep_cpu].task) | ||
1547 | kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid; | ||
1548 | else | ||
1549 | kgdb_sstep_pid = 0; | ||
1550 | } | ||
1527 | /* Free kgdb_active */ | 1551 | /* Free kgdb_active */ |
1528 | atomic_set(&kgdb_active, -1); | 1552 | atomic_set(&kgdb_active, -1); |
1529 | touch_softlockup_watchdog(); | 1553 | touch_softlockup_watchdog(); |