mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: sha@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] commands: smc: disable -c (start cpu) test option for ARMv8
Date: Tue,  5 Oct 2021 13:36:13 +0200	[thread overview]
Message-ID: <20211005113613.3609-1-a.fatoum@pengutronix.de> (raw)

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


             reply	other threads:[~2021-10-05 11:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 11:36 Ahmad Fatoum [this message]
2021-10-05 11:52 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211005113613.3609-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox