Blame 0019-Fix-handling-of-Machine-Check-Exceptions.patch

69165ba
From 744e4c6a6cbbb9ba0569bf8e3ab50171e974b2e3 Mon Sep 17 00:00:00 2001
69165ba
From: Denys Vlasenko <dvlasenk@redhat.com>
69165ba
Date: Mon, 6 Jan 2014 17:18:31 +0100
69165ba
Subject: [ABRT PATCH 19/27] Fix handling of Machine Check Exceptions.
69165ba
69165ba
Closes #764.
69165ba
69165ba
If non-fatal MCE is seen, abrt will detect it as an oops
69165ba
and alert user in a usual manner. When user opens this
69165ba
abrt problem for reporting, he will see that "comment"
69165ba
field is pre-filled with a text.
69165ba
What it says depends on whether mcelog tool is installed.
69165ba
If mcelog is installed, the text will say that hardware errors
69165ba
were detected, and will show the tail of either /var/log/mcelog
69165ba
or syslog.
69165ba
Otherwise the text will say that hardware errors
69165ba
were detected, but they can't be usefully diagnosed,
69165ba
and user is strongly advised to install mcelog tool.
69165ba
69165ba
If fatal MCE is encountered, kernel always panics,
69165ba
(abrt has no chance of catching the oops),
69165ba
kdump kicks in, and then after reboot abrt says that new vmcore
69165ba
is found. When user generates backtrace, he will see oops text
69165ba
which starts with
69165ba
"Machine Check Exception: BANK nnn ..." and (hopefully)
69165ba
is already explanatory enough.
69165ba
69165ba
(Yes, it's weird that kernel shows human-readable error messages
69165ba
on fatal MCEs but doesn't do that for non-fatal ones.
69165ba
This makes fetching MCE info significantly different...
69165ba
I wish kernel would show human-readable MCEs in both cases,
69165ba
we wouldn't need mcelog then... oh well.)
69165ba
69165ba
In order to generate meaningful hash for MCE's,
69165ba
oops hashing was extended for oopses without backtraces.
69165ba
69165ba
Since MCEs, unlike regular oopses, don't contain kernel version,
69165ba
additional magic is added to extract kernel version
69165ba
in vmcore event handling.
69165ba
69165ba
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
69165ba
69165ba
Related to rhbz#1032077
69165ba
69165ba
Signed-off-by: Jakub Filak <jfilak@redhat.com>
69165ba
---
69165ba
 src/lib/kernel.c              | 31 +++++++++++++++++++++++++
69165ba
 src/plugins/koops_event.conf  | 54 +++++++++++++++++++++++++++++++++++++++++++
69165ba
 src/plugins/vmcore_event.conf | 18 ++++++++++++++-
69165ba
 3 files changed, 102 insertions(+), 1 deletion(-)
69165ba
69165ba
diff --git a/src/lib/kernel.c b/src/lib/kernel.c
69165ba
index ce8815b..340ec39 100644
69165ba
--- a/src/lib/kernel.c
69165ba
+++ b/src/lib/kernel.c
69165ba
@@ -115,8 +115,29 @@ static const char *const s_koops_suspicious_strings[] = {
69165ba
      * arch/x86/kernel/cpu/mcheck/p5.c:		"CPU#%d: Machine Check Exception:  0x%8X (type 0x%8X).\n",
69165ba
      * arch/x86/kernel/cpu/mcheck/mce.c:	pr_emerg(HW_ERR "CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n",
69165ba
      * drivers/edac/sb_edac.c:			printk("CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n",
69165ba
+     *
69165ba
+     * MCEs can be fatal (they panic kernel) or not.
69165ba
+     * Fatal MCE are delivered as exception#18 to the CPU.
69165ba
+     * Non-fatal ones sometimes are delivered as exception#18;
69165ba
+     * other times they are silently recorded in magic MSRs, CPU is not alerted.
69165ba
+     * Linux kernel periodically (up to 5 mins interval) reads those MSRs
69165ba
+     * and if MCE is seen there, it is piped in binary form through
69165ba
+     * /dev/mcelog to whoever listens on it. (Such as mcelog tool in --daemon
69165ba
+     * mode; but cat 
69165ba
+     *
69165ba
+     * "Machine Check Exception:" message is printed *only*
69165ba
+     * by fatal MCEs (so far, future kernels may be different).
69165ba
+     * It will be caught as vmcore if kdump is configured.
69165ba
+     *
69165ba
+     * Non-fatal MCEs have "[Hardware Error]: Machine check events logged"
69165ba
+     * message in kernel log.
69165ba
+     * When /dev/mcelog is read, *no additional kernel log messages appear*:
69165ba
+     * if we want more readable data, we must rely on other tools
69165ba
+     * (such as mcelog daemon consuming binary /dev/mcelog and writing
69165ba
+     * human-readable /var/log/mcelog).
69165ba
      */
69165ba
     "Machine Check Exception:",
69165ba
+    "Machine check events logged",
69165ba
 
69165ba
     /* X86 TRAPs */
69165ba
     "divide error:",
69165ba
@@ -299,6 +320,16 @@ next_line:
69165ba
             if (strcasestr(curline, "Call Trace:")) /* yes, it must be case-insensitive */
69165ba
                 inbacktrace = 1;
69165ba
             else
69165ba
+            /* Fatal MCE's have a few lines of useful information between
69165ba
+             * first "Machine check exception:" line and the final "Kernel panic"
69165ba
+             * line. Such oops, of course, is only detectable in kdumps (tested)
69165ba
+             * or possibly pstore-saved logs (I did not try this yet).
69165ba
+             * In order to capture all these lines, we treat final line
69165ba
+             * as "backtrace" (which is admittedly a hack):
69165ba
+             */
69165ba
+            if (strstr(curline, "Kernel panic - not syncing"))
69165ba
+                inbacktrace = 1;
69165ba
+            else
69165ba
             if (strnlen(curline, 9) > 8
69165ba
              && (  (curline[0] == '(' && curline[1] == '[' && curline[2] == '<')
69165ba
                 || (curline[0] == '[' && curline[1] == '<'))
69165ba
diff --git a/src/plugins/koops_event.conf b/src/plugins/koops_event.conf
69165ba
index c0277c8..7dfbe36 100644
69165ba
--- a/src/plugins/koops_event.conf
69165ba
+++ b/src/plugins/koops_event.conf
69165ba
@@ -4,6 +4,60 @@ EVENT=post-create analyzer=Kerneloops
69165ba
         abrt-action-analyze-oops &&
69165ba
         dmesg >>dmesg &&
69165ba
         abrt-action-save-kernel-data
69165ba
+        abrt-action-save-kernel-data || exit $?
69165ba
+        #
69165ba
+        # If it exists, we can save a copy of MCE log here:
69165ba
+        #test -f /var/log/mcelog && cp /var/log/mcelog .
69165ba
+        # but in current config, sosreport already does that.
69165ba
+        #
69165ba
+        # See if MCEs were seen but mcelog isn't installed or running
69165ba
+        grep -qFi 'Machine check events logged' dmesg || exit 0
69165ba
+        #
69165ba
+        # There was an MCE. IOW: it's not a bug, it's a HW error.
69165ba
+        # Did mcelog logged it to /var/log/mcelog
69165ba
+        # (RHEL6 by default does this)?
69165ba
+        test -f /var/log/mcelog &&
69165ba
+        {
69165ba
+                # (Ab)use user comment field to inform user about it.
69165ba
+                echo "The kernel log indicates that hardware errors were detected."
69165ba
+                echo "/var/log/mcelog file may have more information."
69165ba
+                echo "The last 20 lines of /var/log/mcelog are:"
69165ba
+                echo "========================================="
69165ba
+                # Redirecting sterr in case selinux makes it unreadable
69165ba
+                # (annoying anyway, but at least user knows what's going on):
69165ba
+                tail -n20 /var/log/mcelog 2>&1
69165ba
+                exit 0
69165ba
+        } >comment
69165ba
+        #
69165ba
+        # On RHEL7, mcelog is run so that its output ends up in syslog.
69165ba
+        # Do we see that?
69165ba
+        grep -qFi 'mcelog: Hardware event' /var/log/messages &&
69165ba
+        {
69165ba
+                echo "The kernel log indicates that hardware errors were detected."
69165ba
+                echo "System log may have more information."
69165ba
+                echo "The last 20 mcelog lines of system log are:"
69165ba
+                echo "========================================="
69165ba
+                # Redirecting sterr in case selinux makes it unreadable
69165ba
+                # (annoying anyway, but at least user knows what's going on):
69165ba
+                grep -Fi 'mcelog:' /var/log/messages | tail -n20 2>&1
69165ba
+                exit 0
69165ba
+        } >comment
69165ba
+        #
69165ba
+        # Apparently, there is no running mcelog daemon!
69165ba
+        # Let user know that he needs one.
69165ba
+        {
69165ba
+        echo "The kernel log indicates that hardware errors were detected."
69165ba
+        echo "The data was saved by kernel for processing by the mcelog tool."
69165ba
+        echo "However, neither /var/log/mcelog nor system log contain mcelog messages."
69165ba
+        echo "Most likely reason is that mcelog is not installed or not configured"
69165ba
+        echo "to be started during boot."
69165ba
+        echo "Without this tool running, the binary data saved by kernel"
69165ba
+        echo "is of limited usefulness."
69165ba
+        echo "(You can save this data anyway by running 'cat </dev/mcelog >FILE')."
69165ba
+        echo "The recommended course of action is to install mcelog."
69165ba
+        echo "If another hardware error would occur, a user-readable description"
69165ba
+        echo "of it will be saved in system log or /var/log/mcelog."
69165ba
+        } >comment
69165ba
 
69165ba
 # If you want behavior similar to one provided by kerneloops daemon
69165ba
 # distributed by kerneloops.org - that is, if you want
69165ba
diff --git a/src/plugins/vmcore_event.conf b/src/plugins/vmcore_event.conf
69165ba
index f8de3c5..655d842 100644
69165ba
--- a/src/plugins/vmcore_event.conf
69165ba
+++ b/src/plugins/vmcore_event.conf
69165ba
@@ -1,6 +1,22 @@
69165ba
 # analyze
69165ba
 EVENT=analyze_VMcore analyzer=vmcore
69165ba
-        abrt-action-analyze-vmcore &&
69165ba
+        # If kdump machinery already extracted dmesg...
69165ba
+        if test -f vmcore-dmesg.txt; then
69165ba
+            # ...use that
69165ba
+            abrt-dump-oops -o vmcore-dmesg.txt >backtrace || exit $?
69165ba
+            #
69165ba
+            # Does "kernel" element exist?
69165ba
+            test -f kernel && exit 0
69165ba
+            #
69165ba
+            # Try creating it from vmcore-dmesg.txt:
69165ba
+            # MCE oopses don't have kernel version in them,
69165ba
+            # but it should be specified earlier in the log.
69165ba
+            k=`sed -n '/Linux version/ s/.*Linux version \([^ ]*\) .*/\1/p' vmcore-dmesg.txt | tail -n1`
69165ba
+            test "$k" != "" && printf "%s" "$k" >kernel
69165ba
+        else
69165ba
+            # No vmcore-dmesg.txt, do it the hard way:
69165ba
+            abrt-action-analyze-vmcore
69165ba
+        fi &&
69165ba
         abrt-action-analyze-oops &&
69165ba
         abrt-action-save-kernel-data
69165ba
 
69165ba
-- 
69165ba
1.8.3.1
69165ba