QEMU as vhost
This page describes how the QEMU vHost is launched: machine type and accelerator, memory pool mapping, PCIe topology, direct kernel boot, QMP and serial, and how disks are attached. The command is rendered from a YAML vHost template, so fields and defaults belong to the vHost profiles in chapter 5 and the schema in chapter 6.
Launch Configuration
A vHost declares its adapter kind, runtime.binary and runtime.env, memory, cpus, accel and machine. Optional fields are cpu, display, monitor, no_reboot, memory_align, memory_map, serial and args. The qemu-vhost kind declared in resources/vhosts/qemu.yaml renders these fields into QEMU arguments.
vHost profile |
Machine and accelerator |
Purpose |
|---|---|---|
|
|
x86_64 guests with 8 GiB RAM and 4 vCPUs by default. |
|
|
ARM64 guests with RAM at |
|
|
vHost-only and device-model samples with a paused 64 MiB vHost. |
|
|
ARM64 device-model samples. |
Memory and PCIe Topology
Guest RAM is mapped from the pool through
memory-backend-file:mem-pathpoints at the machine pool file,offsetis the guest RAM region offset, andshare=onlets gem5 share the same bytes.memory_mapdescribes the guest physical ranges. Q35 splits RAM below and above 4 GiB when memory is large; AArch64 virt starts at 1 GiB. PCI address holes consume no pool bytes.Each device receives a dedicated
pcie-root-portat slots0x10to0x17with eight functions per port; the vHost kind declaresmax_devices: 64.A device attaches as a
vfio-user-pciclient on its root port, withsocketpointing at the device server Unix socket. Whenpci.romis declared, it is passed as the clientromfile.Disks use the remaining slots, which QEMU assigns itself.
Boot, QMP and Serial
kernelin the vHost enables direct kernel boot: the launcher emits-kernelwith an optional-initrd, and-appendjoins the vHostcmdlinewith deviceguest_hints.cmdlinevalues.The default vHost profiles set
no_rebootso an OS reboot does not hide the end of the session;displayandmonitorare disabled by default.The QMP socket is created with
server=on,wait=off; the launcher negotiates QMP capabilities after start as one of the vHost readiness probes.The serial console is provided through a
chardevsocket and written toserial.log.serial.wait_formakes the launcher wait for a marker in guest output, andserial.timeoutgives that marker a deadline in seconds.vHost and device programs must stay in the foreground.
-daemonizeis rejected by the launcher because it conflicts with process-group ownership.
-machine q35,memory-backend=ram
-accel kvm -m <ram.size>B -smp <cpus> -cpu host
-object {"qom-type":"memory-backend-file","id":"ram","size":<ram.size>,
"mem-path":"<pool>","offset":<ram.offset>,"share":true}
-qmp unix:<run-dir>/m0/qmp.sock,server=on,wait=off
-chardev socket,id=serial0,path=<run-dir>/m0/serial.sock,server=on,wait=off,logfile=<serial.log>
-serial chardev:serial0
-device pcie-root-port,id=rp0,bus=pcie.0,...
-device vfio-user-pci,bus=rp0,socket={"type":"unix","path":"<device.sock>"}
Disks
|
QEMU device |
Notes |
|---|---|---|
|
|
Default bus, suitable for the root filesystem. |
|
|
The serial is derived from the machine and disk identifiers. |
|
|
A SCSI controller is appended when needed. |
|
|
Compatibility with older images. |
Every disk is opened as a file node with -blockdev and then wrapped in a format node (raw or qcow2). The read-only flag comes from the disk declaration, and a disk with boot: true in the vHost receives bootindex=1.
Sources
vHost kind and command template:
resources/vhosts/qemu.yaml.TCG profiles:
resources/vhosts/vhost-x86-tcg.yamlandresources/vhosts/vhost-arm-tcg.yaml.vHost argument rendering and probes:
crates/cosim-topology/src/adapter/mod.rs.Boot vHost:
resources/vhosts/qemu.yaml.