Repository navigation
elfloader: add support for PSCI functions via HVC - #239
Conversation
| help="QEMU CPU", default="@QEMU_SIM_CPU@") | ||
| parser.add_argument('-o', '--cpu-opt', dest='qemu_sim_cpu_opt', type=str, | ||
| help="QEMU CPU Options", default="@QEMU_SIM_CPU_OPT@") | ||
| parser.add_argument('--smp', dest='qemu_sim_smp', type=str, |
There was a problem hiding this comment.
All the other main arguments have a single letter variant, -s is already taken though so I didn't know what to put here.
8a53cb9 to
cea7513
Compare
There was a problem hiding this comment.
I should investigate into HVC on 32-bit ARM.
There was a problem hiding this comment.
Seems to be the same as for 64-bit Arm.
There was a problem hiding this comment.
I initially tried that but it failed for 32-bit ARM on QEMU. Will have to debug.
cea7513 to
d415709
Compare
|
Considering you want to turn on a real CPU core, I don't see why you would need to use a HVC call instead of a SMC call for that. HCV is to call to a hypervisor running in EL2, SMC is to call into EL3. So except if for some reason SMC just fails and HVC is redirected to EL3, I don't see how using HVC can work while SMC doesn't. Is this some Qemu quirk or am I missing something? |
|
Yeah, I think this might be a weird QEMU quirk. But given how little was needed to fix it... However there are a few (but not many) boards with device trees that specify that they want HVC calls for PSCI, e.g. https://elixir.bootlin.com/linux/v6.17.4/source/arch/arm64/boot/dts/qcom/msm8994.dtsi#L178. So it's not unreasonable for the device tree to ask for this... |
I don't know why just doing an I do not know why QEMU has this restriction, I am yet to look into it. |
|
Perhaps this clears things up: |
d415709 to
aa72f55
Compare
|
This is ready for review now. I have added more details in the commit message for the motivation and why this is needed in the first place. I attempted to get 32-bit ARM working but ran into two problems:
This is the log I got: I don't know if I have time to debug the 32-bit ARM case, I can type up more details and post it in an issue. Is it possible to get this merged without 32-bit support? |
aa72f55 to
80ae668
Compare
Indanz
left a comment
There was a problem hiding this comment.
I would prefer working arm32 support, but otherwise looks fine.
| help="QEMU CPU", default="@QEMU_SIM_CPU@") | ||
| parser.add_argument('-o', '--cpu-opt', dest='qemu_sim_cpu_opt', type=str, | ||
| help="QEMU CPU Options", default="@QEMU_SIM_CPU_OPT@") | ||
| parser.add_argument('--smp', dest='qemu_sim_smp', type=str, |
That doesn't make any sense, is this another Qemu quirk? Please just add the 32-bit support and ignore the problem for now (so no FID work-arounds either). Maybe add a printf that it seems broken on Qemu, but trying anyway. |
I was looking at this PSCI specification (DEN0022F.b_Power_State_Coordination_Interface). Section 5.1.4 says the function ID for SMC32 is
Sure. |
Oh, that's just wrong. Bit 30 determines whether the calling convention is 32 or 64 bits, but Elfloader is using the 32 bit calling convention on 64-bit, so all codes should be the same. |
Note that this does not work for 32-bit ARM, at least when tested on QEMU with: ../init-build.sh -DPLATFORM=qemu-arm-virt -DAARCH32=1 -DSMP=1 See [1] for details. [1]: seL4#239 (comment). Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
|
I tested this PR (8c7a9b4, merged onto master 6493e0c) with sel4test on two cores:
It isn’t only QEMU that needs this: the Arm VMs on both EC2 and Compute Engine boot at EL1 and their device trees ask for PSCI over HVC, so without this PR the elfloader can’t bring up a second core on either. I think the checks just need kicking? |
|
Thanks for testing, I'll merge it when the tests pass. |
|
The 32-bit Arm builds fail with "/github/workspace/tools/seL4/elfloader-tool/src/arch-arm/armv/armv7-a/32/smc.S:31: Error: selected processor does not support `hvc #0' in ARM mode". Drop 32-bit HVC support or what should we do? |
|
We could encode the bytes manually? Using |
That assumes that the error is wrong though. To me it is a sign we compile with the wrong options, e.g. we need |
|
clang reports: Which I guess is not on by default for armv7 (we also don't seem to specify a CPU, which might be related) @nspin did this for rust-seL4: google/smccc#33 llvm/llvm-project#185356 (thanks LLM for your bug that I'd argue is actually a feature) For hyp mode we compile for armv7ve, but for non-hyp only for armv7a. But we need this even for non-hyp mode seL4 that is SMP. Apparently Cortex-A9 has no virt extensions (but it has SMP, so how does that work?). So we'd need to compile this code only for the CPUs that need it and pass flags or just encode the instruction directly :) |
|
AI was previously suggesting this change to me but I've not had time to get my head around it - I think it switches this code on only on the CPUs with hypervisor extensions, as you said: |
|
If |
Note that this does not work for 32-bit ARM, at least when tested on QEMU with: ../init-build.sh -DPLATFORM=qemu-arm-virt -DAARCH32=1 -DSMP=1 See [1] for details. [1]: seL4#239 (comment). Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Surely that would use SMC instead of HVC? |
The motivation for this change is that currently if the elfloader is trying to boot multiple CPUs for an SMP configuration of seL4, it will fail unless the PSCI method is SVC. The only other possible PSCI method that is possible is HVC, which can occur when the system is being virtualised by something like QEMU and is executing at EL1. For QEMU, unless it is running with virtualisation explicitly enabled (`virtualization=on`), it will default to accepting only the HVC PSCI method. More details are available in comments in the QEMU source [1]. My understanding is the HVC ABI is the exact same as the SMC one, it's just a difference with exception levels. [1]: https://github.com/qemu/qemu/blob/88b171/hw/arm/virt.c#L2265-L2281 Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Note that this does not work for 32-bit ARM, at least when tested on QEMU with: ../init-build.sh -DPLATFORM=qemu-arm-virt -DAARCH32=1 -DSMP=1 See [1] for details. [1]: seL4#239 (comment) Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Add a --smp argument to the simulate script which specifies the number of cores to emulate. The value will be passed on to QEMU via -smp. Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Note that this does not work for 32-bit ARM, at least when tested on QEMU with: ../init-build.sh -DPLATFORM=qemu-arm-virt -DAARCH32=1 -DSMP=1 See [1] for details. [1]: seL4#239 (comment) Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
My understanding is the HVC ABI is the exact same as the SMC one, it's just a difference with exception levels.
Also adds a commit to automatically add the right
-smpflags with the generatedsimulatescripts.Draft because I did this very quickly and need to review my own changes more.
So far I have tested that SMP/uni-core QEMU works and that I haven't broken PSCI SVC functionality by testing SMP on the Odroid-C4.