Path: blob/master/arch/x86/kernel/cpu/mcheck/mce-apei.c
10775 views
/*1* Bridge between MCE and APEI2*3* On some machine, corrected memory errors are reported via APEI4* generic hardware error source (GHES) instead of corrected Machine5* Check. These corrected memory errors can be reported to user space6* through /dev/mcelog via faking a corrected Machine Check, so that7* the error memory page can be offlined by /sbin/mcelog if the error8* count for one page is beyond the threshold.9*10* For fatal MCE, save MCE record into persistent storage via ERST, so11* that the MCE record can be logged after reboot via ERST.12*13* Copyright 2010 Intel Corp.14* Author: Huang Ying <[email protected]>15*16* This program is free software; you can redistribute it and/or17* modify it under the terms of the GNU General Public License version18* 2 as published by the Free Software Foundation.19*20* This program is distributed in the hope that it will be useful,21* but WITHOUT ANY WARRANTY; without even the implied warranty of22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the23* GNU General Public License for more details.24*25* You should have received a copy of the GNU General Public License26* along with this program; if not, write to the Free Software27* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA28*/2930#include <linux/kernel.h>31#include <linux/acpi.h>32#include <linux/cper.h>33#include <acpi/apei.h>34#include <asm/mce.h>3536#include "mce-internal.h"3738void apei_mce_report_mem_error(int corrected, struct cper_sec_mem_err *mem_err)39{40struct mce m;4142/* Only corrected MC is reported */43if (!corrected)44return;4546mce_setup(&m);47m.bank = 1;48/* Fake a memory read corrected error with unknown channel */49m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | 0x9f;50m.addr = mem_err->physical_addr;51mce_log(&m);52mce_notify_irq();53}54EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);5556#define CPER_CREATOR_MCE \57UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \580x64, 0x90, 0xb8, 0x9d)59#define CPER_SECTION_TYPE_MCE \60UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \610x04, 0x4a, 0x38, 0xfc)6263/*64* CPER specification (in UEFI specification 2.3 appendix N) requires65* byte-packed.66*/67struct cper_mce_record {68struct cper_record_header hdr;69struct cper_section_descriptor sec_hdr;70struct mce mce;71} __packed;7273int apei_write_mce(struct mce *m)74{75struct cper_mce_record rcd;7677memset(&rcd, 0, sizeof(rcd));78memcpy(rcd.hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);79rcd.hdr.revision = CPER_RECORD_REV;80rcd.hdr.signature_end = CPER_SIG_END;81rcd.hdr.section_count = 1;82rcd.hdr.error_severity = CPER_SEV_FATAL;83/* timestamp, platform_id, partition_id are all invalid */84rcd.hdr.validation_bits = 0;85rcd.hdr.record_length = sizeof(rcd);86rcd.hdr.creator_id = CPER_CREATOR_MCE;87rcd.hdr.notification_type = CPER_NOTIFY_MCE;88rcd.hdr.record_id = cper_next_record_id();89rcd.hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR;9091rcd.sec_hdr.section_offset = (void *)&rcd.mce - (void *)&rcd;92rcd.sec_hdr.section_length = sizeof(rcd.mce);93rcd.sec_hdr.revision = CPER_SEC_REV;94/* fru_id and fru_text is invalid */95rcd.sec_hdr.validation_bits = 0;96rcd.sec_hdr.flags = CPER_SEC_PRIMARY;97rcd.sec_hdr.section_type = CPER_SECTION_TYPE_MCE;98rcd.sec_hdr.section_severity = CPER_SEV_FATAL;99100memcpy(&rcd.mce, m, sizeof(*m));101102return erst_write(&rcd.hdr);103}104105ssize_t apei_read_mce(struct mce *m, u64 *record_id)106{107struct cper_mce_record rcd;108int rc, pos;109110rc = erst_get_record_id_begin(&pos);111if (rc)112return rc;113retry:114rc = erst_get_record_id_next(&pos, record_id);115if (rc)116goto out;117/* no more record */118if (*record_id == APEI_ERST_INVALID_RECORD_ID)119goto out;120rc = erst_read(*record_id, &rcd.hdr, sizeof(rcd));121/* someone else has cleared the record, try next one */122if (rc == -ENOENT)123goto retry;124else if (rc < 0)125goto out;126/* try to skip other type records in storage */127else if (rc != sizeof(rcd) ||128uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE))129goto retry;130memcpy(m, &rcd.mce, sizeof(*m));131rc = sizeof(*m);132out:133erst_get_record_id_end();134135return rc;136}137138/* Check whether there is record in ERST */139int apei_check_mce(void)140{141return erst_get_record_count();142}143144int apei_clear_mce(u64 record_id)145{146return erst_clear(record_id);147}148149150