Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
682976c
linux-loader: Create linux-loader crate
bjzhjing Apr 18, 2019
49da615
Relicensing files according to the upstream discussion
bjzhjing May 6, 2019
e983c6a
loader: Define a kernel loader trait
bjzhjing Apr 18, 2019
02a04c0
loader: Add bzImage support
bjzhjing Apr 18, 2019
eef5535
lint: Fix clippy lint warnings
bjzhjing Apr 19, 2019
79bd1d5
tests: Add kcov based coverage generation scripts
May 6, 2019
c39f0f8
buildkite: Initial pipeline
May 6, 2019
62cb152
loader: Add inline links for loader trait and structs
bjzhjing Jun 1, 2019
be2e8b0
loader: Remove dependency on GuestMemoryMmap
bjzhjing Jun 1, 2019
f6da4fe
loader: Add memory overflow checking for kernel end
bjzhjing Jun 1, 2019
b71ddaa
loader: Refactor comments
bjzhjing Jun 1, 2019
97e3c54
loader: Rename high memory field for loader trait and functions
bjzhjing Jun 1, 2019
d758d9e
buildkite: Add repository post-checkout hook to upload bzImage
bjzhjing Jun 1, 2019
9cde9f2
buildkite: Fix path in post-checkout hook
andreeaflorescu Jun 6, 2019
eb49f57
loader: Remove ignore config to run bzImage loader unit test
bjzhjing Jun 6, 2019
81487dc
linux-loader: Fix rustfmt errors
bjzhjing Jun 6, 2019
5be96c6
Update README and pipeline to point to rustvmm/dev container
bjzhjing Jun 6, 2019
a2d63ed
loader: Add elf and bzimage features
bjzhjing Jun 6, 2019
5b6f29e
loader: Condition crates import and usage by feature
bjzhjing Jun 6, 2019
f74075e
tests: Update coverage
bjzhjing Jun 6, 2019
983b4af
tests: Update test_coverage.py
bjzhjing Jun 6, 2019
7e51de8
buildkite: Switch to the rust-vmm-ci pipeline
Jun 7, 2019
d67f657
build: Fix the musl unit tests
Jun 7, 2019
7d7e03d
lib: Force public interfaces documentation
Jun 7, 2019
eeb3c5e
loader: Mark both ELF and bzImage supports x86 specific
Jun 7, 2019
891ea4f
loader: Fix unit test camel casing
Jun 7, 2019
43f5c6b
Rely on right branch of vm-memory for virtio-fs
Jun 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .buildkite/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

DEB_NAME="linux-image-4.9.0-9-amd64_4.9.168-1_amd64.deb"
DEB_URL="http://ftp.debian.org/debian/pool/main/l/linux/${DEB_NAME}"

REPO_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}"
DEB_PATH="${REPO_PATH}/${DEB_NAME}"
EXTRACT_PATH="${REPO_PATH}/src/bzimage-archive"
BZIMAGE_PATH="${EXTRACT_PATH}/boot/vmlinuz-4.9.0-9-amd64"

mkdir -p ${EXTRACT_PATH}

wget $DEB_URL -P ${REPO_PATH}
dpkg-deb -x ${DEB_PATH} ${EXTRACT_PATH}


mv ${BZIMAGE_PATH} ${REPO_PATH}/src/loader/bzimage
rm -r ${EXTRACT_PATH}
rm -f ${DEB_PATH}

26 changes: 26 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
steps:
- label: "build-gnu-x86-bzimage"
commands:
- cargo build --release --features bzimage
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "build-musl-x86-bzimage"
commands:
- cargo build --release --features bzimage --target x86_64-unknown-linux-musl
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true
176 changes: 176 additions & 0 deletions .buildkite/rust-vmm-ci-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
steps:
- label: "build-gnu-x86"
commands:
- cargo build --release
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "build-gnu-arm"
commands:
- cargo build --release
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "build-musl-x86"
commands:
- cargo build --release --target x86_64-unknown-linux-musl
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "build-musl-arm"
commands:
- cargo build --release --target aarch64-unknown-linux-musl
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "style"
command: cargo fmt --all -- --check
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "unittests-gnu-x86"
commands:
- cargo test --all-features
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "unittests-gnu-arm"
commands:
- cargo test --all-features
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "unittests-musl-x86"
command:
- cargo test --all-features --target x86_64-unknown-linux-musl
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "unittests-musl-arm"
command:
- cargo test --all-features --target aarch64-unknown-linux-musl
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "clippy-x86"
commands:
- cargo clippy --all -- -D warnings
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "clippy-arm"
commands:
- cargo clippy --all -- -D warnings
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
image: "rustvmm/dev:v2"
always-pull: true

- label: "check-warnings-x86"
commands:
- RUSTFLAGS="-D warnings" cargo check --all-targets
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "check-warnings-arm"
command:
- RUSTFLAGS="-D warnings" cargo check --all-targets
retry:
automatic: false
agents:
platform: arm.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true

- label: "coverage-x86"
commands:
- pytest tests/test_coverage.py
retry:
automatic: false
agents:
platform: x86_64.metal
plugins:
- docker#v3.0.1:
privileged: true
image: "rustvmm/dev:v2"
always-pull: true
3 changes: 3 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[target.aarch64-unknown-linux-musl]
rustflags = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ]

16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "linux-loader"
version = "0.1.0"
authors = ["Cathy Zhang <cathy.zhang@intel.com>"]
edition = "2018"
license = "Apache-2.0 AND BSD-3-Clause"

[features]
default = ["elf"]
elf = []
bzimage = []

[dependencies.vm-memory]
git = "https://github.com/alexandruag/vm-memory"
branch = "file_backed_regions"
features = ["backend-mmap"]
92 changes: 92 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# ELF Image parsing and loading

The boot process is explained from the following two sides.

## Loader side

It follows ELF standard which is specified in elf.rs.
The entry header and program headers will be inerpreted, and PT_LOAD segments
will be loaded into guest memory.

### Where kernel is loaded

There are two ways on deciding where the program segments will be loaded.

- One way is to provide an option and allow vmm to specify where to load the
image, considering its memory layout.

- The other way is to load image into phdr.p_paddr by default.

## VMM side

### Construct zero page

According to the 64-bit boot protocol, the boot parameters (traditionally known
as "zero page") should be setup, including setup_header, e820 table and other
stuff. However, ELF has no setup_header, nothing returned from ELF loader could
be used to fill boot parameters, vmm is totally responsible for the construction.

### Configure vCPU

- RIP, the start offset of guest memory where kernel is loaded, which is
returned from loader

- 64 bit mode with paging enabled

- GDT must be configured and loaded

# bzImage

The boot process is also explained from the following two sides.

## Loader side

### What will be returned from loader

bzImage includes two parts, the setup and the compressed kernel. The compressed
kernel part will be loaded into guest memory, and the following three parts
will be returned to the VMM by the loader.

- The start address of loaded kernel

- The offset of memory where kernel is end of loading

- The setup header begin at the offset 0x01f1 of bzImage, this one is an extra
compared to the return of ELF loader.

### Where kernel is loaded

The same as ELF image loader, there are two ways for deciding where the
compressed kernel will be loaded.

- VMM specify where to load kernel image.

- Load into code32_start (Boot load address) by default.

### Additional checking

As what the boot protocol said, the kernel is a bzImage kernel if the
protocol >= 2.00 and the 0x01 bit(LOAD_HIGH) is the loadflags field is set. Add
this checking to validate the bzImage.

## VMM side

### Construct zero page

While vmm build "zero page" with e820 table and other stuff, bzImage loader will
return the setup header to fill the boot parameters. Meanwhile,
setup_header.init_size is a must to be filled into zero page, which will be used
during head_64.S boot process.

### Configure vCPU

- RIP, the start address of loaded 64-bit kernel returned from loader + 0x200.
Regarding to the 64-bit boot protocol, kernel is started by jumping to the
64-bit kernel entry point, which is the start address of loaded 64-bit kernel
plus 0x200.

- 64 bit mode with paging enabled

- GDT must be configured and loaded


Loading