Skip to content

cloudarxiv/virtio-inside-out

Repository files navigation

[] Provided QEMU is fully patched. Use README steps for a fresh start.

Setup

  1. Download QEMU source
git clone --branch v9.2.1 --single-branch https://github.com/qemu/qemu.git` # 560MB
git switch -c cs695-dev
  1. Apply patch to add support for virtio-demo-pci (other patches applied similarly)
git apply --stat ../virtio-demo-patch.patch         # generate summary of incoming changes
git apply ../virtio-demo-patch.patch                # apply changes, unstaged
git add --all                                       # stage patch
git commit -m "added support for virtio-demo-pci"   # commit the patch
  1. Configure QEMU to prepare for build
# prepare for an out-of-tree build
cd qemu
mkdir build-0           
cd build-0

# Debug options are help creating detailed qemu traces
../configure --target-list=x86_64-softmmu \  # required
--enable-debug-mutex \
--enable-debug-remap \
--enable-debug-graph-lock \
--enable-cfi-debug \
--enable-debug-tcg \
--enable-kvm \              # required
--enable-virtfs \
--enable-slirp              # required

Install additional packages that are required by the configuration. If you're lazy remove all the config options besides the ones marked #required

  1. Build QEMU
make # approx 10-15 mins. lower with the -j option!

Ensure configure and make are both called from your qemu/build-0 directory. Executables will be stored here.

  1. Start a VM with the QEMU Monitor
# From parent directory
# verify device support
/qemu/build-0/qemu-system-x86_64 -device help | grep virtio-demo-pci

# Download custom VM image (ubuntu 24.04 server image + two drivers of new virtio devices and test programs
# a ~20GB download
wget -i www.cse.iitb.ac.in/~puru/resources/virtio-inside-out/virtio-demo.qcow2

# Start VM

./qemu/build-0/qemu-system-x86_64 -enable-kvm -smp 8 -m 4096 -nic user,model=virtio,hostfwd=tcp::2222-:22 -drive file=virtio-demo.qcow2,media=disk,if=virtio -monitor stdio


6. SSH onto the VM for ease-of-use

ssh -p 2222 vm@localhost


7. (VM) Build and load the virtio-demo frontend driver

cd $HOME/virtio-demo/driver make sudo insmod virtio-demo.ko


8. Attach demo device via QEMU Monitor

(qemu) device_add virtio-demo-pci,id=v0,disable-legacy=on

Observe dmesg in VM after attaching the device.

9. (VM) Build and run the user test app

cd $HOME/virtio-demo/user make ./test-virtio-demo


# Useful Monitor Commands
- `info virtio`, followed by
- `info virtio-status <device_machine_str>`
- `info virtio-queue-status <device_machine_str> <queue_index>`
- `info mtree -f`: To tell if a MemoryRegion is registered in KVM (from kvm_int.h)


# For virtio-xblk-pci
1. Apply the patch

git apply virtio-xblk-helper-patch.patch # create empty source files that need to be filled in.

About

a qemu+virtio tutorial --- usage, internals, new devices

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published