Skip to contentSkip to conversation

ACPI, APEI, Report GHES error information via printk

PATCH In review Huang Ying 2 participants 7 messages Dec 2, 2010

Subsystems (4)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

cover ACPI, APEI, Report GHES error information via printk

The recent consensus is that hardware error should be reported via printk. This patch adds printk support to APEI GHES.

v3:

- Add document for output format per Andrew's comments
- Move pr_pfx into printk.h, hope it is useful for others too
- Fixes some issues according to comments

v2:

- Some minor adjustment of PCIe error section definition and printk format

[PATCH -v3 1/4] printk, Add pr_pfx for library functions
[PATCH -v3 2/4] Add CPER PCIe error section structure and constants definition [PATCH -v3 3/4] ACPI, APEI, Add APEI generic error status printing support [PATCH -v3 4/4] ACPI, APEI, Report GHES error information via printk

author
#1 lore raw

PATCH 1/4 printk, Add pr_pfx for library functions

For library functions doing printk, the log level and line prefix usually need to be specified by the caller. So this patch adds "pr_pfx" to make the life of these library functions easier.

---
 include/linux/printk.h |    7 +++++++
 1 file changed, 7 insertions(+)
include/linux/printk.h +7 -0
@@ -202,6 +202,13 @@ extern void print_hex_dump_bytes(const c
 #endif
 
 /*
+ * Used by library functions, where log level and line prefix need to
+ * be specifieded by the caller.
+ */
+#define pr_pfx(pfx, fmt, ...) \
+	printk("%s" fmt, pfx, ##__VA_ARGS__)
+
+/*
  * ratelimited messages with local ratelimit_state,
  * no local ratelimit_state used in the !PRINTK case
  */
#2 lore raw

Re: [PATCH -v3 1/4] printk, Add pr_pfx for library functions

Quoted 3 lines · Huang Ying

For library functions doing printk, the log level and line prefix usually need to be specified by the caller. So this patch adds "pr_pfx" to make the life of these library functions easier.

[]

include/linux/printk.h extern void print_hex_dump_bytes(const c · line 209

Quoted 2 lines
include/linux/printk.h +2 -0
+#define pr_pfx(pfx, fmt, ...) \
+	printk("%s" fmt, pfx, ##__VA_ARGS__)

I think this would be a very error prone style.

pr_<foo> uses are log levels.

For an casual reader, is pfx a new log level or
is it a prefix or is it both? I do understand
what you intend.

Mutability of the KERN_<level> is pretty unusual. Most all of the uses are ?: style

Here are the first uses in each file that has them:
There aren't many.

$ grep -rP -m1 --include=*.[ch] "KERN_[A-Z]+\s*:\s*KERN" *
arch/avr32/mm/fault.c:			       is_global_init(tsk) ? KERN_EMERG : KERN_INFO,
arch/sparc/kernel/traps_64.c:	       (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
arch/sparc/mm/fault_64.c:	       task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/sparc/mm/fault_32.c:	       task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/x86/kernel/signal.c:		       task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
arch/x86/mm/fault.c:		task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/parisc/kernel/traps.c:	level = user ? KERN_DEBUG : KERN_CRIT;
drivers/pci/pcie/aer/aerdrv_errprint.c:		KERN_WARNING : KERN_ERR, dev_driver_string(&pdev->dev),	\
include/linux/arcdevice.h:            		: x < D_DURING ? KERN_INFO : KERN_DEBUG, \
mm/internal.h:		printk(level <= MMINIT_WARNING ? KERN_WARNING : KERN_DEBUG); \
sound/core/misc.c:	const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;

I don't see why you can't use something like that with a simpler flag for level.

You also miss a chance to use pr_pfx in ghes_print_estatus:

+ if (__ratelimit(&ratelimit)) {
+ printk(
+ "%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
+ pfx, ghes->generic->header.source_id);
+ apei_estatus_print(pfx, ghes->estatus);
+

ghes_print_estatus is only called with a NULL first argument. so the code use of pr_pfx seems dubious in any case.

author
#3 lore raw

Re: [PATCH -v3 1/4] printk, Add pr_pfx for library functions

Hi, Joe,

Quoted 10 lines · Joe Perches
Quoted 3 lines · Huang Ying

For library functions doing printk, the log level and line prefix usually need to be specified by the caller. So this patch adds "pr_pfx" to make the life of these library functions easier.

[]

include/linux/printk.h extern void print_hex_dump_bytes(const c · line 209

Quoted 2 lines
include/linux/printk.h +2 -0
+#define pr_pfx(pfx, fmt, ...) \
+	printk("%s" fmt, pfx, ##__VA_ARGS__)

I think this would be a very error prone style.

Quoted 5 lines

pr_<foo> uses are log levels.

For an casual reader, is pfx a new log level or
is it a prefix or is it both? I do understand
what you intend.

Maybe we can rename it to avoid confusing. Any suggestion? Or just pfx_pr?

Quoted 2 lines

Mutability of the KERN_<level> is pretty unusual. Most all of the uses are ?: style

If printk is used in library functions, the log level and some prefix need to be specified by the caller. That is the intended user. Such as that in 2 of the patch series.

Quoted 16 lines

Here are the first uses in each file that has them:
There aren't many.

$ grep -rP -m1 --include=*.[ch] "KERN_[A-Z]+\s*:\s*KERN" *
arch/avr32/mm/fault.c:			       is_global_init(tsk) ? KERN_EMERG : KERN_INFO,
arch/sparc/kernel/traps_64.c:	       (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
arch/sparc/mm/fault_64.c:	       task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/sparc/mm/fault_32.c:	       task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/x86/kernel/signal.c:		       task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
arch/x86/mm/fault.c:		task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
arch/parisc/kernel/traps.c:	level = user ? KERN_DEBUG : KERN_CRIT;
drivers/pci/pcie/aer/aerdrv_errprint.c:		KERN_WARNING : KERN_ERR, dev_driver_string(&pdev->dev),	\
include/linux/arcdevice.h:            		: x < D_DURING ? KERN_INFO : KERN_DEBUG, \
mm/internal.h:		printk(level <= MMINIT_WARNING ? KERN_WARNING : KERN_DEBUG); \
sound/core/misc.c:	const char *pfx = level ? KERN_DEBUG : KERN_DEFAULT;
Quoted 2 lines

I don't see why you can't use something like that with a simpler flag for level.

That is doable. I just think let caller specify log level and line prefix is more flexible, and uses less code.

Quoted 1 line

You also miss a chance to use pr_pfx in ghes_print_estatus:

Sorry, forget that.

Quoted 9 lines
(quoted diff) +6 -0
+       if (__ratelimit(&ratelimit)) {
+               printk(
+       "%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
+       pfx, ghes->generic->header.source_id);
+               apei_estatus_print(pfx, ghes->estatus);
+

ghes_print_estatus is only called with a NULL first argument. so the code use of pr_pfx seems dubious in any case.

In some following-up patches (not sent out yet), ghes_print_estatus may be called with non-NULL first argument.

Best Regards,
Huang Ying

author
#4 lore raw

PATCH 2/4 Add CPER PCIe error section structure and constants definition

In reply to Huang Ying

On some machine, PCIe error is reported via APEI (ACPI Platform Error Interface). The error data is passed from firmware to Linux via CPER PCIe error section structure.

This patch adds CPER PCIe error section structure and constants definition.

---
 include/linux/cper.h |   86 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 82 insertions(+), 4 deletions(-)
include/linux/cper.h +82 -4
@@ -39,10 +39,12 @@
  * Severity difinition for error_severity in struct cper_record_header
  * and section_severity in struct cper_section_descriptor
  */
-#define CPER_SEV_RECOVERABLE			0x0
-#define CPER_SEV_FATAL				0x1
-#define CPER_SEV_CORRECTED			0x2
-#define CPER_SEV_INFORMATIONAL			0x3
+enum {
+	CPER_SEV_RECOVERABLE,
+	CPER_SEV_FATAL,
+	CPER_SEV_CORRECTED,
+	CPER_SEV_INFORMATIONAL,
+};
 
 /*
  * Validation bits difinition for validation_bits in struct
@@ -201,6 +203,47 @@
 	UUID_LE(0x036F84E1, 0x7F37, 0x428c, 0xA7, 0x9E, 0x57, 0x5F,	\
 		0xDF, 0xAA, 0x84, 0xEC)
 
+#define CPER_PROC_VALID_TYPE			0x0001
+#define CPER_PROC_VALID_ISA			0x0002
+#define CPER_PROC_VALID_ERROR_TYPE		0x0004
+#define CPER_PROC_VALID_OPERATION		0x0008
+#define CPER_PROC_VALID_FLAGS			0x0010
+#define CPER_PROC_VALID_LEVEL			0x0020
+#define CPER_PROC_VALID_VERSION			0x0040
+#define CPER_PROC_VALID_BRAND_INFO		0x0080
+#define CPER_PROC_VALID_ID			0x0100
+#define CPER_PROC_VALID_TARGET_ADDRESS		0x0200
+#define CPER_PROC_VALID_REQUESTOR_ID		0x0400
+#define CPER_PROC_VALID_RESPONDER_ID		0x0800
+#define CPER_PROC_VALID_IP			0x1000
+
+#define CPER_MEM_VALID_ERROR_STATUS		0x0001
+#define CPER_MEM_VALID_PHYSICAL_ADDRESS		0x0002
+#define CPER_MEM_VALID_PHYSICAL_ADDRESS_MASK	0x0004
+#define CPER_MEM_VALID_NODE			0x0008
+#define CPER_MEM_VALID_CARD			0x0010
+#define CPER_MEM_VALID_MODULE			0x0020
+#define CPER_MEM_VALID_BANK			0x0040
+#define CPER_MEM_VALID_DEVICE			0x0080
+#define CPER_MEM_VALID_ROW			0x0100
+#define CPER_MEM_VALID_COLUMN			0x0200
+#define CPER_MEM_VALID_BIT_POSITION		0x0400
+#define CPER_MEM_VALID_REQUESTOR_ID		0x0800
+#define CPER_MEM_VALID_RESPONDER_ID		0x1000
+#define CPER_MEM_VALID_TARGET_ID		0x2000
+#define CPER_MEM_VALID_ERROR_TYPE		0x4000
+
+#define CPER_PCIE_VALID_PORT_TYPE		0x0001
+#define CPER_PCIE_VALID_VERSION			0x0002
+#define CPER_PCIE_VALID_COMMAND_STATUS		0x0004
+#define CPER_PCIE_VALID_DEVICE_ID		0x0008
+#define CPER_PCIE_VALID_SERIAL_NUMBER		0x0010
+#define CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS	0x0020
+#define CPER_PCIE_VALID_CAPABILITY		0x0040
+#define CPER_PCIE_VALID_AER_INFO		0x0080
+
+#define CPER_PCIE_SLOT_SHIFT			3
+
 /*
  * All tables and structs must be byte-packed to match CPER
  * specification, since the tables are provided by the system BIOS
@@ -306,6 +349,41 @@ struct cper_sec_mem_err {
 	__u8	error_type;
 };
 
+struct cper_sec_pcie {
+	__u64		validation_bits;
+	__u32		port_type;
+	struct {
+		__u8	minor;
+		__u8	major;
+		__u8	reserved[2];
+	}		version;
+	__u16		command;
+	__u16		status;
+	__u32		reserved;
+	struct {
+		__u16	vendor_id;
+		__u16	device_id;
+		__u8	class_code[3];
+		__u8	function;
+		__u8	device;
+		__u16	segment;
+		__u8	bus;
+		__u8	secondary_bus;
+		__u16	slot;
+		__u8	reserved;
+	}		device_id;
+	struct {
+		__u32	lower;
+		__u32	upper;
+	}		serial_number;
+	struct {
+		__u16	secondary_status;
+		__u16	control;
+	}		bridge;
+	__u8	capability[60];
+	__u8	aer_info[96];
+};
+
 /* Reset to default packing */
 #pragma pack()
 
author
#5 lore raw

PATCH 3/4 ACPI, APEI, Add APEI generic error status printing support

In reply to Huang Ying

In APEI, Hardware error information reported by firmware to Linux kernel is in the data structure of APEI generic error status (struct acpi_hes_generic_status). While now printk is used by Linux kernel to report hardware error information to user space.

So, this patch adds printing support for the data structure, so that the corresponding hardware error information can be reported to user space via printk.

PCIe AER information printing is not implemented yet. Will refactor the original PCIe AER information printing code to avoid code duplicating.

The output format is as follow:

<error record> :=
APEI generic hardware error status
severity: <integer>, <severity string>
section: <integer>, severity: <integer>, <severity string>
flags: <integer>
<section flags strings>
fru_id: <uuid string>
fru_text: <string>
section_type: <section type string>
<section data>

<severity string>* := recoverable | fatal | corrected | info

<section flags strings># :=
[primary][, containment warning][, reset][, threshold exceeded]\
[, resource not accessible][, latent error]

<section type string> := generic processor error | memory error | \
PCIe error | unknown, <uuid string>

<section data> :=
<generic processor section data> | <memory section data> | \
<pcie section data> | <null>

<generic processor section data> :=
[processor_type: <integer>, <proc type string>]
[processor_isa: <integer>, <proc isa string>]
[error_type: <integer>
<proc error type strings>]
[operation: <integer>, <proc operation string>]
[flags: <integer>
<proc flags strings>]
[level: <integer>]
[version_info: <integer>]
[processor_id: <integer>]
[target_address: <integer>]
[requestor_id: <integer>]
[responder_id: <integer>]
[IP: <integer>]

<proc type string>* := IA32/X64 | IA64

<proc isa string>* := IA32 | IA64 | X64

<processor error type strings># :=
[cache error][, TLB error][, bus error][, micro-architectural error]

<proc operation string>* := unknown or generic | data read | data write | \
instruction execution

<proc flags strings># :=
[restartable][, precise IP][, overflow][, corrected]

<memory section data> :=
[error_status: <integer>]
[physical_address: <integer>]
[physical_address_mask: <integer>]
[node: <integer>]
[card: <integer>]
[module: <integer>]
[bank: <integer>]
[device: <integer>]
[row: <integer>]
[column: <integer>]
[bit_position: <integer>]
[requestor_id: <integer>]
[responder_id: <integer>]
[target_id: <integer>]
[error_type: <integer>, <mem error type string>]

<mem error type string>* :=
unknown | no error | single-bit ECC | multi-bit ECC | \
single-symbol chipkill ECC | multi-symbol chipkill ECC | master abort | \
target abort | parity error | watchdog timeout | invalid address | \
mirror Broken | memory sparing | scrub corrected error | \
scrub uncorrected error

<pcie section data> :=
[port_type: <integer>, <pcie port type string>] [version: <integer>.<integer>]
[command: <integer>, status: <integer>] [device_id: <integer>:<integer>:<integer>.<integer>
slot: <integer>
secondary_bus: <integer>
vendor_id: <integer>, device_id: <integer>
class_code: <integer>]
[serial number: <integer>, <integer>]
[bridge: secondary_status: <integer>, control: <integer>]

<pcie port type string>* := PCIe end point | legacy PCI end point | \
unknown | unknown | root port | upstream switch port | \
downstream switch port | PCIe to PCI/PCI-X bridge | \
PCI/PCI-X to PCIe bridge | root complex integrated endpoint device | \
root complex event collector

Where, [] designate corresponding content is optional

All <field string> description with * has the following format:

field: <integer>, <field string>

Where value of <integer> should be the position of "string" in <field string> description. Otherwise, <field string> will be "unknown".

All <field strings> description with # has the following format:

field: <integer>
<field strings>

Where each string in <fields strings> corresponding to one set bit of <integer>. The bit position is the position of "string" in <field strings> description.

For more detailed explanation of every field, please refer to UEFI specification version 2.3 or later, section Appendix N: Common Platform Error Record.

---
 Documentation/acpi/apei/output_format.txt |  122 +++++++++++
 drivers/acpi/apei/apei-internal.h         |    2 
 drivers/acpi/apei/cper.c                  |  309 ++++++++++++++++++++++++++++++
 3 files changed, 433 insertions(+)
 create mode 100644 Documentation/acpi/apei/output_format.txt
Documentation/acpi/apei/output_format.txt new file +122 -0
@@ -0,0 +1,122 @@
+                     APEI output format
+                     ~~~~~~~~~~~~~~~~~~
+
+APEI uses printk as hardware error reporting interface, the output
+format is as follow.
+
+<error record> :=
+APEI generic hardware error status
+severity: <integer>, <severity string>
+section: <integer>, severity: <integer>, <severity string>
+flags: <integer>
+<section flags strings>
+fru_id: <uuid string>
+fru_text: <string>
+section_type: <section type string>
+<section data>
+
+<severity string>* := recoverable | fatal | corrected | info
+
+<section flags strings># :=
+[primary][, containment warning][, reset][, threshold exceeded]\
+[, resource not accessible][, latent error]
+
+<section type string> := generic processor error | memory error | \
+PCIe error | unknown, <uuid string>
+
+<section data> :=
+<generic processor section data> | <memory section data> | \
+<pcie section data> | <null>
+
+<generic processor section data> :=
+[processor_type: <integer>, <proc type string>]
+[processor_isa: <integer>, <proc isa string>]
+[error_type: <integer>
+<proc error type strings>]
+[operation: <integer>, <proc operation string>]
+[flags: <integer>
+<proc flags strings>]
+[level: <integer>]
+[version_info: <integer>]
+[processor_id: <integer>]
+[target_address: <integer>]
+[requestor_id: <integer>]
+[responder_id: <integer>]
+[IP: <integer>]
+
+<proc type string>* := IA32/X64 | IA64
+
+<proc isa string>* := IA32 | IA64 | X64
+
+<processor error type strings># :=
+[cache error][, TLB error][, bus error][, micro-architectural error]
+
+<proc operation string>* := unknown or generic | data read | data write | \
+instruction execution
+
+<proc flags strings># :=
+[restartable][, precise IP][, overflow][, corrected]
+
+<memory section data> :=
+[error_status: <integer>]
+[physical_address: <integer>]
+[physical_address_mask: <integer>]
+[node: <integer>]
+[card: <integer>]
+[module: <integer>]
+[bank: <integer>]
+[device: <integer>]
+[row: <integer>]
+[column: <integer>]
+[bit_position: <integer>]
+[requestor_id: <integer>]
+[responder_id: <integer>]
+[target_id: <integer>]
+[error_type: <integer>, <mem error type string>]
+
+<mem error type string>* :=
+unknown | no error | single-bit ECC | multi-bit ECC | \
+single-symbol chipkill ECC | multi-symbol chipkill ECC | master abort | \
+target abort | parity error | watchdog timeout | invalid address | \
+mirror Broken | memory sparing | scrub corrected error | \
+scrub uncorrected error
+
+<pcie section data> :=
+[port_type: <integer>, <pcie port type string>]
+[version: <integer>.<integer>]
+[command: <integer>, status: <integer>]
+[device_id: <integer>:<integer>:<integer>.<integer>
+slot: <integer>
+secondary_bus: <integer>
+vendor_id: <integer>, device_id: <integer>
+class_code: <integer>]
+[serial number: <integer>, <integer>]
+[bridge: secondary_status: <integer>, control: <integer>]
+
+<pcie port type string>* := PCIe end point | legacy PCI end point | \
+unknown | unknown | root port | upstream switch port | \
+downstream switch port | PCIe to PCI/PCI-X bridge | \
+PCI/PCI-X to PCIe bridge | root complex integrated endpoint device | \
+root complex event collector
+
+Where, [] designate corresponding content is optional
+
+All <field string> description with * has the following format:
+
+field: <integer>, <field string>
+
+Where value of <integer> should be the position of "string" in <field
+string> description. Otherwise, <field string> will be "unknown".
+
+All <field strings> description with # has the following format:
+
+field: <integer>
+<field strings>
+
+Where each string in <fields strings> corresponding to one set bit of
+<integer>. The bit position is the position of "string" in <field
+strings> description.
+
+For more detailed explanation of every field, please refer to UEFI
+specification version 2.3 or later, section Appendix N: Common
+Platform Error Record.
drivers/acpi/apei/apei-internal.h +2 -0
@@ -109,6 +109,8 @@ static inline u32 apei_estatus_len(struc
 		return sizeof(*estatus) + estatus->data_length;
 }
 
+void apei_estatus_print(const char *pfx,
+			const struct acpi_hest_generic_status *estatus);
 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 +309 -0

315 lines not on this page · raw message

author
#6 lore raw

PATCH 4/4 ACPI, APEI, Report GHES error information via printk

In reply to Huang Ying

printk is one of the methods to report hardware errors to user space. This patch implements hardware error reporting for GHES via printk.

---
 drivers/acpi/apei/ghes.c |   25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
drivers/acpi/apei/ghes.c +21 -4
@@ -43,6 +43,7 @@
 #include <linux/kdebug.h>
 #include <linux/platform_device.h>
 #include <linux/mutex.h>
+#include <linux/ratelimit.h>
 #include <acpi/apei.h>
 #include <acpi/atomicio.h>
 #include <acpi/hed.h>
@@ -255,11 +256,26 @@ static void ghes_do_proc(struct ghes *gh
 		}
 #endif
 	}
+}
+
+static void ghes_print_estatus(const char *pfx, struct ghes *ghes)
+{
+	/* Not more than 2 messages every 5 seconds */
+	static DEFINE_RATELIMIT_STATE(ratelimit, 5*HZ, 2);
 
-	if (!processed && printk_ratelimit())
-		pr_warning(GHES_PFX
-		"Unknown error record from generic hardware error source: %d\n",
-			   ghes->generic->header.source_id);
+	if (pfx == NULL) {
+		if (ghes_severity(ghes->estatus->error_severity) <=
+		    GHES_SEV_CORRECTED)
+			pfx = KERN_WARNING HW_ERR;
+		else
+			pfx = KERN_ERR HW_ERR;
+	}
+	if (__ratelimit(&ratelimit)) {
+		printk(
+	"%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
+	pfx, ghes->generic->header.source_id);
+		apei_estatus_print(pfx, ghes->estatus);
+	}
 }
 
 static int ghes_proc(struct ghes *ghes)
@@ -269,6 +285,7 @@ static int ghes_proc(struct ghes *ghes)
 	rc = ghes_read_estatus(ghes, 0);
 	if (rc)
 		goto out;
+	ghes_print_estatus(NULL, ghes);
 	ghes_do_proc(ghes);
 
 out: