Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch(v1.7): Live Migration and MSync support #7

Open
wants to merge 19 commits into
base: firecracker-v1.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
952d378
feat: Add ability to resume snapshots and write back changes to the b…
pojntfx Mar 21, 2024
e266c12
feat: Add support for suspending and resuming to/from snapshots under…
pojntfx Mar 21, 2024
0a32eb3
feat: Encode snapshot size information in snapshot file to allow susp…
pojntfx Mar 21, 2024
a3b0f09
Revert "feat: Add ability to resume snapshots and write back changes …
pojntfx Apr 5, 2024
c76df56
feat: Add ability to resume snapshots and write back changes to the b…
pojntfx Apr 5, 2024
7a80c7f
Merge pull request #3 from loopholelabs/add-snapshot-flush-configuration
ShivanshVij Apr 5, 2024
c6fc50d
Backporting https://github.com/firecracker-microvm/firecracker/pull/4491
ShivanshVij Apr 18, 2024
81a5067
Backporting https://github.com/firecracker-microvm/firecracker/pull/4539
ShivanshVij Apr 18, 2024
789b390
Backporting https://github.com/codesandbox/firecracker/commit/4164371…
ShivanshVij Apr 18, 2024
665e708
Merge pull request #5 from loopholelabs/disable-msr-star
ShivanshVij Apr 18, 2024
bee01a3
Fixing typo
ShivanshVij Apr 18, 2024
4e3ab7f
Removing PVM MSRs
ShivanshVij Apr 19, 2024
3e573d6
Revert 8d0fa80 and ed7116d
ShivanshVij Apr 19, 2024
fb1a8f9
build: Add CI/CD configuration based on Alpine
pojntfx Jun 20, 2024
30b75c9
build: Bump build system conventions
pojntfx Jun 21, 2024
9294a10
fix: Drop SSH key access
pojntfx Jun 21, 2024
fef2ebc
build: Use new release branch allowlist
pojntfx Jun 21, 2024
47023e7
build: List all packages to build manually
pojntfx Jun 22, 2024
a95755c
fix: Correct ref expression in workflow
pojntfx Jun 22, 2024
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
97 changes: 97 additions & 0 deletions .github/workflows/hydrun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: hydrun CI

on:
push:
pull_request:
schedule:
- cron: "0 0 * * 0"

jobs:
build-linux:
runs-on: ${{ matrix.target.runner }}
permissions:
contents: read
strategy:
matrix:
target:
# Binaries
- id: rust.x86_64
src: .
os: alpine:edge
flags: ""
cmd: ./Hydrunfile rust x86_64
dst: out/*
runner: depot-ubuntu-22.04-32
- id: rust.aarch64
src: .
os: alpine:edge
flags: ""
cmd: ./Hydrunfile rust aarch64
dst: out/*
runner: depot-ubuntu-22.04-arm-32

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore ccache
uses: actions/cache/restore@v4
with:
path: |
/tmp/ccache
key: cache-ccache-${{ matrix.target.id }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up hydrun
run: |
curl -L -o /tmp/hydrun "https://github.com/pojntfx/hydrun/releases/latest/download/hydrun.linux-$(uname -m)"
sudo install /tmp/hydrun /usr/local/bin
- name: Build with hydrun
working-directory: ${{ matrix.target.src }}
run: hydrun -o ${{ matrix.target.os }} ${{ matrix.target.flags }} "${{ matrix.target.cmd }}"
- name: Fix permissions for output
run: sudo chown -R $USER .
- name: Save ccache
uses: actions/cache/save@v4
with:
path: |
/tmp/ccache
key: cache-ccache-${{ matrix.target.id }}
- name: Upload output
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.id }}
path: ${{ matrix.target.dst }}

publish-linux:
runs-on: ubuntu-latest
permissions:
contents: write
needs: build-linux

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download output
uses: actions/download-artifact@v4
with:
path: /tmp/out
- name: Extract branch name
id: extract_branch
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
- name: Publish pre-release to GitHub releases
if: ${{ github.ref == 'refs/heads/firecracker-v1.7-live-migration-and-msync' || github.ref == 'refs/heads/firecracker-v1.7-live-migration-pvm-and-msync' || github.ref == 'refs/heads/main-live-migration-and-msync' }}
uses: softprops/action-gh-release@v2
with:
tag_name: release-${{ steps.extract_branch.outputs.branch }}
prerelease: true
files: |
/tmp/out/*/*
- name: Publish release to GitHub releases
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v2
with:
prerelease: false
files: |
/tmp/out/*/*
29 changes: 29 additions & 0 deletions Hydrunfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

set -e

# Rust
if [ "$1" = "rust" ]; then
# Install native dependencies
apk add rust cargo clang-dev cmake linux-headers make git

# Configure Git
git config --global --add safe.directory '*'

# Build
cp "resources/seccomp/$2-unknown-linux-musl.json" "resources/seccomp/$2-alpine-linux-musl.json"
export RUSTFLAGS='-C target-feature=+crt-static'
cargo build --package firecracker --package jailer --package seccompiler --package rebase-snap --package cpu-template-helper --target "$2-alpine-linux-musl" --all-features --release

# Stage binaries
mkdir -p out

dir="./build/cargo_target/$2-alpine-linux-musl/release"
for file in $(ls "$dir"); do
if [[ -x "$dir/$file" && ! -d "$dir/$file" ]]; then
cp "$dir/$file" "./out/${file}.linux-$2"
fi
done

exit 0
fi
3 changes: 2 additions & 1 deletion docs/cpu_templates/cpu-template-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ CPU features to a heterogeneous fleet consisting of multiple CPU models.
### MSRs excluded from guest CPU configuration dump

| Register name | Index |
| --------------------------------------- | ----------------------- |
|-----------------------------------------|-------------------------|
| MSR_IA32_TSC | 0x00000010 |
| MSR_ARCH_PERFMON_PERFCTRn | 0x000000c1 - 0x000000d2 |
| MSR_ARCH_PERFMON_EVENTSELn | 0x00000186 - 0x00000197 |
Expand Down Expand Up @@ -230,6 +230,7 @@ CPU features to a heterogeneous fleet consisting of multiple CPU models.
| HV_X64_MSR_SYNDBG_RECV_BUFFER | 0x400000f4 |
| HV_X64_MSR_SYNDBG_PENDING_BUFFER | 0x400000f5 |
| HV_X64_MSR_SYNDBG_OPTIONS | 0x400000ff |
| HV_X64_MSR_TSC_INVARIANT_CONTROL | 0x40000118 |

### ARM registers excluded from guest CPU configuration dump

Expand Down
4 changes: 4 additions & 0 deletions resources/seccomp/aarch64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{
"syscall": "fsync"
},
{
"syscall": "msync",
"comment": "Used for live migration to sync dirty pages"
},
{
"syscall": "close"
},
Expand Down
4 changes: 4 additions & 0 deletions resources/seccomp/x86_64-unknown-linux-musl.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
{
"syscall": "fsync"
},
{
"syscall": "msync",
"comment": "Used for live migration to sync dirty pages"
},
{
"syscall": "close"
},
Expand Down
8 changes: 8 additions & 0 deletions src/firecracker/src/api_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ impl ApiServer {
&METRICS.latencies_us.diff_create_snapshot,
"create diff snapshot",
)),
SnapshotType::Msync => Some((
&METRICS.latencies_us.diff_create_snapshot,
"memory synchronization snapshot",
)),
SnapshotType::MsyncAndState => Some((
&METRICS.latencies_us.diff_create_snapshot,
"memory synchronization and state snapshot",
)),
},
VmmAction::LoadSnapshot(_) => {
Some((&METRICS.latencies_us.load_snapshot, "load snapshot"))
Expand Down
5 changes: 5 additions & 0 deletions src/firecracker/src/api_server/request/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, Error> {
mem_backend,
enable_diff_snapshots: snapshot_config.enable_diff_snapshots,
resume_vm: snapshot_config.resume_vm,
shared: snapshot_config.shared,
};

// Construct the `ParsedRequest` object.
Expand Down Expand Up @@ -175,6 +176,7 @@ mod tests {
},
enable_diff_snapshots: false,
resume_vm: false,
shared: false,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
assert!(parsed_request
Expand Down Expand Up @@ -202,6 +204,7 @@ mod tests {
},
enable_diff_snapshots: true,
resume_vm: false,
shared: false,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
assert!(parsed_request
Expand Down Expand Up @@ -229,6 +232,7 @@ mod tests {
},
enable_diff_snapshots: false,
resume_vm: true,
shared: false,
};
let mut parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
assert!(parsed_request
Expand All @@ -253,6 +257,7 @@ mod tests {
},
enable_diff_snapshots: false,
resume_vm: true,
shared: false,
};
let parsed_request = parse_put_snapshot(&Body::new(body), Some("load")).unwrap();
assert_eq!(
Expand Down
7 changes: 7 additions & 0 deletions src/firecracker/swagger/firecracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@ definitions:
enum:
- Full
- Diff
- Msync
- MsyncAndState
description:
Type of snapshot to create. It is optional and by default, a full
snapshot is created.
Expand Down Expand Up @@ -1234,6 +1236,11 @@ definitions:
type: boolean
description:
When set to true, the vm is also resumed if the snapshot load is successful.
shared:
type: boolean
description: When set to true and the guest memory backend is a file,
changes to the memory are asynchronously written back to the
backend as the VM is running.

TokenBucket:
type: object
Expand Down
5 changes: 4 additions & 1 deletion src/vmm/src/arch/x86_64/msr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const APIC_BASE_MSR: u32 = 0x800;
/// Number of APIC MSR indexes
const APIC_MSR_INDEXES: u32 = 0x400;

/// Custom MSRs fall in the range 0x4b564d00-0x4b564dff
/// Custom KVM MSRs fall in the range 0x4b564d00-0x4b564dff
const MSR_KVM_WALL_CLOCK_NEW: u32 = 0x4b56_4d00;
const MSR_KVM_SYSTEM_TIME_NEW: u32 = 0x4b56_4d01;
const MSR_KVM_ASYNC_PF_EN: u32 = 0x4b56_4d02;
Expand Down Expand Up @@ -236,6 +236,7 @@ static SERIALIZABLE_MSR_RANGES: &[MsrRange] = &[
MSR_RANGE!(MSR_K7_HWCR),
MSR_RANGE!(MSR_KVM_POLL_CONTROL),
MSR_RANGE!(MSR_KVM_ASYNC_PF_INT),
MSR_RANGE!(MSR_IA32_TSX_CTRL),
];

/// Specifies whether a particular MSR should be included in vcpu serialization.
Expand Down Expand Up @@ -387,6 +388,8 @@ static UNDUMPABLE_MSR_RANGES: &[MsrRange] = &[
MSR_RANGE!(HV_X64_MSR_SYNDBG_CONTROL, 5),
// HV_X64_MSR_SYNDBG_OPTIONS
MSR_RANGE!(HV_X64_MSR_SYNDBG_OPTIONS),
// HV_X64_MSR_TSC_INVARIANT_CONTROL
MSR_RANGE!(HV_X64_MSR_TSC_INVARIANT_CONTROL),
];

/// Specifies whether a particular MSR should be dumped.
Expand Down
6 changes: 6 additions & 0 deletions src/vmm/src/logger/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ pub struct PerformanceMetrics {
pub vmm_full_create_snapshot: SharedStoreMetric,
/// Measures the snapshot diff create time, at the VMM level, in microseconds.
pub vmm_diff_create_snapshot: SharedStoreMetric,
/// Measures the snapshot memory synchronization time, at the VMM level, in microseconds.
pub vmm_msync_create_snapshot: SharedStoreMetric,
/// Measures the snapshot memory synchronization and state time, at the VMM level, in microseconds.
pub vmm_msync_and_state_create_snapshot: SharedStoreMetric,
/// Measures the snapshot load time, at the VMM level, in microseconds.
pub vmm_load_snapshot: SharedStoreMetric,
/// Measures the microVM pausing duration, at the VMM level, in microseconds.
Expand All @@ -634,6 +638,8 @@ impl PerformanceMetrics {
resume_vm: SharedStoreMetric::new(),
vmm_full_create_snapshot: SharedStoreMetric::new(),
vmm_diff_create_snapshot: SharedStoreMetric::new(),
vmm_msync_create_snapshot: SharedStoreMetric::new(),
vmm_msync_and_state_create_snapshot: SharedStoreMetric::new(),
vmm_load_snapshot: SharedStoreMetric::new(),
vmm_pause_vm: SharedStoreMetric::new(),
vmm_resume_vm: SharedStoreMetric::new(),
Expand Down
Loading
Loading