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

done

u-boot starts up, review

RuslanBukin

PCIe emulation

supported

SMP in host

supported

RuslanBukin

SMP in guest

supported

RuslanBukin

multiple bhyve instances in host

supported

RuslanBukin

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

commit

RuslanBukin

Linux guest

WIP

eta 1 week

RuslanBukin

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

Linux Guest

Step 1. Build linux

git clone https://github.com/torvalds/linux
cd linux
make ARCH=riscv defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

Result file: ./arch/riscv/boot/Image

Step 2. Build busybox

git clone https://git.busybox.net/busybox 
cd busybox
make ARCH=riscv defconfig
make menuconfig
  1. In the "Settings" menu, enable "Build static binary (no shared libs)".
  2. In the "Networking Utilities" menu, disable tc.

make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu-

Step 3. Build initrd

cd busybox
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- CONFIG_PREFIX=../initramfs install
cd ../
mkdir -p initramfs/{bin,sbin,etc,proc,sys,usr/{bin,sbin},dev}
sudo mknod -m 622 initramfs/dev/console c 5 1
sudo mknod -m 666 initramfs/dev/null c 1 3

bash

cat << 'EOF' > initramfs/init
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
echo "Welcome to RISC-V Initrd"
exec /bin/sh
EOF

chmod +x initramfs/init

cd initramfs
find . | cpio -o -H newc | gzip > ../initrd.img

Step 4. Make ramdisk

mkimage -A riscv -T ramdisk -C gzip -n "Ramdisk" -d initrd.img ramdisk.img

Step 5. Create file system.

  1. Create a linux.raw disk image with a FAT32 partition.
  2. Copy linux Image and ramdisk to it.

Step 6. Prepare u-boot

pkg install u-boot-bhyve-riscv

Result file: /usr/local/share/u-boot/u-boot-bhyve-riscv/u-boot.bin

Step 7. Run Bhyve

bhyve -c 1 -m 4096 -o bootrom=/path/to/u-boot.bin -o console=stdio -s 4,virtio-blk,/path/to/linux.raw linux

Step 8. Run Linux from U-Boot

setenv bootargs 'console=ttyS0,115200n8 rw root=/dev/ram0 earlycon=uart8250,mmio32,0x10000'
fatload virtio 0 0x100000000 Image
fatload virtio 0 0x110000000 ramdisk.img
booti 0x100000000 0x110000000 $fdt_addr

riscv/bhyve (last edited 2025-01-27T19:53:20+0000 by RuslanBukin)