zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.96k stars 6.67k forks source link

RISC-V mode supervisor execution #52806

Open josecm opened 1 year ago

josecm commented 1 year ago

I'd like to run Zephyr on top of the bao hypervisor on qemu riscv64. I hit a wall as soon as I started. Zephyr only seems to support machine/user mode execution. However, as the hypervisor depends on the hypervisor extensions for running, it only supports supervisor/user mode guests, i.e. running in VS/VU modes. The same is likely to be a problem for hypervisors which will soon have upstream support for RISC-V such as Xen or Jailhouse.

I'd like to know if there are any on-ongoing efforts or, at least, plans to support supervisor mode execution for zephyr on RISC-V. If not, would the maintainers be open to such an effort?

npitre commented 1 year ago

There is no such plan that I'm aware of. Of course you are welcome to contribute such ability.

The Linux kernel implements an abstraction that appears to take care of most differences e.g.:

#ifdef CONFIG_RISCV_M_MODE
#define CSR_STATUS mstatus
#else
#define CSR_STATUS sstatus
#endif

and CSR_STATUS is then used so the same code can be compiled for either modes, etc. A similar approach could be used here.

josecm commented 1 year ago

@npitre thanks for answering! And yes, that kind of abstraction would be the first task. There is a quite straightforward mapping between s- and m-mode CSRs. But we'll probably get into all kind of other troubles. I'll try to find the time in the next few months to draft a first approach and bootstrap this.

zephyrbot commented 9 months ago

Hi @npitre,

This issue, marked as an Feature Request, was opened a while ago and did not get any traction. Please confirm the issue is correctly assigned and re-assign it otherwise.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@josecm you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!