All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups
@ 2021-03-12  9:20 Johan Hovold
  2021-03-19 22:01 ` Thomas Gleixner
  2021-03-19 22:05 ` [tip: x86/urgent] " tip-bot2 for Johan Hovold
  0 siblings, 2 replies; 4+ messages in thread
From: Johan Hovold @ 2021-03-12  9:20 UTC (permalink / raw)
  To: Thomas Gleixner, x86
  Cc: Ingo Molnar, Borislav Petkov, H. Peter Anvin, Rob Herring,
	linux-kernel, Sebastian Andrzej Siewior, Jens Frederich,
	Jon Nettleton, Johan Hovold, stable

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")
Cc: stable@vger.kernel.org	# 4.17
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 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


diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 6bd20c0de8bc..7cb93a4f4524 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -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
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups
  2021-03-12  9:20 [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups Johan Hovold
@ 2021-03-19 22:01 ` Thomas Gleixner
  2021-03-22  8:22   ` Johan Hovold
  2021-03-19 22:05 ` [tip: x86/urgent] " tip-bot2 for Johan Hovold
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Gleixner @ 2021-03-19 22:01 UTC (permalink / raw)
  To: Johan Hovold, x86
  Cc: Ingo Molnar, Borislav Petkov, H. Peter Anvin, Rob Herring,
	linux-kernel, Sebastian Andrzej Siewior, Jens Frederich,
	Jon Nettleton, Johan Hovold, stable

On Fri, Mar 12 2021 at 10:20, Johan Hovold wrote:
>  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.

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

Sure.

>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip: x86/urgent] x86/apic/of: Fix CPU devicetree-node lookups
  2021-03-12  9:20 [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups Johan Hovold
  2021-03-19 22:01 ` Thomas Gleixner
@ 2021-03-19 22:05 ` tip-bot2 for Johan Hovold
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Johan Hovold @ 2021-03-19 22:05 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Johan Hovold, Thomas Gleixner, x86, linux-kernel

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 <johan@kernel.org>
AuthorDate:    Fri, 12 Mar 2021 10:20:33 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
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")
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210312092033.26317-1-johan@kernel.org
---
 arch/x86/kernel/apic/apic.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index bda4f2a..4f26700 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups
  2021-03-19 22:01 ` Thomas Gleixner
@ 2021-03-22  8:22   ` Johan Hovold
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2021-03-22  8:22 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: x86, Ingo Molnar, Borislav Petkov, H. Peter Anvin, Rob Herring,
	linux-kernel, Sebastian Andrzej Siewior, Jens Frederich,
	Jon Nettleton, stable

On Fri, Mar 19, 2021 at 11:01:37PM +0100, Thomas Gleixner wrote:
> On Fri, Mar 12 2021 at 10:20, Johan Hovold wrote:
> >  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.

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

Great, thanks!

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-22  8:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12  9:20 [PATCH v2 RESEND] x86/apic/of: Fix CPU devicetree-node lookups Johan Hovold
2021-03-19 22:01 ` Thomas Gleixner
2021-03-22  8:22   ` Johan Hovold
2021-03-19 22:05 ` [tip: x86/urgent] " tip-bot2 for Johan Hovold

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.