Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kernel/printk: use symbolic defines for console loglevels

... instead of naked numbers.

Stuff in sysrq.c used to set it to 8 which is supposed to mean above
default level so set it to DEBUG instead as we're terminating/killing all
tasks and we want to be verbose there.

Also, correct the check in x86_64_start_kernel which should be >= as
we're clearly issuing the string there for all debug levels, not only
the magical 10.

Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Joe Perches <joe@perches.com>
Cc: Valdis Kletnieks <Valdis.Kletnieks@vt.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Borislav Petkov and committed by
Linus Torvalds
a8fe19eb 84b5ec8a

+36 -32
+1 -1
arch/x86/kernel/head64.c
··· 172 172 */ 173 173 load_ucode_bsp(); 174 174 175 - if (console_loglevel == 10) 175 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 176 176 early_printk("Kernel alive\n"); 177 177 178 178 clear_page(init_level4_pgt);
+1 -1
arch/x86/platform/uv/uv_nmi.c
··· 85 85 * Default is all stack dumps go to the console and buffer. 86 86 * Lower level to send to log buffer only. 87 87 */ 88 - static int uv_nmi_loglevel = 7; 88 + static int uv_nmi_loglevel = CONSOLE_LOGLEVEL_DEFAULT; 89 89 module_param_named(dump_loglevel, uv_nmi_loglevel, int, 0644); 90 90 91 91 /*
+9 -9
drivers/nubus/nubus.c
··· 473 473 if (slot == 0 && (unsigned long)dir.base % 2) 474 474 dir.base += 1; 475 475 476 - if (console_loglevel >= 10) 476 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 477 477 printk(KERN_DEBUG "nubus_get_functional_resource: parent is 0x%p, dir is 0x%p\n", 478 478 parent->base, dir.base); 479 479 ··· 568 568 569 569 printk(KERN_INFO " video modes supported:\n"); 570 570 nubus_get_subdir(parent, &dir); 571 - if (console_loglevel >= 10) 571 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 572 572 printk(KERN_DEBUG "nubus_get_vidnames: parent is 0x%p, dir is 0x%p\n", 573 573 parent->base, dir.base); 574 574 ··· 629 629 630 630 printk(KERN_INFO " vendor info:\n"); 631 631 nubus_get_subdir(parent, &dir); 632 - if (console_loglevel >= 10) 632 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 633 633 printk(KERN_DEBUG "nubus_get_vendorinfo: parent is 0x%p, dir is 0x%p\n", 634 634 parent->base, dir.base); 635 635 ··· 654 654 struct nubus_dirent ent; 655 655 656 656 nubus_get_subdir(parent, &dir); 657 - if (console_loglevel >= 10) 657 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 658 658 printk(KERN_DEBUG "nubus_get_board_resource: parent is 0x%p, dir is 0x%p\n", 659 659 parent->base, dir.base); 660 660 ··· 753 753 if (nubus_readdir(&dir, &ent) == -1) 754 754 goto badrom; 755 755 756 - if (console_loglevel >= 10) 756 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 757 757 printk(KERN_INFO "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 758 758 /* This one takes us to where we want to go. */ 759 759 if (nubus_readdir(&dir, &ent) == -1) 760 760 goto badrom; 761 - if (console_loglevel >= 10) 761 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 762 762 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 763 763 nubus_get_subdir(&ent, &dir); 764 764 765 765 /* Resource ID 01, also an "Unknown Macintosh" */ 766 766 if (nubus_readdir(&dir, &ent) == -1) 767 767 goto badrom; 768 - if (console_loglevel >= 10) 768 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 769 769 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 770 770 771 771 /* FIXME: the first one is *not* always the right one. We ··· 780 780 path to that address... */ 781 781 if (nubus_readdir(&dir, &ent) == -1) 782 782 goto badrom; 783 - if (console_loglevel >= 10) 783 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) 784 784 printk(KERN_DEBUG "nubus_get_rom_dir: entry %02x %06x\n", ent.type, ent.data); 785 785 786 786 /* Bwahahahaha... */ ··· 816 816 board->fblock = rp; 817 817 818 818 /* Dump the format block for debugging purposes */ 819 - if (console_loglevel >= 10) { 819 + if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) { 820 820 int i; 821 821 printk(KERN_DEBUG "Slot %X, format block at 0x%p\n", 822 822 slot, rp);
+4 -4
drivers/tty/sysrq.c
··· 88 88 int i; 89 89 90 90 i = key - '0'; 91 - console_loglevel = 7; 91 + console_loglevel = CONSOLE_LOGLEVEL_DEFAULT; 92 92 printk("Loglevel set to %d\n", i); 93 93 console_loglevel = i; 94 94 } ··· 343 343 static void sysrq_handle_term(int key) 344 344 { 345 345 send_sig_all(SIGTERM); 346 - console_loglevel = 8; 346 + console_loglevel = CONSOLE_LOGLEVEL_DEBUG; 347 347 } 348 348 static struct sysrq_key_op sysrq_term_op = { 349 349 .handler = sysrq_handle_term, ··· 387 387 static void sysrq_handle_kill(int key) 388 388 { 389 389 send_sig_all(SIGKILL); 390 - console_loglevel = 8; 390 + console_loglevel = CONSOLE_LOGLEVEL_DEBUG; 391 391 } 392 392 static struct sysrq_key_op sysrq_kill_op = { 393 393 .handler = sysrq_handle_kill, ··· 520 520 * routing in the consumers of /proc/kmsg. 521 521 */ 522 522 orig_log_level = console_loglevel; 523 - console_loglevel = 7; 523 + console_loglevel = CONSOLE_LOGLEVEL_DEFAULT; 524 524 printk(KERN_INFO "SysRq : "); 525 525 526 526 op_p = __sysrq_get_key_op(key);
+13 -2
include/linux/printk.h
··· 30 30 return buffer; 31 31 } 32 32 33 + /* printk's without a loglevel use this.. */ 34 + #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL 35 + 36 + /* We show everything that is MORE important than this.. */ 37 + #define CONSOLE_LOGLEVEL_SILENT 0 /* Mum's the word */ 38 + #define CONSOLE_LOGLEVEL_MIN 1 /* Minimum loglevel we let people use */ 39 + #define CONSOLE_LOGLEVEL_QUIET 4 /* Shhh ..., when booted with "quiet" */ 40 + #define CONSOLE_LOGLEVEL_DEFAULT 7 /* anything MORE serious than KERN_DEBUG */ 41 + #define CONSOLE_LOGLEVEL_DEBUG 10 /* issue debug messages */ 42 + #define CONSOLE_LOGLEVEL_MOTORMOUTH 15 /* You can't shut this one up */ 43 + 33 44 extern int console_printk[]; 34 45 35 46 #define console_loglevel (console_printk[0]) ··· 50 39 51 40 static inline void console_silent(void) 52 41 { 53 - console_loglevel = 0; 42 + console_loglevel = CONSOLE_LOGLEVEL_SILENT; 54 43 } 55 44 56 45 static inline void console_verbose(void) 57 46 { 58 47 if (console_loglevel) 59 - console_loglevel = 15; 48 + console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; 60 49 } 61 50 62 51 struct va_format {
+2 -2
init/main.c
··· 203 203 204 204 static int __init debug_kernel(char *str) 205 205 { 206 - console_loglevel = 10; 206 + console_loglevel = CONSOLE_LOGLEVEL_DEBUG; 207 207 return 0; 208 208 } 209 209 210 210 static int __init quiet_kernel(char *str) 211 211 { 212 - console_loglevel = 4; 212 + console_loglevel = CONSOLE_LOGLEVEL_QUIET; 213 213 return 0; 214 214 } 215 215
+1 -1
kernel/debug/kdb/kdb_bt.c
··· 21 21 static void kdb_show_stack(struct task_struct *p, void *addr) 22 22 { 23 23 int old_lvl = console_loglevel; 24 - console_loglevel = 15; 24 + console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; 25 25 kdb_trap_printk++; 26 26 kdb_set_current_task(p); 27 27 if (addr) {
+1 -1
kernel/debug/kdb/kdb_io.c
··· 710 710 } 711 711 if (logging) { 712 712 saved_loglevel = console_loglevel; 713 - console_loglevel = 0; 713 + console_loglevel = CONSOLE_LOGLEVEL_SILENT; 714 714 printk(KERN_INFO "%s", kdb_buffer); 715 715 } 716 716
+1 -1
kernel/debug/kdb/kdb_main.c
··· 1091 1091 static void kdb_dumpregs(struct pt_regs *regs) 1092 1092 { 1093 1093 int old_lvl = console_loglevel; 1094 - console_loglevel = 15; 1094 + console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH; 1095 1095 kdb_trap_printk++; 1096 1096 show_regs(regs); 1097 1097 kdb_trap_printk--;
+3 -10
kernel/printk/printk.c
··· 54 54 #include "console_cmdline.h" 55 55 #include "braille.h" 56 56 57 - /* printk's without a loglevel use this.. */ 58 - #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL 59 - 60 - /* We show everything that is MORE important than this.. */ 61 - #define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */ 62 - #define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */ 63 - 64 57 int console_printk[4] = { 65 - DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */ 58 + CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ 66 59 DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */ 67 - MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */ 68 - DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ 60 + CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */ 61 + CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */ 69 62 }; 70 63 71 64 /* Deferred messaged from sched code are marked by this special level */