• Stars
    star
    190
  • Rank 203,712 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 17 days ago

Reviews

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

Repository Details

Linux kernel loader

Linux-loader

crates.io docs.rs

The linux-loader crate offers support for loading raw ELF (vmlinux) and compressed big zImage (bzImage) format kernel images on x86_64 and PE (Image) kernel images on aarch64. ELF support includes the Linux and PVH boot protocols.

The linux-loader crate is not yet fully independent and self-sufficient, and much of the boot process remains the VMM's responsibility. See [Usage] for details.

Supported features

Usage

Booting a guest using the linux-loader crate involves several steps, depending on the boot protocol used. A simplified overview follows.

Consider an x86_64 VMM that:

  • interfaces with linux-loader;
  • uses GuestMemoryMmap for its guest memory backend;
  • loads an ELF kernel image from a File.

Loading the kernel

One of the first steps in starting the guest is to load the kernel from a Reader into guest memory. For this step, the VMM is required to have configured its guest memory.

In this example, the VMM specifies both the kernel starting address and the starting address of high memory.

use linux_loader::loader::elf::Elf as Loader;
use vm_memory::GuestMemoryMmap;

use std::fs::File;
use std::result::Result;

impl MyVMM {
    fn start_vm(&mut self) {
        let guest_memory = self.create_guest_memory();
        let kernel_file = self.open_kernel_file();

        let load_result = Loader::load::<File, GuestMemoryMmap>(
            &guest_memory,
            Some(self.kernel_start_addr()),
            &mut kernel_file,
            Some(self.himem_start_addr()),
        )
        .expect("Failed to load kernel");
    }
}

Configuring the devices and kernel command line

After the guest memory has been created and the kernel parsed and loaded, the VMM will optionally configure devices and the kernel command line. The latter can then be loaded in guest memory.

impl MyVMM {
    fn start_vm(&mut self) {
        ...
        let cmdline_size = self.kernel_cmdline().as_str().len() + 1;
        linux_loader::loader::load_cmdline::<GuestMemoryMmap>(
            &guest_memory,
            self.cmdline_start_addr(),
            &CString::new(kernel_cmdline).expect("Failed to parse cmdline")
        ).expect("Failed to load cmdline");
    }

Configuring boot parameters

The VMM sets up initial registry values in this phase, without using linux-loader. It can also configure additional boot parameters, using the structs exported by linux-loader.

use linux_loader::configurator::linux::LinuxBootConfigurator;
use linux_loader::configurator::{BootConfigurator, BootParams};

impl MyVMM {
    fn start_vm(&mut self) {
        ...
        let mut bootparams = boot_params::default();
        self.configure_bootparams(&mut bootparams);
        LinuxBootConfigurator::write_bootparams(
            BootParams::new(&params, self.zeropage_addr()),
            &guest_memory,
        ).expect("Failed to write boot params in guest memory");
    }

Done!

Testing

See docs/TESTING.md.

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

vmm-reference

A VMM implementation based of rust-vmm components
Rust
147
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
31
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