From a073a32cad0351f93ed27d24f0f1cd1af80000a5 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Tue, 19 Mar 2013 02:29:01 +0000 Subject: [PATCH] kmsg_dump: Only dump kernel log in error cases (Closes: #703386) - kexec: remove KMSG_DUMP_KEXEC - kmsg_dump: don't run on non-error paths by default Ignore ABI change to kmsg_dump_{,un}register(); I don't think these should be used from OOT and codesearch doesn't find any users. svn path=/dists/sid/linux/; revision=19917 --- debian/changelog | 3 + debian/config/defines | 3 + .../all/kexec-remove-KMSG_DUMP_KEXEC.patch | 100 +++++++++++++++++ ...-t-run-on-non-error-paths-by-default.patch | 105 ++++++++++++++++++ debian/patches/series | 2 + 5 files changed, 213 insertions(+) create mode 100644 debian/patches/bugfix/all/kexec-remove-KMSG_DUMP_KEXEC.patch create mode 100644 debian/patches/bugfix/all/kmsg_dump-don-t-run-on-non-error-paths-by-default.patch diff --git a/debian/changelog b/debian/changelog index bec3e7163..61c0f1327 100644 --- a/debian/changelog +++ b/debian/changelog @@ -68,6 +68,9 @@ linux (3.2.40-1) UNRELEASED; urgency=low * efi: Ensure efivars is loaded on EFI systems (Closes: #703363) - [x86] Use a platform device to trigger loading of efivars - [ia64] Change EFI_VARS from module to built-in + * kmsg_dump: Only dump kernel log in error cases (Closes: #703386) + - kexec: remove KMSG_DUMP_KEXEC + - kmsg_dump: don't run on non-error paths by default -- Ben Hutchings Wed, 27 Feb 2013 03:48:30 +0000 diff --git a/debian/config/defines b/debian/config/defines index 528016f7f..9231cef30 100644 --- a/debian/config/defines +++ b/debian/config/defines @@ -41,6 +41,9 @@ ignore-changes: module:drivers/staging/* # Private to this family of drivers module:drivers/net/wireless/rtlwifi/* +# Should not be used from OOT + kmsg_dump_register + kmsg_dump_unregister [base] arches: diff --git a/debian/patches/bugfix/all/kexec-remove-KMSG_DUMP_KEXEC.patch b/debian/patches/bugfix/all/kexec-remove-KMSG_DUMP_KEXEC.patch new file mode 100644 index 000000000..186fe31ac --- /dev/null +++ b/debian/patches/bugfix/all/kexec-remove-KMSG_DUMP_KEXEC.patch @@ -0,0 +1,100 @@ +From: WANG Cong +Date: Thu, 12 Jan 2012 17:20:11 -0800 +Subject: kexec: remove KMSG_DUMP_KEXEC + +commit a3dd3323058d281abd584b15ad4c5b65064d7a61 upstream. + +KMSG_DUMP_KEXEC is useless because we already save kernel messages inside +/proc/vmcore, and it is unsafe to allow modules to do other stuffs in a +crash dump scenario. + +[akpm@linux-foundation.org: fix powerpc build] +Signed-off-by: WANG Cong +Reported-by: Vivek Goyal +Acked-by: Vivek Goyal +Acked-by: Jarod Wilson +Cc: "Eric W. Biederman" +Cc: KOSAKI Motohiro +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +--- + arch/powerpc/platforms/pseries/nvram.c | 1 - + drivers/char/ramoops.c | 3 +-- + drivers/mtd/mtdoops.c | 3 +-- + include/linux/kmsg_dump.h | 1 - + kernel/kexec.c | 3 --- + 5 files changed, 2 insertions(+), 9 deletions(-) + +diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c +index 330a57b..36f957f 100644 +--- a/arch/powerpc/platforms/pseries/nvram.c ++++ b/arch/powerpc/platforms/pseries/nvram.c +@@ -638,7 +638,6 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, + /* These are almost always orderly shutdowns. */ + return; + case KMSG_DUMP_OOPS: +- case KMSG_DUMP_KEXEC: + break; + case KMSG_DUMP_PANIC: + panicking = true; +diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c +index 7c7f42a1f8..feda90c 100644 +--- a/drivers/char/ramoops.c ++++ b/drivers/char/ramoops.c +@@ -83,8 +83,7 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper, + struct timeval timestamp; + + if (reason != KMSG_DUMP_OOPS && +- reason != KMSG_DUMP_PANIC && +- reason != KMSG_DUMP_KEXEC) ++ reason != KMSG_DUMP_PANIC) + return; + + /* Only dump oopses if dump_oops is set */ +diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c +index db8e827..3ce99e0 100644 +--- a/drivers/mtd/mtdoops.c ++++ b/drivers/mtd/mtdoops.c +@@ -315,8 +315,7 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, + char *dst; + + if (reason != KMSG_DUMP_OOPS && +- reason != KMSG_DUMP_PANIC && +- reason != KMSG_DUMP_KEXEC) ++ reason != KMSG_DUMP_PANIC) + return; + + /* Only dump oopses if dump_oops is set */ +diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h +index ee0c952..fee6631 100644 +--- a/include/linux/kmsg_dump.h ++++ b/include/linux/kmsg_dump.h +@@ -18,7 +18,6 @@ + enum kmsg_dump_reason { + KMSG_DUMP_OOPS, + KMSG_DUMP_PANIC, +- KMSG_DUMP_KEXEC, + KMSG_DUMP_RESTART, + KMSG_DUMP_HALT, + KMSG_DUMP_POWEROFF, +diff --git a/kernel/kexec.c b/kernel/kexec.c +index 090ee10..20ed47a 100644 +--- a/kernel/kexec.c ++++ b/kernel/kexec.c +@@ -32,7 +32,6 @@ + #include + #include + #include +-#include + #include + + #include +@@ -1094,8 +1093,6 @@ void crash_kexec(struct pt_regs *regs) + if (kexec_crash_image) { + struct pt_regs fixed_regs; + +- kmsg_dump(KMSG_DUMP_KEXEC); +- + crash_setup_regs(&fixed_regs, regs); + crash_save_vmcoreinfo(); + machine_crash_shutdown(&fixed_regs); diff --git a/debian/patches/bugfix/all/kmsg_dump-don-t-run-on-non-error-paths-by-default.patch b/debian/patches/bugfix/all/kmsg_dump-don-t-run-on-non-error-paths-by-default.patch new file mode 100644 index 000000000..273e673fe --- /dev/null +++ b/debian/patches/bugfix/all/kmsg_dump-don-t-run-on-non-error-paths-by-default.patch @@ -0,0 +1,105 @@ +From: Matthew Garrett +Date: Mon, 5 Mar 2012 14:59:10 -0800 +Subject: kmsg_dump: don't run on non-error paths by default + +commit c22ab332902333f83766017478c1ef6607ace681 upstream. + +Since commit 04c6862c055f ("kmsg_dump: add kmsg_dump() calls to the +reboot, halt, poweroff and emergency_restart paths"), kmsg_dump() gets +run on normal paths including poweroff and reboot. + +This is less than ideal given pstore implementations that can only +represent single backtraces, since a reboot may overwrite a stored oops +before it's been picked up by userspace. In addition, some pstore +backends may have low performance and provide a significant delay in +reboot as a result. + +This patch adds a printk.always_kmsg_dump kernel parameter (which can also +be changed from userspace). Without it, the code will only be run on +failure paths rather than on normal paths. The option can be enabled in +environments where there's a desire to attempt to audit whether or not a +reboot was cleanly requested or not. + +Signed-off-by: Matthew Garrett +Acked-by: Seiji Aguchi +Cc: Seiji Aguchi +Cc: David Woodhouse +Cc: Marco Stornelli +Cc: Artem Bityutskiy +Cc: KOSAKI Motohiro +Cc: Vivek Goyal +Cc: Don Zickus +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +--- + Documentation/kernel-parameters.txt | 6 ++++++ + include/linux/kmsg_dump.h | 9 +++++++-- + kernel/printk.c | 6 ++++++ + 3 files changed, 19 insertions(+), 2 deletions(-) + +diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt +index 033d4e6..d99fd9c 100644 +--- a/Documentation/kernel-parameters.txt ++++ b/Documentation/kernel-parameters.txt +@@ -2211,6 +2211,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted. + + default: off. + ++ printk.always_kmsg_dump= ++ Trigger kmsg_dump for cases other than kernel oops or ++ panics ++ Format: (1/Y/y=enable, 0/N/n=disable) ++ default: disabled ++ + printk.time= Show timing data prefixed to each printk message line + Format: (1/Y/y=enable, 0/N/n=disable) + +diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h +index fee6631..35f7237 100644 +--- a/include/linux/kmsg_dump.h ++++ b/include/linux/kmsg_dump.h +@@ -15,13 +15,18 @@ + #include + #include + ++/* ++ * Keep this list arranged in rough order of priority. Anything listed after ++ * KMSG_DUMP_OOPS will not be logged by default unless printk.always_kmsg_dump ++ * is passed to the kernel. ++ */ + enum kmsg_dump_reason { +- KMSG_DUMP_OOPS, + KMSG_DUMP_PANIC, ++ KMSG_DUMP_OOPS, ++ KMSG_DUMP_EMERG, + KMSG_DUMP_RESTART, + KMSG_DUMP_HALT, + KMSG_DUMP_POWEROFF, +- KMSG_DUMP_EMERG, + }; + + /** +diff --git a/kernel/printk.c b/kernel/printk.c +index 13c0a11..32690a0 100644 +--- a/kernel/printk.c ++++ b/kernel/printk.c +@@ -702,6 +702,9 @@ static bool printk_time = 0; + #endif + module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR); + ++static bool always_kmsg_dump; ++module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR); ++ + /* Check if we have any console registered that can be called early in boot. */ + static int have_callable_console(void) + { +@@ -1732,6 +1735,9 @@ void kmsg_dump(enum kmsg_dump_reason reason) + unsigned long l1, l2; + unsigned long flags; + ++ if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump) ++ return; ++ + /* Theoretically, the log could move on after we do this, but + there's not a lot we can do about that. The new messages + will overwrite the start of what we dump. */ diff --git a/debian/patches/series b/debian/patches/series index 29a13fc5c..5f2d312df 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -616,3 +616,5 @@ features/x86/efi-stub/0019-x86-efi-Fix-processor-specific-memcpy-build-error.pat debian/pps-avoid-abi-change-in-3.2.40.patch bugfix/x86/drm-i915-Unconditionally-initialise-the-interrupt-wo.patch debian/efi-autoload-efivars.patch +bugfix/all/kexec-remove-KMSG_DUMP_KEXEC.patch +bugfix/all/kmsg_dump-don-t-run-on-non-error-paths-by-default.patch