[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240618172447.GA1387@yaz-khff2.amd.com>
Date: Tue, 18 Jun 2024 13:24:47 -0400
From: Yazen Ghannam <yazen.ghannam@....com>
To: Borislav Petkov <bp@...en8.de>
Cc: "linux-edac@...r.kernel.org" <linux-edac@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"tony.luck@...el.com" <tony.luck@...el.com>,
"x86@...nel.org" <x86@...nel.org>,
"Naik, Avadhut" <Avadhut.Naik@....com>,
"Allen, John" <John.Allen@....com>
Subject: Re: [PATCH 3/3] x86/mce: Use mce_prep_record() helpers for
apei_smca_report_x86_error()
On Tue, Jun 18, 2024 at 11:11:59AM -0400, Ghannam, Yazen wrote:
> On Sat, Jun 15, 2024 at 12:44:20AM +0200, Borislav Petkov wrote:
[...]
> >
> > And looking at
> >
> > convert_apicid_to_cpu()
> >
> > which already does that loop, we probably should talk to tglx whether we can
> > simply export that helper.
> >
> > And better yet if he's done some more helpful caching of the reverse mapping:
> > apicid to CPU number. As part of the topology rewrite. Because then we don't
> > need the loop at all.
> >
>
> Agreed. Here's another option: topo_lookup_cpuid()
>
What do you think of the following example?
Thanks,
Yazen
----
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index abe3a8f22cbd..d8c3c3c818bc 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -171,11 +171,17 @@ static inline unsigned int topology_num_threads_per_package(void)
#ifdef CONFIG_X86_LOCAL_APIC
int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level);
+int topology_get_cpunr(u32 apic_id);
#else
static inline int topology_get_logical_id(u32 apicid, enum x86_topology_domains at_level)
{
return 0;
}
+
+static inline int topology_get_cpunr(u32 apic_id)
+{
+ return -ENODEV;
+}
#endif
#ifdef CONFIG_SMP
diff --git a/arch/x86/kernel/cpu/mce/apei.c b/arch/x86/kernel/cpu/mce/apei.c
index 0cbadfaf2400..415cae8d69bf 100644
--- a/arch/x86/kernel/cpu/mce/apei.c
+++ b/arch/x86/kernel/cpu/mce/apei.c
@@ -66,8 +66,8 @@ 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));
- unsigned int cpu;
struct mce m;
+ int cpu;
if (!boot_cpu_has(X86_FEATURE_SMCA))
return -EINVAL;
@@ -97,13 +97,9 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
if (ctx_info->reg_arr_size < 48)
return -EINVAL;
- for_each_possible_cpu(cpu) {
- if (cpu_data(cpu).topo.initial_apicid == lapic_id)
- break;
- }
-
- if (!cpu_possible(cpu))
- return -EINVAL;
+ cpu = topology_get_cpunr(lapic_id);
+ if (cpu < 0)
+ return cpu;
mce_prep_record_common(&m);
mce_prep_record_per_cpu(cpu, &m);
diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c
index 621a151ccf7d..fc74578ee3bd 100644
--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -95,7 +95,15 @@ static inline u32 topo_apicid(u32 apicid, enum x86_topology_domains dom)
return apicid & (UINT_MAX << x86_topo_system.dom_shifts[dom - 1]);
}
-static int topo_lookup_cpuid(u32 apic_id)
+/**
+ * topology_get_cpunr - Retrieve the CPU number for the given APIC ID
+ * @apic_id: The APIC ID for which to lookup the CPU number
+ *
+ * Returns:
+ * - >= 0: The CPU number for the given APIC ID
+ * - -ENODEV: @apic_id does not match any known CPU
+ */
+int topology_get_cpunr(u32 apic_id)
{
int i;
@@ -106,10 +114,11 @@ static int topo_lookup_cpuid(u32 apic_id)
}
return -ENODEV;
}
+EXPORT_SYMBOL_GPL(topology_get_cpunr);
static __init int topo_get_cpunr(u32 apic_id)
{
- int cpu = topo_lookup_cpuid(apic_id);
+ int cpu = topology_get_cpunr(apic_id);
if (cpu >= 0)
return cpu;
@@ -388,7 +397,7 @@ int topology_hotplug_apic(u32 apic_id, u32 acpi_id)
if (!test_bit(apic_id, apic_maps[TOPO_SMT_DOMAIN].map))
return -ENODEV;
- cpu = topo_lookup_cpuid(apic_id);
+ cpu = topology_get_cpunr(apic_id);
if (cpu < 0)
return -ENOSPC;
Powered by blists - more mailing lists