spl: opensbi: wait for ack from secondary harts before entering OpenSBI
authorLukas Auer <lukas.auer@aisec.fraunhofer.de>
Sun, 8 Dec 2019 22:28:52 +0000 (23:28 +0100)
committerAndes <uboot@andestech.com>
Tue, 10 Dec 2019 00:23:10 +0000 (08:23 +0800)
At the start, OpenSBI relocates itself to its link address. If the link
address ranges of U-Boot SPL and OpenSBI overlap, the relocation can
lead to code corruption if a hart is still running U-Boot SPL during
relocation. To avoid this problem, the main hart is specified as the
preferred boot hart to perform the relocation. This fixes the code
corruption problems based on the assumption that since the main hart
schedules the secondary harts to enter OpenSBI, it will be the last to
enter OpenSBI. However it was reported that this assumption is not
always correct.

To make sure the assumption always holds true, wait for all secondary
harts to acknowledge the call-function request before entering OpenSBI
on the main hart.

Reported-by: Rick Chen <rick@andestech.com>
Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
Reviewed-by: Rick Chen <rick@andestech.com>
Tested-by: Rick Chen <rick@andestech.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
common/spl/spl_opensbi.c

index 58bf2468ce3c515637d496d6754181ee2ec040c3..6404373ecadfbdd9c713f2209879051aa3cf2159 100644 (file)
@@ -76,9 +76,19 @@ void spl_invoke_opensbi(struct spl_image_info *spl_image)
        invalidate_icache_all();
 
 #ifdef CONFIG_SMP
+       /*
+        * Start OpenSBI on all secondary harts and wait for acknowledgment.
+        *
+        * OpenSBI first relocates itself to its link address. This is done by
+        * the main hart. To make sure no hart is still running U-Boot SPL
+        * during relocation, we wait for all secondary harts to acknowledge
+        * the call-function request before entering OpenSBI on the main hart.
+        * Otherwise, code corruption can occur if the link address ranges of
+        * U-Boot SPL and OpenSBI overlap.
+        */
        ret = smp_call_function((ulong)spl_image->entry_point,
                                (ulong)spl_image->fdt_addr,
-                               (ulong)&opensbi_info, 0);
+                               (ulong)&opensbi_info, 1);
        if (ret)
                hang();
 #endif