linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP
@ 2019-10-04 15:52 Nicolas Saenz Julienne
  2019-11-18 11:49 ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-10-04 15:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: wahrenst, f.fainelli, Nicolas Saenz Julienne, kernelci.org bot,
	Russell King, linux-arm-kernel

On SMP builds, in order to properly link CPU devices with their
respective DT nodes we start by matching the boot CPU. This is achieved
by comparing the 'reg' property on each of the CPU DT nodes with the
MPIDR. The association is necessary as to validate the whole CPU logical
map, which ultimately links CPU devices and their DT nodes.

On setups built without SMP, no MPIDR read is performed. The only thing
expected is for the 'reg' property in the CPU DT node to contain the
value 0x0.

This causes problems on MP setups built without SMP. As their boot CPU
DT node contains the relevant MPIDR as opposed to 0x0. No match is then
possible. This causes troubles further down the line as drivers are
unable to get the CPU's DT node.

Change the way we choose whether to get the MPIDR or not. On builds
without SMP check the number of CPUs defined in DT. Anything > 1 means
the MPIDR should be available and matched accordingly.

Note that if there was a rogue UP device exposing multiple active CPUs
in its DT the possible outcomes depend on the ARM series. For example
Cortex-A9 specifies that the MPIDR is returns 0x0 on UP devices. On the
other hand ARM1176JZ's TRM doesn't define a MPIDR register and specifies
that any unwarranted register access will raise an undefined exception.
Overall, given the bogus DT, a reasonable outcome.

This was originally seen on a Raspberry Pi 2 built with bcm2835_defconfig.

Reported-by: "kernelci.org bot" <bot@kernelci.org>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Tested-by: Stefan Wahren <wahrenst@gmx.net>

---

Changes since v1:
  - Rewrite patch description
  - Use of_get_available_child_count()

Note: kept Setfan's Tested-by as the changes only affect a corner case.

 arch/arm/kernel/devtree.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
index 39c978698406..cd11742d9bc2 100644
--- a/arch/arm/kernel/devtree.c
+++ b/arch/arm/kernel/devtree.c
@@ -74,7 +74,7 @@ void __init arm_dt_init_cpu_maps(void)
 	struct device_node *cpu, *cpus;
 	int found_method = 0;
 	u32 i, j, cpuidx = 1;
-	u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
+	u32 mpidr = 0;
 
 	u32 tmp_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
 	bool bootcpu_valid = false;
@@ -83,6 +83,9 @@ void __init arm_dt_init_cpu_maps(void)
 	if (!cpus)
 		return;
 
+	if (is_smp() || of_get_available_child_count(cpus) > 1)
+		mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
+
 	for_each_of_cpu_node(cpu) {
 		const __be32 *cell;
 		int prop_bytes;
-- 
2.23.0


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

* Re: [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP
  2019-10-04 15:52 [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP Nicolas Saenz Julienne
@ 2019-11-18 11:49 ` Nicolas Saenz Julienne
  2019-11-18 12:55   ` Russell King - ARM Linux admin
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-11-18 11:49 UTC (permalink / raw)
  To: linux-kernel
  Cc: f.fainelli, kernelci.org bot, Russell King, wahrenst, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 2864 bytes --]

On Fri, 2019-10-04 at 17:52 +0200, Nicolas Saenz Julienne wrote:
> On SMP builds, in order to properly link CPU devices with their
> respective DT nodes we start by matching the boot CPU. This is achieved
> by comparing the 'reg' property on each of the CPU DT nodes with the
> MPIDR. The association is necessary as to validate the whole CPU logical
> map, which ultimately links CPU devices and their DT nodes.
> 
> On setups built without SMP, no MPIDR read is performed. The only thing
> expected is for the 'reg' property in the CPU DT node to contain the
> value 0x0.
> 
> This causes problems on MP setups built without SMP. As their boot CPU
> DT node contains the relevant MPIDR as opposed to 0x0. No match is then
> possible. This causes troubles further down the line as drivers are
> unable to get the CPU's DT node.
> 
> Change the way we choose whether to get the MPIDR or not. On builds
> without SMP check the number of CPUs defined in DT. Anything > 1 means
> the MPIDR should be available and matched accordingly.
> 
> Note that if there was a rogue UP device exposing multiple active CPUs
> in its DT the possible outcomes depend on the ARM series. For example
> Cortex-A9 specifies that the MPIDR is returns 0x0 on UP devices. On the
> other hand ARM1176JZ's TRM doesn't define a MPIDR register and specifies
> that any unwarranted register access will raise an undefined exception.
> Overall, given the bogus DT, a reasonable outcome.
> 
> This was originally seen on a Raspberry Pi 2 built with bcm2835_defconfig.
> 
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> Tested-by: Stefan Wahren <wahrenst@gmx.net>

ping :)

> ---
> 
> Changes since v1:
>   - Rewrite patch description
>   - Use of_get_available_child_count()
> 
> Note: kept Setfan's Tested-by as the changes only affect a corner case.
> 
>  arch/arm/kernel/devtree.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
> index 39c978698406..cd11742d9bc2 100644
> --- a/arch/arm/kernel/devtree.c
> +++ b/arch/arm/kernel/devtree.c
> @@ -74,7 +74,7 @@ void __init arm_dt_init_cpu_maps(void)
>  	struct device_node *cpu, *cpus;
>  	int found_method = 0;
>  	u32 i, j, cpuidx = 1;
> -	u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
> +	u32 mpidr = 0;
>  
>  	u32 tmp_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
>  	bool bootcpu_valid = false;
> @@ -83,6 +83,9 @@ void __init arm_dt_init_cpu_maps(void)
>  	if (!cpus)
>  		return;
>  
> +	if (is_smp() || of_get_available_child_count(cpus) > 1)
> +		mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
> +
>  	for_each_of_cpu_node(cpu) {
>  		const __be32 *cell;
>  		int prop_bytes;


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP
  2019-11-18 11:49 ` Nicolas Saenz Julienne
@ 2019-11-18 12:55   ` Russell King - ARM Linux admin
  2019-11-18 17:45     ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: Russell King - ARM Linux admin @ 2019-11-18 12:55 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: linux-kernel, f.fainelli, kernelci.org bot, wahrenst, linux-arm-kernel

On Mon, Nov 18, 2019 at 12:49:04PM +0100, Nicolas Saenz Julienne wrote:
> On Fri, 2019-10-04 at 17:52 +0200, Nicolas Saenz Julienne wrote:
> > On SMP builds, in order to properly link CPU devices with their
> > respective DT nodes we start by matching the boot CPU. This is achieved
> > by comparing the 'reg' property on each of the CPU DT nodes with the
> > MPIDR. The association is necessary as to validate the whole CPU logical
> > map, which ultimately links CPU devices and their DT nodes.

No, that is not the primary purpose of the CPU logical map.  The CPU 
logical map is there to map the CPU logical number to a hardware number,
necessary for programming hardware.

> > On setups built without SMP, no MPIDR read is performed. The only thing
> > expected is for the 'reg' property in the CPU DT node to contain the
> > value 0x0.
> > 
> > This causes problems on MP setups built without SMP. As their boot CPU
> > DT node contains the relevant MPIDR as opposed to 0x0. No match is then
> > possible. This causes troubles further down the line as drivers are
> > unable to get the CPU's DT node.

So the DT is incorrect for the platform - it is not describing the
hardware.  Why can't the DT be fixed?  Clearly, it would have never
worked with the mainline kernel today.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

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

* Re: [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP
  2019-11-18 12:55   ` Russell King - ARM Linux admin
@ 2019-11-18 17:45     ` Nicolas Saenz Julienne
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2019-11-18 17:45 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: linux-kernel, f.fainelli, kernelci.org bot, wahrenst, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 1798 bytes --]

Hi Russell, thanks for the review.

On Mon, 2019-11-18 at 12:55 +0000, Russell King - ARM Linux admin wrote:
> On Mon, Nov 18, 2019 at 12:49:04PM +0100, Nicolas Saenz Julienne wrote:
> > On Fri, 2019-10-04 at 17:52 +0200, Nicolas Saenz Julienne wrote:
> > > On SMP builds, in order to properly link CPU devices with their
> > > respective DT nodes we start by matching the boot CPU. This is achieved
> > > by comparing the 'reg' property on each of the CPU DT nodes with the
> > > MPIDR. The association is necessary as to validate the whole CPU logical
> > > map, which ultimately links CPU devices and their DT nodes.
> 
> No, that is not the primary purpose of the CPU logical map.  The CPU 
> logical map is there to map the CPU logical number to a hardware number,
> necessary for programming hardware.

Noted.

> > > On setups built without SMP, no MPIDR read is performed. The only thing
> > > expected is for the 'reg' property in the CPU DT node to contain the
> > > value 0x0.
> > > 
> > > This causes problems on MP setups built without SMP. As their boot CPU
> > > DT node contains the relevant MPIDR as opposed to 0x0. No match is then
> > > possible. This causes troubles further down the line as drivers are
> > > unable to get the CPU's DT node.
> 
> So the DT is incorrect for the platform - it is not describing the
> hardware.  Why can't the DT be fixed?  Clearly, it would have never
> worked with the mainline kernel today.

Sorry but I don't see any incorrect DT here. From the ARM CPU bindings I gather
that (at least since ARMv7) every CPU node should contain its corresponding
MPIDR. It transpires that ARM's DT cpu map init code should take that into
account regardles of whether the kernel supports SMP, isn't it?

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2019-11-18 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 15:52 [PATCH v2] ARM: dt: check MPIDR on MP devices built without SMP Nicolas Saenz Julienne
2019-11-18 11:49 ` Nicolas Saenz Julienne
2019-11-18 12:55   ` Russell King - ARM Linux admin
2019-11-18 17:45     ` Nicolas Saenz Julienne

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).