18ec89bc8SRob Bradford[](https://travis-ci.com/cloud-hypervisor/cloud-hypervisor) 20d819377SSamuel Ortiz 3919226f3SSamuel Ortiz1. [What is Cloud Hypervisor?](#1-what-is-cloud-hypervisor) 4919226f3SSamuel Ortiz * [Requirements](#requirements) 5919226f3SSamuel Ortiz + [High Level](#high-level) 6919226f3SSamuel Ortiz + [Architectures](#architectures) 7919226f3SSamuel Ortiz + [Guest OS](#guest-os) 8919226f3SSamuel Ortiz2. [Getting Started](#2-getting-started) 9919226f3SSamuel Ortiz * [Clone and build](#clone-and-build) 10919226f3SSamuel Ortiz * [Run](#run) 11919226f3SSamuel Ortiz + [Cloud image](#cloud-image) 12919226f3SSamuel Ortiz + [Custom kernel and disk image](#custom-kernel-and-disk-image) 13919226f3SSamuel Ortiz - [Building your kernel](#building-your-kernel) 14919226f3SSamuel Ortiz - [Disk image](#disk-image) 15919226f3SSamuel Ortiz - [Booting the guest VM](#booting-the-guest-vm) 16919226f3SSamuel Ortiz3. [Status](#2-status) 17b55d75eaSSebastien Boeuf * [Device Model](#device-model) 18919226f3SSamuel Ortiz * [TODO](#todo) 19919226f3SSamuel Ortiz4. [rust-vmm dependency](#4-rust-vmm-dependency) 20919226f3SSamuel Ortiz * [Firecracker and crosvm](#firecracker-and-crosvm) 21919226f3SSamuel Ortiz5. [Community](#5-community) 22919226f3SSamuel Ortiz * [Join us](#join-us) 23919226f3SSamuel Ortiz6. [Security](#6-security) 24919226f3SSamuel Ortiz 25919226f3SSamuel Ortiz# 1. What is Cloud Hypervisor? 26919226f3SSamuel Ortiz 27919226f3SSamuel Ortiz**This project is an experiment and should not be used with production workloads.** 28919226f3SSamuel Ortiz 29919226f3SSamuel OrtizCloud Hypervisor is an open source Virtual Machine Monitor (VMM) that runs on top of [KVM](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt). 30919226f3SSamuel OrtizThe project focuses on exclusively running modern, cloud workloads, on top of a limited set of hardware architectures and platforms. 31919226f3SSamuel OrtizCloud workloads refers to those that are usually run by customers inside a cloud provider. For our purposes this means modern 32919226f3SSamuel OrtizLinux* distributions with most I/O handled by paravirtualised devices (i.e. virtio), no requirement for legacy devices and recent CPUs and KVM. 33919226f3SSamuel Ortiz 34919226f3SSamuel OrtizCloud Hypervisor is implemented in [Rust](https://www.rust-lang.org/) and is based on the [rust-vmm](https://github.com/rust-vmm) crates. 35919226f3SSamuel Ortiz 36919226f3SSamuel Ortiz## Objectives 37919226f3SSamuel Ortiz 38919226f3SSamuel Ortiz### High Level 39919226f3SSamuel Ortiz 40919226f3SSamuel Ortiz* KVM and KVM only based 41919226f3SSamuel Ortiz* Minimal emulation 42919226f3SSamuel Ortiz* Low latency 43919226f3SSamuel Ortiz* Low memory footprint 44919226f3SSamuel Ortiz* Low complexity 45919226f3SSamuel Ortiz* High performance 46919226f3SSamuel Ortiz* Small attack surface 47919226f3SSamuel Ortiz* 64-bit support only 48919226f3SSamuel Ortiz* Build time configurable CPU, memory, PCI and NVDIMM hotplug 49919226f3SSamuel Ortiz* Machine to machine migration 50919226f3SSamuel Ortiz 51919226f3SSamuel Ortiz### Architectures 52919226f3SSamuel Ortiz 53919226f3SSamuel Ortiz`cloud-hypervisor` only supports the `x86-64` CPU architecture for now. 54919226f3SSamuel Ortiz 55919226f3SSamuel OrtizWe're planning to add support for the `AArch64` architecture in the future. 56919226f3SSamuel Ortiz 57919226f3SSamuel Ortiz### Guest OS 58919226f3SSamuel Ortiz* `64-bit Linux` 59919226f3SSamuel Ortiz 60919226f3SSamuel OrtizSupport for *modern* 64-bit Windows guest is being evaluated. 61919226f3SSamuel Ortiz 62919226f3SSamuel Ortiz# 2. Getting Started 63919226f3SSamuel Ortiz 64919226f3SSamuel OrtizWe create a folder to build and run `cloud-hypervisor` at `$HOME/cloud-hypervisor` 65919226f3SSamuel Ortiz 66919226f3SSamuel Ortiz```shell 67919226f3SSamuel Ortiz$ export CLOUDH=$HOME/cloud-hypervisor 68919226f3SSamuel Ortiz$ mkdir $CLOUDH 69919226f3SSamuel Ortiz``` 70919226f3SSamuel Ortiz 71919226f3SSamuel Ortiz## Clone and build 72919226f3SSamuel Ortiz 73919226f3SSamuel OrtizFirst you need to clone and build the cloud-hypervisor repo: 74919226f3SSamuel Ortiz 75919226f3SSamuel Ortiz```shell 76919226f3SSamuel Ortiz$ pushd $CLOUDH 778ec89bc8SRob Bradford$ git clone https://github.com/cloud-hypervisor/cloud-hypervisor.git 78919226f3SSamuel Ortiz$ cd cloud-hypervisor 79919226f3SSamuel Ortiz$ cargo build --release 80919226f3SSamuel Ortiz 81919226f3SSamuel Ortiz# We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host. 82919226f3SSamuel Ortiz$ sudo setcap cap_net_admin+ep ./target/release/cloud-hypervisor 83919226f3SSamuel Ortiz 84919226f3SSamuel Ortiz$ popd 85919226f3SSamuel Ortiz``` 86919226f3SSamuel Ortiz 87919226f3SSamuel OrtizThis will build a `cloud-hypervisor` binary under `$CLOUDH/cloud-hypervisor/target/release/cloud-hypervisor`. 88919226f3SSamuel Ortiz 898676759cSSamuel Ortiz### Containerized builds and tests 908676759cSSamuel Ortiz 918676759cSSamuel OrtizIf you want to build and test Cloud Hypervisor without having to install all the 928676759cSSamuel Ortizrequired dependencies (The rust toolchain, cargo tools, etc), you can also use 938676759cSSamuel OrtizCloud Hypervisor's development script: `dev_cli.sh`. Please note that upon its 948676759cSSamuel Ortizfirst invocation, this script will pull a fairly large container image. 958676759cSSamuel Ortiz 968676759cSSamuel OrtizFor example, to build the Cloud Hypervisor release binary: 978676759cSSamuel Ortiz 988676759cSSamuel Ortiz```shell 998676759cSSamuel Ortiz$ pushd $CLOUDH 1008676759cSSamuel Ortiz$ cd cloud-hypervisor 1018676759cSSamuel Ortiz$ ./scripts/dev_cli.sh build --release 1028676759cSSamuel Ortiz``` 1038676759cSSamuel Ortiz 1048676759cSSamuel OrtizWith `dev_cli.sh`, one can also run the Cloud Hypervisor CI locally. This can be 1058676759cSSamuel Ortizvery convenient for debugging CI errors without having to fully rely on the 1068676759cSSamuel OrtizCloud Hypervisor CI infrastructure. 1078676759cSSamuel Ortiz 1088676759cSSamuel OrtizFor example, to run the Cloud Hypervisor unit tests: 1098676759cSSamuel Ortiz 1108676759cSSamuel Ortiz```shell 1113bf46d4cSBo Chen$ ./scripts/dev_cli.sh tests --unit 1128676759cSSamuel Ortiz``` 1138676759cSSamuel Ortiz 1148676759cSSamuel OrtizRun the `./scripts/dev_cli.sh --help` command to view all the supported 1158676759cSSamuel Ortizdevelopment script commands and their related options. 1168676759cSSamuel Ortiz 117919226f3SSamuel Ortiz## Run 118919226f3SSamuel Ortiz 119919226f3SSamuel OrtizYou can run a guest VM by either using an existing cloud image or booting into your own kernel and disk image. 120919226f3SSamuel Ortiz 121919226f3SSamuel Ortiz### Cloud image 122919226f3SSamuel Ortiz 1239900daacSRob Bradford`cloud-hypervisor` supports booting disk images containing all needed 1249900daacSRob Bradfordcomponents to run cloud workloads, a.k.a. cloud images. To do that we rely on 1259900daacSRob Bradfordthe [Rust Hypervisor 1268ec89bc8SRob BradfordFirmware](https://github.com/cloud-hypervisor/rust-hypervisor-firmware) project to provide 1279900daacSRob Bradfordan ELF 128919226f3SSamuel Ortizformatted KVM firmware for `cloud-hypervisor` to directly boot into. 129919226f3SSamuel Ortiz 130*a3342bdbSSebastien BoeufWe need to get the latest `rust-hypervisor-firmware` release and also a working cloud image. Here we will use a Ubuntu image: 131919226f3SSamuel Ortiz 132919226f3SSamuel Ortiz```shell 133919226f3SSamuel Ortiz$ pushd $CLOUDH 134*a3342bdbSSebastien Boeuf$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img 135*a3342bdbSSebastien Boeuf$ qemu-img convert -p -f qcow2 -O raw focal-server-cloudimg-amd64.img focal-server-cloudimg-amd64.raw 13692a62d80SWei Liu$ wget https://github.com/cloud-hypervisor/rust-hypervisor-firmware/releases/download/0.2.8/hypervisor-fw 137919226f3SSamuel Ortiz$ popd 138919226f3SSamuel Ortiz``` 139919226f3SSamuel Ortiz 140919226f3SSamuel Ortiz```shell 141919226f3SSamuel Ortiz$ pushd $CLOUDH 142919226f3SSamuel Ortiz$ sudo setcap cap_net_admin+ep ./cloud-hypervisor/target/release/cloud-hypervisor 143919226f3SSamuel Ortiz$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 144919226f3SSamuel Ortiz --kernel ./hypervisor-fw \ 145*a3342bdbSSebastien Boeuf --disk path=focal-server-cloudimg-amd64.raw \ 146e8e21aebSSamuel Ortiz --cpus boot=4 \ 14700df79a5SSamuel Ortiz --memory size=1024M \ 148919226f3SSamuel Ortiz --net "tap=,mac=,ip=,mask=" \ 149919226f3SSamuel Ortiz --rng 150919226f3SSamuel Ortiz$ popd 151919226f3SSamuel Ortiz``` 152919226f3SSamuel Ortiz 1535652cc7aSSebastien BoeufMultiple arguments can be given to the `--disk` parameter. 1549900daacSRob Bradford 155919226f3SSamuel Ortiz### Custom kernel and disk image 156919226f3SSamuel Ortiz 157919226f3SSamuel Ortiz#### Building your kernel 158919226f3SSamuel Ortiz 1599900daacSRob Bradford`cloud-hypervisor` also supports direct kernel boot into a `vmlinux` ELF kernel 160d5d40537SRob Bradfordimage. In order to support virtio-fs and virtio-iommu we have our own development branch. You are of course able to use your own kernel but these instructions will continue with the version that we develop and test against. 161d5d40537SRob Bradford 162d5d40537SRob BradfordTo build the kernel: 163919226f3SSamuel Ortiz 164919226f3SSamuel Ortiz```shell 165919226f3SSamuel Ortiz 166d5d40537SRob Bradford# Clone the Cloud Hypervisor Linux branch 167919226f3SSamuel Ortiz$ pushd $CLOUDH 16803398532SSebastien Boeuf$ git clone --depth 1 https://github.com/cloud-hypervisor/linux.git -b virtio-fs-virtio-iommu-virtio-mem-5.6-rc4 linux-cloud-hypervisor 169d5d40537SRob Bradford$ pushd linux-cloud-hypervisor 170919226f3SSamuel Ortiz 171919226f3SSamuel Ortiz# Use the cloud-hypervisor kernel config to build your kernel 172df2570a4SSebastien Boeuf$ cp $CLOUDH/cloud-hypervisor/resources/linux-config .config 173919226f3SSamuel Ortiz$ make bzImage -j `nproc` 174919226f3SSamuel Ortiz$ popd 175919226f3SSamuel Ortiz``` 176919226f3SSamuel Ortiz 177919226f3SSamuel OrtizThe `vmlinux` kernel image will then be located at `linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin`. 178919226f3SSamuel Ortiz 179919226f3SSamuel Ortiz#### Disk image 180919226f3SSamuel Ortiz 181*a3342bdbSSebastien BoeufFor the disk image, we will use a Ubuntu cloud image that contains a root partition: 182919226f3SSamuel Ortiz 183919226f3SSamuel Ortiz```shell 184919226f3SSamuel Ortiz$ pushd $CLOUDH 185*a3342bdbSSebastien Boeuf$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img 186*a3342bdbSSebastien Boeuf$ qemu-img convert -p -f qcow2 -O raw focal-server-cloudimg-amd64.img focal-server-cloudimg-amd64.raw 187919226f3SSamuel Ortiz$ popd 188919226f3SSamuel Ortiz``` 189919226f3SSamuel Ortiz 190919226f3SSamuel Ortiz#### Booting the guest VM 191919226f3SSamuel Ortiz 192*a3342bdbSSebastien BoeufNow we can directly boot into our custom kernel and make it use the Ubuntu root partition. 193919226f3SSamuel OrtizIf we want to have 4 vCPUs and 512 MBytes of memory: 194919226f3SSamuel Ortiz 195919226f3SSamuel Ortiz```shell 196919226f3SSamuel Ortiz$ pushd $CLOUDH 197919226f3SSamuel Ortiz$ sudo setcap cap_net_admin+ep ./cloud-hypervisor/target/release/cloud-hypervisor 198919226f3SSamuel Ortiz$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 199919226f3SSamuel Ortiz --kernel ./linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \ 200*a3342bdbSSebastien Boeuf --disk path=focal-server-cloudimg-amd64.raw \ 201*a3342bdbSSebastien Boeuf --cmdline "console=hvc0 root=/dev/vda1 rw" \ 202e8e21aebSSamuel Ortiz --cpus boot=4 \ 20346eaea16SSamuel Ortiz --memory size=1024M \ 20446eaea16SSamuel Ortiz --net "tap=,mac=,ip=,mask=" \ 20546eaea16SSamuel Ortiz --rng 20646eaea16SSamuel Ortiz``` 20746eaea16SSamuel Ortiz 20846eaea16SSamuel OrtizThe above example use the `virtio-console` device as the guest console, and this 20946eaea16SSamuel Ortizdevice may not be enabled soon enough by the guest kernel to get early kernel 21046eaea16SSamuel Ortizdebug messages. 21146eaea16SSamuel Ortiz 21246eaea16SSamuel OrtizWhen in need for earlier debug messages, using the legacy serial device based 21346eaea16SSamuel Ortizconsole is preferred: 21446eaea16SSamuel Ortiz 21546eaea16SSamuel Ortiz``` 21646eaea16SSamuel Ortiz$ ./cloud-hypervisor/target/release/cloud-hypervisor \ 21746eaea16SSamuel Ortiz --kernel ./linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin \ 21846eaea16SSamuel Ortiz --console off \ 21946eaea16SSamuel Ortiz --serial tty \ 220*a3342bdbSSebastien Boeuf --disk path=focal-server-cloudimg-amd64.raw \ 221*a3342bdbSSebastien Boeuf --cmdline "console=ttyS0 root=/dev/vda1 rw" \ 222e8e21aebSSamuel Ortiz --cpus boot=4 \ 22300df79a5SSamuel Ortiz --memory size=1024M \ 224919226f3SSamuel Ortiz --net "tap=,mac=,ip=,mask=" \ 225919226f3SSamuel Ortiz --rng 226919226f3SSamuel Ortiz``` 227919226f3SSamuel Ortiz 228919226f3SSamuel Ortiz# 3. Status 229919226f3SSamuel Ortiz 230919226f3SSamuel Ortiz`cloud-hypervisor` is in a very early, pre-alpha stage. Use at your own risk! 231919226f3SSamuel Ortiz 232*a3342bdbSSebastien BoeufAs of 2020-07-02, the following cloud images are supported: 2331e97d141SRob Bradford* [Ubuntu Bionic](https://cloud-images.ubuntu.com/bionic/current/) (cloudimg) 234c790bba9SRob Bradford* [Ubuntu Focal](https://cloud-images.ubuntu.com/focal/current/) (cloudimg) 2351e97d141SRob Bradford 2361e97d141SRob BradfordDirect kernel boot to userspace should work with most rootfs. 237919226f3SSamuel Ortiz 2386444e29bSRob Bradford## Hot Plug 2396444e29bSRob Bradford 2406444e29bSRob BradfordThis [document](https://github.com/cloud-hypervisor/cloud-hypervisor/blob/master/docs/hotplug.md) details how to add devices to 2416444e29bSRob Bradforda running VM. Currently only CPU hot plug is supported. 2426444e29bSRob Bradford 243b55d75eaSSebastien Boeuf## Device Model 244b55d75eaSSebastien Boeuf 2458ec89bc8SRob BradfordFollow this [documentation](https://github.com/cloud-hypervisor/cloud-hypervisor/blob/master/docs/device_model.md). 246b55d75eaSSebastien Boeuf 247919226f3SSamuel Ortiz## TODO 248919226f3SSamuel Ortiz 249919226f3SSamuel OrtizWe are not tracking the `cloud-hypervisor` TODO list from a specific git tracked file but through 2508ec89bc8SRob Bradford[github issues](https://github.com/cloud-hypervisor/cloud-hypervisor/issues/new) instead. 251919226f3SSamuel Ortiz 252919226f3SSamuel Ortiz# 4. `rust-vmm` project dependency 253919226f3SSamuel Ortiz 254919226f3SSamuel OrtizIn order to satisfy the design goal of having a high-performance, security-focused hypervisor the decision 255919226f3SSamuel Ortizwas made to use the [Rust](https://www.rust-lang.org/) programming language. 256919226f3SSamuel OrtizThe language's strong focus on memory and thread safety makes it an ideal candidate for implementing VMMs 257919226f3SSamuel Ortiz 258919226f3SSamuel OrtizInstead of implementing the VMM components from scratch, `cloud-hypervisor` is importing the [rust-vmm](https://github.com/rust-vmm) 259919226f3SSamuel Ortizcrates, and sharing code and architecture together with other VMMs like e.g. Amazon's [Firecracker](https://firecracker-microvm.github.io/) 260919226f3SSamuel Ortizand Google's [crosvm](https://chromium.googlesource.com/chromiumos/platform/crosvm/). 261919226f3SSamuel Ortiz 262919226f3SSamuel Ortiz`cloud-hypervisor` embraces the rust-vmm project goals, which is to be able to share and re-use 263919226f3SSamuel Ortizas many virtualization crates as possible. As such, the `cloud-hypervisor` relationship with the rust-vmm 264919226f3SSamuel Ortizproject is twofold: 265919226f3SSamuel Ortiz 266919226f3SSamuel Ortiz1. It will use as much of the rust-vmm code as possible. Any new rust-vmm crate that's relevant to the project 267919226f3SSamuel Ortiz goals will be integrated as soon as possible. 268919226f3SSamuel Ortiz2. As it is likely that the rust-vmm project will lack some of the features that `cloud-hypervisor` needs (e.g. ACPI, 269919226f3SSamuel Ortiz VFIO, vhost-user, etc), we will be using the `cloud-hypervisor` VMM to implement and test them, and contribute them 270919226f3SSamuel Ortiz back to the rust-vmm project. 271919226f3SSamuel Ortiz 272919226f3SSamuel Ortiz## Firecracker and crosvm 273919226f3SSamuel Ortiz 274919226f3SSamuel OrtizA large part of the `cloud-hypervisor` code is based on either the Firecracker or the crosvm projects implementations. 275919226f3SSamuel OrtizBoth of these are VMMs written in Rust with a focus on safety and security, like Cloud Hypervisor. 276919226f3SSamuel Ortiz 277919226f3SSamuel OrtizHowever we want to emphasize that the Cloud Hypervisor project is neither a fork nor a reimplementation of any of those 278919226f3SSamuel Ortizprojects. The goals and use cases we're trying to meet are different. 279919226f3SSamuel OrtizWe're aiming at supporting cloud workloads, i.e. those modern, full Linux distribution images currently being run by 280919226f3SSamuel OrtizCloud Service Provider (CSP) tenants. 281919226f3SSamuel Ortiz 282919226f3SSamuel OrtizOur primary target is not to support client or serverless use cases, and as such our code base already diverges 283919226f3SSamuel Ortizfrom the crosvm and Firecracker ones. As we add more features to support our use cases, we believe that the divergence 284919226f3SSamuel Ortizwill increase while at the same time sharing as much of the fundamental virtualization code through the rust-vmm project 285919226f3SSamuel Ortizcrates as possible. 286919226f3SSamuel Ortiz 287919226f3SSamuel Ortiz# 5. Community 288919226f3SSamuel Ortiz 289919226f3SSamuel OrtizWe are working on building a global, diverse and collaborative community around the Cloud Hypervisor project. 290919226f3SSamuel OrtizAnyone who is interested in [contributing](CONTRIBUTING.md) to the project is welcome to participate. 291919226f3SSamuel Ortiz 292919226f3SSamuel OrtizWe believe that contributing to a open source project like Cloud Hypervisor covers a lot more than just sending 293919226f3SSamuel Ortizcode. Testing, documentation, pull request reviews, bug reports, feature requests, project improvement suggestions, 294919226f3SSamuel Ortizetc, are all equal and welcome means of contribution. See the [CONTRIBUTING](CONTRIBUTING.md) document for more details. 295919226f3SSamuel Ortiz 296919226f3SSamuel Ortiz## Join us 297919226f3SSamuel Ortiz 2982e0f1c2aSSamuel OrtizGet an [invite to our Slack channel](https://join.slack.com/t/cloud-hypervisor/shared_invite/enQtNjY3MTE3MDkwNDQ4LWQ1MTA1ZDVmODkwMWQ1MTRhYzk4ZGNlN2UwNTI3ZmFlODU0OTcwOWZjMTkwZDExYWE3YjFmNzgzY2FmNDAyMjI) 299919226f3SSamuel Ortizand [join us on Slack](https://cloud-hypervisor.slack.com/). 300919226f3SSamuel Ortiz 301919226f3SSamuel Ortiz# 6. Security 302919226f3SSamuel Ortiz 303919226f3SSamuel Ortiz**Reporting a Potential Security Vulnerability**: If you have discovered 304919226f3SSamuel Ortizpotential security vulnerability in this project, please send an e-mail to 305919226f3SSamuel Ortizsecure@intel.com. For issues related to Intel Products, please visit 306919226f3SSamuel Ortizhttps://security-center.intel.com. 307919226f3SSamuel Ortiz 308919226f3SSamuel OrtizIt is important to include the following details: 309919226f3SSamuel Ortiz - The projects and versions affected 310919226f3SSamuel Ortiz - Detailed description of the vulnerability 311919226f3SSamuel Ortiz - Information on known exploits 312919226f3SSamuel Ortiz 313919226f3SSamuel OrtizVulnerability information is extremely sensitive. Please encrypt all security 314919226f3SSamuel Ortizvulnerability reports using our *PGP key* 315919226f3SSamuel Ortiz 316919226f3SSamuel OrtizA member of the Intel Product Security Team will review your e-mail and 317919226f3SSamuel Ortizcontact you to to collaborate on resolving the issue. For more information on 318919226f3SSamuel Ortizhow Intel works to resolve security issues, see: *Vulnerability Handling 319919226f3SSamuel OrtizGuidelines* 320919226f3SSamuel Ortiz 321919226f3SSamuel OrtizPGP Key: https://www.intel.com/content/www/us/en/security-center/pgp-public-key.html 322919226f3SSamuel Ortiz 323919226f3SSamuel OrtizVulnerability Handling Guidelines: https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html 324