.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * printk_safe.c - Safe printk for printk-deadlock-prone contexts |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or |
---|
5 | | - * modify it under the terms of the GNU General Public License |
---|
6 | | - * as published by the Free Software Foundation; either version 2 |
---|
7 | | - * of the License, or (at your option) any later version. |
---|
8 | | - * |
---|
9 | | - * This program is distributed in the hope that it will be useful, |
---|
10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | | - * GNU General Public License for more details. |
---|
13 | | - * |
---|
14 | | - * You should have received a copy of the GNU General Public License |
---|
15 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
---|
16 | 4 | */ |
---|
17 | 5 | |
---|
18 | 6 | #include <linux/preempt.h> |
---|
19 | 7 | #include <linux/spinlock.h> |
---|
20 | 8 | #include <linux/debug_locks.h> |
---|
| 9 | +#include <linux/kdb.h> |
---|
21 | 10 | #include <linux/smp.h> |
---|
22 | 11 | #include <linux/cpumask.h> |
---|
23 | 12 | #include <linux/irq_work.h> |
---|
24 | 13 | #include <linux/printk.h> |
---|
| 14 | +#include <linux/kprobes.h> |
---|
25 | 15 | |
---|
26 | 16 | #include "internal.h" |
---|
27 | 17 | |
---|
.. | .. |
---|
32 | 22 | * is later flushed into the main ring buffer via IRQ work. |
---|
33 | 23 | * |
---|
34 | 24 | * The alternative implementation is chosen transparently |
---|
35 | | - * by examinig current printk() context mask stored in @printk_context |
---|
| 25 | + * by examining current printk() context mask stored in @printk_context |
---|
36 | 26 | * per-CPU variable. |
---|
37 | 27 | * |
---|
38 | 28 | * The implementation allows to flush the strings also from another CPU. |
---|
.. | .. |
---|
313 | 303 | return printk_safe_log_store(s, fmt, args); |
---|
314 | 304 | } |
---|
315 | 305 | |
---|
316 | | -void notrace printk_nmi_enter(void) |
---|
| 306 | +void noinstr printk_nmi_enter(void) |
---|
317 | 307 | { |
---|
318 | | - this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK); |
---|
| 308 | + this_cpu_add(printk_context, PRINTK_NMI_CONTEXT_OFFSET); |
---|
319 | 309 | } |
---|
320 | 310 | |
---|
321 | | -void notrace printk_nmi_exit(void) |
---|
| 311 | +void noinstr printk_nmi_exit(void) |
---|
322 | 312 | { |
---|
323 | | - this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK); |
---|
| 313 | + this_cpu_sub(printk_context, PRINTK_NMI_CONTEXT_OFFSET); |
---|
324 | 314 | } |
---|
325 | 315 | |
---|
326 | 316 | /* |
---|
.. | .. |
---|
379 | 369 | |
---|
380 | 370 | __printf(1, 0) int vprintk_func(const char *fmt, va_list args) |
---|
381 | 371 | { |
---|
| 372 | +#ifdef CONFIG_KGDB_KDB |
---|
| 373 | + /* Allow to pass printk() to kdb but avoid a recursion. */ |
---|
| 374 | + if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) |
---|
| 375 | + return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); |
---|
| 376 | +#endif |
---|
| 377 | + |
---|
382 | 378 | /* |
---|
383 | 379 | * Try to use the main logbuf even in NMI. But avoid calling console |
---|
384 | 380 | * drivers that might have their own locks. |
---|
.. | .. |
---|
387 | 383 | raw_spin_trylock(&logbuf_lock)) { |
---|
388 | 384 | int len; |
---|
389 | 385 | |
---|
390 | | - len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); |
---|
| 386 | + len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, fmt, args); |
---|
391 | 387 | raw_spin_unlock(&logbuf_lock); |
---|
392 | 388 | defer_console_output(); |
---|
393 | 389 | return len; |
---|