Skip to content

Commit 5a14fea

Browse files
Anton Vorontsovgregkh
authored andcommitted
kernel/debug: Mask KGDB NMI upon entry
The new arch callback should manage NMIs that usually cause KGDB to enter. That is, not all NMIs should be enabled/disabled, but only those that issue kgdb_handle_exception(). We must mask it as serial-line interrupt can be used as an NMI, so if the original KGDB-entry cause was say a breakpoint, then every input to KDB console will cause KGDB to reenter, which we don't want. Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org> Acked-by: Jason Wessel <jason.wessel@windriver.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c5dd553 commit 5a14fea

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

include/linux/kgdb.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ extern void kgdb_arch_late(void);
240240
* hardware breakpoints.
241241
* @correct_hw_break: Allow an architecture to specify how to correct the
242242
* hardware debug registers.
243+
* @enable_nmi: Manage NMI-triggered entry to KGDB
243244
*/
244245
struct kgdb_arch {
245246
unsigned char gdb_bpt_instr[BREAK_INSTR_SIZE];
@@ -252,6 +253,8 @@ struct kgdb_arch {
252253
void (*disable_hw_break)(struct pt_regs *regs);
253254
void (*remove_all_hw_break)(void);
254255
void (*correct_hw_break)(void);
256+
257+
void (*enable_nmi)(bool on);
255258
};
256259

257260
/**

kernel/debug/debug_core.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
672672
{
673673
struct kgdb_state kgdb_var;
674674
struct kgdb_state *ks = &kgdb_var;
675+
int ret = 0;
676+
677+
if (arch_kgdb_ops.enable_nmi)
678+
arch_kgdb_ops.enable_nmi(0);
675679

676680
ks->cpu = raw_smp_processor_id();
677681
ks->ex_vector = evector;
@@ -681,11 +685,15 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
681685
ks->linux_regs = regs;
682686

683687
if (kgdb_reenter_check(ks))
684-
return 0; /* Ouch, double exception ! */
688+
goto out; /* Ouch, double exception ! */
685689
if (kgdb_info[ks->cpu].enter_kgdb != 0)
686-
return 0;
690+
goto out;
687691

688-
return kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER);
692+
ret = kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER);
693+
out:
694+
if (arch_kgdb_ops.enable_nmi)
695+
arch_kgdb_ops.enable_nmi(1);
696+
return ret;
689697
}
690698

691699
int kgdb_nmicallback(int cpu, void *regs)

0 commit comments

Comments
 (0)