mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] commands: smc: disable -c (start cpu) test option for ARMv8
@ 2021-10-05 11:36 Ahmad Fatoum
  2021-10-05 11:52 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-10-05 11:36 UTC (permalink / raw)
  To: barebox; +Cc: sha, Ahmad Fatoum

This option is meant for debugging and was only tested on an ARMv7 CPU.
On ARMv8, the handshake times out and the code executing on the second
CPU invokes undefined behavior by modifying the stack base from a non-
naked function. This led so far to a warning, which went unnoticed, but
a follow-up commit will make it an error to use arm_setup_stack on
ARM64. Prepare for this by disabling -c usage on ARM64.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Please reorder before "ARM: document arm_setup_stack() pitfalls"
---
 commands/smc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/commands/smc.c b/commands/smc.c
index 2a53e1b64752..31430655829a 100644
--- a/commands/smc.c
+++ b/commands/smc.c
@@ -9,14 +9,15 @@
 
 #include <asm/psci.h>
 #include <asm/secure.h>
+#include <asm/barebox-arm.h>
 #include <linux/arm-smccc.h>
 
-#define STACK_SIZE 100
+#define HANDSHAKE_STACK_SIZE 100
 #define HANDSHAKE_MAGIC	0xBA12EB0C
 #define ERROR_MAGIC	0xDEADBEEF
 
 struct cpu_context {
-	unsigned long stack[STACK_SIZE];
+	unsigned long stack[HANDSHAKE_STACK_SIZE];
 	long handshake;
 };
 
@@ -35,12 +36,12 @@ static void noinline cpu_handshake(long *handshake)
 		;
 }
 
-static void __naked second_entry(unsigned long arg0)
+static void NAKED second_entry(unsigned long arg0)
 {
 	struct cpu_context *context = (void*)arg0;
 
 	arm_cpu_lowlevel_init();
-	arm_setup_stack((unsigned long)&context->stack[STACK_SIZE]);
+	arm_setup_stack((unsigned long)&context->stack[HANDSHAKE_STACK_SIZE]);
 	barrier();
 
 	cpu_handshake(&context->handshake);
@@ -110,6 +111,11 @@ static int do_smc(int argc, char *argv[])
 			printf("found psci version %ld.%ld\n", res.a0 >> 16, res.a0 & 0xffff);
 			break;
 		case 'c':
+			if (IS_ENABLED(CONFIG_CPU_64)) {
+				printf("CPU bootstrap test not supported for ARMv8\n");
+				return COMMAND_ERROR;
+			}
+
 			if (!context)
 				context = dma_alloc_coherent(sizeof(*context),
 							     DMA_ADDRESS_BROKEN);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

* Re: [PATCH] commands: smc: disable -c (start cpu) test option for ARMv8
  2021-10-05 11:36 [PATCH] commands: smc: disable -c (start cpu) test option for ARMv8 Ahmad Fatoum
@ 2021-10-05 11:52 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-10-05 11:52 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Tue, Oct 05, 2021 at 01:36:13PM +0200, Ahmad Fatoum wrote:
> This option is meant for debugging and was only tested on an ARMv7 CPU.
> On ARMv8, the handshake times out and the code executing on the second
> CPU invokes undefined behavior by modifying the stack base from a non-
> naked function. This led so far to a warning, which went unnoticed, but
> a follow-up commit will make it an error to use arm_setup_stack on
> ARM64. Prepare for this by disabling -c usage on ARM64.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Please reorder before "ARM: document arm_setup_stack() pitfalls"
> ---
>  commands/smc.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-10-05 11:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 11:36 [PATCH] commands: smc: disable -c (start cpu) test option for ARMv8 Ahmad Fatoum
2021-10-05 11:52 ` Sascha Hauer

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git