~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/kernel/cpu/mce/apei.c

Version: ~ [ linux-5.6-rc3 ] ~ [ linux-5.5.6 ] ~ [ linux-5.4.22 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.106 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.171 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.214 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.214 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.82 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Bridge between MCE and APEI
  3  *
  4  * On some machine, corrected memory errors are reported via APEI
  5  * generic hardware error source (GHES) instead of corrected Machine
  6  * Check. These corrected memory errors can be reported to user space
  7  * through /dev/mcelog via faking a corrected Machine Check, so that
  8  * the error memory page can be offlined by /sbin/mcelog if the error
  9  * count for one page is beyond the threshold.
 10  *
 11  * For fatal MCE, save MCE record into persistent storage via ERST, so
 12  * that the MCE record can be logged after reboot via ERST.
 13  *
 14  * Copyright 2010 Intel Corp.
 15  *   Author: Huang Ying <ying.huang@intel.com>
 16  *
 17  * This program is free software; you can redistribute it and/or
 18  * modify it under the terms of the GNU General Public License version
 19  * 2 as published by the Free Software Foundation.
 20  *
 21  * This program is distributed in the hope that it will be useful,
 22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 24  * GNU General Public License for more details.
 25  *
 26  * You should have received a copy of the GNU General Public License
 27  * along with this program; if not, write to the Free Software
 28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 29  */
 30 
 31 #include <linux/export.h>
 32 #include <linux/kernel.h>
 33 #include <linux/acpi.h>
 34 #include <linux/cper.h>
 35 #include <acpi/apei.h>
 36 #include <acpi/ghes.h>
 37 #include <asm/mce.h>
 38 
 39 #include "internal.h"
 40 
 41 void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
 42 {
 43         struct mce m;
 44 
 45         if (!(mem_err->validation_bits & CPER_MEM_VALID_PA))
 46                 return;
 47 
 48         mce_setup(&m);
 49         m.bank = -1;
 50         /* Fake a memory read error with unknown channel */
 51         m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | 0x9f;
 52 
 53         if (severity >= GHES_SEV_RECOVERABLE)
 54                 m.status |= MCI_STATUS_UC;
 55 
 56         if (severity >= GHES_SEV_PANIC) {
 57                 m.status |= MCI_STATUS_PCC;
 58                 m.tsc = rdtsc();
 59         }
 60 
 61         m.addr = mem_err->physical_addr;
 62         mce_log(&m);
 63 }
 64 EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
 65 
 66 #define CPER_CREATOR_MCE                                                \
 67         UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c,     \
 68                 0x64, 0x90, 0xb8, 0x9d)
 69 #define CPER_SECTION_TYPE_MCE                                           \
 70         UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96,     \
 71                 0x04, 0x4a, 0x38, 0xfc)
 72 
 73 /*
 74  * CPER specification (in UEFI specification 2.3 appendix N) requires
 75  * byte-packed.
 76  */
 77 struct cper_mce_record {
 78         struct cper_record_header hdr;
 79         struct cper_section_descriptor sec_hdr;
 80         struct mce mce;
 81 } __packed;
 82 
 83 int apei_write_mce(struct mce *m)
 84 {
 85         struct cper_mce_record rcd;
 86 
 87         memset(&rcd, 0, sizeof(rcd));
 88         memcpy(rcd.hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
 89         rcd.hdr.revision = CPER_RECORD_REV;
 90         rcd.hdr.signature_end = CPER_SIG_END;
 91         rcd.hdr.section_count = 1;
 92         rcd.hdr.error_severity = CPER_SEV_FATAL;
 93         /* timestamp, platform_id, partition_id are all invalid */
 94         rcd.hdr.validation_bits = 0;
 95         rcd.hdr.record_length = sizeof(rcd);
 96         rcd.hdr.creator_id = CPER_CREATOR_MCE;
 97         rcd.hdr.notification_type = CPER_NOTIFY_MCE;
 98         rcd.hdr.record_id = cper_next_record_id();
 99         rcd.hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR;
100 
101         rcd.sec_hdr.section_offset = (void *)&rcd.mce - (void *)&rcd;
102         rcd.sec_hdr.section_length = sizeof(rcd.mce);
103         rcd.sec_hdr.revision = CPER_SEC_REV;
104         /* fru_id and fru_text is invalid */
105         rcd.sec_hdr.validation_bits = 0;
106         rcd.sec_hdr.flags = CPER_SEC_PRIMARY;
107         rcd.sec_hdr.section_type = CPER_SECTION_TYPE_MCE;
108         rcd.sec_hdr.section_severity = CPER_SEV_FATAL;
109 
110         memcpy(&rcd.mce, m, sizeof(*m));
111 
112         return erst_write(&rcd.hdr);
113 }
114 
115 ssize_t apei_read_mce(struct mce *m, u64 *record_id)
116 {
117         struct cper_mce_record rcd;
118         int rc, pos;
119 
120         rc = erst_get_record_id_begin(&pos);
121         if (rc)
122                 return rc;
123 retry:
124         rc = erst_get_record_id_next(&pos, record_id);
125         if (rc)
126                 goto out;
127         /* no more record */
128         if (*record_id == APEI_ERST_INVALID_RECORD_ID)
129                 goto out;
130         rc = erst_read(*record_id, &rcd.hdr, sizeof(rcd));
131         /* someone else has cleared the record, try next one */
132         if (rc == -ENOENT)
133                 goto retry;
134         else if (rc < 0)
135                 goto out;
136         /* try to skip other type records in storage */
137         else if (rc != sizeof(rcd) ||
138                  uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE))
139                 goto retry;
140         memcpy(m, &rcd.mce, sizeof(*m));
141         rc = sizeof(*m);
142 out:
143         erst_get_record_id_end();
144 
145         return rc;
146 }
147 
148 /* Check whether there is record in ERST */
149 int apei_check_mce(void)
150 {
151         return erst_get_record_count();
152 }
153 
154 int apei_clear_mce(u64 record_id)
155 {
156         return erst_clear(record_id);
157 }
158 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp