stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/apic/of: Fix CPU devicetree-node lookups
@ 2020-12-10 13:39 Johan Hovold
  2021-02-03 15:56 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2020-12-10 13:39 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Ingo Molnar, Borislav Petkov, x86, 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 users of mainline kernels as the above mentioned drivers are
currently not used on x86 as far as I know.

Fixes: 4e07db9c8db8 ("x86/devicetree: Use CPU description from Device Tree")
Cc: stable <stable@vger.kernel.org>     # 4.17
Signed-off-by: Johan Hovold <johan@kernel.org>
---

Thomas,

Hope this looks better to you.

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.

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 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index b3eef1d5c903..19c0119892dd 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2311,6 +2311,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] 2+ messages in thread

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

On Thu, Dec 10, 2020 at 02:39:10PM +0100, Johan Hovold wrote:
> 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 users of mainline kernels as the above mentioned drivers are
> currently not used on x86 as far as I know.
> 
> Fixes: 4e07db9c8db8 ("x86/devicetree: Use CPU description from Device Tree")
> Cc: stable <stable@vger.kernel.org>     # 4.17
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> 
> Thomas,
> 
> Hope this looks better to you.
> 
> 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.

Did you have a chance to look at this one yet?

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 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
> index b3eef1d5c903..19c0119892dd 100644
> --- a/arch/x86/kernel/apic/apic.c
> +++ b/arch/x86/kernel/apic/apic.c
> @@ -2311,6 +2311,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	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-03 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 13:39 [PATCH v2] x86/apic/of: Fix CPU devicetree-node lookups Johan Hovold
2021-02-03 15:56 ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).