The page is dedicated to riscv "H"-extension[1].
The RISC-V Hypervisor specification virtualizes supervisor-level architecture to efficiently host guest operating systems atop a type-1 or type-2 hypervisor. Virtual machine implementations require the RISC-V Hypervisor specification. The Hypervisor specification will help drive RISC-V adoption in cloud and embedded applications where virtualization is critical, such as in data centers, automotive applications, and industrial control applications.
https://github.com/riscv/riscv-isa-manual/blob/main/src/hypervisor.adoc
https://five-embeddev.com/riscv-priv-isa-manual/Priv-v1.12/hypervisor.html
Code:
Project Status
Feature |
Status |
Notes |
Owner |
spike |
supported |
working in multi-core |
|
qemu |
supported |
working in multi-core |
|
VMID/ASID bits management for stage 2 |
no support |
TODO |
|
MSI interrupts |
no support |
TODO |
|
u-boot |
WIP |
u-boot starts up, review |
|
PCIe emulation |
supported |
|
|
SMP in host |
supported |
|
|
SMP in guest |
supported |
|
|
multiple bhyve instances in host |
unknown |
|
|
bhyve SBI implementation ID |
|
||
stage 2 pmap |
|
||
check if APLIC emulation needs locking to protect structures |
added |
|
|
check if we want to trap rdcycle / rdtime and emulate it |
|
|
|
SBI RFNC extension support |
|
|
|
Hardware
At the moment, no real hardware with H-extension implemented available.
Instructions
Build FreeBSD (VM host)
Apply VMM kernel & userspace patches to your freebsd repository and build it as usual.
Prepare OpenSBI (host)
git clone https://github.com/riscv/opensbi.git cd opensbi gmake -j24 CROSS_COMPILE=riscv64-none-elf- PLATFORM=generic
Alternatively,
sudo pkg install opensbi
Fetch guest root fs
fetch https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow2.xz unxz FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow2.xz
QEMU
git clone https://github.com/qemu/qemu cd qemu mkdir build && cd build ../configure --target-list=riscv64-softmmu gmake -j `sysctl -n hw.ncpu`
Run QEMU
Add more storage devices if needed (e.g. VM-host rootfs). In my case I use mdroot, so the only drive in the command line below is guest-rootfs disk.
./qemu-system-riscv64 -nographic \ -machine virt \ -cpu 'rv64,h=true' \ -smp 8 \ -device virtio-scsi-pci,id=scsi \ -drive file=FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow2,id=disk,format=qcow2,if=none,cache=writeback -device scsi-hd,drive=disk \ -m 16G \ -device virtio-rng-pci \ -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf \ -kernel /usr/obj/usr/home/br/dev/freebsd/riscv.riscv64/sys/GENERIC/kernel.bin
Bhyve
This has to be run on freebsd that is booted up in QEMU. Ensure you have u-boot.bin on your qemu rootfs.
bhyve -c 8 -m 256 -o bootrom=/usr/local/share/u-boot/u-boot-bhyve-riscv/u-boot.bin -o console=stdio -s 4,virtio-blk,/dev/da0 test