• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A VMM implementation based of rust-vmm components

vmm-reference

โ— vmm-reference is for experimental purposes and should NOT be used in production. โ—

Design

The purpose of the reference VMM is twofold:

  1. To validate the rust-vmm crates that compose it and demonstrate their functionality in a use-case-agnostic, end-to-end VMM.
  2. To serve as a starting point in the creation of tailor-made VMMs that users build according to their needs. Users can fork the reference VMM, mix and match its components and UI to create a functional VMM with a minimal attack surface and resource footprint, custom-made to suit their isolation requirements.

The reference VMM consists of rust-vmm crates and minimal glue code that sticks them together. The end result is a binary, roughly split between a simple CLI and a vmm crate, which ingests all the available rust-vmm building blocks compiled with all their available features. As crate development progresses, in the future, we may have feature X in crate A mutually incompatible with feature Y in crate B - therefore the reference VMM, which depends on both crates A and B, will no longer support features X and Y simultaneously. If and when this situation occurs, multiple binaries for the reference VMM will be supplied.

The vmm crate allows for pluggable UIs via a VMMConfig structure. A basic command line parser demonstrates how a frontend can be stitched to the VMM.

For more details, see DESIGN.md.

Usage

The reference VMM can be used out of the box as a hello-world example of a fully functional VMM built with rust-vmm crates.

To start a basic VM with one vCPU and 256 MiB memory, you can use the following command:

vmm-reference                      \
    --kernel path=/path/to/vmlinux \
    [--block <blkdev_config> - TBD]
    [--net <netdev_config> - TBD]

The default configuration can be updated through the command line.

The crate's Cargo.toml controls which VMM functionalities are available. By default, all rust-vmm crates are listed as dependencies and therefore included. Users can play freely with the building blocks by modifying the TOML, and the prepackaged CLI can quickly validate the altered configurations. Advanced users can, of course, plug in their own front-end.

CLI reference

  • memory - guest memory configurations
    • size_mib - u32, guest memory size in MiB (decimal)
      • default: 256 MiB
  • kernel - guest kernel configurations
    • path - String, path to the guest kernel image
    • cmdline - String, kernel command line
      • default: "console=ttyS0 i8042.nokbd reboot=t panic=1 pci=off"
    • kernel_load_addr - u64, start address for high memory (decimal)
      • default: 0x100000
  • vcpus - vCPU configurations
    • num - u8, number of vCPUs (decimal)
      • default: 1
  • block - block device configuration
    • path - String, path to the root filesystem
  • net - network device configuration
    • tap - String, tap name, only the API support is added for now, an actual network device configuration is done in the following PR under review.

Note: For now, only the path to the root block device can be configured via command line. The block device will implicitly be read-write and with cache flush command supported. Passing the block argument is optional, if you want to skip it, make sure you pass to the path argument of the kernel configuration, a suitable image (for example a Busybox one). We plan on extending the API to be able to configure more block devices and more parameters for those (not just the path). We also want to offer the same support in the near future for network and vsock devices.

Example: Override the kernel command line

vmm-reference \
    --kernel path=/path/to/kernel/image,cmdline="reboot=t panic=1 pci=off"

Example: VM with 2 vCPUs and 1 GiB memory

vmm-reference                           \
    --memory size_mib=1024          \
    --vcpu num=2                        \
    --kernel path=/path/to/kernel/image

Testing

The reference VMM is, first and foremost, a vehicle for end-to-end testing of rust-vmm crates. Each crate must contain individual functional and performance tests that exercise as wide a range of use cases as possible; the reference VMM is not meant to reiterate on that, but to validate all the pieces put together. The Rust unit tests are testing modules in isolation and private interfaces, while the two Rust integration tests (one for each supported kernel image format, i.e. ELF and bzImage) exercise the only public function of the Vmm object, run(). The Python integration tests make use of the VMM in varied configurations that arenโ€™t overly complex and illustrate realistic use cases (e.g. one test runs a VMM with a virtio block device, one test will run a VMM with PCI, etc.).

To be able to successfully run all the tests in this repo, pre-created resources are stored in S3. The resources are downloaded locally inside the resources directory. This is handled transparently by the test cases. Note: The resources once downloaded are cached, so they are not downloaded on every run.

Running Tests

Recommended way is to run the tests inside a container using the rustvmm/dev docker image as below. (Note: You may need to run docker as sudo.)

docker run --device=/dev/kvm -it \
    --security-opt seccomp=unconfined \
    --volume $(pwd):/vmm-reference rustvmm/dev:v11

Inside the container, to run the tests, first cd vmm-reference and then follow the instructions as follows.

vmm-reference is a workspace, so to run all the Rust tests, the following command should be used:

cargo test --workspace

There is no single command yet for running all the Python integration tests in one shot. To run the tests from a single file, you can use:

pytest <path_to_the_file>

For example:

pytest tests/test_run_reference_vmm.py

A single Python test can be run as well, as shown below:

pytest <path_to_the_file>::<test_name>

For example:

pytest tests/test_run_reference_vmm.py::test_reference_vmm_with_disk

License

This project is licensed under either of:

More Repositories

1

community

rust-vmm community content
459
star
2

vm-virtio

virtio implementation
Rust
370
star
3

vm-memory

Virtual machine's guest memory crate
Rust
310
star
4

kvm-ioctls

Rust
269
star
5

linux-loader

Linux kernel loader
Rust
190
star
6

vhost

Rust
126
star
7

kvm-bindings

Rust
113
star
8

vmm-sys-util

Helpers and utilities used by multiple rust-vmm components and VMMs
Rust
79
star
9

vhost-device

'vhost-user' device backends workspace
Rust
69
star
10

seccompiler

Provides easy-to-use Linux seccomp-bpf jailing.
Rust
69
star
11

rust-vmm-container

Container with all dependencies required for running rust-vmm crates integration tests.
Shell
65
star
12

event-manager

Rust
45
star
13

vm-device

Rust
36
star
14

mshv

Crates for Microsoft Hypervisor ioctls and bindings
Rust
32
star
15

vm-superio

Emulation for legacy devices
Rust
30
star
16

vm-allocator

Provides allocations and release strategies for resources used during the lifetime of a VM.
Rust
30
star
17

rust-vmm-ci

Python
18
star
18

vhost-user-backend

Deprecated repository, code now lives in: https://github.com/rust-vmm/vhost/
Rust
18
star
19

virtio-bindings

This crate is now part of the vm-virtio workspace: https://github.com/rust-vmm/vm-virtio
Rust
15
star
20

vfio-ioctls

Safe wrappers for VFIO
Rust
15
star
21

vfio

Rust
14
star
22

crate-template

This is the template used by all repositories which represent a crate. The purpose is to speed up the creation of new crates and keep the same standard in rust-vmm.
Rust
12
star
23

vfio-bindings

Rust
11
star
24

vm-fdt

Rust
11
star
25

acpi_tables

Rust
9
star
26

xen-sys

Rust
9
star
27

kvm

Rust
8
star
28

vmm-vcpu

7
star
29

kvm_wrapper

Deprecated. Use https://github.com/rust-vmm/kvm-bindings instead.
Rust
6
star
30

vfio-user

Rust
4
star
31

vm-pci

Rust
2
star
32

io-rate-limiter

Rust
1
star
33

.github

1
star