/
Setup development environment for vhost-device

Setup development environment for vhost-device

This is a description for how to setup development environment for vhost-virtio. In this documentation, it uses virtio-rng as an example for the building steps and how to launch the QEMU and vhost-virtio programs.

Build vhost-device

  1. Checkout the main branch of the vhost-device package:

    $ git clone https://github.com/rust-vmm/vhost-device
  2. Build the dependency libarary libgpiod:

    $ git clone --depth 1 --branch v2.0.x https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ $ cd libgpiod $ ./autogen.sh --prefix="$PWD/install/" $ make install
  3. Build the vhost-device daemons. After building, binaries are located under the folder “target/debug/":

    $ cargo build

Build QEMU (v6.0.0)

  1. Download QEMU code base and checkout tag v6.0.0:

    $ git clone https://gitlab.com/qemu-project/qemu $ git checkout v6.0.0
  2. Apply three offline patches:

    $ git clone 0001-vhost-user-rng-Add-vhost-user-rng-implementation.patch $ git clone 0002-vhost-user-rng-pci-Add-vhost-user-rng-pci-implementa.patch $ git clone 0003-vhost-user-rng-backend-Add-RNG-vhost-user-daemon-imp.patch

    These three patches are placed in the folder hackbox2:/home/mathieu.poirier/for-leo/patches/qemu.

  3. Build QEMU:

    $ ./configure --target-list=aarch64-softmmu --disable-werror $ make -j8

Run virtual machine

  1. Run vhost-device-rng in the vhost-device directory:

    $ ./target/debug/vhost-device-rng \ --socket-path=/home/mpoirier/work/stratos/host-arm64/rng.sock \ -c 1 -m 512 -p 1000
  2. Run QEMU for creating Arm64 virtual machine:

    #!/bin/bash /path/to/qemu/build/aarch64-softmmu/qemu-system-aarch64 -M virt \ -machine virtualization=true -machine virt,gic-version=3 \ -cpu max -smp 8 -m 4096 \ -drive if=pflash,format=raw,file=efi.img,readonly \ -drive if=pflash,format=raw,file=varstore.img \ -drive if=virtio,format=qcow2,file=disk.img \ -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ -numa node,memdev=mem \ -chardev socket,path=./rng.sock0,id=rng0 \ -device vhost-user-rng-pci,chardev=rng0 \ -device virtio-net-pci,netdev=net0 \ -netdev user,id=net0,hostfwd=tcp::8022-:22 \ -nographic \ -kernel Image -append "earlycon root=/dev/vda2"

    The images efi.img, varstore.img, disk.img, and Image have been uploaded in the folder hackbox2: /home/mathieu.poirier/for-leo/.

Notes

In the folder hackbox2: /home/mathieu.poirier/for-leo/patches/debug, there is a debug patch to apply to the vhost-device-rng to help understand how things work. There are instructions in the changelog to exercise the daemon from the virtualized kernel.

Related content