mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 13:55:32 +00:00
![Chris Down](/assets/img/avatar_default.png)
We have a number of systems industry-wide that have a subset of their functionality that works as follows: 1. Receive a message from local kmsg, serial console, or netconsole; 2. Apply a set of rules to classify the message; 3. Do something based on this classification (like scheduling a remediation for the machine), rinse, and repeat. As a couple of examples of places we have this implemented just inside Facebook, although this isn't a Facebook-specific problem, we have this inside our netconsole processing (for alarm classification), and as part of our machine health checking. We use these messages to determine fairly important metrics around production health, and it's important that we get them right. While for some kinds of issues we have counters, tracepoints, or metrics with a stable interface which can reliably indicate the issue, in order to react to production issues quickly we need to work with the interface which most kernel developers naturally use when developing: printk. Most production issues come from unexpected phenomena, and as such usually the code in question doesn't have easily usable tracepoints or other counters available for the specific problem being mitigated. We have a number of lines of monitoring defence against problems in production (host metrics, process metrics, service metrics, etc), and where it's not feasible to reliably monitor at another level, this kind of pragmatic netconsole monitoring is essential. As one would expect, monitoring using printk is rather brittle for a number of reasons -- most notably that the message might disappear entirely in a new version of the kernel, or that the message may change in some way that the regex or other classification methods start to silently fail. One factor that makes this even harder is that, under normal operation, many of these messages are never expected to be hit. For example, there may be a rare hardware bug which one wants to detect if it was to ever happen again, but its recurrence is not likely or anticipated. This precludes using something like checking whether the printk in question was printed somewhere fleetwide recently to determine whether the message in question is still present or not, since we don't anticipate that it should be printed anywhere, but still need to monitor for its future presence in the long-term. This class of issue has happened on a number of occasions, causing unhealthy machines with hardware issues to remain in production for longer than ideal. As a recent example, some monitoring around blk_update_request fell out of date and caused semi-broken machines to remain in production for longer than would be desirable. Searching through the codebase to find the message is also extremely fragile, because many of the messages are further constructed beyond their callsite (eg. btrfs_printk and other module-specific wrappers, each with their own functionality). Even if they aren't, guessing the format and formulation of the underlying message based on the aesthetics of the message emitted is not a recipe for success at scale, and our previous issues with fleetwide machine health checking demonstrate as much. This provides a solution to the issue of silently changed or deleted printks: we record pointers to all printk format strings known at compile time into a new .printk_index section, both in vmlinux and modules. At runtime, this can then be iterated by looking at <debugfs>/printk/index/<module>, which emits the following format, both readable by humans and able to be parsed by machines: $ head -1 vmlinux; shuf -n 5 vmlinux # <level[,flags]> filename:line function "format" <5> block/blk-settings.c:661 disk_stack_limits "%s: Warning: Device %s is misaligned\n" <4> kernel/trace/trace.c:8296 trace_create_file "Could not create tracefs '%s' entry\n" <6> arch/x86/kernel/hpet.c:144 _hpet_print_config "hpet: %s(%d):\n" <6> init/do_mounts.c:605 prepare_namespace "Waiting for root device %s...\n" <6> drivers/acpi/osl.c:1410 acpi_no_auto_serialize_setup "ACPI: auto-serialization disabled\n" This mitigates the majority of cases where we have a highly-specific printk which we want to match on, as we can now enumerate and check whether the format changed or the printk callsite disappeared entirely in userspace. This allows us to catch changes to printks we monitor earlier and decide what to do about it before it becomes problematic. There is no additional runtime cost for printk callers or printk itself, and the assembly generated is exactly the same. Signed-off-by: Chris Down <chris@chrisdown.name> Cc: Petr Mladek <pmladek@suse.com> Cc: Jessica Yu <jeyu@kernel.org> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: John Ogness <john.ogness@linutronix.de> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Kees Cook <keescook@chromium.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Tested-by: Petr Mladek <pmladek@suse.com> Reported-by: kernel test robot <lkp@intel.com> Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Jessica Yu <jeyu@kernel.org> # for module.{c,h} Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/e42070983637ac5e384f17fbdbe86d19c7b212a5.1623775748.git.chris@chrisdown.name
742 lines
22 KiB
C
742 lines
22 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __KERNEL_PRINTK__
|
|
#define __KERNEL_PRINTK__
|
|
|
|
#include <stdarg.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kern_levels.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/cache.h>
|
|
#include <linux/ratelimit_types.h>
|
|
#include <linux/once_lite.h>
|
|
|
|
extern const char linux_banner[];
|
|
extern const char linux_proc_banner[];
|
|
|
|
extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
|
|
|
|
#define PRINTK_MAX_SINGLE_HEADER_LEN 2
|
|
|
|
static inline int printk_get_level(const char *buffer)
|
|
{
|
|
if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
|
|
switch (buffer[1]) {
|
|
case '0' ... '7':
|
|
case 'c': /* KERN_CONT */
|
|
return buffer[1];
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static inline const char *printk_skip_level(const char *buffer)
|
|
{
|
|
if (printk_get_level(buffer))
|
|
return buffer + 2;
|
|
|
|
return buffer;
|
|
}
|
|
|
|
static inline const char *printk_skip_headers(const char *buffer)
|
|
{
|
|
while (printk_get_level(buffer))
|
|
buffer = printk_skip_level(buffer);
|
|
|
|
return buffer;
|
|
}
|
|
|
|
#define CONSOLE_EXT_LOG_MAX 8192
|
|
|
|
/* printk's without a loglevel use this.. */
|
|
#define MESSAGE_LOGLEVEL_DEFAULT CONFIG_MESSAGE_LOGLEVEL_DEFAULT
|
|
|
|
/* We show everything that is MORE important than this.. */
|
|
#define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */
|
|
#define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */
|
|
#define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */
|
|
#define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */
|
|
|
|
/*
|
|
* Default used to be hard-coded at 7, quiet used to be hardcoded at 4,
|
|
* we're now allowing both to be set from kernel config.
|
|
*/
|
|
#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT
|
|
#define CONSOLE_LOGLEVEL_QUIET CONFIG_CONSOLE_LOGLEVEL_QUIET
|
|
|
|
extern int console_printk[];
|
|
|
|
#define console_loglevel (console_printk[0])
|
|
#define default_message_loglevel (console_printk[1])
|
|
#define minimum_console_loglevel (console_printk[2])
|
|
#define default_console_loglevel (console_printk[3])
|
|
|
|
static inline void console_silent(void)
|
|
{
|
|
console_loglevel = CONSOLE_LOGLEVEL_SILENT;
|
|
}
|
|
|
|
static inline void console_verbose(void)
|
|
{
|
|
if (console_loglevel)
|
|
console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
|
|
}
|
|
|
|
/* strlen("ratelimit") + 1 */
|
|
#define DEVKMSG_STR_MAX_SIZE 10
|
|
extern char devkmsg_log_str[];
|
|
struct ctl_table;
|
|
|
|
extern int suppress_printk;
|
|
|
|
struct va_format {
|
|
const char *fmt;
|
|
va_list *va;
|
|
};
|
|
|
|
/*
|
|
* FW_BUG
|
|
* Add this to a message where you are sure the firmware is buggy or behaves
|
|
* really stupid or out of spec. Be aware that the responsible BIOS developer
|
|
* should be able to fix this issue or at least get a concrete idea of the
|
|
* problem by reading your message without the need of looking at the kernel
|
|
* code.
|
|
*
|
|
* Use it for definite and high priority BIOS bugs.
|
|
*
|
|
* FW_WARN
|
|
* Use it for not that clear (e.g. could the kernel messed up things already?)
|
|
* and medium priority BIOS bugs.
|
|
*
|
|
* FW_INFO
|
|
* Use this one if you want to tell the user or vendor about something
|
|
* suspicious, but generally harmless related to the firmware.
|
|
*
|
|
* Use it for information or very low priority BIOS bugs.
|
|
*/
|
|
#define FW_BUG "[Firmware Bug]: "
|
|
#define FW_WARN "[Firmware Warn]: "
|
|
#define FW_INFO "[Firmware Info]: "
|
|
|
|
/*
|
|
* HW_ERR
|
|
* Add this to a message for hardware errors, so that user can report
|
|
* it to hardware vendor instead of LKML or software vendor.
|
|
*/
|
|
#define HW_ERR "[Hardware Error]: "
|
|
|
|
/*
|
|
* DEPRECATED
|
|
* Add this to a message whenever you want to warn user space about the use
|
|
* of a deprecated aspect of an API so they can stop using it
|
|
*/
|
|
#define DEPRECATED "[Deprecated]: "
|
|
|
|
/*
|
|
* Dummy printk for disabled debugging statements to use whilst maintaining
|
|
* gcc's format checking.
|
|
*/
|
|
#define no_printk(fmt, ...) \
|
|
({ \
|
|
if (0) \
|
|
printk(fmt, ##__VA_ARGS__); \
|
|
0; \
|
|
})
|
|
|
|
#ifdef CONFIG_EARLY_PRINTK
|
|
extern asmlinkage __printf(1, 2)
|
|
void early_printk(const char *fmt, ...);
|
|
#else
|
|
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
|
|
asmlinkage __printf(4, 0)
|
|
int vprintk_emit(int facility, int level,
|
|
const struct dev_printk_info *dev_info,
|
|
const char *fmt, va_list args);
|
|
|
|
asmlinkage __printf(1, 0)
|
|
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, ...);
|
|
|
|
/*
|
|
* Please don't use printk_ratelimit(), because it shares ratelimiting state
|
|
* with all other unrelated printk_ratelimit() callsites. Instead use
|
|
* printk_ratelimited() or plain old __ratelimit().
|
|
*/
|
|
extern int __printk_ratelimit(const char *func);
|
|
#define printk_ratelimit() __printk_ratelimit(__func__)
|
|
extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
|
|
unsigned int interval_msec);
|
|
|
|
extern int printk_delay_msec;
|
|
extern int dmesg_restrict;
|
|
|
|
extern int
|
|
devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, void *buf,
|
|
size_t *lenp, loff_t *ppos);
|
|
|
|
extern void wake_up_klogd(void);
|
|
|
|
char *log_buf_addr_get(void);
|
|
u32 log_buf_len_get(void);
|
|
void log_buf_vmcoreinfo_setup(void);
|
|
void __init setup_log_buf(int early);
|
|
__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
|
|
void dump_stack_print_info(const char *log_lvl);
|
|
void show_regs_print_info(const char *log_lvl);
|
|
extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold;
|
|
extern asmlinkage void dump_stack(void) __cold;
|
|
extern void printk_safe_flush(void);
|
|
extern void printk_safe_flush_on_panic(void);
|
|
#else
|
|
static inline __printf(1, 0)
|
|
int vprintk(const char *s, va_list args)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline __printf(1, 2) __cold
|
|
int _printk(const char *s, ...)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline __printf(1, 2) __cold
|
|
int _printk_deferred(const char *s, ...)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline int printk_ratelimit(void)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
|
|
unsigned int interval_msec)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline void wake_up_klogd(void)
|
|
{
|
|
}
|
|
|
|
static inline char *log_buf_addr_get(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline u32 log_buf_len_get(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void log_buf_vmcoreinfo_setup(void)
|
|
{
|
|
}
|
|
|
|
static inline void setup_log_buf(int early)
|
|
{
|
|
}
|
|
|
|
static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...)
|
|
{
|
|
}
|
|
|
|
static inline void dump_stack_print_info(const char *log_lvl)
|
|
{
|
|
}
|
|
|
|
static inline void show_regs_print_info(const char *log_lvl)
|
|
{
|
|
}
|
|
|
|
static inline void dump_stack_lvl(const char *log_lvl)
|
|
{
|
|
}
|
|
|
|
static inline void dump_stack(void)
|
|
{
|
|
}
|
|
|
|
static inline void printk_safe_flush(void)
|
|
{
|
|
}
|
|
|
|
static inline void printk_safe_flush_on_panic(void)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_SMP
|
|
extern int __printk_cpu_trylock(void);
|
|
extern void __printk_wait_on_cpu_lock(void);
|
|
extern void __printk_cpu_unlock(void);
|
|
|
|
/**
|
|
* printk_cpu_lock_irqsave() - Acquire the printk cpu-reentrant spinning
|
|
* lock and disable interrupts.
|
|
* @flags: Stack-allocated storage for saving local interrupt state,
|
|
* to be passed to printk_cpu_unlock_irqrestore().
|
|
*
|
|
* If the lock is owned by another CPU, spin until it becomes available.
|
|
* Interrupts are restored while spinning.
|
|
*/
|
|
#define printk_cpu_lock_irqsave(flags) \
|
|
for (;;) { \
|
|
local_irq_save(flags); \
|
|
if (__printk_cpu_trylock()) \
|
|
break; \
|
|
local_irq_restore(flags); \
|
|
__printk_wait_on_cpu_lock(); \
|
|
}
|
|
|
|
/**
|
|
* printk_cpu_unlock_irqrestore() - Release the printk cpu-reentrant spinning
|
|
* lock and restore interrupts.
|
|
* @flags: Caller's saved interrupt state, from printk_cpu_lock_irqsave().
|
|
*/
|
|
#define printk_cpu_unlock_irqrestore(flags) \
|
|
do { \
|
|
__printk_cpu_unlock(); \
|
|
local_irq_restore(flags); \
|
|
} while (0) \
|
|
|
|
#else
|
|
|
|
#define printk_cpu_lock_irqsave(flags) ((void)flags)
|
|
#define printk_cpu_unlock_irqrestore(flags) ((void)flags)
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
extern int kptr_restrict;
|
|
|
|
/**
|
|
* pr_fmt - used by the pr_*() macros to generate the printk format string
|
|
* @fmt: format string passed from a pr_*() macro
|
|
*
|
|
* This macro can be used to generate a unified format string for pr_*()
|
|
* macros. A common use is to prefix all pr_*() messages in a file with a common
|
|
* string. For example, defining this at the top of a source file:
|
|
*
|
|
* #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
*
|
|
* would prefix all pr_info, pr_emerg... messages in the file with the module
|
|
* name.
|
|
*/
|
|
#ifndef pr_fmt
|
|
#define pr_fmt(fmt) fmt
|
|
#endif
|
|
|
|
struct module;
|
|
|
|
#ifdef CONFIG_PRINTK_INDEX
|
|
struct pi_entry {
|
|
const char *fmt;
|
|
const char *func;
|
|
const char *file;
|
|
unsigned int line;
|
|
|
|
/*
|
|
* While printk and pr_* have the level stored in the string at compile
|
|
* time, some subsystems dynamically add it at runtime through the
|
|
* format string. For these dynamic cases, we allow the subsystem to
|
|
* tell us the level at compile time.
|
|
*
|
|
* NULL indicates that the level, if any, is stored in fmt.
|
|
*/
|
|
const char *level;
|
|
|
|
/*
|
|
* The format string used by various subsystem specific printk()
|
|
* wrappers to prefix the message.
|
|
*
|
|
* Note that the static prefix defined by the pr_fmt() macro is stored
|
|
* directly in the message format (@fmt), not here.
|
|
*/
|
|
const char *subsys_fmt_prefix;
|
|
} __packed;
|
|
|
|
#define __printk_index_emit(_fmt, _level, _subsys_fmt_prefix) \
|
|
do { \
|
|
if (__builtin_constant_p(_fmt) && __builtin_constant_p(_level)) { \
|
|
/*
|
|
* We check __builtin_constant_p multiple times here
|
|
* for the same input because GCC will produce an error
|
|
* if we try to assign a static variable to fmt if it
|
|
* is not a constant, even with the outer if statement.
|
|
*/ \
|
|
static const struct pi_entry _entry \
|
|
__used = { \
|
|
.fmt = __builtin_constant_p(_fmt) ? (_fmt) : NULL, \
|
|
.func = __func__, \
|
|
.file = __FILE__, \
|
|
.line = __LINE__, \
|
|
.level = __builtin_constant_p(_level) ? (_level) : NULL, \
|
|
.subsys_fmt_prefix = _subsys_fmt_prefix,\
|
|
}; \
|
|
static const struct pi_entry *_entry_ptr \
|
|
__used __section(".printk_index") = &_entry; \
|
|
} \
|
|
} while (0)
|
|
|
|
#else /* !CONFIG_PRINTK_INDEX */
|
|
#define __printk_index_emit(...) do {} while (0)
|
|
#endif /* CONFIG_PRINTK_INDEX */
|
|
|
|
/*
|
|
* Some subsystems have their own custom printk that applies a va_format to a
|
|
* generic format, for example, to include a device number or other metadata
|
|
* alongside the format supplied by the caller.
|
|
*
|
|
* In order to store these in the way they would be emitted by the printk
|
|
* infrastructure, the subsystem provides us with the start, fixed string, and
|
|
* any subsequent text in the format string.
|
|
*
|
|
* We take a variable argument list as pr_fmt/dev_fmt/etc are sometimes passed
|
|
* as multiple arguments (eg: `"%s: ", "blah"`), and we must only take the
|
|
* first one.
|
|
*
|
|
* subsys_fmt_prefix must be known at compile time, or compilation will fail
|
|
* (since this is a mistake). If fmt or level is not known at compile time, no
|
|
* index entry will be made (since this can legitimately happen).
|
|
*/
|
|
#define printk_index_subsys_emit(subsys_fmt_prefix, level, fmt, ...) \
|
|
__printk_index_emit(fmt, level, subsys_fmt_prefix)
|
|
|
|
#define printk_index_wrap(_p_func, _fmt, ...) \
|
|
({ \
|
|
__printk_index_emit(_fmt, NULL, NULL); \
|
|
_p_func(_fmt, ##__VA_ARGS__); \
|
|
})
|
|
|
|
|
|
#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
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_EMERG loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_emerg(fmt, ...) \
|
|
printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_alert - Print an alert-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_ALERT loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_alert(fmt, ...) \
|
|
printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_crit - Print a critical-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_CRIT loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_crit(fmt, ...) \
|
|
printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_err - Print an error-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_ERR loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_err(fmt, ...) \
|
|
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_warn - Print a warning-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_WARNING loglevel. It uses pr_fmt()
|
|
* to generate the format string.
|
|
*/
|
|
#define pr_warn(fmt, ...) \
|
|
printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_notice - Print a notice-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_NOTICE loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_notice(fmt, ...) \
|
|
printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
|
|
/**
|
|
* pr_info - Print an info-level message
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_INFO loglevel. It uses pr_fmt() to
|
|
* generate the format string.
|
|
*/
|
|
#define pr_info(fmt, ...) \
|
|
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
|
|
|
|
/**
|
|
* pr_cont - Continues a previous log message in the same line.
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_CONT loglevel. It should only be
|
|
* used when continuing a log message with no newline ('\n') enclosed. Otherwise
|
|
* it defaults back to KERN_DEFAULT loglevel.
|
|
*/
|
|
#define pr_cont(fmt, ...) \
|
|
printk(KERN_CONT fmt, ##__VA_ARGS__)
|
|
|
|
/**
|
|
* pr_devel - Print a debug-level message conditionally
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to a printk with KERN_DEBUG loglevel if DEBUG is
|
|
* defined. Otherwise it does nothing.
|
|
*
|
|
* It uses pr_fmt() to generate the format string.
|
|
*/
|
|
#ifdef DEBUG
|
|
#define pr_devel(fmt, ...) \
|
|
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_devel(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
|
|
/* If you are writing a driver, please use dev_dbg instead */
|
|
#if defined(CONFIG_DYNAMIC_DEBUG) || \
|
|
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
|
|
#include <linux/dynamic_debug.h>
|
|
|
|
/**
|
|
* pr_debug - Print a debug-level message conditionally
|
|
* @fmt: format string
|
|
* @...: arguments for the format string
|
|
*
|
|
* This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is
|
|
* set. Otherwise, if DEBUG is defined, it's equivalent to a printk with
|
|
* KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
|
|
*
|
|
* It uses pr_fmt() to generate the format string (dynamic_pr_debug() uses
|
|
* pr_fmt() internally).
|
|
*/
|
|
#define pr_debug(fmt, ...) \
|
|
dynamic_pr_debug(fmt, ##__VA_ARGS__)
|
|
#elif defined(DEBUG)
|
|
#define pr_debug(fmt, ...) \
|
|
printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_debug(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/*
|
|
* Print a one-time message (analogous to WARN_ONCE() et al):
|
|
*/
|
|
|
|
#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, ...) \
|
|
printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_alert_once(fmt, ...) \
|
|
printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_crit_once(fmt, ...) \
|
|
printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_err_once(fmt, ...) \
|
|
printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_warn_once(fmt, ...) \
|
|
printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_notice_once(fmt, ...) \
|
|
printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_info_once(fmt, ...) \
|
|
printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
|
|
/* no pr_cont_once, don't do that... */
|
|
|
|
#if defined(DEBUG)
|
|
#define pr_devel_once(fmt, ...) \
|
|
printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_devel_once(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/* If you are writing a driver, please use dev_dbg instead */
|
|
#if defined(DEBUG)
|
|
#define pr_debug_once(fmt, ...) \
|
|
printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_debug_once(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/*
|
|
* ratelimited messages with local ratelimit_state,
|
|
* no local ratelimit_state used in the !PRINTK case
|
|
*/
|
|
#ifdef CONFIG_PRINTK
|
|
#define printk_ratelimited(fmt, ...) \
|
|
({ \
|
|
static DEFINE_RATELIMIT_STATE(_rs, \
|
|
DEFAULT_RATELIMIT_INTERVAL, \
|
|
DEFAULT_RATELIMIT_BURST); \
|
|
\
|
|
if (__ratelimit(&_rs)) \
|
|
printk(fmt, ##__VA_ARGS__); \
|
|
})
|
|
#else
|
|
#define printk_ratelimited(fmt, ...) \
|
|
no_printk(fmt, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
#define pr_emerg_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_alert_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_crit_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_err_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_warn_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_notice_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
|
|
#define pr_info_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
|
|
/* no pr_cont_ratelimited, don't do that... */
|
|
|
|
#if defined(DEBUG)
|
|
#define pr_devel_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_devel_ratelimited(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/* If you are writing a driver, please use dev_dbg instead */
|
|
#if defined(CONFIG_DYNAMIC_DEBUG) || \
|
|
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
|
|
/* descriptor check is first to prevent flooding with "callbacks suppressed" */
|
|
#define pr_debug_ratelimited(fmt, ...) \
|
|
do { \
|
|
static DEFINE_RATELIMIT_STATE(_rs, \
|
|
DEFAULT_RATELIMIT_INTERVAL, \
|
|
DEFAULT_RATELIMIT_BURST); \
|
|
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
|
|
if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
|
|
__ratelimit(&_rs)) \
|
|
__dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
|
|
} while (0)
|
|
#elif defined(DEBUG)
|
|
#define pr_debug_ratelimited(fmt, ...) \
|
|
printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#else
|
|
#define pr_debug_ratelimited(fmt, ...) \
|
|
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
|
|
#endif
|
|
|
|
extern const struct file_operations kmsg_fops;
|
|
|
|
enum {
|
|
DUMP_PREFIX_NONE,
|
|
DUMP_PREFIX_ADDRESS,
|
|
DUMP_PREFIX_OFFSET
|
|
};
|
|
extern int hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
|
|
int groupsize, char *linebuf, size_t linebuflen,
|
|
bool ascii);
|
|
#ifdef CONFIG_PRINTK
|
|
extern void print_hex_dump(const char *level, const char *prefix_str,
|
|
int prefix_type, int rowsize, int groupsize,
|
|
const void *buf, size_t len, bool ascii);
|
|
#else
|
|
static inline void print_hex_dump(const char *level, const char *prefix_str,
|
|
int prefix_type, int rowsize, int groupsize,
|
|
const void *buf, size_t len, bool ascii)
|
|
{
|
|
}
|
|
static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
|
|
const void *buf, size_t len)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_DYNAMIC_DEBUG) || \
|
|
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
|
|
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
|
|
groupsize, buf, len, ascii) \
|
|
dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
|
|
groupsize, buf, len, ascii)
|
|
#elif defined(DEBUG)
|
|
#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \
|
|
groupsize, buf, len, ascii) \
|
|
print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \
|
|
groupsize, buf, len, ascii)
|
|
#else
|
|
static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,
|
|
int rowsize, int groupsize,
|
|
const void *buf, size_t len, bool ascii)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
/**
|
|
* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
|
|
* @prefix_str: string to prefix each line with;
|
|
* caller supplies trailing spaces for alignment if desired
|
|
* @prefix_type: controls whether prefix of an offset, address, or none
|
|
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
|
|
* @buf: data blob to dump
|
|
* @len: number of bytes in the @buf
|
|
*
|
|
* Calls print_hex_dump(), with log level of KERN_DEBUG,
|
|
* rowsize of 16, groupsize of 1, and ASCII output included.
|
|
*/
|
|
#define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
|
|
print_hex_dump_debug(prefix_str, prefix_type, 16, 1, buf, len, true)
|
|
|
|
#endif
|