Skip to content

Add SMP support for ARM/RISC-V#353

Merged
Ivan-Velickovic merged 15 commits intoseL4:mainfrom
au-ts:julia/smp
Nov 25, 2025
Merged

Add SMP support for ARM/RISC-V#353
Ivan-Velickovic merged 15 commits intoseL4:mainfrom
au-ts:julia/smp

Conversation

@midnightveil
Copy link
Contributor

@midnightveil midnightveil commented Nov 11, 2025

This PR adds support for SMP builds of the kernel on AArch64.

We have a psci_target_cpus[] array, currently hardcoded, for the IDs of the cores to boot. This should match the values specified in the device tree /cpu@0/ node's <reg> field. Note that due to quirks of various platforms (e.g. OdroidC4), these do not (but can) match the MPIDR values that hardware reports, so we maintain a different table of their MPIDR values.

There a few TODOs scattered throughout this code.

@midnightveil
Copy link
Contributor Author

Ping @Indanz as you had comments on the previous iteration of this code in the smp branch. This has followed your pieces of advice.

_start:

mrs x0, mpidr_el1
and x0, x0,#0xFF // Check processor id
Copy link
Contributor Author

@midnightveil midnightveil Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a quick note on why this was removed: this is wrong, as we are not guaranteed that the CPU we are booting on will have the Aff0 value of the MPIDR_EL1 to be 0. Nor do we expect that this part of the code should run on multiple cores. This dates back the initial public release of seL4CP.

@midnightveil midnightveil force-pushed the julia/smp branch 2 times, most recently from 9d7020c to 9e6c71b Compare November 11, 2025 07:17
@Ivan-Velickovic Ivan-Velickovic changed the title Add SMP support for AArch64 Add SMP support for ARM/RISC-V Nov 21, 2025
@Ivan-Velickovic
Copy link
Collaborator

Ivan-Velickovic commented Nov 21, 2025

Once we finish the code changes we'll need to update a couple sections on the manual (e.g the list/description of Microkit configs and the QEMU sections on how to boot with multiple cores).

We'll also need to adjust the porting platform support section for the SMP related changes.

@midnightveil
Copy link
Contributor Author

This is blocked on seL4/seL4#1563

@Ivan-Velickovic Ivan-Velickovic force-pushed the julia/smp branch 3 times, most recently from 2cb38c4 to 4ae3ae4 Compare November 24, 2025 07:23
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
this fixes real hardware

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
@midnightveil midnightveil force-pushed the julia/smp branch 2 times, most recently from 6c316d3 to 83cfaad Compare November 25, 2025 01:43
Ivan-Velickovic and others added 11 commits November 25, 2025 12:46
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
This means that the board names are the same, but we
build extra configurations of the boards with different
kernel configurations for SMP support. This is cleaner, as
we were finding that renaming the boards was broken a lot
of our build systems code which needed to be duplicate for
new boards.

I'm not entirely convinced this is the best possible solution,
but it is the nicest we can think of.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Move smc functionality to separate file.

Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Julia Vassiliki <julia.vassiliki@unsw.edu.au>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
To account for [1].

[1]: seL4/seL4@11c5d50

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
@midnightveil
Copy link
Contributor Author

Previous before force push cleanups: https://github.com/au-ts/microkit/tree/julia/smp-presquash

diff
diff --git a/flake.nix b/flake.nix
index 5a3f926..65a24df 100644
--- a/flake.nix
+++ b/flake.nix
@@ -96,6 +96,7 @@
             ninja
             libxml2
             qemu
+            gnutar
           ];

           # Necessary for Rust bindgen
diff --git a/loader/src/aarch64/cpus.c b/loader/src/aarch64/cpus.c
index dc76a1f..7ba31e2 100644
--- a/loader/src/aarch64/cpus.c
+++ b/loader/src/aarch64/cpus.c
@@ -24,7 +24,7 @@ size_t cpu_mpidrs[NUM_ACTIVE_CPUS];

 void plat_save_hw_id(int logical_cpu, size_t hw_id)
 {
-    cpu_mpidrs[(uint8_t)logical_cpu] = hw_id;
+    cpu_mpidrs[logical_cpu] = hw_id;
 }

 uint64_t plat_get_hw_id(int logical_cpu)
@@ -73,6 +73,9 @@ void arm_secondary_cpu_entry(int logical_cpu, uint64_t mpidr_el1)
     } else if (logical_cpu >= NUM_ACTIVE_CPUS) {
         LDR_PRINT("ERROR", logical_cpu, "secondary CPU should not be >NUM_ACTIVE_CPUS\n");
         goto fail;
+    } else if (logical_cpu < 0) {
+        LDR_PRINT("ERROR", logical_cpu, "secondary CPU should not have negative logical id\n");
+        goto fail;
     }

     plat_save_hw_id(logical_cpu, mpidr_el1);

@Ivan-Velickovic Ivan-Velickovic merged commit 9c5b306 into seL4:main Nov 25, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants