.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * APEI Boot Error Record Table (BERT) support |
---|
3 | 4 | * |
---|
.. | .. |
---|
16 | 17 | * |
---|
17 | 18 | * For more information about BERT, please refer to ACPI Specification |
---|
18 | 19 | * version 4.0, section 17.3.1 |
---|
19 | | - * |
---|
20 | | - * This file is licensed under GPLv2. |
---|
21 | | - * |
---|
22 | 20 | */ |
---|
23 | 21 | |
---|
24 | 22 | #include <linux/kernel.h> |
---|
.. | .. |
---|
32 | 30 | #undef pr_fmt |
---|
33 | 31 | #define pr_fmt(fmt) "BERT: " fmt |
---|
34 | 32 | |
---|
| 33 | +#define ACPI_BERT_PRINT_MAX_RECORDS 5 |
---|
| 34 | +#define ACPI_BERT_PRINT_MAX_LEN 1024 |
---|
| 35 | + |
---|
35 | 36 | static int bert_disable; |
---|
36 | 37 | |
---|
| 38 | +/* |
---|
| 39 | + * Print "all" the error records in the BERT table, but avoid huge spam to |
---|
| 40 | + * the console if the BIOS included oversize records, or too many records. |
---|
| 41 | + * Skipping some records here does not lose anything because the full |
---|
| 42 | + * data is available to user tools in: |
---|
| 43 | + * /sys/firmware/acpi/tables/data/BERT |
---|
| 44 | + */ |
---|
37 | 45 | static void __init bert_print_all(struct acpi_bert_region *region, |
---|
38 | 46 | unsigned int region_len) |
---|
39 | 47 | { |
---|
40 | 48 | struct acpi_hest_generic_status *estatus = |
---|
41 | 49 | (struct acpi_hest_generic_status *)region; |
---|
42 | 50 | int remain = region_len; |
---|
| 51 | + int printed = 0, skipped = 0; |
---|
43 | 52 | u32 estatus_len; |
---|
44 | 53 | |
---|
45 | | - if (!estatus->block_status) |
---|
46 | | - return; |
---|
47 | | - |
---|
48 | | - while (remain > sizeof(struct acpi_bert_region)) { |
---|
49 | | - if (cper_estatus_check(estatus)) { |
---|
50 | | - pr_err(FW_BUG "Invalid error record.\n"); |
---|
51 | | - return; |
---|
52 | | - } |
---|
53 | | - |
---|
| 54 | + while (remain >= sizeof(struct acpi_bert_region)) { |
---|
54 | 55 | estatus_len = cper_estatus_len(estatus); |
---|
55 | 56 | if (remain < estatus_len) { |
---|
56 | 57 | pr_err(FW_BUG "Truncated status block (length: %u).\n", |
---|
57 | 58 | estatus_len); |
---|
58 | | - return; |
---|
| 59 | + break; |
---|
59 | 60 | } |
---|
60 | 61 | |
---|
61 | | - pr_info_once("Error records from previous boot:\n"); |
---|
| 62 | + /* No more error records. */ |
---|
| 63 | + if (!estatus->block_status) |
---|
| 64 | + break; |
---|
62 | 65 | |
---|
63 | | - cper_estatus_print(KERN_INFO HW_ERR, estatus); |
---|
| 66 | + if (cper_estatus_check(estatus)) { |
---|
| 67 | + pr_err(FW_BUG "Invalid error record.\n"); |
---|
| 68 | + break; |
---|
| 69 | + } |
---|
| 70 | + |
---|
| 71 | + if (estatus_len < ACPI_BERT_PRINT_MAX_LEN && |
---|
| 72 | + printed < ACPI_BERT_PRINT_MAX_RECORDS) { |
---|
| 73 | + pr_info_once("Error records from previous boot:\n"); |
---|
| 74 | + cper_estatus_print(KERN_INFO HW_ERR, estatus); |
---|
| 75 | + printed++; |
---|
| 76 | + } else { |
---|
| 77 | + skipped++; |
---|
| 78 | + } |
---|
64 | 79 | |
---|
65 | 80 | /* |
---|
66 | 81 | * Because the boot error source is "one-time polled" type, |
---|
.. | .. |
---|
70 | 85 | estatus->block_status = 0; |
---|
71 | 86 | |
---|
72 | 87 | estatus = (void *)estatus + estatus_len; |
---|
73 | | - /* No more error records. */ |
---|
74 | | - if (!estatus->block_status) |
---|
75 | | - return; |
---|
76 | | - |
---|
77 | 88 | remain -= estatus_len; |
---|
78 | 89 | } |
---|
| 90 | + |
---|
| 91 | + if (skipped) |
---|
| 92 | + pr_info(HW_ERR "Skipped %d error records\n", skipped); |
---|
79 | 93 | } |
---|
80 | 94 | |
---|
81 | 95 | static int __init setup_bert_disable(char *str) |
---|
82 | 96 | { |
---|
83 | 97 | bert_disable = 1; |
---|
84 | 98 | |
---|
85 | | - return 0; |
---|
| 99 | + return 1; |
---|
86 | 100 | } |
---|
87 | 101 | __setup("bert_disable", setup_bert_disable); |
---|
88 | 102 | |
---|
.. | .. |
---|
124 | 138 | rc = bert_check_table(bert_tab); |
---|
125 | 139 | if (rc) { |
---|
126 | 140 | pr_err(FW_BUG "table invalid.\n"); |
---|
127 | | - return rc; |
---|
| 141 | + goto out_put_bert_tab; |
---|
128 | 142 | } |
---|
129 | 143 | |
---|
130 | 144 | region_len = bert_tab->region_length; |
---|
.. | .. |
---|
132 | 146 | rc = apei_resources_add(&bert_resources, bert_tab->address, |
---|
133 | 147 | region_len, true); |
---|
134 | 148 | if (rc) |
---|
135 | | - return rc; |
---|
| 149 | + goto out_put_bert_tab; |
---|
136 | 150 | rc = apei_resources_request(&bert_resources, "APEI BERT"); |
---|
137 | 151 | if (rc) |
---|
138 | 152 | goto out_fini; |
---|
.. | .. |
---|
147 | 161 | apei_resources_release(&bert_resources); |
---|
148 | 162 | out_fini: |
---|
149 | 163 | apei_resources_fini(&bert_resources); |
---|
| 164 | +out_put_bert_tab: |
---|
| 165 | + acpi_put_table((struct acpi_table_header *)bert_tab); |
---|
150 | 166 | |
---|
151 | 167 | return rc; |
---|
152 | 168 | } |
---|