Skip to contentSkip to conversation

x86/apic/of: Fix CPU devicetree-node lookups

PATCH RESEND Applied Johan Hovold 3 participants 4 messages Mar 12, 2021 – Mar 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 x86/apic/of: Fix CPU devicetree-node lookups

Architectures that describe the CPU topology in devicetree and that do not have an identity mapping between physical and logical CPU ids need to override the default implementation of arch_match_cpu_phys_id().

Failing to do so breaks CPU devicetree-node lookups using of_get_cpu_node() and of_cpu_device_node_get() which several drivers rely on. It also causes the CPU struct devices exported through sysfs to point to the wrong devicetree nodes.

On x86, CPUs are described in devicetree using their APIC ids and those do not generally coincide with the logical ids, even if CPU0 typically uses APIC id 0. Add the missing implementation of arch_match_cpu_phys_id() so that CPU-node lookups work also with SMP.

Apart from fixing the broken sysfs devicetree-node links this likely do not affect current users of mainline kernels on x86.

Fixes 4e07db9c8db8 ("x86/devicetree: Use CPU description from Device Tree")
---
 arch/x86/kernel/apic/apic.c | 5 +++++
 1 file changed, 5 insertions(+)

It's been over three months so resending.

Can someone please pick this up for 5.12 or -next?

Again, my use case for this is still out-of-tree, but since CPU-node lookup is generic functionality and with observable impact also for mainline users (sysfs) I added a stable tag in v2. Just drop the tag if you think it's unwarranted.

Johan

Changes in v2
- rewrite commit message
- add Fixes tag
- add stable tag for the benefit of out-of-tree users

arch/x86/kernel/apic/apic.c +5 -0
index 6bd20c0de8bc..7cb93a4f4524 100644
@@ -2330,6 +2330,11 @@ static int cpuid_to_apicid[] = {
 	[0 ... NR_CPUS - 1] = -1,
 };
 
+bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
+{
+	return phys_id == cpuid_to_apicid[cpu];
+}
+
 #ifdef CONFIG_SMP
 /**
  * apic_id_is_primary_thread - Check whether APIC ID belongs to a primary thread
Signature · 1 line
2.26.2
#1 lore raw
Quoted 4 lines · Johan Hovold
 arch/x86/kernel/apic/apic.c | 5 +++++
 1 file changed, 5 insertions(+)

It's been over three months so resending.

Sorry, was probably lost in my post X-mas mark all mails read habit.

Quoted 1 line

Can someone please pick this up for 5.12 or -next?

Sure.

Quoted 4 lines

Changes in v2
- rewrite commit message
- add Fixes tag
- add stable tag for the benefit of out-of-tree users

I'm keeping it for correctness sake and not for this reason.

Thanks,

tglx

#2 lore raw
Quoted 7 lines · Thomas Gleixner
Quoted 4 lines · Johan Hovold
 arch/x86/kernel/apic/apic.c | 5 +++++
 1 file changed, 5 insertions(+)

It's been over three months so resending.

Sorry, was probably lost in my post X-mas mark all mails read habit.

Figured that may have had something to do with it, and I guess you didn't see my reminder either as you'd marked the thread as read. I'll resend sooner next time.

Quoted 3 lines
Quoted 1 line

Can someone please pick this up for 5.12 or -next?

Sure.

Great, thanks!

Johan

merge bot Applied
#3 lore raw
In reply to Johan Hovold
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     dd926880da8dbbe409e709c1d3c1620729a94732
Gitweb:        https://git.kernel.org/tip/dd926880da8dbbe409e709c1d3c1620729a94732
Author:        Johan Hovold <[email protected]>
AuthorDate:    Fri, 12 Mar 2021 10:20:33 +01:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 19 Mar 2021 23:01:49 +01:00

x86/apic/of: Fix CPU devicetree-node lookups

Architectures that describe the CPU topology in devicetree and do not have an identity mapping between physical and logical CPU ids must override the default implementation of arch_match_cpu_phys_id().

Failing to do so breaks CPU devicetree-node lookups using of_get_cpu_node() and of_cpu_device_node_get() which several drivers rely on. It also causes the CPU struct devices exported through sysfs to point to the wrong devicetree nodes.

On x86, CPUs are described in devicetree using their APIC ids and those do not generally coincide with the logical ids, even if CPU0 typically uses APIC id 0.

Add the missing implementation of arch_match_cpu_phys_id() so that CPU-node lookups work also with SMP.

Apart from fixing the broken sysfs devicetree-node links this likely does not affect current users of mainline kernels on x86.

Fixes 4e07db9c8db8 ("x86/devicetree: Use CPU description from Device Tree")
---
 arch/x86/kernel/apic/apic.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/kernel/apic/apic.c +5 -0
index bda4f2a..4f26700 100644
@@ -2342,6 +2342,11 @@ static int cpuid_to_apicid[] = {
 	[0 ... NR_CPUS - 1] = -1,
 };
 
+bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
+{
+	return phys_id == cpuid_to_apicid[cpu];
+}
+
 #ifdef CONFIG_SMP
 /**
  * apic_id_is_primary_thread - Check whether APIC ID belongs to a primary thread