Skip to contentSkip to conversation

ACPI, APEI support

PATCH New Huang Ying 2 participants 14 messages Apr 27, 2010 – May 11, 2010

Subsystems (10)
Documentation x86 ACPI PCI +6 more subsystems
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

This patchset adds the APEI (ACPI Platform Error Interface) support to Linux kernel.

01-06 include the basic APEI HEST parsing and EINJ support. They have been posted to mailing list before and get some reviews and ACKs. Changes since the last post are as follow.

- Make APEI infrastructure and HEST parsing configurable built-in instead of modules to solve some dependency issues.

- Some minor fixes, such as printk

07-10 are newly added to support GHES (Generic Hardware Error Source) corrected memory error. On some machines, Machine Check can not report physical address for some corrected memory errors, but GHES can do that. So this simplified GHES is implemented and posted firstly.

11-12 are newly added to support using ERST for persistent storage of MCE. This can improve fatal MCE report.

[PATCH 01/12] ACPI, IO memory pre-mapping and atomic accessing
[PATCH 02/12] ACPI, APEI, APEI supporting infrastructure
[PATCH 03/12] ACPI, APEI, HEST table parsing
[PATCH 04/12] ACPI, APEI, EINJ support
[PATCH 05/12] ACPI, APEI, Document for APEI
[PATCH 06/12] ACPI, APEI, PCIE AER, use general HEST table parsing in AER firmware_first setup [PATCH 07/12] ACPI Hardware Error Device (PNP0C33) support
[PATCH 08/12] Unified UUID/GUID definition
[PATCH 09/12] ACPI, APEI, UEFI Common Platform Error Record (CPER) header [PATCH 10/12] ACPI, APEI, Generic Hardware Error Source memory error support [PATCH 11/12] ACPI, APEI, Error Record Serialization Table (ERST) support [PATCH 12/12] ACPI, APEI, Use ERST for persistent storage of MCE

author
#1 lore raw

PATCH 1/12 ACPI, IO memory pre-mapping and atomic accessing

Some ACPI IO accessing need to be done in atomic context. For example, APEI ERST operations may be used for permanent storage in hardware error handler. That is, it may be called in atomic contexts such as IRQ or NMI, etc. And, ERST/EINJ implement their operations via IO memory/port accessing. But the IO memory accessing method provided by ACPI (acpi_read/acpi_write) maps the IO memory during it is accessed, so it can not be used in atomic context. To solve the issue, the IO memory should be pre-mapped during EINJ/ERST initializing. A linked list is used to record which memory area has been mapped, when memory is accessed in hardware error handler, search the linked list for the mapped virtual address from the given physical address.

---
 drivers/acpi/Makefile   |    1 
 drivers/acpi/atomicio.c |  360 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/atomicio.h |   10 +
 3 files changed, 371 insertions(+)
 create mode 100644 drivers/acpi/atomicio.c
 create mode 100644 include/acpi/atomicio.h
drivers/acpi/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-y				+= acpi.o \
 
 # All the builtin files are in the "acpi." module_param namespace.
 acpi-y				+= osl.o utils.o reboot.o
+acpi-y				+= atomicio.o
 acpi-y				+= hest.o
 
 # sleep related files
drivers/acpi/atomicio.c new file +360 -0

360 lines not on this page · raw message

include/acpi/atomicio.h new file +10 -0
@@ -0,0 +1,10 @@
+#ifndef ACPI_ATOMIC_IO_H
+#define ACPI_ATOMIC_IO_H
+
+int acpi_pre_map_gar(struct acpi_generic_address *reg);
+int acpi_post_unmap_gar(struct acpi_generic_address *reg);
+
+int acpi_atomic_read(u64 *val, struct acpi_generic_address *reg);
+int acpi_atomic_write(u64 val, struct acpi_generic_address *reg);
+
+#endif
author
#2 lore raw

PATCH 2/12 ACPI, APEI, APEI supporting infrastructure

In reply to Huang Ying

APEI stands for ACPI Platform Error Interface, which allows to report errors (for example from the chipset) to the operating system. This improves NMI handling especially. In addition it supports error serialization and error injection.

For more information about APEI, please refer to ACPI Specification version 4.0, chapter 17.

This patch provides some common functions used by more than one APEI tables, mainly framework of interpreter for EINJ and ERST.

A machine readable language is defined for EINJ and ERST for OS to execute, and so to drive the firmware to fulfill the corresponding functions. The machine language for EINJ and ERST is compatible, so a common framework is defined for them.

---
 drivers/acpi/Kconfig              |    2 
 drivers/acpi/Makefile             |    2 
 drivers/acpi/apei/Kconfig         |    9 
 drivers/acpi/apei/Makefile        |    3 
 drivers/acpi/apei/apei-base.c     |  593 ++++++++++++++++++++++++++++++++++++++
 drivers/acpi/apei/apei-internal.h |   95 ++++++
 6 files changed, 704 insertions(+)
 create mode 100644 drivers/acpi/apei/Kconfig
 create mode 100644 drivers/acpi/apei/Makefile
 create mode 100644 drivers/acpi/apei/apei-base.c
 create mode 100644 drivers/acpi/apei/apei-internal.h
drivers/acpi/Kconfig +2 -0
@@ -360,4 +360,6 @@ config ACPI_SBS
 	  To compile this driver as a module, choose M here:
 	  the modules will be called sbs and sbshc.
 
+source "drivers/acpi/apei/Kconfig"
+
 endif	# ACPI
drivers/acpi/Makefile +2 -0
@@ -67,3 +67,5 @@ processor-y			+= processor_idle.o proces
 processor-$(CONFIG_CPU_FREQ)	+= processor_perflib.o
 
 obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o
+
+obj-$(CONFIG_ACPI_APEI)		+= apei/
drivers/acpi/apei/Kconfig new file +9 -0
@@ -0,0 +1,9 @@
+config ACPI_APEI
+	bool "ACPI Platform Error Interface (APEI)"
+	depends on X86
+	help
+	  APEI allows to report errors (for example from the chipset)
+	  to the operating system. This improves NMI handling
+	  especially. In addition it supports error serialization and
+	  error injection.
+
drivers/acpi/apei/Makefile new file +3 -0
@@ -0,0 +1,3 @@
+obj-$(CONFIG_ACPI_APEI)		+= apei.o
+
+apei-y := apei-base.o
drivers/acpi/apei/apei-base.c new file +593 -0

593 lines not on this page · raw message

drivers/acpi/apei/apei-internal.h new file +95 -0

95 lines not on this page · raw message

author
#3 lore raw

PATCH 3/12 ACPI, APEI, HEST table parsing

In reply to Huang Ying

HEST describes error sources in detail; communicating operational parameters (i.e. severity levels, masking bits, and threshold values) to OS as necessary. It also allows the platform to report error sources for which OS would typically not implement support (for example, chipset-specific error registers).

HEST information may be needed by other subsystems. For example, HEST PCIE AER error source information describes whether a PCIE root port works in "firmware first" mode, this is needed by general PCIE AER error subsystem. So a public HEST tabling parsing interface is provided.

---
 drivers/acpi/apei/Makefile |    2 
 drivers/acpi/apei/hest.c   |  173 +++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/apei.h        |   13 +++
 3 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/apei/hest.c
 create mode 100644 include/acpi/apei.h
drivers/acpi/apei/Makefile +1 -1
@@ -1,3 +1,3 @@
 obj-$(CONFIG_ACPI_APEI)		+= apei.o
 
-apei-y := apei-base.o
+apei-y := apei-base.o hest.o
drivers/acpi/apei/hest.c new file +173 -0

173 lines not on this page · raw message

include/acpi/apei.h new file +13 -0
@@ -0,0 +1,13 @@
+/*
+ * apei.h - ACPI Platform Error Interface
+ */
+
+#ifndef ACPI_APEI_H
+#define ACPI_APEI_H
+
+extern int hest_disable;
+
+typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data);
+int apei_hest_parse(apei_hest_func_t func, void *data);
+
+#endif
author
#4 lore raw

PATCH 4/12 ACPI, APEI, EINJ support

In reply to Huang Ying

EINJ provides a hardware error injection mechanism, this is useful for debugging and testing of other APEI and RAS features.

---
 drivers/acpi/apei/Kconfig  |    7 
 drivers/acpi/apei/Makefile |    1 
 drivers/acpi/apei/einj.c   |  485 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 493 insertions(+)
 create mode 100644 drivers/acpi/apei/einj.c
drivers/acpi/apei/Kconfig +7 -0
@@ -7,3 +7,10 @@ config ACPI_APEI
 	  especially. In addition it supports error serialization and
 	  error injection.
 
+config ACPI_APEI_EINJ
+	tristate "APEI Error INJection (EINJ)"
+	depends on ACPI_APEI && DEBUG_FS
+	help
+	  EINJ provides a hardware error injection mechanism, it is
+	  mainly used for debugging and testing the other parts of
+	  APEI and some other RAS features.
drivers/acpi/apei/Makefile +1 -0
@@ -1,3 +1,4 @@
 obj-$(CONFIG_ACPI_APEI)		+= apei.o
+obj-$(CONFIG_ACPI_APEI_EINJ)	+= einj.o
 
 apei-y := apei-base.o hest.o
drivers/acpi/apei/einj.c new file +485 -0

485 lines not on this page · raw message

author
#5 lore raw

PATCH 5/12 ACPI, APEI, Document for APEI

In reply to Huang Ying

Add document for APEI, including kernel parameters and EINJ debug file sytem interface.

---
 Documentation/acpi/apei/einj.txt    |   49 ++++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt |    5 +++
 2 files changed, 54 insertions(+)
 create mode 100644 Documentation/acpi/apei/einj.txt
Documentation/acpi/apei/einj.txt new file +49 -0
@@ -0,0 +1,49 @@
+			APEI Error INJection
+			~~~~~~~~~~~~~~~~~~~~
+
+EINJ provides a hardware error injection mechanism, it is very useful
+for debugging and testing of other APEI and RAS features.
+
+To use EINJ, make the following is enabled in your kernel
+configuration:
+
+CONFIG_DEBUG_FS
+CONFIG_ACPI_APEI
+CONFIG_ACPI_APEI_EINJ
+
+The user interface of EINJ is in debug file system, under the
+directory apei/einj. The following files are provided.
+
+- available_error_type
+  Read this file will return the error injection capability of the
+  platform, that is, which error types are supported. The error type
+  definition is as follow, the left field is the error type value, the
+  right field is error description.
+
+    0x00000001	Processor Correctable
+    0x00000002	Processor Uncorrectable non-fatal
+    0x00000004	Processor Uncorrectable fatal
+    0x00000008  Memory Correctable
+    0x00000010  Memory Uncorrectable non-fatal
+    0x00000020  Memory Uncorrectable fatal
+    0x00000040	PCI Express Correctable
+    0x00000080	PCI Express Uncorrectable fatal
+    0x00000100	PCI Express Uncorrectable non-fatal
+    0x00000200	Platform Correctable
+    0x00000400	Platform Uncorrectable non-fatal
+    0x00000800	Platform Uncorrectable fatal
+
+  The format of file contents are as above, except there are only the
+  available error type lines.
+
+- error_type
+  This file is used to set the error type value. The error type value
+  is defined in "available_error_type" description.
+
+- error_inject
+  Write any integer to this file to trigger the error
+  injection. Before this, please specify all necessary error
+  parameters.
+
+For more information about EINJ, please refer to ACPI specification
+version 4.0, section 17.5.
Documentation/kernel-parameters.txt +5 -0
@@ -843,6 +843,11 @@ and is between 256 and 4096 characters.
 	hd=		[EIDE] (E)IDE hard drive subsystem geometry
 			Format: <cyl>,<head>,<sect>
 
+	hest_disable	[ACPI]
+			Disable Hardware Error Source Table (HEST) support,
+			corresponding firmware-first mode error processing
+			logic will be disabled.
+
 	highmem=nn[KMG]	[KNL,BOOT] forces the highmem zone to have an exact
 			size of <nn>. This works even on boxes that have no
 			highmem otherwise. This also works to reduce highmem
author
#6 lore raw

PATCH 6/12 ACPI, APEI, PCIE AER, use general HEST table parsing in AER firmware_first setup

In reply to Huang Ying

Now, a dedicated HEST tabling parsing code is used for PCIE AER firmware_first setup. It is rebased on general HEST tabling parsing code of APEI. The firmware_first setup code is moved from PCI core to AER driver too, because it is only AER related.

---
 drivers/acpi/Makefile              |    1 
 drivers/acpi/hest.c                |  135 -------------------------------------
 drivers/pci/pcie/aer/aerdrv.h      |   17 ++++
 drivers/pci/pcie/aer/aerdrv_acpi.c |   77 +++++++++++++++++++++
 drivers/pci/pcie/aer/aerdrv_core.c |    8 +-
 drivers/pci/probe.c                |    8 --
 include/acpi/acpi_hest.h           |   12 ---
 include/linux/pci.h                |    3 
 8 files changed, 100 insertions(+), 161 deletions(-)
 delete mode 100644 drivers/acpi/hest.c
 delete mode 100644 include/acpi/acpi_hest.h
drivers/acpi/Makefile +0 -1
@@ -20,7 +20,6 @@ obj-y				+= acpi.o \
 # All the builtin files are in the "acpi." module_param namespace.
 acpi-y				+= osl.o utils.o reboot.o
 acpi-y				+= atomicio.o
-acpi-y				+= hest.o
 
 # sleep related files
 acpi-y				+= wakeup.o
drivers/acpi/hest.c deleted +0 -135

135 lines not on this page · raw message

drivers/pci/pcie/aer/aerdrv.h +17 -0
@@ -134,4 +134,21 @@ static inline int aer_osc_setup(struct p
 }
 #endif
 
+#ifdef CONFIG_ACPI_APEI
+extern int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
+#else
+static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
+{
+	if (pci_dev->__aer_firmware_first_valid)
+		return pci_dev->__aer_firmware_first;
+	return 0;
+}
+#endif
+
+static inline void pcie_aer_force_firmware_first(struct pci_dev *pci_dev,
+						 int enable)
+{
+	pci_dev->__aer_firmware_first = !!enable;
+	pci_dev->__aer_firmware_first_valid = 1;
+}
 #endif /* _AERDRV_H_ */
drivers/pci/pcie/aer/aerdrv_acpi.c +77 -0

86 lines not on this page · raw message

drivers/pci/pcie/aer/aerdrv_core.c +4 -4
@@ -36,7 +36,7 @@ int pci_enable_pcie_error_reporting(stru
 	u16 reg16 = 0;
 	int pos;
 
-	if (dev->aer_firmware_first)
+	if (pcie_aer_get_firmware_first(dev))
 		return -EIO;
 
 	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
@@ -64,7 +64,7 @@ int pci_disable_pcie_error_reporting(str
 	u16 reg16 = 0;
 	int pos;
 
-	if (dev->aer_firmware_first)
+	if (pcie_aer_get_firmware_first(dev))
 		return -EIO;
 
 	pos = pci_pcie_cap(dev);
@@ -859,7 +859,7 @@ void aer_delete_rootport(struct aer_rpc
  */
 int aer_init(struct pcie_device *dev)
 {
-	if (dev->port->aer_firmware_first) {
+	if (pcie_aer_get_firmware_first(dev->port)) {
 		dev_printk(KERN_DEBUG, &dev->device,
 			   "PCIe errors handled by platform firmware.\n");
 		goto out;
@@ -873,7 +873,7 @@ out:
 	if (forceload) {
 		dev_printk(KERN_DEBUG, &dev->device,
 			   "aerdrv forceload requested.\n");
-		dev->port->aer_firmware_first = 0;
+		pcie_aer_force_firmware_first(dev->port, 0);
 		return 0;
 	}
 	return -ENXIO;
drivers/pci/probe.c +0 -8
@@ -10,7 +10,6 @@
 #include <linux/module.h>
 #include <linux/cpumask.h>
 #include <linux/pci-aspm.h>
-#include <acpi/acpi_hest.h>
 #include "pci.h"
 
 #define CARDBUS_LATENCY_TIMER	176	/* secondary latency timer */
@@ -904,12 +903,6 @@ void set_pcie_hotplug_bridge(struct pci_
 		pdev->is_hotplug_bridge = 1;
 }
 
-static void set_pci_aer_firmware_first(struct pci_dev *pdev)
-{
-	if (acpi_hest_firmware_first_pci(pdev))
-		pdev->aer_firmware_first = 1;
-}
-
 #define LEGACY_IO_RESOURCE	(IORESOURCE_IO | IORESOURCE_PCI_FIXED)
 
 /**
@@ -939,7 +932,6 @@ int pci_setup_device(struct pci_dev *dev
 	dev->multifunction = !!(hdr_type & 0x80);
 	dev->error_state = pci_channel_io_normal;
 	set_pcie_port_type(dev);
-	set_pci_aer_firmware_first(dev);
 
 	list_for_each_entry(slot, &dev->bus->slots, list)
 		if (PCI_SLOT(dev->devfn) == slot->number)
include/acpi/acpi_hest.h deleted +0 -12
@@ -1,12 +0,0 @@
-#ifndef __ACPI_HEST_H
-#define __ACPI_HEST_H
-
-#include <linux/pci.h>
-
-#ifdef CONFIG_ACPI
-extern int acpi_hest_firmware_first_pci(struct pci_dev *pci);
-#else
-static inline int acpi_hest_firmware_first_pci(struct pci_dev *pci) { return 0; }
-#endif
-
-#endif
include/linux/pci.h +2 -1
@@ -311,7 +311,8 @@ struct pci_dev {
 	unsigned int	is_virtfn:1;
 	unsigned int	reset_fn:1;
 	unsigned int    is_hotplug_bridge:1;
-	unsigned int    aer_firmware_first:1;
+	unsigned int    __aer_firmware_first_valid:1;
+	unsigned int	__aer_firmware_first:1;
 	pci_dev_flags_t dev_flags;
 	atomic_t	enable_cnt;	/* pci_enable_device has been called */
 
author
#7 lore raw

PATCH 7/12 ACPI Hardware Error Device (PNP0C33) support

In reply to Huang Ying

Hardware Error Device (PNP0C33) is used to report some hardware errors notified via SCI, mainly the corrected errors. Some APEI Generic Hardware Error Source (GHES) may use SCI on hardware error device to notify hardware error to kernel.

After receiving notification from ACPI core, it is forwarded to all listeners via a notifier chain. The listener such as APEI GHES should check corresponding error source for new events when notified.

---
 drivers/acpi/Kconfig  |    7 +++
 drivers/acpi/Makefile |    1 
 drivers/acpi/hed.c    |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/acpi/hed.h    |   18 ++++++++
 4 files changed, 138 insertions(+)
 create mode 100644 drivers/acpi/hed.c
 create mode 100644 include/acpi/hed.h
drivers/acpi/Kconfig +7 -0
@@ -360,6 +360,13 @@ config ACPI_SBS
 	  To compile this driver as a module, choose M here:
 	  the modules will be called sbs and sbshc.
 
+config ACPI_HED
+	tristate "Hardware Error Device"
+	help
+	  This driver supports the Hardware Error Device (PNP0C33),
+	  which is used to report some hardware errors notified via
+	  SCI, mainly the corrected errors.
+
 source "drivers/acpi/apei/Kconfig"
 
 endif	# ACPI
drivers/acpi/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_ACPI_BATTERY)	+= battery.o
 obj-$(CONFIG_ACPI_SBS)		+= sbshc.o
 obj-$(CONFIG_ACPI_SBS)		+= sbs.o
 obj-$(CONFIG_ACPI_POWER_METER)	+= power_meter.o
+obj-$(CONFIG_ACPI_HED)		+= hed.o
 
 # processor has its own "processor." module_param namespace
 processor-y			:= processor_driver.o processor_throttling.o
drivers/acpi/hed.c new file +112 -0

112 lines not on this page · raw message

include/acpi/hed.h new file +18 -0
@@ -0,0 +1,18 @@
+/*
+ * hed.h - ACPI Hardware Error Device
+ *
+ * Copyright (C) 2009, Intel Corp.
+ *	Author: Huang Ying <[email protected]>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#ifndef ACPI_HED_H
+#define ACPI_HED_H
+
+#include <linux/notifier.h>
+
+int register_acpi_hed_notifier(struct notifier_block *nb);
+void unregister_acpi_hed_notifier(struct notifier_block *nb);
+
+#endif
author
#8 lore raw

PATCH 8/12 Unified UUID/GUID definition

In reply to Huang Ying

There are many different UUID/GUID definitions in kernel, such as that in EFI, many file systems, some drivers, etc. Every kernel components need UUID/GUID has its own definition. This patch provides a unified definition for UUID/GUID.

UUID is defined via typedef. This makes that UUID appears more like a preliminary type, and makes the data type explicit (comparing with implicit "u8 uuid[16]").

The binary representation of UUID/GUID can be little-endian (used by EFI, etc) or big-endian (defined by RFC4122), so both is defined.

---
 include/linux/uuid.h |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/Makefile         |    2 -
 lib/uuid.c           |   53 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/uuid.h
 create mode 100644 lib/uuid.c
include/linux/uuid.h new file +70 -0
@@ -0,0 +1,70 @@
+/*
+ * UUID/GUID definition
+ *
+ * Copyright (C) 2010, Intel Corp.
+ *	Huang Ying <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _LINUX_UUID_H_
+#define _LINUX_UUID_H_
+
+#include <linux/types.h>
+#include <linux/string.h>
+
+typedef struct {
+	__u8 b[16];
+} uuid_le;
+
+typedef struct {
+	__u8 b[16];
+} uuid_be;
+
+#define UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)		\
+((uuid_le)								\
+{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
+   (b) & 0xff, ((b) >> 8) & 0xff,					\
+   (c) & 0xff, ((c) >> 8) & 0xff,					\
+   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+
+#define UUID_BE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)		\
+((uuid_be)								\
+{{ ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff, \
+   ((b) >> 8) & 0xff, (b) & 0xff,					\
+   ((c) >> 8) & 0xff, (c) & 0xff,					\
+   (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
+
+#define NULL_UUID_LE							\
+	UUID_LE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00,	\
+		0x00, 0x00, 0x00, 0x00)
+
+#define NULL_UUID_BE							\
+	UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00,	\
+		0x00, 0x00, 0x00, 0x00)
+
+static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
+{
+	return memcmp(&u1, &u2, sizeof(uuid_le));
+}
+
+static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)
+{
+	return memcmp(&u1, &u2, sizeof(uuid_be));
+}
+
+extern void uuid_le_gen(uuid_le *u);
+extern void uuid_be_gen(uuid_be *u);
+
+#endif
lib/Makefile +1 -1
@@ -21,7 +21,7 @@ lib-y	+= kobject.o kref.o klist.o
 
 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
 	 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
-	 string_helpers.o gcd.o lcm.o list_sort.o
+	 string_helpers.o gcd.o lcm.o list_sort.o uuid.o
 
 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
 CFLAGS_kobject.o += -DDEBUG
lib/uuid.c new file +53 -0

53 lines not on this page · raw message

author
#9 lore raw

PATCH 9/12 ACPI, APEI, UEFI Common Platform Error Record (CPER) header

In reply to Huang Ying

CPER stands for Common Platform Error Record, it is the hardware error record format used to describe platform hardware error by various APEI tables, such as ERST, BERT and HEST etc.

For more information about CPER, please refer to Appendix N of UEFI Specification version 2.3.

This patch mainly includes the data structure difinition header file used by other files.

---
 drivers/acpi/apei/Makefile        |    2 
 drivers/acpi/apei/apei-internal.h |   19 ++
 drivers/acpi/apei/cper.c          |   84 ++++++++++
 include/linux/cper.h              |  314 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 418 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/apei/cper.c
 create mode 100644 include/linux/cper.h
drivers/acpi/apei/Makefile +1 -1
@@ -1,4 +1,4 @@
 obj-$(CONFIG_ACPI_APEI)		+= apei.o
 obj-$(CONFIG_ACPI_APEI_EINJ)	+= einj.o
 
-apei-y := apei-base.o hest.o
+apei-y := apei-base.o hest.o cper.o
drivers/acpi/apei/apei-internal.h +19 -0
@@ -6,6 +6,8 @@
 #ifndef APEI_INTERNAL_H
 #define APEI_INTERNAL_H
 
+#include <linux/cper.h>
+
 struct apei_exec_context;
 
 typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
@@ -92,4 +94,21 @@ int apei_exec_collect_resources(struct a
 
 struct dentry;
 struct dentry *apei_get_debugfs_dir(void);
+
+#define apei_estatus_for_each_section(estatus, section)			\
+	for (section = (struct acpi_hest_generic_data *)(estatus + 1);	\
+	     (void *)section - (void *)estatus < estatus->data_length;	\
+	     section = (void *)(section+1) + section->error_data_length)
+
+static inline u32 apei_estatus_len(struct acpi_hest_generic_status *estatus)
+{
+	if (estatus->raw_data_length)
+		return estatus->raw_data_offset + \
+			estatus->raw_data_length;
+	else
+		return sizeof(*estatus) + estatus->data_length;
+}
+
+int apei_estatus_check_header(const struct acpi_hest_generic_status *estatus);
+int apei_estatus_check(const struct acpi_hest_generic_status *estatus);
 #endif
drivers/acpi/apei/cper.c new file +84 -0

84 lines not on this page · raw message

include/linux/cper.h new file +314 -0

314 lines not on this page · raw message

author
#10 lore raw

PATCH 10/12 ACPI, APEI, Generic Hardware Error Source memory error support

In reply to Huang Ying

Generic Hardware Error Source provides a way to report platform hardware errors (such as that from chipset). It works in so called "Firmware First" mode, that is, hardware errors are reported to firmware firstly, then reported to Linux by firmware. This way, some non-standard hardware error registers or non-standard hardware link can be checked by firmware to produce more valuable hardware error information for Linux.

Now, only SCI notification type and memory errors are supported. More notification type and hardware error type will be added later. These memory errors are reported to user space through /dev/mcelog via faking a corrected Machine Check, so that the error memory page can be offlined by /sbin/mcelog if the error count for one page is beyond the threshold.

On some machines, Machine Check can not report physical address for some corrected memory errors, but GHES can do that. So this simplified GHES is implemented firstly.

---
 arch/x86/include/asm/mce.h            |    8 
 arch/x86/kernel/cpu/mcheck/Makefile   |    2 
 arch/x86/kernel/cpu/mcheck/mce-apei.c |   52 ++++
 drivers/acpi/apei/Kconfig             |   14 +
 drivers/acpi/apei/Makefile            |    1 
 drivers/acpi/apei/ghes.c              |  425 ++++++++++++++++++++++++++++++++++
 6 files changed, 502 insertions(+)
 create mode 100644 arch/x86/kernel/cpu/mcheck/mce-apei.c
 create mode 100644 drivers/acpi/apei/ghes.c
arch/x86/include/asm/mce.h +8 -0
@@ -225,5 +225,13 @@ extern void mcheck_intel_therm_init(void
 static inline void mcheck_intel_therm_init(void) { }
 #endif
 
+/*
+ * Used by APEI to report memory error via /dev/mcelog
+ */
+
+struct cper_sec_mem_err;
+extern void apei_mce_report_mem_error(int corrected,
+				      struct cper_sec_mem_err *mem_err);
+
 #endif /* __KERNEL__ */
 #endif /* _ASM_X86_MCE_H */
arch/x86/kernel/cpu/mcheck/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_X86_MCE_THRESHOLD) += thres
 obj-$(CONFIG_X86_MCE_INJECT)	+= mce-inject.o
 
 obj-$(CONFIG_X86_THERMAL_VECTOR) += therm_throt.o
+
+obj-$(CONFIG_ACPI_APEI)		+= mce-apei.o
arch/x86/kernel/cpu/mcheck/mce-apei.c new file +52 -0

52 lines not on this page · raw message

drivers/acpi/apei/Kconfig +14 -0
@@ -7,6 +7,20 @@ config ACPI_APEI
 	  especially. In addition it supports error serialization and
 	  error injection.
 
+config ACPI_APEI_GHES
+	tristate "APEI Generic Hardware Error Source"
+	depends on ACPI_APEI && X86
+	select ACPI_HED
+	help
+	  Generic Hardware Error Source provides a way to report
+	  platform hardware errors (such as that from chipset). It
+	  works in so called "Firmware First" mode, that is, hardware
+	  errors are reported to firmware firstly, then reported to
+	  Linux by firmware. This way, some non-standard hardware
+	  error registers or non-standard hardware link can be checked
+	  by firmware to produce more valuable hardware error
+	  information for Linux.
+
 config ACPI_APEI_EINJ
 	tristate "APEI Error INJection (EINJ)"
 	depends on ACPI_APEI && DEBUG_FS
drivers/acpi/apei/Makefile +1 -0
@@ -1,4 +1,5 @@
 obj-$(CONFIG_ACPI_APEI)		+= apei.o
+obj-$(CONFIG_ACPI_APEI_GHES)	+= ghes.o
 obj-$(CONFIG_ACPI_APEI_EINJ)	+= einj.o
 
 apei-y := apei-base.o hest.o cper.o
drivers/acpi/apei/ghes.c new file +425 -0

425 lines not on this page · raw message

author
#11 lore raw

PATCH 11/12 ACPI, APEI, Error Record Serialization Table (ERST) support

In reply to Huang Ying

ERST is a way provided by APEI to save and retrieve hardware error record to and from some simple persistent storage (such as flash).

The Linux kernel support implementation is quite simple and workable in NMI context. So it can be used to save hardware error record into flash in hardware error exception or NMI handler, where other more complex persistent storage such as disk is not usable. After saving hardware error records via ERST in hardware error exception or NMI handler, the error records can be retrieved and logged into disk or network after a clean reboot.

For more information about ERST, please refer to ACPI Specification version 4.0, section 17.4.

---
 Documentation/kernel-parameters.txt |    4 
 drivers/acpi/apei/Makefile          |    2 
 drivers/acpi/apei/erst.c            |  852 ++++++++++++++++++++++++++++++++++++
 include/acpi/apei.h                 |   21 
 4 files changed, 878 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/apei/erst.c
Documentation/kernel-parameters.txt +4 -0
@@ -750,6 +750,10 @@ and is between 256 and 4096 characters.
 			Default value is 0.
 			Value can be changed at runtime via /selinux/enforce.
 
+	erst_disable	[ACPI]
+			Disable Error Record Serialization Table (ERST)
+			support.
+
 	ether=		[HW,NET] Ethernet cards parameters
 			This option is obsoleted by the "netdev=" option, which
 			has equivalent usage. See its documentation for details.
drivers/acpi/apei/Makefile +1 -1
@@ -2,4 +2,4 @@ obj-$(CONFIG_ACPI_APEI)		+= apei.o
 obj-$(CONFIG_ACPI_APEI_GHES)	+= ghes.o
 obj-$(CONFIG_ACPI_APEI_EINJ)	+= einj.o
 
-apei-y := apei-base.o hest.o cper.o
+apei-y := apei-base.o hest.o cper.o erst.o
drivers/acpi/apei/erst.c new file +852 -0

852 lines not on this page · raw message

include/acpi/apei.h +21 -0
@@ -5,9 +5,30 @@
 #ifndef ACPI_APEI_H
 #define ACPI_APEI_H
 
+#include <linux/acpi.h>
+#include <linux/cper.h>
+#include <asm/ioctls.h>
+
+#define APEI_ERST_INVALID_RECORD_ID	0xffffffffffffffffULL
+
+#define APEI_ERST_CLEAR_RECORD		_IOW('E', 1, u64)
+#define APEI_ERST_GET_RECORD_COUNT	_IOR('E', 2, u32)
+
+#ifdef __KERNEL__
+
 extern int hest_disable;
+extern int erst_disable;
 
 typedef int (*apei_hest_func_t)(struct acpi_hest_header *hest_hdr, void *data);
 int apei_hest_parse(apei_hest_func_t func, void *data);
 
+int erst_write(const struct cper_record_header *record);
+ssize_t erst_get_record_count(void);
+int erst_get_next_record_id(u64 *record_id);
+ssize_t erst_read(u64 record_id, struct cper_record_header *record,
+		  size_t buflen);
+ssize_t erst_read_next(struct cper_record_header *record, size_t buflen);
+int erst_clear(u64 record_id);
+
+#endif
 #endif
author
#12 lore raw

PATCH 12/12 ACPI, APEI, Use ERST for persistent storage of MCE

In reply to Huang Ying

Traditionally, fatal MCE will cause Linux print error log to console then reboot. Because MCE registers will preserve their content after warm reboot, the hardware error can be logged to disk or network after reboot. But system may fail to warm reboot, then you may lose the hardware error log. ERST can help here. Through saving the hardware error log into flash via ERST before go panic, the hardware error log can be gotten from the flash after system boot successful again.

The fatal MCE processing procedure with ERST involved is as follow:

- Hardware detect error, MCE raised
- MCE read MCE registers, check error severity (fatal), prepare error record
- Write MCE error record into flash via ERST
- Go panic, then trigger system reboot
- System reboot, /sbin/mcelog run, it reads /dev/mcelog to check flash for error record of previous boot via ERST, and output and clear them if available
- /sbin/mcelog logs error records into disk or network

ERST only accepts CPER record format, but there is no pre-defined CPER section can accommodate all information in struct mce, so a customized section type is defined to hold struct mce inside a CPER record as an error section.

---
 arch/x86/kernel/cpu/mcheck/mce-apei.c     |   86 ++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/mcheck/mce-internal.h |   23 ++++++++
 arch/x86/kernel/cpu/mcheck/mce.c          |   79 +++++++++++++++++++++++----
 3 files changed, 177 insertions(+), 11 deletions(-)
arch/x86/kernel/cpu/mcheck/mce-apei.c +86 -0
@@ -8,6 +8,9 @@
  * the error memory page can be offlined by /sbin/mcelog if the error
  * count for one page is beyond the threshold.
  *
+ * For fatal MCE, save MCE record into persistent storage via ERST, so
+ * that the MCE record can be logged after reboot via ERST.
+ *
  * Copyright 2010 Intel Corp.
  *   Author: Huang Ying <[email protected]>
  *
@@ -50,3 +53,86 @@ void apei_mce_report_mem_error(int corre
 	mce_notify_irq();
 }
 EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
+
+#define CPER_CREATOR_MCE						\
+	UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c,	\
+		0x64, 0x90, 0xb8, 0x9d)
+#define CPER_SECTION_TYPE_MCE						\
+	UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96,	\
+		0x04, 0x4a, 0x38, 0xfc)
+
+/*
+ * CPER specification (in UEFI specification 2.3 appendix N) requires
+ * byte-packed.
+ */
+struct cper_mce_record {
+	struct cper_record_header hdr;
+	struct cper_section_descriptor sec_hdr;
+	struct mce mce;
+} __packed;
+
+int apei_write_mce(struct mce *m)
+{
+	struct cper_mce_record rcd;
+
+	memset(&rcd, 0, sizeof(rcd));
+	memcpy(rcd.hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE);
+	rcd.hdr.revision = CPER_RECORD_REV;
+	rcd.hdr.signature_end = CPER_SIG_END;
+	rcd.hdr.section_count = 1;
+	rcd.hdr.error_severity = CPER_SER_FATAL;
+	/* timestamp, platform_id, partition_id are all invalid */
+	rcd.hdr.validation_bits = 0;
+	rcd.hdr.record_length = sizeof(rcd);
+	rcd.hdr.creator_id = CPER_CREATOR_MCE;
+	rcd.hdr.notification_type = CPER_NOTIFY_MCE;
+	rcd.hdr.record_id = cper_next_record_id();
+	rcd.hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR;
+
+	rcd.sec_hdr.section_offset = (void *)&rcd.mce - (void *)&rcd;
+	rcd.sec_hdr.section_length = sizeof(rcd.mce);
+	rcd.sec_hdr.revision = CPER_SEC_REV;
+	/* fru_id and fru_text is invalid */
+	rcd.sec_hdr.validation_bits = 0;
+	rcd.sec_hdr.flags = CPER_SEC_PRIMARY;
+	rcd.sec_hdr.section_type = CPER_SECTION_TYPE_MCE;
+	rcd.sec_hdr.section_severity = CPER_SER_FATAL;
+
+	memcpy(&rcd.mce, m, sizeof(*m));
+
+	return erst_write(&rcd.hdr);
+}
+
+ssize_t apei_read_mce(struct mce *m, u64 *record_id)
+{
+	struct cper_mce_record rcd;
+	ssize_t len;
+
+	len = erst_read_next(&rcd.hdr, sizeof(rcd));
+	if (len <= 0)
+		return len;
+	/* Can not skip other records in storage via ERST unless clear them */
+	else if (len != sizeof(rcd) ||
+		 uuid_le_cmp(rcd.hdr.creator_id, CPER_CREATOR_MCE)) {
+		if (printk_ratelimit())
+			pr_warning(
+			"MCE-APEI: Can not skip the unknown record in ERST");
+		return -EIO;
+	}
+
+	memcpy(m, &rcd.mce, sizeof(*m));
+	*record_id = rcd.hdr.record_id;
+
+	return sizeof(*m);
+}
+
+/* Check whether there is record in ERST */
+int apei_check_mce(void)
+{
+	return erst_get_record_count();
+}
+
+int apei_clear_mce(u64 record_id)
+{
+	return erst_clear(record_id);
+}
arch/x86/kernel/cpu/mcheck/mce-internal.h +23 -0
@@ -28,3 +28,26 @@ extern int mce_ser;
 
 extern struct mce_bank *mce_banks;
 
+#ifdef CONFIG_ACPI_APEI
+int apei_write_mce(struct mce *m);
+ssize_t apei_read_mce(struct mce *m, u64 *record_id);
+int apei_check_mce(void);
+int apei_clear_mce(u64 record_id);
+#else
+static inline int apei_write_mce(struct mce *m)
+{
+	return -EINVAL;
+}
+static inline ssize_t apei_read_mce(struct mce *m, u64 *record_id)
+{
+	return 0;
+}
+static inline int apei_check_mce(void)
+{
+	return 0;
+}
+static inline int apei_clear_mce(u64 record_id)
+{
+	return -EINVAL;
+}
+#endif
arch/x86/kernel/cpu/mcheck/mce.c +68 -11

131 lines not on this page · raw message

Reviewed-by
#13 lore raw
In reply to Huang Ying
Quoted 11 lines · Huang Ying

This patchset adds the APEI (ACPI Platform Error Interface) support to Linux kernel.

01-06 include the basic APEI HEST parsing and EINJ support. They have been posted to mailing list before and get some reviews and ACKs. Changes since the last post are as follow.

- Make APEI infrastructure and HEST parsing configurable built-in instead of modules to solve some dependency issues.

Quoted 6 lines

- Some minor fixes, such as printk

07-10 are newly added to support GHES (Generic Hardware Error Source) corrected memory error. On some machines, Machine Check can not report physical address for some corrected memory errors, but GHES can do that. So this simplified GHES is implemented and posted firstly.

I read all the code again and it looks all good to go for .35 to me.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.