Skip to content

Commit ad394f6

Browse files
Anton Vorontsovgregkh
authored andcommitted
kdb: Implement disable_nmi command
This command disables NMI-entry. If NMI source has been previously shared with a serial console ("debug port"), this effectively releases the port from KDB exclusive use, and makes the console available for normal use. Of course, NMI can be reenabled, enable_nmi modparam is used for that: echo 1 > /sys/module/kdb/parameters/enable_nmi 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 5a14fea commit ad394f6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

kernel/debug/kdb/kdb_main.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/smp.h>
2222
#include <linux/utsname.h>
2323
#include <linux/vmalloc.h>
24+
#include <linux/atomic.h>
2425
#include <linux/module.h>
2526
#include <linux/mm.h>
2627
#include <linux/init.h>
@@ -2107,6 +2108,32 @@ static int kdb_dmesg(int argc, const char **argv)
21072108
return 0;
21082109
}
21092110
#endif /* CONFIG_PRINTK */
2111+
2112+
/* Make sure we balance enable/disable calls, must disable first. */
2113+
static atomic_t kdb_nmi_disabled;
2114+
2115+
static int kdb_disable_nmi(int argc, const char *argv[])
2116+
{
2117+
if (atomic_read(&kdb_nmi_disabled))
2118+
return 0;
2119+
atomic_set(&kdb_nmi_disabled, 1);
2120+
arch_kgdb_ops.enable_nmi(0);
2121+
return 0;
2122+
}
2123+
2124+
static int kdb_param_enable_nmi(const char *val, const struct kernel_param *kp)
2125+
{
2126+
if (!atomic_add_unless(&kdb_nmi_disabled, -1, 0))
2127+
return -EINVAL;
2128+
arch_kgdb_ops.enable_nmi(1);
2129+
return 0;
2130+
}
2131+
2132+
static const struct kernel_param_ops kdb_param_ops_enable_nmi = {
2133+
.set = kdb_param_enable_nmi,
2134+
};
2135+
module_param_cb(enable_nmi, &kdb_param_ops_enable_nmi, NULL, 0600);
2136+
21102137
/*
21112138
* kdb_cpu - This function implements the 'cpu' command.
21122139
* cpu [<cpunum>]
@@ -2851,6 +2878,10 @@ static void __init kdb_inittab(void)
28512878
kdb_register_repeat("dmesg", kdb_dmesg, "[lines]",
28522879
"Display syslog buffer", 0, KDB_REPEAT_NONE);
28532880
#endif
2881+
if (arch_kgdb_ops.enable_nmi) {
2882+
kdb_register_repeat("disable_nmi", kdb_disable_nmi, "",
2883+
"Disable NMI entry to KDB", 0, KDB_REPEAT_NONE);
2884+
}
28542885
kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"",
28552886
"Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE);
28562887
kdb_register_repeat("kill", kdb_kill, "<-signal> <pid>",

0 commit comments

Comments
 (0)