xref: /cloud-hypervisor/docs/vdpa.md (revision 888a4652328bcbb3cac0336b415166bebfc7c6f4)
1*888a4652SSebastien Boeuf# Virtio Data Path Acceleration
2*888a4652SSebastien Boeuf
3*888a4652SSebastien BoeufvDPA aims at achieving bare-metal performance for devices passed into a virtual
4*888a4652SSebastien Boeufmachine. It is an alternative to VFIO, as it provides a simpler solution for
5*888a4652SSebastien Boeufachieving migration.
6*888a4652SSebastien Boeuf
7*888a4652SSebastien BoeufIt is a kernel framework introduced recently to handle devices complying with
8*888a4652SSebastien Boeufthe VIRTIO specification on their data-path, while the control path is vendor
9*888a4652SSebastien Boeufspecific. In practice, virtqueues are accessed directly through DMA mechanism
10*888a4652SSebastien Boeufbetween the hardware and the guest. The control path is accessed through the
11*888a4652SSebastien BoeufvDPA framework, being exposed through the vhost interface as a vhost-vdpa
12*888a4652SSebastien Boeufdevice.
13*888a4652SSebastien Boeuf
14*888a4652SSebastien BoeufBecause DMA accesses between device and guest are going through virtqueues,
15*888a4652SSebastien Boeufmigration can be achieved without requiring device's driver to implement any
16*888a4652SSebastien Boeufspecific migration support. In case of VFIO, each vendor is expected to provide
17*888a4652SSebastien Boeufan implementation of the VFIO migration framework, complicating things as it
18*888a4652SSebastien Boeufmust be done for each and every device's driver.
19*888a4652SSebastien Boeuf
20*888a4652SSebastien BoeufThe official [website](https://vdpa-dev.gitlab.io/) contains some extensive
21*888a4652SSebastien Boeufdocumentation on the topic.
22*888a4652SSebastien Boeuf
23*888a4652SSebastien Boeuf## Usage
24*888a4652SSebastien Boeuf
25*888a4652SSebastien Boeuf`VdpaConfig` (known as `--vdpa` from the CLI perspective) contains the list of
26*888a4652SSebastien Boeufparameters available for the vDPA device.
27*888a4652SSebastien Boeuf
28*888a4652SSebastien Boeuf```rust
29*888a4652SSebastien Boeufstruct VdpaConfig {
30*888a4652SSebastien Boeuf    path: PathBuf,
31*888a4652SSebastien Boeuf    num_queues: usize,
32*888a4652SSebastien Boeuf    id: Option<String>,
33*888a4652SSebastien Boeuf    pci_segment: u16,
34*888a4652SSebastien Boeuf}
35*888a4652SSebastien Boeuf```
36*888a4652SSebastien Boeuf
37*888a4652SSebastien Boeuf```
38*888a4652SSebastien Boeuf--vdpa <vdpa>	vDPA device "path=<device_path>,num_queues=<number_of_queues>,iommu=on|off,id=<device_id>,pci_segment=<segment_id>"
39*888a4652SSebastien Boeuf```
40*888a4652SSebastien Boeuf
41*888a4652SSebastien Boeuf### `path`
42*888a4652SSebastien Boeuf
43*888a4652SSebastien BoeufPath of the vDPA device. Usually `/dev/vhost-vdpa-X`.
44*888a4652SSebastien Boeuf
45*888a4652SSebastien BoeufThis parameter is mandatory.
46*888a4652SSebastien Boeuf
47*888a4652SSebastien BoeufValue is a string.
48*888a4652SSebastien Boeuf
49*888a4652SSebastien Boeuf_Example_
50*888a4652SSebastien Boeuf
51*888a4652SSebastien Boeuf```
52*888a4652SSebastien Boeuf--vdpa path=/dev/vhost-vdpa-0
53*888a4652SSebastien Boeuf```
54*888a4652SSebastien Boeuf
55*888a4652SSebastien Boeuf### `num_queues`
56*888a4652SSebastien Boeuf
57*888a4652SSebastien BoeufNumber of virtqueues supported by the vDPA device.
58*888a4652SSebastien Boeuf
59*888a4652SSebastien BoeufThis parameter is optional.
60*888a4652SSebastien Boeuf
61*888a4652SSebastien BoeufValue is an unsigned integer set to `1` by default.
62*888a4652SSebastien Boeuf
63*888a4652SSebastien Boeuf_Example_
64*888a4652SSebastien Boeuf
65*888a4652SSebastien Boeuf```
66*888a4652SSebastien Boeuf--vdpa path=/dev/vhost-vdpa-0,num_queues=2
67*888a4652SSebastien Boeuf```
68*888a4652SSebastien Boeuf
69*888a4652SSebastien Boeuf### `id`
70*888a4652SSebastien Boeuf
71*888a4652SSebastien BoeufIdentifier of the vDPA device.
72*888a4652SSebastien Boeuf
73*888a4652SSebastien BoeufThis parameter is optional. If provided, it must be unique across the entire
74*888a4652SSebastien Boeufvirtual machine.
75*888a4652SSebastien Boeuf
76*888a4652SSebastien BoeufValue is a string.
77*888a4652SSebastien Boeuf
78*888a4652SSebastien Boeuf_Example_
79*888a4652SSebastien Boeuf
80*888a4652SSebastien Boeuf```
81*888a4652SSebastien Boeuf--vdpa path=/dev/vhost-vdpa-0,id=vdpa0
82*888a4652SSebastien Boeuf```
83*888a4652SSebastien Boeuf
84*888a4652SSebastien Boeuf### `pci_segment`
85*888a4652SSebastien Boeuf
86*888a4652SSebastien BoeufPCI segment number to which the vDPA device should be attached to.
87*888a4652SSebastien Boeuf
88*888a4652SSebastien BoeufThis parameter is optional.
89*888a4652SSebastien Boeuf
90*888a4652SSebastien BoeufValue is an unsigned integer of 16 bits set to `0` by default.
91*888a4652SSebastien Boeuf
92*888a4652SSebastien Boeuf_Example_
93*888a4652SSebastien Boeuf
94*888a4652SSebastien Boeuf```
95*888a4652SSebastien Boeuf--vdpa path=/dev/vhost-vdpa-0,pci_segment=1
96*888a4652SSebastien Boeuf```
97*888a4652SSebastien Boeuf
98*888a4652SSebastien Boeuf## Example with vDPA block simulator
99*888a4652SSebastien Boeuf
100*888a4652SSebastien BoeufThe vDPA framework provides a simulator with both `virtio-block` and
101*888a4652SSebastien Boeuf`virtio-net` implementations. This is very useful for testing vDPA when we
102*888a4652SSebastien Boeufdon't have access to the specific hardware.
103*888a4652SSebastien Boeuf
104*888a4652SSebastien BoeufGiven the host kernel has the appropriate modules available, let's load them
105*888a4652SSebastien Boeufall:
106*888a4652SSebastien Boeuf
107*888a4652SSebastien Boeuf```
108*888a4652SSebastien Boeufsudo modprobe vdpa
109*888a4652SSebastien Boeufsudo modprobe vhost_vdpa
110*888a4652SSebastien Boeufsudo modprobe vdpa_sim
111*888a4652SSebastien Boeufsudo modprobe vdpa_sim_blk
112*888a4652SSebastien Boeuf```
113*888a4652SSebastien Boeuf
114*888a4652SSebastien BoeufGiven you have the `iproute2/vdpa` tool installed, let's now create the
115*888a4652SSebastien Boeuf`virtio-block` vDPA device:
116*888a4652SSebastien Boeuf
117*888a4652SSebastien Boeuf```sh
118*888a4652SSebastien Boeufsudo vdpa dev add name vdpa-blk1 mgmtdev vdpasim_blk
119*888a4652SSebastien Boeufsudo chown $USER:$USER /dev/vhost-vdpa-0
120*888a4652SSebastien Boeufsudo chmod 660 /dev/vhost-vdpa-0
121*888a4652SSebastien Boeuf```
122*888a4652SSebastien Boeuf
123*888a4652SSebastien BoeufIncrease the maximum locked memory to ensure setting up IOMMU mappings will
124*888a4652SSebastien Boeufsucceed:
125*888a4652SSebastien Boeuf
126*888a4652SSebastien Boeuf```sh
127*888a4652SSebastien Boeufulimit -l unlimited
128*888a4652SSebastien Boeuf```
129*888a4652SSebastien Boeuf
130*888a4652SSebastien BoeufStart Cloud Hypervisor:
131*888a4652SSebastien Boeuf
132*888a4652SSebastien Boeuf```sh
133*888a4652SSebastien Boeufcloud-hypervisor \
134*888a4652SSebastien Boeuf    --cpus boot=1 \
135*888a4652SSebastien Boeuf    --memory size=1G,hugepages=on \
136*888a4652SSebastien Boeuf    --disk path=focal-server-cloudimg-amd64.raw \
137*888a4652SSebastien Boeuf    --kernel vmlinux \
138*888a4652SSebastien Boeuf    --cmdline "root=/dev/vda1 console=hvc0" \
139*888a4652SSebastien Boeuf    --vdpa path=/dev/vhost-vdpa-0,num_queues=1
140*888a4652SSebastien Boeuf```
141*888a4652SSebastien Boeuf
142*888a4652SSebastien BoeufThe `virtio-block` device backed by the vDPA simulator can be found as
143*888a4652SSebastien Boeuf`/dev/vdb` in the guest:
144*888a4652SSebastien Boeuf
145*888a4652SSebastien Boeuf```
146*888a4652SSebastien Boeufcloud@cloud:~$ lsblk
147*888a4652SSebastien BoeufNAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
148*888a4652SSebastien Boeufnullb0  252:0    0  250G  0 disk
149*888a4652SSebastien Boeufvda     254:0    0  2.2G  0 disk
150*888a4652SSebastien Boeuf├─vda1  254:1    0  2.1G  0 part /
151*888a4652SSebastien Boeuf├─vda14 254:14   0    4M  0 part
152*888a4652SSebastien Boeuf└─vda15 254:15   0  106M  0 part /boot/efi
153*888a4652SSebastien Boeufvdb     254:16   0  128M  0 disk
154*888a4652SSebastien Boeuf```
155