hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/kernel/printk/printk_safe.c
....@@ -1,27 +1,17 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 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/>.
164 */
175
186 #include <linux/preempt.h>
197 #include <linux/spinlock.h>
208 #include <linux/debug_locks.h>
9
+#include <linux/kdb.h>
2110 #include <linux/smp.h>
2211 #include <linux/cpumask.h>
2312 #include <linux/irq_work.h>
2413 #include <linux/printk.h>
14
+#include <linux/kprobes.h>
2515
2616 #include "internal.h"
2717
....@@ -32,7 +22,7 @@
3222 * is later flushed into the main ring buffer via IRQ work.
3323 *
3424 * 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
3626 * per-CPU variable.
3727 *
3828 * The implementation allows to flush the strings also from another CPU.
....@@ -313,14 +303,14 @@
313303 return printk_safe_log_store(s, fmt, args);
314304 }
315305
316
-void notrace printk_nmi_enter(void)
306
+void noinstr printk_nmi_enter(void)
317307 {
318
- this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
308
+ this_cpu_add(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
319309 }
320310
321
-void notrace printk_nmi_exit(void)
311
+void noinstr printk_nmi_exit(void)
322312 {
323
- this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
313
+ this_cpu_sub(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
324314 }
325315
326316 /*
....@@ -379,6 +369,12 @@
379369
380370 __printf(1, 0) int vprintk_func(const char *fmt, va_list args)
381371 {
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
+
382378 /*
383379 * Try to use the main logbuf even in NMI. But avoid calling console
384380 * drivers that might have their own locks.
....@@ -387,7 +383,7 @@
387383 raw_spin_trylock(&logbuf_lock)) {
388384 int len;
389385
390
- len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args);
386
+ len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, fmt, args);
391387 raw_spin_unlock(&logbuf_lock);
392388 defer_console_output();
393389 return len;