Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "tty/serial: Add kgdb_nmi driver"

This reverts commit 0c57dfcc6c1d037243c2f8fbf62eab3633326ec0.

The functionality was supoosed to be used by a later patch in the
series that never landed [1]. Drop it.

NOTE: part of functionality was already reverted by commit
39d0be87438a ("serial: kgdb_nmi: Remove unused knock code"). Also note
that this revert is not a clean revert given code changes that have
happened in the meantime.

It's obvious that nobody is using this code since the two exposed
functions (kgdb_register_nmi_console() and
kgdb_unregister_nmi_console()) are both no-ops if
"arch_kgdb_ops.enable_nmi" is not defined. No architectures define it.

[1] https://lore.kernel.org/lkml/1348522080-32629-9-git-send-email-anton.vorontsov@linaro.org/

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: URL [1]
Link: https://lore.kernel.org/r/20250129082535.1.Ia095eac1ae357f87d23e7af2206741f5d40788f1@changeid
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Douglas Anderson and committed by
Greg Kroah-Hartman
c08b0f2c c213375e

-316
-19
drivers/tty/serial/Kconfig
··· 179 179 180 180 Say Y if you have an external 8250/16C550 UART. If unsure, say N. 181 181 182 - config SERIAL_KGDB_NMI 183 - bool "Serial console over KGDB NMI debugger port" 184 - depends on KGDB_SERIAL_CONSOLE 185 - help 186 - This special driver allows you to temporary use NMI debugger port 187 - as a normal console (assuming that the port is attached to KGDB). 188 - 189 - Unlike KDB's disable_nmi command, with this driver you are always 190 - able to go back to the debugger using KGDB escape sequence ($3#33). 191 - This is because this console driver processes the input in NMI 192 - context, and thus is able to intercept the magic sequence. 193 - 194 - Note that since the console interprets input and uses polling 195 - communication methods, for things like PPP you still must fully 196 - detach debugger port from the KGDB NMI (i.e. disable_nmi), and 197 - use raw console. 198 - 199 - If unsure, say N. 200 - 201 182 config SERIAL_MESON 202 183 tristate "Meson serial port support" 203 184 depends on ARCH_MESON || COMPILE_TEST
-1
drivers/tty/serial/Makefile
··· 96 96 # GPIOLIB helpers for modem control lines 97 97 obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o 98 98 99 - obj-$(CONFIG_SERIAL_KGDB_NMI) += kgdb_nmi.o 100 99 obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 101 100 obj-$(CONFIG_SERIAL_NUVOTON_MA35D1) += ma35d1_serial.o
-280
drivers/tty/serial/kgdb_nmi.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * KGDB NMI serial console 4 - * 5 - * Copyright 2010 Google, Inc. 6 - * Arve Hjønnevåg <arve@android.com> 7 - * Colin Cross <ccross@android.com> 8 - * Copyright 2012 Linaro Ltd. 9 - * Anton Vorontsov <anton.vorontsov@linaro.org> 10 - */ 11 - 12 - #include <linux/kernel.h> 13 - #include <linux/module.h> 14 - #include <linux/compiler.h> 15 - #include <linux/slab.h> 16 - #include <linux/errno.h> 17 - #include <linux/atomic.h> 18 - #include <linux/console.h> 19 - #include <linux/tty.h> 20 - #include <linux/tty_driver.h> 21 - #include <linux/tty_flip.h> 22 - #include <linux/serial_core.h> 23 - #include <linux/interrupt.h> 24 - #include <linux/hrtimer.h> 25 - #include <linux/tick.h> 26 - #include <linux/kfifo.h> 27 - #include <linux/kgdb.h> 28 - #include <linux/kdb.h> 29 - 30 - static atomic_t kgdb_nmi_num_readers = ATOMIC_INIT(0); 31 - 32 - static int kgdb_nmi_console_setup(struct console *co, char *options) 33 - { 34 - arch_kgdb_ops.enable_nmi(1); 35 - 36 - /* The NMI console uses the dbg_io_ops to issue console messages. To 37 - * avoid duplicate messages during kdb sessions we must inform kdb's 38 - * I/O utilities that messages sent to the console will automatically 39 - * be displayed on the dbg_io. 40 - */ 41 - dbg_io_ops->cons = co; 42 - 43 - return 0; 44 - } 45 - 46 - static void kgdb_nmi_console_write(struct console *co, const char *s, uint c) 47 - { 48 - int i; 49 - 50 - for (i = 0; i < c; i++) 51 - dbg_io_ops->write_char(s[i]); 52 - } 53 - 54 - static struct tty_driver *kgdb_nmi_tty_driver; 55 - 56 - static struct tty_driver *kgdb_nmi_console_device(struct console *co, int *idx) 57 - { 58 - *idx = co->index; 59 - return kgdb_nmi_tty_driver; 60 - } 61 - 62 - static struct console kgdb_nmi_console = { 63 - .name = "ttyNMI", 64 - .setup = kgdb_nmi_console_setup, 65 - .write = kgdb_nmi_console_write, 66 - .device = kgdb_nmi_console_device, 67 - .flags = CON_PRINTBUFFER | CON_ANYTIME, 68 - .index = -1, 69 - }; 70 - 71 - /* 72 - * This is usually the maximum rate on debug ports. We make fifo large enough 73 - * to make copy-pasting to the terminal usable. 74 - */ 75 - #define KGDB_NMI_BAUD 115200 76 - #define KGDB_NMI_FIFO_SIZE roundup_pow_of_two(KGDB_NMI_BAUD / 8 / HZ) 77 - 78 - struct kgdb_nmi_tty_priv { 79 - struct tty_port port; 80 - struct timer_list timer; 81 - STRUCT_KFIFO(char, KGDB_NMI_FIFO_SIZE) fifo; 82 - }; 83 - 84 - static struct tty_port *kgdb_nmi_port; 85 - 86 - /* 87 - * The tasklet is cheap, it does not cause wakeups when reschedules itself, 88 - * instead it waits for the next tick. 89 - */ 90 - static void kgdb_nmi_tty_receiver(struct timer_list *t) 91 - { 92 - struct kgdb_nmi_tty_priv *priv = from_timer(priv, t, timer); 93 - char ch; 94 - 95 - priv->timer.expires = jiffies + (HZ/100); 96 - add_timer(&priv->timer); 97 - 98 - if (likely(!atomic_read(&kgdb_nmi_num_readers) || 99 - !kfifo_len(&priv->fifo))) 100 - return; 101 - 102 - while (kfifo_out(&priv->fifo, &ch, 1)) 103 - tty_insert_flip_char(&priv->port, ch, TTY_NORMAL); 104 - tty_flip_buffer_push(&priv->port); 105 - } 106 - 107 - static int kgdb_nmi_tty_activate(struct tty_port *port, struct tty_struct *tty) 108 - { 109 - struct kgdb_nmi_tty_priv *priv = 110 - container_of(port, struct kgdb_nmi_tty_priv, port); 111 - 112 - kgdb_nmi_port = port; 113 - priv->timer.expires = jiffies + (HZ/100); 114 - add_timer(&priv->timer); 115 - 116 - return 0; 117 - } 118 - 119 - static void kgdb_nmi_tty_shutdown(struct tty_port *port) 120 - { 121 - struct kgdb_nmi_tty_priv *priv = 122 - container_of(port, struct kgdb_nmi_tty_priv, port); 123 - 124 - del_timer(&priv->timer); 125 - kgdb_nmi_port = NULL; 126 - } 127 - 128 - static const struct tty_port_operations kgdb_nmi_tty_port_ops = { 129 - .activate = kgdb_nmi_tty_activate, 130 - .shutdown = kgdb_nmi_tty_shutdown, 131 - }; 132 - 133 - static int kgdb_nmi_tty_install(struct tty_driver *drv, struct tty_struct *tty) 134 - { 135 - struct kgdb_nmi_tty_priv *priv; 136 - int ret; 137 - 138 - priv = kzalloc(sizeof(*priv), GFP_KERNEL); 139 - if (!priv) 140 - return -ENOMEM; 141 - 142 - INIT_KFIFO(priv->fifo); 143 - timer_setup(&priv->timer, kgdb_nmi_tty_receiver, 0); 144 - tty_port_init(&priv->port); 145 - priv->port.ops = &kgdb_nmi_tty_port_ops; 146 - tty->driver_data = priv; 147 - 148 - ret = tty_port_install(&priv->port, drv, tty); 149 - if (ret) { 150 - pr_err("%s: can't install tty port: %d\n", __func__, ret); 151 - goto err; 152 - } 153 - return 0; 154 - err: 155 - tty_port_destroy(&priv->port); 156 - kfree(priv); 157 - return ret; 158 - } 159 - 160 - static void kgdb_nmi_tty_cleanup(struct tty_struct *tty) 161 - { 162 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 163 - 164 - tty->driver_data = NULL; 165 - tty_port_destroy(&priv->port); 166 - kfree(priv); 167 - } 168 - 169 - static int kgdb_nmi_tty_open(struct tty_struct *tty, struct file *file) 170 - { 171 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 172 - unsigned int mode = file->f_flags & O_ACCMODE; 173 - int ret; 174 - 175 - ret = tty_port_open(&priv->port, tty, file); 176 - if (!ret && (mode == O_RDONLY || mode == O_RDWR)) 177 - atomic_inc(&kgdb_nmi_num_readers); 178 - 179 - return ret; 180 - } 181 - 182 - static void kgdb_nmi_tty_close(struct tty_struct *tty, struct file *file) 183 - { 184 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 185 - unsigned int mode = file->f_flags & O_ACCMODE; 186 - 187 - if (mode == O_RDONLY || mode == O_RDWR) 188 - atomic_dec(&kgdb_nmi_num_readers); 189 - 190 - tty_port_close(&priv->port, tty, file); 191 - } 192 - 193 - static void kgdb_nmi_tty_hangup(struct tty_struct *tty) 194 - { 195 - struct kgdb_nmi_tty_priv *priv = tty->driver_data; 196 - 197 - tty_port_hangup(&priv->port); 198 - } 199 - 200 - static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty) 201 - { 202 - /* Actually, we can handle any amount as we use polled writes. */ 203 - return 2048; 204 - } 205 - 206 - static ssize_t kgdb_nmi_tty_write(struct tty_struct *tty, const u8 *buf, 207 - size_t c) 208 - { 209 - int i; 210 - 211 - for (i = 0; i < c; i++) 212 - dbg_io_ops->write_char(buf[i]); 213 - return c; 214 - } 215 - 216 - static const struct tty_operations kgdb_nmi_tty_ops = { 217 - .open = kgdb_nmi_tty_open, 218 - .close = kgdb_nmi_tty_close, 219 - .install = kgdb_nmi_tty_install, 220 - .cleanup = kgdb_nmi_tty_cleanup, 221 - .hangup = kgdb_nmi_tty_hangup, 222 - .write_room = kgdb_nmi_tty_write_room, 223 - .write = kgdb_nmi_tty_write, 224 - }; 225 - 226 - int kgdb_register_nmi_console(void) 227 - { 228 - int ret; 229 - 230 - if (!arch_kgdb_ops.enable_nmi) 231 - return 0; 232 - 233 - kgdb_nmi_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW); 234 - if (IS_ERR(kgdb_nmi_tty_driver)) { 235 - pr_err("%s: cannot allocate tty\n", __func__); 236 - return PTR_ERR(kgdb_nmi_tty_driver); 237 - } 238 - kgdb_nmi_tty_driver->driver_name = "ttyNMI"; 239 - kgdb_nmi_tty_driver->name = "ttyNMI"; 240 - kgdb_nmi_tty_driver->num = 1; 241 - kgdb_nmi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; 242 - kgdb_nmi_tty_driver->subtype = SERIAL_TYPE_NORMAL; 243 - kgdb_nmi_tty_driver->init_termios = tty_std_termios; 244 - tty_termios_encode_baud_rate(&kgdb_nmi_tty_driver->init_termios, 245 - KGDB_NMI_BAUD, KGDB_NMI_BAUD); 246 - tty_set_operations(kgdb_nmi_tty_driver, &kgdb_nmi_tty_ops); 247 - 248 - ret = tty_register_driver(kgdb_nmi_tty_driver); 249 - if (ret) { 250 - pr_err("%s: can't register tty driver: %d\n", __func__, ret); 251 - goto err_drv_reg; 252 - } 253 - 254 - register_console(&kgdb_nmi_console); 255 - 256 - return 0; 257 - err_drv_reg: 258 - tty_driver_kref_put(kgdb_nmi_tty_driver); 259 - return ret; 260 - } 261 - EXPORT_SYMBOL_GPL(kgdb_register_nmi_console); 262 - 263 - int kgdb_unregister_nmi_console(void) 264 - { 265 - int ret; 266 - 267 - if (!arch_kgdb_ops.enable_nmi) 268 - return 0; 269 - arch_kgdb_ops.enable_nmi(0); 270 - 271 - ret = unregister_console(&kgdb_nmi_console); 272 - if (ret) 273 - return ret; 274 - 275 - tty_unregister_driver(kgdb_nmi_tty_driver); 276 - tty_driver_kref_put(kgdb_nmi_tty_driver); 277 - 278 - return 0; 279 - } 280 - EXPORT_SYMBOL_GPL(kgdb_unregister_nmi_console);
-8
drivers/tty/serial/kgdboc.c
··· 186 186 if (configured != 1) 187 187 return; 188 188 189 - if (kgdb_unregister_nmi_console()) 190 - return; 191 189 kgdboc_unregister_kbd(); 192 190 kgdb_unregister_io_module(&kgdboc_io_ops); 193 191 } ··· 248 250 if (err) 249 251 goto noconfig; 250 252 251 - err = kgdb_register_nmi_console(); 252 - if (err) 253 - goto nmi_con_failed; 254 - 255 253 configured = 1; 256 254 257 255 return 0; 258 256 259 - nmi_con_failed: 260 - kgdb_unregister_io_module(&kgdboc_io_ops); 261 257 noconfig: 262 258 kgdboc_unregister_kbd(); 263 259 configured = 0;
-8
include/linux/kgdb.h
··· 306 306 307 307 extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs); 308 308 309 - #ifdef CONFIG_SERIAL_KGDB_NMI 310 - extern int kgdb_register_nmi_console(void); 311 - extern int kgdb_unregister_nmi_console(void); 312 - #else 313 - static inline int kgdb_register_nmi_console(void) { return 0; } 314 - static inline int kgdb_unregister_nmi_console(void) { return 0; } 315 - #endif 316 - 317 309 extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops); 318 310 extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops); 319 311 extern struct kgdb_io *dbg_io_ops;