Commit 85e3e7fb authored by John Ogness's avatar John Ogness Committed by Petr Mladek
Browse files

printk: remove NMI tracking



All NMI contexts are handled the same as the safe context: store the
message and defer printing. There is no need to have special NMI
context tracking for this. Using in_nmi() is enough.

There are several parts of the kernel that are manually calling into
the printk NMI context tracking in order to cause general printk
deferred printing:

    arch/arm/kernel/smp.c
    arch/powerpc/kexec/crash.c
    kernel/trace/trace.c

For arm/kernel/smp.c and powerpc/kexec/crash.c, provide a new
function pair printk_deferred_enter/exit that explicitly achieves the
same objective.

For ftrace, remove the printk context manipulation completely. It was
added in commit 03fc7f9c ("printk/nmi: Prevent deadlock when
accessing the main log buffer in NMI"). The purpose was to enforce
storing messages directly into the ring buffer even in NMI context.
It really should have only modified the behavior in NMI context.
There is no need for a special behavior any longer. All messages are
always stored directly now. The console deferring is handled
transparently in vprintk().

Signed-off-by: default avatarJohn Ogness <john.ogness@linutronix.de>
[pmladek@suse.com: Remove special handling in ftrace.c completely.
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210715193359.25946-5-john.ogness@linutronix.de
parent 93d102f0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -667,9 +667,9 @@ static void do_handle_IPI(int ipinr)
		break;

	case IPI_CPU_BACKTRACE:
		printk_nmi_enter();
		printk_deferred_enter();
		nmi_cpu_backtrace(get_irq_regs());
		printk_nmi_exit();
		printk_deferred_exit();
		break;

	default:
+1 −1
Original line number Diff line number Diff line
@@ -313,7 +313,7 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
	int (*old_handler)(struct pt_regs *regs);

	/* Avoid hardlocking with irresponsive CPU holding logbuf_lock */
	printk_nmi_enter();
	printk_deferred_enter();

	/*
	 * This function is only called after the system
+0 −2
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ extern void rcu_nmi_exit(void);
	do {							\
		lockdep_off();					\
		arch_nmi_enter();				\
		printk_nmi_enter();				\
		BUG_ON(in_nmi() == NMI_MASK);			\
		__preempt_count_add(NMI_OFFSET + HARDIRQ_OFFSET);	\
	} while (0)
@@ -135,7 +134,6 @@ extern void rcu_nmi_exit(void);
	do {							\
		BUG_ON(!in_nmi());				\
		__preempt_count_sub(NMI_OFFSET + HARDIRQ_OFFSET);	\
		printk_nmi_exit();				\
		arch_nmi_exit();				\
		lockdep_on();					\
	} while (0)
+19 −12
Original line number Diff line number Diff line
@@ -149,18 +149,6 @@ static inline __printf(1, 2) __cold
void early_printk(const char *s, ...) { }
#endif

#ifdef CONFIG_PRINTK_NMI
extern void printk_nmi_enter(void);
extern void printk_nmi_exit(void);
extern void printk_nmi_direct_enter(void);
extern void printk_nmi_direct_exit(void);
#else
static inline void printk_nmi_enter(void) { }
static inline void printk_nmi_exit(void) { }
static inline void printk_nmi_direct_enter(void) { }
static inline void printk_nmi_direct_exit(void) { }
#endif /* PRINTK_NMI */

struct dev_printk_info;

#ifdef CONFIG_PRINTK
@@ -180,6 +168,16 @@ int printk(const char *fmt, ...);
 */
__printf(1, 2) __cold int printk_deferred(const char *fmt, ...);

extern void __printk_safe_enter(void);
extern void __printk_safe_exit(void);
/*
 * The printk_deferred_enter/exit macros are available only as a hack for
 * some code paths that need to defer all printk console printing. Interrupts
 * must be disabled for the deferred duration.
 */
#define printk_deferred_enter __printk_safe_enter
#define printk_deferred_exit __printk_safe_exit

/*
 * Please don't use printk_ratelimit(), because it shares ratelimiting state
 * with all other unrelated printk_ratelimit() callsites.  Instead use
@@ -224,6 +222,15 @@ int printk_deferred(const char *s, ...)
{
	return 0;
}

static inline void printk_deferred_enter(void)
{
}

static inline void printk_deferred_exit(void)
{
}

static inline int printk_ratelimit(void)
{
	return 0;
+0 −5
Original line number Diff line number Diff line
@@ -1506,11 +1506,6 @@ config PRINTK
	  very difficult to diagnose system problems, saying N here is
	  strongly discouraged.

config PRINTK_NMI
	def_bool y
	depends on PRINTK
	depends on HAVE_NMI

config BUG
	bool "BUG() support" if EXPERT
	default y
Loading