diff mbox series

[v2,2/5] x86/mce: Fixup APIC ID search for x86 CPER decoding

Message ID 20240624212008.663832-3-yazen.ghannam@amd.com (mailing list archive)
State New
Headers show
Series Rework mce_setup() | expand

Commit Message

Yazen Ghannam June 24, 2024, 9:20 p.m. UTC
Replace redundant local search code with a call to an x86/topology
helper function.

Additionally, this now handles the case where a CPU match is not found.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
Link:
https://lkml.kernel.org/r/20240618172447.GA1387@yaz-khff2.amd.com

v1->v2:
* New in v2.

 arch/x86/kernel/cpu/mce/apei.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Thomas Gleixner June 25, 2024, 6:50 a.m. UTC | #1
On Mon, Jun 24 2024 at 16:20, Yazen Ghannam wrote:
>  	/*
>  	 * The starting address of the register array extracted from BERT must
>  	 * match with the first expected register in the register layout of
> @@ -99,16 +103,8 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
>  
>  	mce_setup(&m);
>  
> -	m.extcpu = -1;
> -	m.socketid = -1;
> -
> -	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;
> -			break;
> -		}
> -	}
> +	m.extcpu   = cpu;
> +	m.socketid = cpu_data(cpu).topo.pkg_id;

topology_physical_package_id() ?

Thanks,

        tglx
Yazen Ghannam June 26, 2024, 1:44 a.m. UTC | #2
On Tue, Jun 25, 2024 at 08:50:47AM +0200, Thomas Gleixner wrote:
> On Mon, Jun 24 2024 at 16:20, Yazen Ghannam wrote:
> >  	/*
> >  	 * The starting address of the register array extracted from BERT must
> >  	 * match with the first expected register in the register layout of
> > @@ -99,16 +103,8 @@ int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
> >  
> >  	mce_setup(&m);
> >  
> > -	m.extcpu = -1;
> > -	m.socketid = -1;
> > -
> > -	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;
> > -			break;
> > -		}
> > -	}
> > +	m.extcpu   = cpu;
> > +	m.socketid = cpu_data(cpu).topo.pkg_id;
> 
> topology_physical_package_id() ?
>

Yes, will change.

Thanks,
Yazen
diff mbox series

Patch

diff --git a/arch/x86/kernel/cpu/mce/apei.c b/arch/x86/kernel/cpu/mce/apei.c
index 7f7309ff67d0..59f1c9ea47f5 100644
--- a/arch/x86/kernel/cpu/mce/apei.c
+++ b/arch/x86/kernel/cpu/mce/apei.c
@@ -66,12 +66,16 @@  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;
 
+	cpu = topology_get_cpunr(lapic_id);
+	if (cpu < 0)
+		return cpu;
+
 	/*
 	 * The starting address of the register array extracted from BERT must
 	 * match with the first expected register in the register layout of
@@ -99,16 +103,8 @@  int apei_smca_report_x86_error(struct cper_ia_proc_ctx *ctx_info, u64 lapic_id)
 
 	mce_setup(&m);
 
-	m.extcpu = -1;
-	m.socketid = -1;
-
-	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;
-			break;
-		}
-	}
+	m.extcpu   = cpu;
+	m.socketid = cpu_data(cpu).topo.pkg_id;
 
 	m.apicid = lapic_id;
 	m.bank = (ctx_info->msr_addr >> 4) & 0xFF;