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.

  1. https://github.com/riscv/riscv-isa-manual/blob/main/src/hypervisor.adoc

  2. 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

RuslanBukin

qemu

supported

working in multi-core

RuslanBukin

VMID/ASID bits management for stage 2

no support

TODO

MSI interrupts

no support

TODO

u-boot

WIP

u-boot starts up, review

RuslanBukin

PCIe emulation

supported

SMP in host

supported

RuslanBukin

SMP in guest

supported

RuslanBukin

multiple bhyve instances in host

unknown

bhyve SBI implementation ID

done

RuslanBukin

stage 2 pmap

done

RuslanBukin

check if APLIC emulation needs locking to protect structures

added

RuslanBukin

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

riscv/bhyve (last edited 2024-08-14T11:12:03+0000 by RuslanBukin)