aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arc/kernel/kgdb.c12
-rw-r--r--arch/arm/kernel/kgdb.c14
-rw-r--r--arch/arm64/kernel/kgdb.c14
-rw-r--r--arch/h8300/kernel/kgdb.c2
-rw-r--r--arch/hexagon/kernel/kgdb.c34
-rw-r--r--arch/microblaze/kernel/kgdb.c2
-rw-r--r--arch/mips/kernel/kgdb.c25
-rw-r--r--arch/nios2/kernel/kgdb.c2
-rw-r--r--arch/powerpc/kernel/kgdb.c8
-rw-r--r--arch/sh/kernel/kgdb.c14
-rw-r--r--arch/sparc/kernel/kgdb_32.c2
-rw-r--r--arch/sparc/kernel/kgdb_64.c2
-rw-r--r--arch/sparc/kernel/smp_64.c2
-rw-r--r--arch/x86/kernel/kgdb.c11
-rw-r--r--include/linux/kgdb.h24
-rw-r--r--kernel/debug/debug_core.c65
-rw-r--r--kernel/debug/debug_core.h1
-rw-r--r--kernel/debug/kdb/kdb_bt.c11
-rw-r--r--kernel/debug/kdb/kdb_debugger.c7
-rw-r--r--kernel/debug/kdb/kdb_main.c14
20 files changed, 125 insertions, 141 deletions
diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
index 9a3c34af2ae8..96bca9963c63 100644
--- a/arch/arc/kernel/kgdb.c
+++ b/arch/arc/kernel/kgdb.c
@@ -192,19 +192,13 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
192 instruction_pointer(regs) = ip; 192 instruction_pointer(regs) = ip;
193} 193}
194 194
195static void kgdb_call_nmi_hook(void *ignored) 195void kgdb_call_nmi_hook(void *ignored)
196{ 196{
197 /* Default implementation passes get_irq_regs() but we don't */
197 kgdb_nmicallback(raw_smp_processor_id(), NULL); 198 kgdb_nmicallback(raw_smp_processor_id(), NULL);
198} 199}
199 200
200void kgdb_roundup_cpus(unsigned long flags) 201const struct kgdb_arch arch_kgdb_ops = {
201{
202 local_irq_enable();
203 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
204 local_irq_disable();
205}
206
207struct kgdb_arch arch_kgdb_ops = {
208 /* breakpoint instruction: TRAP_S 0x3 */ 202 /* breakpoint instruction: TRAP_S 0x3 */
209#ifdef CONFIG_CPU_BIG_ENDIAN 203#ifdef CONFIG_CPU_BIG_ENDIAN
210 .gdb_bpt_instr = {0x78, 0x7e}, 204 .gdb_bpt_instr = {0x78, 0x7e},
diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c
index caa0dbe3dc61..6a95b9296640 100644
--- a/arch/arm/kernel/kgdb.c
+++ b/arch/arm/kernel/kgdb.c
@@ -170,18 +170,6 @@ static struct undef_hook kgdb_compiled_brkpt_hook = {
170 .fn = kgdb_compiled_brk_fn 170 .fn = kgdb_compiled_brk_fn
171}; 171};
172 172
173static void kgdb_call_nmi_hook(void *ignored)
174{
175 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
176}
177
178void kgdb_roundup_cpus(unsigned long flags)
179{
180 local_irq_enable();
181 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
182 local_irq_disable();
183}
184
185static int __kgdb_notify(struct die_args *args, unsigned long cmd) 173static int __kgdb_notify(struct die_args *args, unsigned long cmd)
186{ 174{
187 struct pt_regs *regs = args->regs; 175 struct pt_regs *regs = args->regs;
@@ -274,7 +262,7 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
274 * and we handle the normal undef case within the do_undefinstr 262 * and we handle the normal undef case within the do_undefinstr
275 * handler. 263 * handler.
276 */ 264 */
277struct kgdb_arch arch_kgdb_ops = { 265const struct kgdb_arch arch_kgdb_ops = {
278#ifndef __ARMEB__ 266#ifndef __ARMEB__
279 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7} 267 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
280#else /* ! __ARMEB__ */ 268#else /* ! __ARMEB__ */
diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c
index a20de58061a8..ce46c4cdf368 100644
--- a/arch/arm64/kernel/kgdb.c
+++ b/arch/arm64/kernel/kgdb.c
@@ -284,18 +284,6 @@ static struct step_hook kgdb_step_hook = {
284 .fn = kgdb_step_brk_fn 284 .fn = kgdb_step_brk_fn
285}; 285};
286 286
287static void kgdb_call_nmi_hook(void *ignored)
288{
289 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
290}
291
292void kgdb_roundup_cpus(unsigned long flags)
293{
294 local_irq_enable();
295 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
296 local_irq_disable();
297}
298
299static int __kgdb_notify(struct die_args *args, unsigned long cmd) 287static int __kgdb_notify(struct die_args *args, unsigned long cmd)
300{ 288{
301 struct pt_regs *regs = args->regs; 289 struct pt_regs *regs = args->regs;
@@ -357,7 +345,7 @@ void kgdb_arch_exit(void)
357 unregister_die_notifier(&kgdb_notifier); 345 unregister_die_notifier(&kgdb_notifier);
358} 346}
359 347
360struct kgdb_arch arch_kgdb_ops; 348const struct kgdb_arch arch_kgdb_ops;
361 349
362int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) 350int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
363{ 351{
diff --git a/arch/h8300/kernel/kgdb.c b/arch/h8300/kernel/kgdb.c
index 1a1d30cb0609..602e478afbd5 100644
--- a/arch/h8300/kernel/kgdb.c
+++ b/arch/h8300/kernel/kgdb.c
@@ -129,7 +129,7 @@ void kgdb_arch_exit(void)
129 /* Nothing to do */ 129 /* Nothing to do */
130} 130}
131 131
132struct kgdb_arch arch_kgdb_ops = { 132const struct kgdb_arch arch_kgdb_ops = {
133 /* Breakpoint instruction: trapa #2 */ 133 /* Breakpoint instruction: trapa #2 */
134 .gdb_bpt_instr = { 0x57, 0x20 }, 134 .gdb_bpt_instr = { 0x57, 0x20 },
135}; 135};
diff --git a/arch/hexagon/kernel/kgdb.c b/arch/hexagon/kernel/kgdb.c
index 16c24b22d0b2..3fabd3ff3bbd 100644
--- a/arch/hexagon/kernel/kgdb.c
+++ b/arch/hexagon/kernel/kgdb.c
@@ -83,7 +83,7 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
83 { "syscall_nr", GDB_SIZEOF_REG, offsetof(struct pt_regs, syscall_nr)}, 83 { "syscall_nr", GDB_SIZEOF_REG, offsetof(struct pt_regs, syscall_nr)},
84}; 84};
85 85
86struct kgdb_arch arch_kgdb_ops = { 86const struct kgdb_arch arch_kgdb_ops = {
87 /* trap0(#0xDB) 0x0cdb0054 */ 87 /* trap0(#0xDB) 0x0cdb0054 */
88 .gdb_bpt_instr = {0x54, 0x00, 0xdb, 0x0c}, 88 .gdb_bpt_instr = {0x54, 0x00, 0xdb, 0x0c},
89}; 89};
@@ -115,38 +115,6 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
115 instruction_pointer(regs) = pc; 115 instruction_pointer(regs) = pc;
116} 116}
117 117
118#ifdef CONFIG_SMP
119
120/**
121 * kgdb_roundup_cpus - Get other CPUs into a holding pattern
122 * @flags: Current IRQ state
123 *
124 * On SMP systems, we need to get the attention of the other CPUs
125 * and get them be in a known state. This should do what is needed
126 * to get the other CPUs to call kgdb_wait(). Note that on some arches,
127 * the NMI approach is not used for rounding up all the CPUs. For example,
128 * in case of MIPS, smp_call_function() is used to roundup CPUs. In
129 * this case, we have to make sure that interrupts are enabled before
130 * calling smp_call_function(). The argument to this function is
131 * the flags that will be used when restoring the interrupts. There is
132 * local_irq_save() call before kgdb_roundup_cpus().
133 *
134 * On non-SMP systems, this is not called.
135 */
136
137static void hexagon_kgdb_nmi_hook(void *ignored)
138{
139 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
140}
141
142void kgdb_roundup_cpus(unsigned long flags)
143{
144 local_irq_enable();
145 smp_call_function(hexagon_kgdb_nmi_hook, NULL, 0);
146 local_irq_disable();
147}
148#endif
149
150 118
151/* Not yet working */ 119/* Not yet working */
152void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, 120void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs,
diff --git a/arch/microblaze/kernel/kgdb.c b/arch/microblaze/kernel/kgdb.c
index 6366f69d118e..130cd0f064ce 100644
--- a/arch/microblaze/kernel/kgdb.c
+++ b/arch/microblaze/kernel/kgdb.c
@@ -143,7 +143,7 @@ void kgdb_arch_exit(void)
143/* 143/*
144 * Global data 144 * Global data
145 */ 145 */
146struct kgdb_arch arch_kgdb_ops = { 146const struct kgdb_arch arch_kgdb_ops = {
147#ifdef __MICROBLAZEEL__ 147#ifdef __MICROBLAZEEL__
148 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */ 148 .gdb_bpt_instr = {0x18, 0x00, 0x0c, 0xba}, /* brki r16, 0x18 */
149#else 149#else
diff --git a/arch/mips/kernel/kgdb.c b/arch/mips/kernel/kgdb.c
index eb6c0d582626..149100e1bc7c 100644
--- a/arch/mips/kernel/kgdb.c
+++ b/arch/mips/kernel/kgdb.c
@@ -207,7 +207,7 @@ void arch_kgdb_breakpoint(void)
207 ".set\treorder"); 207 ".set\treorder");
208} 208}
209 209
210static void kgdb_call_nmi_hook(void *ignored) 210void kgdb_call_nmi_hook(void *ignored)
211{ 211{
212 mm_segment_t old_fs; 212 mm_segment_t old_fs;
213 213
@@ -219,13 +219,6 @@ static void kgdb_call_nmi_hook(void *ignored)
219 set_fs(old_fs); 219 set_fs(old_fs);
220} 220}
221 221
222void kgdb_roundup_cpus(unsigned long flags)
223{
224 local_irq_enable();
225 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
226 local_irq_disable();
227}
228
229static int compute_signal(int tt) 222static int compute_signal(int tt)
230{ 223{
231 struct hard_trap_info *ht; 224 struct hard_trap_info *ht;
@@ -394,18 +387,16 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
394 return -1; 387 return -1;
395} 388}
396 389
397struct kgdb_arch arch_kgdb_ops; 390const struct kgdb_arch arch_kgdb_ops = {
391#ifdef CONFIG_CPU_BIG_ENDIAN
392 .gdb_bpt_instr = { spec_op << 2, 0x00, 0x00, break_op },
393#else
394 .gdb_bpt_instr = { break_op, 0x00, 0x00, spec_op << 2 },
395#endif
396};
398 397
399int kgdb_arch_init(void) 398int kgdb_arch_init(void)
400{ 399{
401 union mips_instruction insn = {
402 .r_format = {
403 .opcode = spec_op,
404 .func = break_op,
405 }
406 };
407 memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);
408
409 register_die_notifier(&kgdb_notifier); 400 register_die_notifier(&kgdb_notifier);
410 401
411 return 0; 402 return 0;
diff --git a/arch/nios2/kernel/kgdb.c b/arch/nios2/kernel/kgdb.c
index 117859122d1c..37b25f844a2d 100644
--- a/arch/nios2/kernel/kgdb.c
+++ b/arch/nios2/kernel/kgdb.c
@@ -165,7 +165,7 @@ void kgdb_arch_exit(void)
165 /* Nothing to do */ 165 /* Nothing to do */
166} 166}
167 167
168struct kgdb_arch arch_kgdb_ops = { 168const struct kgdb_arch arch_kgdb_ops = {
169 /* Breakpoint instruction: trap 30 */ 169 /* Breakpoint instruction: trap 30 */
170 .gdb_bpt_instr = { 0xba, 0x6f, 0x3b, 0x00 }, 170 .gdb_bpt_instr = { 0xba, 0x6f, 0x3b, 0x00 },
171}; 171};
diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index 59c578f865aa..e1865565f0ae 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -117,14 +117,14 @@ int kgdb_skipexception(int exception, struct pt_regs *regs)
117 return kgdb_isremovedbreak(regs->nip); 117 return kgdb_isremovedbreak(regs->nip);
118} 118}
119 119
120static int kgdb_call_nmi_hook(struct pt_regs *regs) 120static int kgdb_debugger_ipi(struct pt_regs *regs)
121{ 121{
122 kgdb_nmicallback(raw_smp_processor_id(), regs); 122 kgdb_nmicallback(raw_smp_processor_id(), regs);
123 return 0; 123 return 0;
124} 124}
125 125
126#ifdef CONFIG_SMP 126#ifdef CONFIG_SMP
127void kgdb_roundup_cpus(unsigned long flags) 127void kgdb_roundup_cpus(void)
128{ 128{
129 smp_send_debugger_break(); 129 smp_send_debugger_break();
130} 130}
@@ -477,7 +477,7 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
477/* 477/*
478 * Global data 478 * Global data
479 */ 479 */
480struct kgdb_arch arch_kgdb_ops; 480const struct kgdb_arch arch_kgdb_ops;
481 481
482static int kgdb_not_implemented(struct pt_regs *regs) 482static int kgdb_not_implemented(struct pt_regs *regs)
483{ 483{
@@ -502,7 +502,7 @@ int kgdb_arch_init(void)
502 old__debugger_break_match = __debugger_break_match; 502 old__debugger_break_match = __debugger_break_match;
503 old__debugger_fault_handler = __debugger_fault_handler; 503 old__debugger_fault_handler = __debugger_fault_handler;
504 504
505 __debugger_ipi = kgdb_call_nmi_hook; 505 __debugger_ipi = kgdb_debugger_ipi;
506 __debugger = kgdb_debugger; 506 __debugger = kgdb_debugger;
507 __debugger_bpt = kgdb_handle_breakpoint; 507 __debugger_bpt = kgdb_handle_breakpoint;
508 __debugger_sstep = kgdb_singlestep; 508 __debugger_sstep = kgdb_singlestep;
diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
index d24bd2d2ffad..6d61f8cf4c13 100644
--- a/arch/sh/kernel/kgdb.c
+++ b/arch/sh/kernel/kgdb.c
@@ -311,18 +311,6 @@ BUILD_TRAP_HANDLER(singlestep)
311 local_irq_restore(flags); 311 local_irq_restore(flags);
312} 312}
313 313
314static void kgdb_call_nmi_hook(void *ignored)
315{
316 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
317}
318
319void kgdb_roundup_cpus(unsigned long flags)
320{
321 local_irq_enable();
322 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
323 local_irq_disable();
324}
325
326static int __kgdb_notify(struct die_args *args, unsigned long cmd) 314static int __kgdb_notify(struct die_args *args, unsigned long cmd)
327{ 315{
328 int ret; 316 int ret;
@@ -379,7 +367,7 @@ void kgdb_arch_exit(void)
379 unregister_die_notifier(&kgdb_notifier); 367 unregister_die_notifier(&kgdb_notifier);
380} 368}
381 369
382struct kgdb_arch arch_kgdb_ops = { 370const struct kgdb_arch arch_kgdb_ops = {
383 /* Breakpoint instruction: trapa #0x3c */ 371 /* Breakpoint instruction: trapa #0x3c */
384#ifdef CONFIG_CPU_LITTLE_ENDIAN 372#ifdef CONFIG_CPU_LITTLE_ENDIAN
385 .gdb_bpt_instr = { 0x3c, 0xc3 }, 373 .gdb_bpt_instr = { 0x3c, 0xc3 },
diff --git a/arch/sparc/kernel/kgdb_32.c b/arch/sparc/kernel/kgdb_32.c
index 639c8e54530a..7580775a14b9 100644
--- a/arch/sparc/kernel/kgdb_32.c
+++ b/arch/sparc/kernel/kgdb_32.c
@@ -166,7 +166,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
166 regs->npc = regs->pc + 4; 166 regs->npc = regs->pc + 4;
167} 167}
168 168
169struct kgdb_arch arch_kgdb_ops = { 169const struct kgdb_arch arch_kgdb_ops = {
170 /* Breakpoint instruction: ta 0x7d */ 170 /* Breakpoint instruction: ta 0x7d */
171 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d }, 171 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
172}; 172};
diff --git a/arch/sparc/kernel/kgdb_64.c b/arch/sparc/kernel/kgdb_64.c
index a68bbddbdba4..5d6c2d287e85 100644
--- a/arch/sparc/kernel/kgdb_64.c
+++ b/arch/sparc/kernel/kgdb_64.c
@@ -195,7 +195,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
195 regs->tnpc = regs->tpc + 4; 195 regs->tnpc = regs->tpc + 4;
196} 196}
197 197
198struct kgdb_arch arch_kgdb_ops = { 198const struct kgdb_arch arch_kgdb_ops = {
199 /* Breakpoint instruction: ta 0x72 */ 199 /* Breakpoint instruction: ta 0x72 */
200 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 }, 200 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
201}; 201};
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index 4792e08ad36b..f45d876983f1 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -1014,7 +1014,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
1014} 1014}
1015 1015
1016#ifdef CONFIG_KGDB 1016#ifdef CONFIG_KGDB
1017void kgdb_roundup_cpus(unsigned long flags) 1017void kgdb_roundup_cpus(void)
1018{ 1018{
1019 smp_cross_call(&xcall_kgdb_capture, 0, 0, 0); 1019 smp_cross_call(&xcall_kgdb_capture, 0, 0, 0);
1020} 1020}
diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
index 8e36f249646e..5db08425063e 100644
--- a/arch/x86/kernel/kgdb.c
+++ b/arch/x86/kernel/kgdb.c
@@ -422,21 +422,16 @@ static void kgdb_disable_hw_debug(struct pt_regs *regs)
422#ifdef CONFIG_SMP 422#ifdef CONFIG_SMP
423/** 423/**
424 * kgdb_roundup_cpus - Get other CPUs into a holding pattern 424 * kgdb_roundup_cpus - Get other CPUs into a holding pattern
425 * @flags: Current IRQ state
426 * 425 *
427 * On SMP systems, we need to get the attention of the other CPUs 426 * On SMP systems, we need to get the attention of the other CPUs
428 * and get them be in a known state. This should do what is needed 427 * and get them be in a known state. This should do what is needed
429 * to get the other CPUs to call kgdb_wait(). Note that on some arches, 428 * to get the other CPUs to call kgdb_wait(). Note that on some arches,
430 * the NMI approach is not used for rounding up all the CPUs. For example, 429 * the NMI approach is not used for rounding up all the CPUs. For example,
431 * in case of MIPS, smp_call_function() is used to roundup CPUs. In 430 * in case of MIPS, smp_call_function() is used to roundup CPUs.
432 * this case, we have to make sure that interrupts are enabled before
433 * calling smp_call_function(). The argument to this function is
434 * the flags that will be used when restoring the interrupts. There is
435 * local_irq_save() call before kgdb_roundup_cpus().
436 * 431 *
437 * On non-SMP systems, this is not called. 432 * On non-SMP systems, this is not called.
438 */ 433 */
439void kgdb_roundup_cpus(unsigned long flags) 434void kgdb_roundup_cpus(void)
440{ 435{
441 apic->send_IPI_allbutself(APIC_DM_NMI); 436 apic->send_IPI_allbutself(APIC_DM_NMI);
442} 437}
@@ -804,7 +799,7 @@ knl_write:
804 (char *)bpt->saved_instr, BREAK_INSTR_SIZE); 799 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
805} 800}
806 801
807struct kgdb_arch arch_kgdb_ops = { 802const struct kgdb_arch arch_kgdb_ops = {
808 /* Breakpoint instruction: */ 803 /* Breakpoint instruction: */
809 .gdb_bpt_instr = { 0xcc }, 804 .gdb_bpt_instr = { 0xcc },
810 .flags = KGDB_HW_BREAKPOINT, 805 .flags = KGDB_HW_BREAKPOINT,
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index e465bb15912d..fbf144aaa749 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -177,22 +177,28 @@ kgdb_arch_handle_exception(int vector, int signo, int err_code,
177 struct pt_regs *regs); 177 struct pt_regs *regs);
178 178
179/** 179/**
180 * kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU
181 * @ignored: This parameter is only here to match the prototype.
182 *
183 * If you're using the default implementation of kgdb_roundup_cpus()
184 * this function will be called per CPU. If you don't implement
185 * kgdb_call_nmi_hook() a default will be used.
186 */
187
188extern void kgdb_call_nmi_hook(void *ignored);
189
190/**
180 * kgdb_roundup_cpus - Get other CPUs into a holding pattern 191 * kgdb_roundup_cpus - Get other CPUs into a holding pattern
181 * @flags: Current IRQ state
182 * 192 *
183 * On SMP systems, we need to get the attention of the other CPUs 193 * On SMP systems, we need to get the attention of the other CPUs
184 * and get them into a known state. This should do what is needed 194 * and get them into a known state. This should do what is needed
185 * to get the other CPUs to call kgdb_wait(). Note that on some arches, 195 * to get the other CPUs to call kgdb_wait(). Note that on some arches,
186 * the NMI approach is not used for rounding up all the CPUs. For example, 196 * the NMI approach is not used for rounding up all the CPUs. Normally
187 * in case of MIPS, smp_call_function() is used to roundup CPUs. In 197 * those architectures can just not implement this and get the default.
188 * this case, we have to make sure that interrupts are enabled before
189 * calling smp_call_function(). The argument to this function is
190 * the flags that will be used when restoring the interrupts. There is
191 * local_irq_save() call before kgdb_roundup_cpus().
192 * 198 *
193 * On non-SMP systems, this is not called. 199 * On non-SMP systems, this is not called.
194 */ 200 */
195extern void kgdb_roundup_cpus(unsigned long flags); 201extern void kgdb_roundup_cpus(void);
196 202
197/** 203/**
198 * kgdb_arch_set_pc - Generic call back to the program counter 204 * kgdb_arch_set_pc - Generic call back to the program counter
@@ -281,7 +287,7 @@ struct kgdb_io {
281 int is_console; 287 int is_console;
282}; 288};
283 289
284extern struct kgdb_arch arch_kgdb_ops; 290extern const struct kgdb_arch arch_kgdb_ops;
285 291
286extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs); 292extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
287 293
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 65c0f1363788..5cc608de6883 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -55,6 +55,7 @@
55#include <linux/mm.h> 55#include <linux/mm.h>
56#include <linux/vmacache.h> 56#include <linux/vmacache.h>
57#include <linux/rcupdate.h> 57#include <linux/rcupdate.h>
58#include <linux/irq.h>
58 59
59#include <asm/cacheflush.h> 60#include <asm/cacheflush.h>
60#include <asm/byteorder.h> 61#include <asm/byteorder.h>
@@ -220,6 +221,62 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs)
220 return 0; 221 return 0;
221} 222}
222 223
224#ifdef CONFIG_SMP
225
226/*
227 * Default (weak) implementation for kgdb_roundup_cpus
228 */
229
230static DEFINE_PER_CPU(call_single_data_t, kgdb_roundup_csd);
231
232void __weak kgdb_call_nmi_hook(void *ignored)
233{
234 /*
235 * NOTE: get_irq_regs() is supposed to get the registers from
236 * before the IPI interrupt happened and so is supposed to
237 * show where the processor was. In some situations it's
238 * possible we might be called without an IPI, so it might be
239 * safer to figure out how to make kgdb_breakpoint() work
240 * properly here.
241 */
242 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
243}
244
245void __weak kgdb_roundup_cpus(void)
246{
247 call_single_data_t *csd;
248 int this_cpu = raw_smp_processor_id();
249 int cpu;
250 int ret;
251
252 for_each_online_cpu(cpu) {
253 /* No need to roundup ourselves */
254 if (cpu == this_cpu)
255 continue;
256
257 csd = &per_cpu(kgdb_roundup_csd, cpu);
258
259 /*
260 * If it didn't round up last time, don't try again
261 * since smp_call_function_single_async() will block.
262 *
263 * If rounding_up is false then we know that the
264 * previous call must have at least started and that
265 * means smp_call_function_single_async() won't block.
266 */
267 if (kgdb_info[cpu].rounding_up)
268 continue;
269 kgdb_info[cpu].rounding_up = true;
270
271 csd->func = kgdb_call_nmi_hook;
272 ret = smp_call_function_single_async(cpu, csd);
273 if (ret)
274 kgdb_info[cpu].rounding_up = false;
275 }
276}
277
278#endif
279
223/* 280/*
224 * Some architectures need cache flushes when we set/clear a 281 * Some architectures need cache flushes when we set/clear a
225 * breakpoint: 282 * breakpoint:
@@ -535,6 +592,8 @@ return_normal:
535 arch_kgdb_ops.correct_hw_break(); 592 arch_kgdb_ops.correct_hw_break();
536 if (trace_on) 593 if (trace_on)
537 tracing_on(); 594 tracing_on();
595 kgdb_info[cpu].debuggerinfo = NULL;
596 kgdb_info[cpu].task = NULL;
538 kgdb_info[cpu].exception_state &= 597 kgdb_info[cpu].exception_state &=
539 ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE); 598 ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
540 kgdb_info[cpu].enter_kgdb--; 599 kgdb_info[cpu].enter_kgdb--;
@@ -593,7 +652,7 @@ return_normal:
593 652
594 /* Signal the other CPUs to enter kgdb_wait() */ 653 /* Signal the other CPUs to enter kgdb_wait() */
595 else if ((!kgdb_single_step) && kgdb_do_roundup) 654 else if ((!kgdb_single_step) && kgdb_do_roundup)
596 kgdb_roundup_cpus(flags); 655 kgdb_roundup_cpus();
597#endif 656#endif
598 657
599 /* 658 /*
@@ -667,6 +726,8 @@ kgdb_restore:
667 if (trace_on) 726 if (trace_on)
668 tracing_on(); 727 tracing_on();
669 728
729 kgdb_info[cpu].debuggerinfo = NULL;
730 kgdb_info[cpu].task = NULL;
670 kgdb_info[cpu].exception_state &= 731 kgdb_info[cpu].exception_state &=
671 ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE); 732 ~(DCPU_WANT_MASTER | DCPU_IS_SLAVE);
672 kgdb_info[cpu].enter_kgdb--; 733 kgdb_info[cpu].enter_kgdb--;
@@ -747,6 +808,8 @@ int kgdb_nmicallback(int cpu, void *regs)
747 struct kgdb_state kgdb_var; 808 struct kgdb_state kgdb_var;
748 struct kgdb_state *ks = &kgdb_var; 809 struct kgdb_state *ks = &kgdb_var;
749 810
811 kgdb_info[cpu].rounding_up = false;
812
750 memset(ks, 0, sizeof(struct kgdb_state)); 813 memset(ks, 0, sizeof(struct kgdb_state));
751 ks->cpu = cpu; 814 ks->cpu = cpu;
752 ks->linux_regs = regs; 815 ks->linux_regs = regs;
diff --git a/kernel/debug/debug_core.h b/kernel/debug/debug_core.h
index 127d9bc49fb4..b4a7c326d546 100644
--- a/kernel/debug/debug_core.h
+++ b/kernel/debug/debug_core.h
@@ -42,6 +42,7 @@ struct debuggerinfo_struct {
42 int ret_state; 42 int ret_state;
43 int irq_depth; 43 int irq_depth;
44 int enter_kgdb; 44 int enter_kgdb;
45 bool rounding_up;
45}; 46};
46 47
47extern struct debuggerinfo_struct kgdb_info[]; 48extern struct debuggerinfo_struct kgdb_info[];
diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c
index 7921ae4fca8d..7e2379aa0a1e 100644
--- a/kernel/debug/kdb/kdb_bt.c
+++ b/kernel/debug/kdb/kdb_bt.c
@@ -186,7 +186,16 @@ kdb_bt(int argc, const char **argv)
186 kdb_printf("btc: cpu status: "); 186 kdb_printf("btc: cpu status: ");
187 kdb_parse("cpu\n"); 187 kdb_parse("cpu\n");
188 for_each_online_cpu(cpu) { 188 for_each_online_cpu(cpu) {
189 sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu)); 189 void *kdb_tsk = KDB_TSK(cpu);
190
191 /* If a CPU failed to round up we could be here */
192 if (!kdb_tsk) {
193 kdb_printf("WARNING: no task for cpu %ld\n",
194 cpu);
195 continue;
196 }
197
198 sprintf(buf, "btt 0x%px\n", kdb_tsk);
190 kdb_parse(buf); 199 kdb_parse(buf);
191 touch_nmi_watchdog(); 200 touch_nmi_watchdog();
192 } 201 }
diff --git a/kernel/debug/kdb/kdb_debugger.c b/kernel/debug/kdb/kdb_debugger.c
index 15e1a7af5dd0..53a0df6e4d92 100644
--- a/kernel/debug/kdb/kdb_debugger.c
+++ b/kernel/debug/kdb/kdb_debugger.c
@@ -118,13 +118,6 @@ int kdb_stub(struct kgdb_state *ks)
118 kdb_bp_remove(); 118 kdb_bp_remove();
119 KDB_STATE_CLEAR(DOING_SS); 119 KDB_STATE_CLEAR(DOING_SS);
120 KDB_STATE_SET(PAGER); 120 KDB_STATE_SET(PAGER);
121 /* zero out any offline cpu data */
122 for_each_present_cpu(i) {
123 if (!cpu_online(i)) {
124 kgdb_info[i].debuggerinfo = NULL;
125 kgdb_info[i].task = NULL;
126 }
127 }
128 if (ks->err_code == DIE_OOPS || reason == KDB_REASON_OOPS) { 121 if (ks->err_code == DIE_OOPS || reason == KDB_REASON_OOPS) {
129 ks->pass_exception = 1; 122 ks->pass_exception = 1;
130 KDB_FLAG_SET(CATASTROPHIC); 123 KDB_FLAG_SET(CATASTROPHIC);
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index d72b32c66f7d..82a3b32a7cfc 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -658,7 +658,7 @@ static void kdb_cmderror(int diag)
658 */ 658 */
659struct defcmd_set { 659struct defcmd_set {
660 int count; 660 int count;
661 int usable; 661 bool usable;
662 char *name; 662 char *name;
663 char *usage; 663 char *usage;
664 char *help; 664 char *help;
@@ -666,7 +666,7 @@ struct defcmd_set {
666}; 666};
667static struct defcmd_set *defcmd_set; 667static struct defcmd_set *defcmd_set;
668static int defcmd_set_count; 668static int defcmd_set_count;
669static int defcmd_in_progress; 669static bool defcmd_in_progress;
670 670
671/* Forward references */ 671/* Forward references */
672static int kdb_exec_defcmd(int argc, const char **argv); 672static int kdb_exec_defcmd(int argc, const char **argv);
@@ -676,9 +676,9 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
676 struct defcmd_set *s = defcmd_set + defcmd_set_count - 1; 676 struct defcmd_set *s = defcmd_set + defcmd_set_count - 1;
677 char **save_command = s->command; 677 char **save_command = s->command;
678 if (strcmp(argv0, "endefcmd") == 0) { 678 if (strcmp(argv0, "endefcmd") == 0) {
679 defcmd_in_progress = 0; 679 defcmd_in_progress = false;
680 if (!s->count) 680 if (!s->count)
681 s->usable = 0; 681 s->usable = false;
682 if (s->usable) 682 if (s->usable)
683 /* macros are always safe because when executed each 683 /* macros are always safe because when executed each
684 * internal command re-enters kdb_parse() and is 684 * internal command re-enters kdb_parse() and is
@@ -695,7 +695,7 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
695 if (!s->command) { 695 if (!s->command) {
696 kdb_printf("Could not allocate new kdb_defcmd table for %s\n", 696 kdb_printf("Could not allocate new kdb_defcmd table for %s\n",
697 cmdstr); 697 cmdstr);
698 s->usable = 0; 698 s->usable = false;
699 return KDB_NOTIMP; 699 return KDB_NOTIMP;
700 } 700 }
701 memcpy(s->command, save_command, s->count * sizeof(*(s->command))); 701 memcpy(s->command, save_command, s->count * sizeof(*(s->command)));
@@ -737,7 +737,7 @@ static int kdb_defcmd(int argc, const char **argv)
737 defcmd_set_count * sizeof(*defcmd_set)); 737 defcmd_set_count * sizeof(*defcmd_set));
738 s = defcmd_set + defcmd_set_count; 738 s = defcmd_set + defcmd_set_count;
739 memset(s, 0, sizeof(*s)); 739 memset(s, 0, sizeof(*s));
740 s->usable = 1; 740 s->usable = true;
741 s->name = kdb_strdup(argv[1], GFP_KDB); 741 s->name = kdb_strdup(argv[1], GFP_KDB);
742 if (!s->name) 742 if (!s->name)
743 goto fail_name; 743 goto fail_name;
@@ -756,7 +756,7 @@ static int kdb_defcmd(int argc, const char **argv)
756 s->help[strlen(s->help)-1] = '\0'; 756 s->help[strlen(s->help)-1] = '\0';
757 } 757 }
758 ++defcmd_set_count; 758 ++defcmd_set_count;
759 defcmd_in_progress = 1; 759 defcmd_in_progress = true;
760 kfree(save_defcmd_set); 760 kfree(save_defcmd_set);
761 return 0; 761 return 0;
762fail_help: 762fail_help: