Skip to content

Commit e9876da

Browse files
yghannambp3tk0v
authored andcommitted
x86/mce/apei: Handle variable SMCA BERT record size
The ACPI Boot Error Record Table (BERT) is being used by the kernel to report errors that occurred in a previous boot. On some modern AMD systems, these very errors within the BERT are reported through the x86 Common Platform Error Record (CPER) format which consists of one or more Processor Context Information Structures. These context structures provide a starting address and represent an x86 MSR range in which the data constitutes a contiguous set of MSRs starting from, and including the starting address. It's common, for AMD systems that implement this behavior, that the MSR range represents the MCAX register space used for the Scalable MCA feature. The apei_smca_report_x86_error() function decodes and passes this information through the MCE notifier chain. However, this function assumes a fixed register size based on the original HW/FW implementation. This assumption breaks with the addition of two new MCAX registers viz. MCA_SYND1 and MCA_SYND2. These registers are added at the end of the MCAX register space, so they won't be included when decoding the CPER data. Rework apei_smca_report_x86_error() to support a variable register array size. This covers any case where the MSR context information starts at the MCAX address for MCA_STATUS and ends at any other register within the MCAX register space. [ Yazen: Add Avadhut as co-developer for wrapper changes.] [ bp: Massage. ] Signed-off-by: Yazen Ghannam <[email protected]> Co-developed-by: Avadhut Naik <[email protected]> Signed-off-by: Avadhut Naik <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Qiuxu Zhuo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d4fca13 commit e9876da

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

arch/x86/kernel/cpu/mce/apei.c

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
6868
int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
6969
{
7070
const u64 *i_mce = ((const u64 *) (ctx_info + 1));
71+
unsigned int cpu, num_regs;
7172
bool apicid_found = false;
7273
struct mce_hw_err err;
73-
unsigned int cpu;
7474
struct mce *m;
7575

7676
if (!boot_cpu_has(X86_FEATURE_SMCA))
@@ -89,16 +89,12 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
8989
return -EINVAL;
9090

9191
/*
92-
* The register array size must be large enough to include all the
93-
* SMCA registers which need to be extracted.
94-
*
9592
* The number of registers in the register array is determined by
9693
* Register Array Size/8 as defined in UEFI spec v2.8, sec N.2.4.2.2.
97-
* The register layout is fixed and currently the raw data in the
98-
* register array includes 6 SMCA registers which the kernel can
99-
* extract.
94+
* Sanity-check registers array size.
10095
*/
101-
if (ctx_info->reg_arr_size < 48)
96+
num_regs = ctx_info->reg_arr_size >> 3;
97+
if (!num_regs)
10298
return -EINVAL;
10399

104100
for_each_possible_cpu(cpu) {
@@ -117,12 +113,60 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
117113
mce_prep_record_per_cpu(cpu, m);
118114

119115
m->bank = (ctx_info->msr_addr >> 4) & 0xFF;
120-
m->status = *i_mce;
121-
m->addr = *(i_mce + 1);
122-
m->misc = *(i_mce + 2);
123-
/* Skipping MCA_CONFIG */
124-
m->ipid = *(i_mce + 4);
125-
m->synd = *(i_mce + 5);
116+
117+
/*
118+
* The SMCA register layout is fixed and includes 16 registers.
119+
* The end of the array may be variable, but the beginning is known.
120+
* Cap the number of registers to expected max (15).
121+
*/
122+
if (num_regs > 15)
123+
num_regs = 15;
124+
125+
switch (num_regs) {
126+
/* MCA_SYND2 */
127+
case 15:
128+
err.vendor.amd.synd2 = *(i_mce + 14);
129+
fallthrough;
130+
/* MCA_SYND1 */
131+
case 14:
132+
err.vendor.amd.synd1 = *(i_mce + 13);
133+
fallthrough;
134+
/* MCA_MISC4 */
135+
case 13:
136+
/* MCA_MISC3 */
137+
case 12:
138+
/* MCA_MISC2 */
139+
case 11:
140+
/* MCA_MISC1 */
141+
case 10:
142+
/* MCA_DEADDR */
143+
case 9:
144+
/* MCA_DESTAT */
145+
case 8:
146+
/* reserved */
147+
case 7:
148+
/* MCA_SYND */
149+
case 6:
150+
m->synd = *(i_mce + 5);
151+
fallthrough;
152+
/* MCA_IPID */
153+
case 5:
154+
m->ipid = *(i_mce + 4);
155+
fallthrough;
156+
/* MCA_CONFIG */
157+
case 4:
158+
/* MCA_MISC0 */
159+
case 3:
160+
m->misc = *(i_mce + 2);
161+
fallthrough;
162+
/* MCA_ADDR */
163+
case 2:
164+
m->addr = *(i_mce + 1);
165+
fallthrough;
166+
/* MCA_STATUS */
167+
case 1:
168+
m->status = *i_mce;
169+
}
126170

127171
mce_log(&err);
128172

0 commit comments

Comments
 (0)