xref: /aosp_15_r20/external/crosvm/docs/book/src/devices/vhost_user.md (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1# Vhost-user devices
2
3Crosvm supports [vhost-user] devices for most virtio devices (block, net, etc ) so that device
4emulation can be done outside of the main vmm process.
5
6Here is a diagram showing how vhost-user block device back-end (implementing the actual disk in
7userspace) and a vhost-user block front-end (implementing the device facing the guest OS) in crosvm
8VMM work together.
9
10<!-- Image from https://docs.google.com/presentation/d/1s6wH5L_F8NNiXls5UgWbD34jtBmijoZuiyLu76Fc2NM/edit#slide=id.ge5067b4ec2_0_55 -->
11
12![vhost-user diagram](images/vhost_user.png)
13
14## How to run
15
16Let's take a block device as an example and see how to start vhost-user devices.
17
18First, start vhost-user block backend with `crosvm devices` command, which waits for a vmm process
19connecting to the socket.
20
21```sh
22# One-time commands to create a disk image.
23fallocate -l 1G disk.img
24mkfs.ext4 disk.img
25
26VHOST_USER_SOCK=/tmp/vhost-user.socket
27
28# Start vhost-user block backend listening on $VHOST_USER_SOCK
29crosvm devices --block vhost=${VHOST_USER_SOCK},path=disk.img
30```
31
32Then, open another terminal and start a vmm process with `--vhost-user` flag (the frontend).
33
34```sh
35crosvm run \
36  --vhost-user block,socket="${VHOST_USER_SOCK}" \
37  <usual crosvm arguments>
38  /path/to/bzImage
39```
40
41As a result, `disk.img` should be exposed as `/dev/vda` just like with `--block disk.img`.
42
43[vhost-user]: https://qemu-project.gitlab.io/qemu/interop/vhost-user.html
44