Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: riscv: Modify S-mode boot flow to compatible with M-mode firmware #6447

Merged
merged 5 commits into from
Mar 15, 2024

Conversation

gagachang
Copy link
Contributor

In system of S-mode OP-TEE, M-mode firmware transfers control flow to OP-TEE during boot. M-mode runs one hart, which called boot hart, to executes system initialization and jumps into OP-TEE.

However, the ID of boot hart might not be always zero. That is, M-mode firmware may choose a hart, whose ID is non-zero, to jump into OP-TEE "_start" symbol to do OP-TEE initialization. Therefore, it is not feasible to let all harts enter "_start" symbol, and judge whether current hart is primary boot hart, by checking ID is zero or not. Fix it by letting non-boot hart enter "reset_secondary", in S-mode OP-TEE. So that all the harts can do their right things regardless of their hart ID.

Only OP-TEE runs in M-mode will judge primary hart by checking whether the hart ID is zero.

@gagachang
Copy link
Contributor Author

Hello @maroueneboubakri
Please also check this PR, thanks!

@maroueneboubakri
Copy link
Contributor

Hi @gagachang, I still need more time on this, since it may impacts our intended execution flow (not SBI based).

@gagachang
Copy link
Contributor Author

gagachang commented Nov 20, 2023

Hi @gagachang, I still need more time on this, since it may impacts our intended execution flow (not SBI based).

Hi @maroueneboubakri ,Sure!
May I know your execution flow?
I remembered your system is "dual-core" based, one hart runs linux and another hart runs OP-TEE ?
Does OP-TEE run as M-mode ?

@gagachang
Copy link
Contributor Author

Hi @maroueneboubakri
Any progress about this PR?

@maroueneboubakri
Copy link
Contributor

Hi @gagachang, Still didn't try it, I prioritize it once I finish ongoing work in my pipe !

@gagachang
Copy link
Contributor Author

Just rebase to master branch

@gagachang
Copy link
Contributor Author

Hi @maroueneboubakri
Please see #6602 for udomain

@gagachang
Copy link
Contributor Author

@maroueneboubakri
I've updated the PR and added CFG_RISCV_WITH_M_MODE_SM.

core/arch/riscv/riscv.mk Outdated Show resolved Hide resolved
core/arch/riscv/plat-virt/conf.mk Show resolved Hide resolved
core/arch/riscv/riscv.mk Outdated Show resolved Hide resolved
core/arch/riscv/kernel/entry.S Outdated Show resolved Hide resolved
@gagachang
Copy link
Contributor Author

Hi @maroueneboubakri
Any update on this PR?
If it is not feasible on your side, maybe we should think another general solution.

@gagachang gagachang force-pushed the dev-riscv-hsm-boot branch 2 times, most recently from 61188ea to 631ee90 Compare March 2, 2024 16:14
@gagachang
Copy link
Contributor Author

@maroueneboubakri
I change the way to solve the issue.
Please check b54d6b7 and 631ee90.

The issue here is because openSBI boots OP-TEE with "random" hart.
This commit uses "hart lottery" to solve this issue.

@maroueneboubakri
Copy link
Contributor

Hi @gagachang,

I'll try the PR out this week.

Best
Maro

@gagachang
Copy link
Contributor Author

Hi @gagachang,

I'll try the PR out this week.

Best Maro

Thank you! Let me know if there is any issue.

@maroueneboubakri
Copy link
Contributor

Reviewed-by: Marouene Boubakri <[email protected]>

OP-TEE may communicate with the untrusted domain by different solutions,
such as M-mode secure monitor based solution, or direct messaging based
solution. This commit adds CFG_RISCV_WITH_M_MODE_SM to indicate that
OP-TEE uses M-mode secure monitor based solution for the communication.

The CFG_RISCV_WITH_M_MODE_SM should depend on CFG_RISCV_S_MODE and
CFG_RISCV_SBI, since we are using "ecall" to trap into M-mode secure
monitor.

Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Marouene Boubakri <[email protected]>
In RISC-V QEMU virtual platform, OP-TEE OS uses M-mode secure monitor
based solution to communicate with the untrusted domain. Therefore, set
CFG_RISCV_WITH_M_MODE_SM to 'y' in its configuration file.

Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Marouene Boubakri <[email protected]>
Use CFG_RISCV_WITH_M_MODE_SM to determine if OP-TEE uses M-mode secure
monitor based solution to communicate with the untrusetd domain.

Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Marouene Boubakri <[email protected]>
The ID of primary hart should not be restricted to zero. Thus,
determining primary hart and secondart harts by zero hart ID is not
feasible.

We refer to RISC-V linux kernel [1] to fix this issue, by adding a
"hart_lottery" variable. The first hart who enters OP-TEE will win the
lottery, atomically increment this variable, and be the primary hart.
Other harts enter OP-TEE later won't win the lottery, so they execute
the secondary boot sequence.

[1]:
https://github.com/torvalds/linux/blob/v6.7/arch/riscv/kernel/head.S#L244

Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Marouene Boubakri <[email protected]>
When the system adopts M-mode secure monitor based solution, the
secondary harts need to hand over the control back to the secure
monitor after the initial boot sequence. Add related code for this
purpose.

Signed-off-by: Alvin Chang <[email protected]>
Reviewed-by: Marouene Boubakri <[email protected]>
@gagachang
Copy link
Contributor Author

@maroueneboubakri
Tags applied, thanks!

@jforissier jforissier merged commit 63bfec5 into OP-TEE:master Mar 15, 2024
6 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