Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <yazen.ghannam@amd.com>
Co-developed-by: Avadhut Naik <avadhut.naik@amd.com>
Signed-off-by: Avadhut Naik <avadhut.naik@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
Link: https://lore.kernel.org/r/20241022194158.110073-5-avadhut.naik@amd.com

authored by

Yazen Ghannam and committed by
Borislav Petkov (AMD)
e9876daf d4fca135

+58 -14
+58 -14
arch/x86/kernel/cpu/mce/apei.c
··· 68 68 int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id) 69 69 { 70 70 const u64 *i_mce = ((const u64 *) (ctx_info + 1)); 71 + unsigned int cpu, num_regs; 71 72 bool apicid_found = false; 72 73 struct mce_hw_err err; 73 - unsigned int cpu; 74 74 struct mce *m; 75 75 76 76 if (!boot_cpu_has(X86_FEATURE_SMCA)) ··· 89 89 return -EINVAL; 90 90 91 91 /* 92 - * The register array size must be large enough to include all the 93 - * SMCA registers which need to be extracted. 94 - * 95 92 * The number of registers in the register array is determined by 96 93 * 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. 100 95 */ 101 - if (ctx_info->reg_arr_size < 48) 96 + num_regs = ctx_info->reg_arr_size >> 3; 97 + if (!num_regs) 102 98 return -EINVAL; 103 99 104 100 for_each_possible_cpu(cpu) { ··· 113 117 mce_prep_record_per_cpu(cpu, m); 114 118 115 119 m->bank = (ctx_info->msr_addr >> 4) & 0xFF; 116 - m->status = *i_mce; 117 - m->addr = *(i_mce + 1); 118 - m->misc = *(i_mce + 2); 119 - /* Skipping MCA_CONFIG */ 120 - m->ipid = *(i_mce + 4); 121 - m->synd = *(i_mce + 5); 120 + 121 + /* 122 + * The SMCA register layout is fixed and includes 16 registers. 123 + * The end of the array may be variable, but the beginning is known. 124 + * Cap the number of registers to expected max (15). 125 + */ 126 + if (num_regs > 15) 127 + num_regs = 15; 128 + 129 + switch (num_regs) { 130 + /* MCA_SYND2 */ 131 + case 15: 132 + err.vendor.amd.synd2 = *(i_mce + 14); 133 + fallthrough; 134 + /* MCA_SYND1 */ 135 + case 14: 136 + err.vendor.amd.synd1 = *(i_mce + 13); 137 + fallthrough; 138 + /* MCA_MISC4 */ 139 + case 13: 140 + /* MCA_MISC3 */ 141 + case 12: 142 + /* MCA_MISC2 */ 143 + case 11: 144 + /* MCA_MISC1 */ 145 + case 10: 146 + /* MCA_DEADDR */ 147 + case 9: 148 + /* MCA_DESTAT */ 149 + case 8: 150 + /* reserved */ 151 + case 7: 152 + /* MCA_SYND */ 153 + case 6: 154 + m->synd = *(i_mce + 5); 155 + fallthrough; 156 + /* MCA_IPID */ 157 + case 5: 158 + m->ipid = *(i_mce + 4); 159 + fallthrough; 160 + /* MCA_CONFIG */ 161 + case 4: 162 + /* MCA_MISC0 */ 163 + case 3: 164 + m->misc = *(i_mce + 2); 165 + fallthrough; 166 + /* MCA_ADDR */ 167 + case 2: 168 + m->addr = *(i_mce + 1); 169 + fallthrough; 170 + /* MCA_STATUS */ 171 + case 1: 172 + m->status = *i_mce; 173 + } 122 174 123 175 mce_log(&err); 124 176