Skip to content

Commit

Permalink
printk: remove deferred printing
Browse files Browse the repository at this point in the history
Since printing occurs either atomically or from the printing
kthread, there is no need for any deferring or tracking possible
recursion paths. Remove all printk defer functions and context
tracking.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
jogness authored and Sebastian Andrzej Siewior committed Sep 13, 2021
1 parent 5944a17 commit 2178197
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 261 deletions.
2 changes: 0 additions & 2 deletions arch/arm/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,7 @@ static void do_handle_IPI(int ipinr)
break;

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

default:
Expand Down
3 changes: 0 additions & 3 deletions arch/powerpc/kexec/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
unsigned int i;
int (*old_handler)(struct pt_regs *regs);

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

/*
* This function is only called after the system
* has panicked or is otherwise in a critical state.
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/dumpstack_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
*/
if (visit_mask) {
if (*visit_mask & (1UL << info->type)) {
printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
pr_warn_once("WARNING: stack recursion on stack type %d\n", info->type);
goto unknown;
}
*visit_mask |= 1UL << info->type;
Expand Down
3 changes: 2 additions & 1 deletion arch/x86/kernel/dumpstack_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
if (visit_mask) {
if (*visit_mask & (1UL << info->type)) {
if (task == current)
printk_deferred_once(KERN_WARNING "WARNING: stack recursion on stack type %d\n", info->type);
pr_warn_once("WARNING: stack recursion on stack type %d\n",
info->type);
goto unknown;
}
*visit_mask |= 1UL << info->type;
Expand Down
3 changes: 1 addition & 2 deletions arch/x86/kernel/i8259.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ static void mask_and_ack_8259A(struct irq_data *data)
* lets ACK and report it. [once per IRQ]
*/
if (!(spurious_irq_mask & irqmask)) {
printk_deferred(KERN_DEBUG
"spurious 8259A interrupt: IRQ%d.\n", irq);
printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
spurious_irq_mask |= irqmask;
}
atomic_inc(&irq_err_count);
Expand Down
16 changes: 7 additions & 9 deletions arch/x86/kernel/unwind_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static void unwind_dump(struct unwind_state *state)

dumped_before = true;

printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
state->stack_info.type, state->stack_info.next_sp,
state->stack_mask, state->graph_idx);
printk("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\n",
state->stack_info.type, state->stack_info.next_sp,
state->stack_mask, state->graph_idx);

for (sp = PTR_ALIGN(state->orig_sp, sizeof(long)); sp;
sp = PTR_ALIGN(stack_info.next_sp, sizeof(long))) {
Expand All @@ -59,13 +59,11 @@ static void unwind_dump(struct unwind_state *state)

if (zero) {
if (!prev_zero)
printk_deferred("%p: %0*x ...\n",
sp, BITS_PER_LONG/4, 0);
printk("%p: %0*x ...\n", sp, BITS_PER_LONG/4, 0);
continue;
}

printk_deferred("%p: %0*lx (%pB)\n",
sp, BITS_PER_LONG/4, word, (void *)word);
printk("%p: %0*lx (%pB)\n", sp, BITS_PER_LONG/4, word, (void *)word);
}
}
}
Expand Down Expand Up @@ -342,13 +340,13 @@ bool unwind_next_frame(struct unwind_state *state)
goto the_end;

if (state->regs) {
printk_deferred_once(KERN_WARNING
pr_warn_once(
"WARNING: kernel stack regs at %p in %s:%d has bad 'bp' value %p\n",
state->regs, state->task->comm,
state->task->pid, next_bp);
unwind_dump(state);
} else {
printk_deferred_once(KERN_WARNING
pr_warn_once(
"WARNING: kernel stack frame pointer at %p in %s:%d has bad value %p\n",
state->bp, state->task->comm,
state->task->pid, next_bp);
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/unwind_orc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <asm/orc_lookup.h>

#define orc_warn(fmt, ...) \
printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
pr_warn_once("WARNING: " fmt, ##__VA_ARGS__)

#define orc_warn_current(args...) \
({ \
Expand Down
5 changes: 2 additions & 3 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,9 +1507,8 @@ static void _warn_unseeded_randomness(const char *func_name, void *caller,
print_once = true;
#endif
if (__ratelimit(&unseeded_warning))
printk_deferred(KERN_NOTICE "random: %s called from %pS "
"with crng_init=%d\n", func_name, caller,
crng_init);
pr_notice("random: %s called from %pS with crng_init=%d\n",
func_name, caller, crng_init);
}

/*
Expand Down
34 changes: 0 additions & 34 deletions include/linux/printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,6 @@ int vprintk(const char *fmt, va_list args);
asmlinkage __printf(1, 2) __cold
int _printk(const char *fmt, ...);

/*
* Special printk facility for scheduler/timekeeping use only, _DO_NOT_USE_ !
*/
__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
Expand Down Expand Up @@ -215,19 +200,6 @@ int _printk(const char *s, ...)
{
return 0;
}
static inline __printf(1, 2) __cold
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)
{
Expand Down Expand Up @@ -471,8 +443,6 @@ struct pi_entry {
* See the vsnprintf() documentation for format string extensions over C99.
*/
#define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
#define printk_deferred(fmt, ...) \
printk_index_wrap(_printk_deferred, fmt, ##__VA_ARGS__)

/**
* pr_emerg - Print an emergency-level message
Expand Down Expand Up @@ -610,13 +580,9 @@ struct pi_entry {
#ifdef CONFIG_PRINTK
#define printk_once(fmt, ...) \
DO_ONCE_LITE(printk, fmt, ##__VA_ARGS__)
#define printk_deferred_once(fmt, ...) \
DO_ONCE_LITE(printk_deferred, fmt, ##__VA_ARGS__)
#else
#define printk_once(fmt, ...) \
no_printk(fmt, ##__VA_ARGS__)
#define printk_deferred_once(fmt, ...) \
no_printk(fmt, ##__VA_ARGS__)
#endif

#define pr_emerg_once(fmt, ...) \
Expand Down
10 changes: 2 additions & 8 deletions include/linux/suspend.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,23 +550,17 @@ static inline void unlock_system_sleep(void) {}
#ifdef CONFIG_PM_SLEEP_DEBUG
extern bool pm_print_times_enabled;
extern bool pm_debug_messages_on;
extern __printf(2, 3) void __pm_pr_dbg(bool defer, const char *fmt, ...);
extern __printf(1, 2) void pm_pr_dbg(const char *fmt, ...);
#else
#define pm_print_times_enabled (false)
#define pm_debug_messages_on (false)

#include <linux/printk.h>

#define __pm_pr_dbg(defer, fmt, ...) \
#define pm_pr_dbg(fmt, ...) \
no_printk(KERN_DEBUG fmt, ##__VA_ARGS__)
#endif

#define pm_pr_dbg(fmt, ...) \
__pm_pr_dbg(false, fmt, ##__VA_ARGS__)

#define pm_deferred_pr_dbg(fmt, ...) \
__pm_pr_dbg(true, fmt, ##__VA_ARGS__)

#ifdef CONFIG_PM_AUTOSLEEP

/* kernel/power/autosleep.c */
Expand Down
10 changes: 3 additions & 7 deletions kernel/power/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,13 @@ static int __init pm_debug_messages_setup(char *str)
__setup("pm_debug_messages", pm_debug_messages_setup);

/**
* __pm_pr_dbg - Print a suspend debug message to the kernel log.
* @defer: Whether or not to use printk_deferred() to print the message.
* pm_pr_dbg - Print a suspend debug message to the kernel log.
* @fmt: Message format.
*
* The message will be emitted if enabled through the pm_debug_messages
* sysfs attribute.
*/
void __pm_pr_dbg(bool defer, const char *fmt, ...)
void pm_pr_dbg(const char *fmt, ...)
{
struct va_format vaf;
va_list args;
Expand All @@ -563,10 +562,7 @@ void __pm_pr_dbg(bool defer, const char *fmt, ...)
vaf.fmt = fmt;
vaf.va = &args;

if (defer)
printk_deferred(KERN_DEBUG "PM: %pV", &vaf);
else
printk(KERN_DEBUG "PM: %pV", &vaf);
printk(KERN_DEBUG "PM: %pV", &vaf);

va_end(args);
}
Expand Down
1 change: 0 additions & 1 deletion kernel/printk/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y = printk.o
obj-$(CONFIG_PRINTK) += printk_safe.o
obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
obj-$(CONFIG_PRINTK) += printk_ringbuffer.o
obj-$(CONFIG_PRINTK_INDEX) += index.o
36 changes: 0 additions & 36 deletions kernel/printk/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/*
* internal.h - printk internal definitions
*/
#include <linux/percpu.h>

#ifdef CONFIG_PRINTK

Expand All @@ -12,41 +11,6 @@ enum printk_info_flags {
LOG_CONT = 8, /* text is a fragment of a continuation line */
};

__printf(4, 0)
int vprintk_store(int facility, int level,
const struct dev_printk_info *dev_info,
const char *fmt, va_list args);

__printf(1, 0) int vprintk_default(const char *fmt, va_list args);
__printf(1, 0) int vprintk_deferred(const char *fmt, va_list args);

bool printk_percpu_data_ready(void);

#define printk_safe_enter_irqsave(flags) \
do { \
local_irq_save(flags); \
__printk_safe_enter(); \
} while (0)

#define printk_safe_exit_irqrestore(flags) \
do { \
__printk_safe_exit(); \
local_irq_restore(flags); \
} while (0)

void defer_console_output(void);

u16 printk_parse_prefix(const char *text, int *level,
enum printk_info_flags *flags);
#else

/*
* In !PRINTK builds we still export console_sem
* semaphore and some of console functions (console_unlock()/etc.), so
* printk-safe must preserve the existing local IRQ guarantees.
*/
#define printk_safe_enter_irqsave(flags) local_irq_save(flags)
#define printk_safe_exit_irqrestore(flags) local_irq_restore(flags)

static inline bool printk_percpu_data_ready(void) { return false; }
#endif /* CONFIG_PRINTK */

0 comments on commit 2178197

Please sign in to comment.