LCOV - code coverage report
Current view: top level - kernel/printk - printk_safe.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 9 12 75.0 %
Date: 2023-08-24 13:40:31 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0-or-later
       2             : /*
       3             :  * printk_safe.c - Safe printk for printk-deadlock-prone contexts
       4             :  */
       5             : 
       6             : #include <linux/preempt.h>
       7             : #include <linux/kdb.h>
       8             : #include <linux/smp.h>
       9             : #include <linux/cpumask.h>
      10             : #include <linux/printk.h>
      11             : #include <linux/kprobes.h>
      12             : 
      13             : #include "internal.h"
      14             : 
      15             : static DEFINE_PER_CPU(int, printk_context);
      16             : 
      17             : /* Can be preempted by NMI. */
      18         990 : void __printk_safe_enter(void)
      19             : {
      20        2970 :         this_cpu_inc(printk_context);
      21         990 : }
      22             : 
      23             : /* Can be preempted by NMI. */
      24         990 : void __printk_safe_exit(void)
      25             : {
      26        2970 :         this_cpu_dec(printk_context);
      27         990 : }
      28             : 
      29         284 : asmlinkage int vprintk(const char *fmt, va_list args)
      30             : {
      31             : #ifdef CONFIG_KGDB_KDB
      32             :         /* Allow to pass printk() to kdb but avoid a recursion. */
      33             :         if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0))
      34             :                 return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args);
      35             : #endif
      36             : 
      37             :         /*
      38             :          * Use the main logbuf even in NMI. But avoid calling console
      39             :          * drivers that might have their own locks.
      40             :          */
      41         568 :         if (this_cpu_read(printk_context) || in_nmi()) {
      42             :                 int len;
      43             : 
      44           0 :                 len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, fmt, args);
      45           0 :                 defer_console_output();
      46           0 :                 return len;
      47             :         }
      48             : 
      49             :         /* No obstacles. */
      50         284 :         return vprintk_default(fmt, args);
      51             : }
      52             : EXPORT_SYMBOL(vprintk);

Generated by: LCOV version 1.14