Re: [PATCH 3/3] x86/mce: Use mce_prep_record() helpers for apei_smca_report_x86_error()

From: Borislav Petkov
Date: Mon Jun 03 2024 - 12:56:11 EST


On Mon, Jun 03, 2024 at 10:34:10AM -0400, Yazen Ghannam wrote:
> One day I'll break this habit. Thanks again for the reminder. :)

Sure, np. :-)

> >> for_each_possible_cpu(cpu) {
> >> - if (cpu_data(cpu).topo.initial_apicid == lapic_id) {
> >> - m.extcpu = cpu;
> >> - m.socketid = cpu_data(m.extcpu).topo.pkg_id;
> >> + if (cpu_data(cpu).topo.initial_apicid == lapic_id)
> >> break;
> >> - }
> >> }
> >>
> >> - m.apicid = lapic_id;
> >> + if (!cpu_possible(cpu))
> >> + return -EINVAL;
> >
> > What's that test for? You just iterated over the possible CPUs using
> > "cpu" as the iterator there...
> >
>
> This is to catch the case where there was no break from the loop.

If the CPU is possible != whether there was a apicid match.

Here's how you do that and I'd let you figure out why yours doesn't
always work:

diff --git a/arch/x86/kernel/cpu/mce/apei.c b/arch/x86/kernel/cpu/mce/apei.c
index 0cbadfaf2400..3885fe05f01e 100644
--- a/arch/x86/kernel/cpu/mce/apei.c
+++ b/arch/x86/kernel/cpu/mce/apei.c
@@ -66,6 +66,7 @@ EXPORT_SYMBOL_GPL(apei_mce_report_mem_error);
int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
{
const u64 *i_mce = ((const u64 *) (ctx_info + 1));
+ bool apicid_found = false;
unsigned int cpu;
struct mce m;

@@ -98,11 +99,13 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
return -EINVAL;

for_each_possible_cpu(cpu) {
- if (cpu_data(cpu).topo.initial_apicid == lapic_id)
+ if (cpu_data(cpu).topo.initial_apicid == lapic_id) {
+ apicid_found = true;
break;
+ }
}

- if (!cpu_possible(cpu))
+ if (!apicid_found)
return -EINVAL;

mce_prep_record_common(&m);


Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette