xref: /cloud-hypervisor/docs/device_model.md (revision 6ac8dc8745533a6eb31abbb444e9ce1d26733200)
1b55d75eaSSebastien Boeuf# Device Model
2b55d75eaSSebastien Boeuf
3b55d75eaSSebastien BoeufThis document describes the device model supported by `cloud-hypervisor`.
4b55d75eaSSebastien Boeuf
5b55d75eaSSebastien Boeuf## Summary
6b55d75eaSSebastien Boeuf
7b55d75eaSSebastien Boeuf| Device | Build configurable | Enabled by default | Runtime configurable |
864305dabSSebastien Boeuf| :----: | :----: | :----: | :----: |
9*6ac8dc87SDylan Bargatze| Serial port | :x: | :x: | :heavy_check_mark: |
10*6ac8dc87SDylan Bargatze| RTC/CMOS | :heavy_check_mark: | :heavy_check_mark: | :x: |
11*6ac8dc87SDylan Bargatze| I/O APIC | :x: | :x: | :heavy_check_mark: |
12*6ac8dc87SDylan Bargatze| i8042 shutdown/reboot | :x: | :x: | :x: |
13*6ac8dc87SDylan Bargatze| ACPI shutdown/reboot | :x: | :heavy_check_mark: | :x: |
14*6ac8dc87SDylan Bargatze| virtio-blk | :x: | :x: | :heavy_check_mark: |
15*6ac8dc87SDylan Bargatze| virtio-console | :x: | :x: | :heavy_check_mark: |
16*6ac8dc87SDylan Bargatze| virtio-iommu | :x: | :x: | :heavy_check_mark: |
17*6ac8dc87SDylan Bargatze| virtio-net | :x: | :x: | :heavy_check_mark: |
18*6ac8dc87SDylan Bargatze| virtio-pmem | :x: | :x: | :heavy_check_mark: |
19*6ac8dc87SDylan Bargatze| virtio-rng | :x: | :x: | :heavy_check_mark: |
20*6ac8dc87SDylan Bargatze| virtio-vsock | :x: | :x: | :heavy_check_mark: |
21*6ac8dc87SDylan Bargatze| vhost-user-blk | :x: | :x: | :heavy_check_mark: |
22*6ac8dc87SDylan Bargatze| vhost-user-fs | :x: | :x: | :heavy_check_mark: |
23*6ac8dc87SDylan Bargatze| vhost-user-net | :x: | :x: | :heavy_check_mark: |
24*6ac8dc87SDylan Bargatze| VFIO | :heavy_check_mark: | :x: | :heavy_check_mark: |
25b55d75eaSSebastien Boeuf
26b55d75eaSSebastien Boeuf## Legacy devices
27b55d75eaSSebastien Boeuf
28b55d75eaSSebastien Boeuf### Serial port
29b55d75eaSSebastien Boeuf
30b55d75eaSSebastien BoeufSimple emulation of a serial port by reading and writing to specific port I/O
3106d83d2eSHenry Wangaddresses. The serial port can be very useful to gather early logs from the
3206d83d2eSHenry Wangoperating system booted inside the VM.
3306d83d2eSHenry Wang
3406d83d2eSHenry WangFor x86_64, The default serial port is from an emulated 16550A device. It can
3506d83d2eSHenry Wangbe used as the default console for Linux when booting with the option
3606d83d2eSHenry Wang`console=ttyS0`. For AArch64, the default serial port is from an emulated
3706d83d2eSHenry WangPL011 UART device. The related command line for AArch64 is `console=ttyAMA0`.
38b55d75eaSSebastien Boeuf
39b55d75eaSSebastien BoeufThis device is always built-in, and it is disabled by default. It can be
40b55d75eaSSebastien Boeufenabled with the `--serial` option, as long as its parameter is not `off`.
41b55d75eaSSebastien Boeuf
42b55d75eaSSebastien Boeuf### RTC/CMOS
43b55d75eaSSebastien Boeuf
44b55d75eaSSebastien BoeufFor environments such as Windows or EFI which cannot rely on KVM clock, the
45b55d75eaSSebastien Boeufemulation of this legacy device makes the platform usable.
46b55d75eaSSebastien Boeuf
47b55d75eaSSebastien BoeufThis device is built-in by default, but it can be compiled out with Rust
48b55d75eaSSebastien Boeuffeatures. When compiled in, it is always enabled, and cannot be disabled
49b55d75eaSSebastien Boeuffrom the command line.
50b55d75eaSSebastien Boeuf
51d0c0a98eSHenry WangFor AArch64 machines, an ARM PrimeCell Real Time Clock(PL031) is implemented.
52d0c0a98eSHenry WangThis device is built-in by default for the AArch64 platform, and it is always
53d0c0a98eSHenry Wangenabled, and cannot be disabled from the command line.
54d0c0a98eSHenry Wang
55b55d75eaSSebastien Boeuf### I/O APIC
56b55d75eaSSebastien Boeuf
57b55d75eaSSebastien Boeuf`cloud-hypervisor` supports a so-called split IRQ chip implementation by
58b55d75eaSSebastien Boeufimplementing support for the [IOAPIC](https://wiki.osdev.org/IOAPIC).
59b55d75eaSSebastien BoeufBy moving part of the IRQ chip implementation from kernel space to user space,
60b55d75eaSSebastien Boeufthe IRQ chip emulation does not always run in a fully privileged mode.
61b55d75eaSSebastien Boeuf
62b55d75eaSSebastien BoeufThe device is always built-in, and it is enabled depending on the presence of
63b55d75eaSSebastien Boeufthe serial port. If the serial port is disabled, and because no other device
64b55d75eaSSebastien Boeufwould require pin based interrupts (INTx), the I/O APIC is disabled.
65b55d75eaSSebastien Boeuf
66b55d75eaSSebastien Boeuf### i8042
67b55d75eaSSebastien Boeuf
68b55d75eaSSebastien BoeufSimplified PS/2 port since it supports only one key to trigger a reboot or
69b55d75eaSSebastien Boeufshutdown, depending on the ACPI support.
70b55d75eaSSebastien Boeuf
71b55d75eaSSebastien BoeufThis device is always built-in, but it is disabled by default. Because ACPI is
72b55d75eaSSebastien Boeufenabled by default, the handling of reboot/shutdown goes through the dedicated
73b55d75eaSSebastien BoeufACPI device. In case ACPI is disabled, this device is enabled to bring to the
74b55d75eaSSebastien BoeufVM some reboot/shutdown support.
75b55d75eaSSebastien Boeuf
76d0c0a98eSHenry Wang### ARM PrimeCell General Purpose Input/Output (PL061)
77d0c0a98eSHenry Wang
78d0c0a98eSHenry WangSimplified ARM PrimeCell GPIO (PL061) implementation. Only supports key 3 to
79d0c0a98eSHenry Wangtrigger a graceful shutdown of the AArch64 guest.
80d0c0a98eSHenry Wang
81b55d75eaSSebastien Boeuf### ACPI device
82b55d75eaSSebastien Boeuf
83b55d75eaSSebastien BoeufThis is a dedicated device for handling ACPI shutdown and reboot when ACPI is
84b55d75eaSSebastien Boeufenabled.
85b55d75eaSSebastien Boeuf
86b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled by default since the ACPI
87b55d75eaSSebastien Boeuffeature is enabled by default.
88b55d75eaSSebastien Boeuf
89b55d75eaSSebastien Boeuf## Virtio devices
90b55d75eaSSebastien Boeuf
9158474854SSebastien BoeufFor all virtio devices listed below, only `virtio-pci` transport layer is
92bb6c93d5SHenry Wangsupported. Cloud Hypervisor supports multiple PCI segments, and users can
93bb6c93d5SHenry Wangappend `,pci_segment=<PCI_segment_number>` to the device flag in the Cloud
94bb6c93d5SHenry WangHypervisor command line to assign devices to a specific PCI segment.
95b55d75eaSSebastien Boeuf
96b55d75eaSSebastien Boeuf### virtio-block
97b55d75eaSSebastien Boeuf
98b55d75eaSSebastien BoeufThe `virtio-blk` device exposes a block device to the guest. This device is
99b55d75eaSSebastien Boeufusually used to boot the operating system running in the VM.
100b55d75eaSSebastien Boeuf
101b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
102b55d75eaSSebastien Boeufflag `--disk`.
103b55d75eaSSebastien Boeuf
104b55d75eaSSebastien Boeuf### virtio-console
105b55d75eaSSebastien Boeuf
106b55d75eaSSebastien Boeuf`cloud-hypervisor` exposes a `virtio-console` device to the guest. Although
107b55d75eaSSebastien Boeufusing this device as a guest console can potentially cut some early boot
108b55d75eaSSebastien Boeufmessages, it can reduce the guest boot time and provides a complete console
109b55d75eaSSebastien Boeufimplementation.
110b55d75eaSSebastien Boeuf
111b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled by default to provide a guest
112b55d75eaSSebastien Boeufconsole. It can be disabled, switching back to the legacy serial port by
113b55d75eaSSebastien Boeufselecting `--serial tty --console off` from the command line.
114b55d75eaSSebastien Boeuf
115b55d75eaSSebastien Boeuf### virtio-iommu
116b55d75eaSSebastien Boeuf
117b55d75eaSSebastien BoeufAs we want to improve our nested guests support, we added support for exposing
11837a2c13aSAlyssa Rossa [paravirtualized IOMMU](iommu.md) device through virtio. This allows for a
11937a2c13aSAlyssa Rosssafer nested virtio and directly assigned devices support.
120b55d75eaSSebastien Boeuf
121b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
122b55d75eaSSebastien Boeufparameter `iommu=on` in any of the virtio or VFIO devices. If at least one of
123b55d75eaSSebastien Boeufthese devices needs to be connected to the paravirtualized IOMMU, the
124b55d75eaSSebastien Boeuf`virtio-iommu` device will be created.
125b55d75eaSSebastien Boeuf
126b55d75eaSSebastien Boeuf### virtio-net
127b55d75eaSSebastien Boeuf
128b55d75eaSSebastien BoeufThe `virtio-net` device provides network connectivity for the guest, as it
129b55d75eaSSebastien Boeufcreates a network interface connected to a TAP interface automatically created
130b55d75eaSSebastien Boeufby the `cloud-hypervisor` on the host.
131b55d75eaSSebastien Boeuf
132b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
133b55d75eaSSebastien Boeufflag `--net`.
134b55d75eaSSebastien Boeuf
135b55d75eaSSebastien Boeuf### virtio-pmem
136b55d75eaSSebastien Boeuf
137b55d75eaSSebastien BoeufThe `virtio-pmem` implementation emulates a virtual persistent memory device
138b55d75eaSSebastien Boeufthat `cloud-hypervisor` can e.g. boot from. Booting from a `virtio-pmem` device
139b55d75eaSSebastien Boeufallows to bypass the guest page cache and improve the guest memory footprint.
140b55d75eaSSebastien Boeuf
141b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
142b55d75eaSSebastien Boeufflag `--pmem`.
143b55d75eaSSebastien Boeuf
144b55d75eaSSebastien Boeuf### virtio-rng
145b55d75eaSSebastien Boeuf
146b55d75eaSSebastien BoeufA VM does not generate entropy like a real machine would, which is an issue
147b55d75eaSSebastien Boeufwhen workloads running in the guest need random numbers to be generated. The
148b55d75eaSSebastien Boeuf`virtio-rng` device provides entropy to the guest by relying on the generator
149b55d75eaSSebastien Boeufthat can be found on the host. By default, the chosen source of entropy is
150b55d75eaSSebastien Boeuf`/dev/urandom`.
151b55d75eaSSebastien Boeuf
152b55d75eaSSebastien BoeufThis device is always built-in, and it is always enabled. The `--rng` flag can
153b55d75eaSSebastien Boeufbe used to change the source of entropy.
154b55d75eaSSebastien Boeuf
155b55d75eaSSebastien Boeuf### virtio-vsock
156b55d75eaSSebastien Boeuf
157b55d75eaSSebastien BoeufIn order to more efficiently and securely communicate between host and guest,
158b55d75eaSSebastien Boeufwe added a hybrid implementation of the [VSOCK](http://man7.org/linux/man-pages/man7/vsock.7.html)
159b55d75eaSSebastien Boeufsocket address family over virtio.
160b55d75eaSSebastien BoeufCredits go to the [Firecracker](https://github.com/firecracker-microvm/firecracker/blob/master/docs/vsock.md)
161b55d75eaSSebastien Boeufproject as our implementation is a copy of theirs.
162b55d75eaSSebastien Boeuf
163b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
164b55d75eaSSebastien Boeufflag `--vsock`.
165b55d75eaSSebastien Boeuf
166b55d75eaSSebastien Boeuf## Vhost-user devices
167b55d75eaSSebastien Boeuf
168b55d75eaSSebastien BoeufVhost-user devices are virtio backends running outside of the VMM, as its own
169b55d75eaSSebastien Boeufseparate process. They are usually used to bring more flexibility and increased
170b55d75eaSSebastien Boeufisolation.
171b55d75eaSSebastien Boeuf
172b55d75eaSSebastien Boeuf### vhost-user-blk
173b55d75eaSSebastien Boeuf
174b55d75eaSSebastien BoeufAs part of the general effort to offload paravirtualized I/O to external
175b55d75eaSSebastien Boeufprocesses, we added support for vhost-user-blk backends. This enables
176b55d75eaSSebastien Boeuf`cloud-hypervisor` users to plug a `vhost-user` based block device (e.g. SPDK)
177b55d75eaSSebastien Boeufinto the VMM as their virtio block backend.
178b55d75eaSSebastien Boeuf
1793c8cf098SRob BradfordThis device is always built-in, and it is enabled when `vhost_user=true` and
1803c8cf098SRob Bradford`socket` are provided to the `--disk` parameter.
181b55d75eaSSebastien Boeuf
182b55d75eaSSebastien Boeuf### vhost-user-fs
183b55d75eaSSebastien Boeuf
184b55d75eaSSebastien Boeuf`cloud-hypervisor` supports the [virtio-fs](https://virtio-fs.gitlab.io/)
185b55d75eaSSebastien Boeufshared file system, allowing for an efficient and reliable way of sharing
186b55d75eaSSebastien Boeufa filesystem between the host and the cloud-hypervisor guest.
187b55d75eaSSebastien Boeuf
18837a2c13aSAlyssa RossSee our [filesystem sharing](fs.md) documentation for more details on how to
18937a2c13aSAlyssa Rossuse virtio-fs with cloud-hypervisor.
190b55d75eaSSebastien Boeuf
191b55d75eaSSebastien BoeufThis device is always built-in, and it is enabled based on the presence of the
192b55d75eaSSebastien Boeufflag `--fs`.
193b55d75eaSSebastien Boeuf
194b55d75eaSSebastien Boeuf### vhost-user-net
195b55d75eaSSebastien Boeuf
196b55d75eaSSebastien BoeufAs part of the general effort to offload paravirtualized I/O to external
197b55d75eaSSebastien Boeufprocesses, we added support for [vhost-user-net](https://access.redhat.com/solutions/3394851)
198b55d75eaSSebastien Boeufbackends. This enables `cloud-hypervisor` users to plug a `vhost-user` based
199b55d75eaSSebastien Boeufnetworking device (e.g. DPDK) into the VMM as their virtio network backend.
200b55d75eaSSebastien Boeuf
201f322e924SRob BradfordThis device is always built-in, and it is enabled when `vhost_user=true` and
202f322e924SRob Bradford`socket` are provided to the `--net` parameter.
203b55d75eaSSebastien Boeuf
204b55d75eaSSebastien Boeuf## VFIO
205b55d75eaSSebastien Boeuf
206b55d75eaSSebastien BoeufVFIO (Virtual Function I/O) is a kernel framework that exposes direct device
207b55d75eaSSebastien Boeufaccess to userspace. `cloud-hypervisor` uses VFIO to directly assign host
208b55d75eaSSebastien Boeufphysical devices into its guest.
209b55d75eaSSebastien Boeuf
21037a2c13aSAlyssa RossSee our [VFIO documentation](vfio.md) for more details on how to directly
21137a2c13aSAlyssa Rossassign host devices to `cloud-hypervisor` guests.
212b55d75eaSSebastien Boeuf
213b55d75eaSSebastien BoeufBecause VFIO implies `vfio-pci` in the `cloud-hypervisor` context, the VFIO
214b55d75eaSSebastien Boeufsupport is built-in when the `pci` feature is selected. And because the `pci`
215b55d75eaSSebastien Boeuffeature is built-in by default, VFIO support is also built-in by default.
216b55d75eaSSebastien BoeufWhen VFIO support is built-in, a physical device can be passed through, using
217b55d75eaSSebastien Boeufthe flag `--device` in order to enable the VFIO code.
218