Skip to content

Commit d0a63f0

Browse files
committed
Merge tag 'ras_core_for_v6.12_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 RAS updates from Borislav Petkov: - Reorganize the struct mce populating functions so that MCA errors reported through BIOS' BERT method can report the correct CPU number the error has been detected on * tag 'ras_core_for_v6.12_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mce: Use mce_prep_record() helpers for apei_smca_report_x86_error() x86/mce: Define mce_prep_record() helpers for common and per-CPU fields x86/mce: Rename mce_setup() to mce_prep_record()
2 parents 79f1a6a + 793aa4b commit d0a63f0

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

arch/x86/include/asm/mce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static inline int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info,
221221
u64 lapic_id) { return -EINVAL; }
222222
#endif
223223

224-
void mce_setup(struct mce *m);
224+
void mce_prep_record(struct mce *m);
225225
void mce_log(struct mce *m);
226226
DECLARE_PER_CPU(struct device *, mce_device);
227227

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ static void __log_error(unsigned int bank, u64 status, u64 addr, u64 misc)
780780
{
781781
struct mce m;
782782

783-
mce_setup(&m);
783+
mce_prep_record(&m);
784784

785785
m.status = status;
786786
m.misc = misc;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void apei_mce_report_mem_error(int severity, struct cper_sec_mem_err *mem_err)
4444
else
4545
lsb = PAGE_SHIFT;
4646

47-
mce_setup(&m);
47+
mce_prep_record(&m);
4848
m.bank = -1;
4949
/* Fake a memory read error with unknown channel */
5050
m.status = MCI_STATUS_VAL | MCI_STATUS_EN | MCI_STATUS_ADDRV | MCI_STATUS_MISCV | 0x9f;
@@ -66,6 +66,7 @@ EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
6666
int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
6767
{
6868
const u64 *i_mce = ((const u64 *) (ctx_info + 1));
69+
bool apicid_found = false;
6970
unsigned int cpu;
7071
struct mce m;
7172

@@ -97,20 +98,19 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
9798
if (ctx_info->reg_arr_size < 48)
9899
return -EINVAL;
99100

100-
mce_setup(&m);
101-
102-
m.extcpu = -1;
103-
m.socketid = -1;
104-
105101
for_each_possible_cpu(cpu) {
106102
if (cpu_data(cpu).topo.initial_apicid == lapic_id) {
107-
m.extcpu = cpu;
108-
m.socketid = cpu_data(m.extcpu).topo.pkg_id;
103+
apicid_found = true;
109104
break;
110105
}
111106
}
112107

113-
m.apicid = lapic_id;
108+
if (!apicid_found)
109+
return -EINVAL;
110+
111+
mce_prep_record_common(&m);
112+
mce_prep_record_per_cpu(cpu, &m);
113+
114114
m.bank = (ctx_info->msr_addr >> 4) & 0xFF;
115115
m.status = *i_mce;
116116
m.addr = *(i_mce + 1);

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,32 @@ static struct irq_work mce_irq_work;
117117
*/
118118
BLOCKING_NOTIFIER_HEAD(x86_mce_decoder_chain);
119119

120-
/* Do initial initialization of a struct mce */
121-
void mce_setup(struct mce *m)
120+
void mce_prep_record_common(struct mce *m)
122121
{
123122
memset(m, 0, sizeof(struct mce));
124-
m->cpu = m->extcpu = smp_processor_id();
123+
124+
m->cpuid = cpuid_eax(1);
125+
m->cpuvendor = boot_cpu_data.x86_vendor;
126+
m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP);
125127
/* need the internal __ version to avoid deadlocks */
126-
m->time = __ktime_get_real_seconds();
127-
m->cpuvendor = boot_cpu_data.x86_vendor;
128-
m->cpuid = cpuid_eax(1);
129-
m->socketid = cpu_data(m->extcpu).topo.pkg_id;
130-
m->apicid = cpu_data(m->extcpu).topo.initial_apicid;
131-
m->mcgcap = __rdmsr(MSR_IA32_MCG_CAP);
132-
m->ppin = cpu_data(m->extcpu).ppin;
133-
m->microcode = boot_cpu_data.microcode;
128+
m->time = __ktime_get_real_seconds();
129+
}
130+
131+
void mce_prep_record_per_cpu(unsigned int cpu, struct mce *m)
132+
{
133+
m->cpu = cpu;
134+
m->extcpu = cpu;
135+
m->apicid = cpu_data(cpu).topo.initial_apicid;
136+
m->microcode = cpu_data(cpu).microcode;
137+
m->ppin = topology_ppin(cpu);
138+
m->socketid = topology_physical_package_id(cpu);
139+
}
140+
141+
/* Do initial initialization of a struct mce */
142+
void mce_prep_record(struct mce *m)
143+
{
144+
mce_prep_record_common(m);
145+
mce_prep_record_per_cpu(smp_processor_id(), m);
134146
}
135147

136148
DEFINE_PER_CPU(struct mce, injectm);
@@ -436,11 +448,11 @@ static noinstr void mce_wrmsrl(u32 msr, u64 v)
436448
static noinstr void mce_gather_info(struct mce *m, struct pt_regs *regs)
437449
{
438450
/*
439-
* Enable instrumentation around mce_setup() which calls external
451+
* Enable instrumentation around mce_prep_record() which calls external
440452
* facilities.
441453
*/
442454
instrumentation_begin();
443-
mce_setup(m);
455+
mce_prep_record(m);
444456
instrumentation_end();
445457

446458
m->mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);

arch/x86/kernel/cpu/mce/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ enum mca_msr {
261261

262262
/* Decide whether to add MCE record to MCE event pool or filter it out. */
263263
extern bool filter_mce(struct mce *m);
264+
void mce_prep_record_common(struct mce *m);
265+
void mce_prep_record_per_cpu(unsigned int cpu, struct mce *m);
264266

265267
#ifdef CONFIG_X86_MCE_AMD
266268
extern bool amd_filter_mce(struct mce *m);

0 commit comments

Comments
 (0)