Page MenuHomeFreeBSD

bhyve/riscv kernel part
Needs ReviewPublic

Authored by br on Mon, Jun 10, 8:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jun 25, 12:33 PM
Unknown Object (File)
Tue, Jun 25, 12:25 PM
Unknown Object (File)
Tue, Jun 25, 12:25 PM
Unknown Object (File)
Tue, Jun 25, 12:21 PM
Unknown Object (File)
Thu, Jun 13, 4:30 PM
Unknown Object (File)
Wed, Jun 12, 2:01 AM
Unknown Object (File)
Tue, Jun 11, 4:46 AM

Details

Reviewers
mhorne
markj
jrtc27
Group Reviewers
bhyve
riscv
Summary

Basic VMM support for RISC-V.

Lots of TODOs indicated within the code, but working for me on single core, single guest VM instance.

Page: https://wiki.freebsd.org/riscv/bhyve

Test Plan

tested in Spike

./spike -m4096 -d --isa RV64IMAFDCH_zicntr_zihpm_sstc --kernel /usr/obj/usr/home/br/dev/freebsd/riscv.riscv64/sys/GENERIC/kernel.bin ../../opensbi/build/platform/generic/firmware/fw_jump.elf

and then

bhyve -m 2560 -o bootrom=/kernel.bin -o console=stdio -s 4,ahci-hd,/bin/ls test

(in both host&guest kernels I have a small mdroot embedded)

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

br requested review of this revision.Mon, Jun 10, 8:52 PM

Without wanting to give a detailed review of the whole thing, I will say that implementing SBI should be done in userspace, it doesn't need to be in the kernel (and really needs to be in userspace to be able to handle the console I/O calls), just like arm64 has PSCI in userspace. You want to just have it send up a VM_EXITCODE_ECALL.

Without wanting to give a detailed review of the whole thing, I will say that implementing SBI should be done in userspace, it doesn't need to be in the kernel (and really needs to be in userspace to be able to handle the console I/O calls), just like arm64 has PSCI in userspace. You want to just have it send up a VM_EXITCODE_ECALL.

Good idea. Agree, we can move it to userspace.

  • fix macro HSTATUS_VGEIN_S
  • rename vmm_call_hyp() to vmm_switch() for world switch

Handle entire SBI in userspace based on jrtc27@ suggestion. We may need however to handle the IPI or TIME (in case of no SSTC) extensions here in kernel for speed (?), so leave the no-op vmm_sbi.c file for now for debugging purposes.

Hi, just a preliminary look, much of the vmm code is beyond me. I hope to test this stuff in a couple weeks!

Two things which could be extracted and committed now:

  • Addition of new SBI implementation IDs
  • Addition of fpe.c. I am hoping to tackle kernel FPU context soon, which can make use of what you have added here.
sys/riscv/include/vmm.h
2–31

Optional, but lately it seems we are encouraging new copyright additions to include proper SPDX tag and omit the boilerplate.

sys/riscv/riscv/fpe.c
178 ↗(On Diff #139701)
sys/riscv/vmm/vmm_ktr.h
70

I guess there is still no shared directory for common vmm code?

sys/riscv/vmm/vmm_riscv.c
406

Seems like handled should just be a bool.

sys/riscv/vmm/vmm_switch.S
203

vmm_switch LGTM.

share/mk/bsd.cpu.mk
354 ↗(On Diff #139929)

This one is for userspace, and we might not even need to enable 'h' there?

Address comments

share/mk/bsd.cpu.mk
354 ↗(On Diff #139929)

Right we don't need this for userspace. Thanks.

sys/riscv/vmm/vmm_ktr.h
70

no such directory yet

sys/riscv/vmm/vmm_riscv.c
406

Fixed!