mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
115c455eaf | ||
|
|
259b8aa1c8 | ||
|
|
2a9978f3c0 | ||
|
|
3c4ff7de01 | ||
|
|
de6d6f2558 | ||
|
|
baf719c6ff | ||
|
|
c59c61a983 | ||
|
|
448fafd23a | ||
|
|
196a59f209 | ||
|
|
35d1998965 | ||
|
|
c5904a413e | ||
|
|
7729024451 | ||
|
|
5580dd6e6a | ||
|
|
21ea5afa0a | ||
|
|
a09d536dc1 | ||
|
|
f8a5c149eb | ||
|
|
8e6bdcbf11 | ||
|
|
93631b5e23 | ||
|
|
ade953e582 | ||
|
|
a3bd7eb9a0 | ||
|
|
b0dd4e72c5 | ||
|
|
ed1b415bad | ||
|
|
71708c9794 | ||
|
|
f58f9cf16a | ||
|
|
a7d967215f | ||
|
|
0e29fe1517 | ||
|
|
fbb648166a | ||
|
|
ea87988f93 | ||
|
|
f35d573431 | ||
|
|
a489a11ccf | ||
|
|
4f1fb3632b | ||
|
|
693e456793 | ||
|
|
8c1b112a60 | ||
|
|
26cab16830 | ||
|
|
c588138187 | ||
|
|
4b72e5a886 | ||
|
|
51febbb7fe | ||
|
|
551d36e502 | ||
|
|
6a5a2ac83d | ||
|
|
37666f842d | ||
|
|
a09d828713 | ||
|
|
67904a90fc | ||
|
|
196e653a50 | ||
|
|
355148c3d6 | ||
|
|
1dff2503a6 | ||
|
|
f4c85aef89 | ||
|
|
0131a408bf | ||
|
|
bd506500d7 | ||
|
|
80724b1662 | ||
|
|
1f6b43db49 | ||
|
|
878c2275a2 | ||
|
|
5fc018abdd | ||
|
|
690e10eef4 | ||
|
|
ea12024793 | ||
|
|
e082ed23ed | ||
|
|
d1953633e2 | ||
|
|
23f1490667 | ||
|
|
b312a970ef | ||
|
|
6e544d0a30 | ||
|
|
bc84ac4699 | ||
|
|
78f0f30751 | ||
|
|
8b0d43e2fe | ||
|
|
61430fb345 |
2
.github/workflows/audit.yaml
vendored
2
.github/workflows/audit.yaml
vendored
@@ -11,6 +11,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions-rust-lang/audit@v1
|
- uses: actions-rs/audit-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
5
.github/workflows/build.yaml
vendored
5
.github/workflows/build.yaml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
- "1.77.0"
|
- "1.70"
|
||||||
target:
|
target:
|
||||||
- x86_64-unknown-linux-gnu
|
- x86_64-unknown-linux-gnu
|
||||||
- x86_64-unknown-linux-musl
|
- x86_64-unknown-linux-musl
|
||||||
@@ -29,10 +29,11 @@ jobs:
|
|||||||
run: sudo apt install -y musl-tools
|
run: sudo apt install -y musl-tools
|
||||||
|
|
||||||
- name: Install Rust toolchain (${{ matrix.rust }})
|
- name: Install Rust toolchain (${{ matrix.rust }})
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
|
override: true
|
||||||
|
|
||||||
- name: Build (default features)
|
- name: Build (default features)
|
||||||
run: cargo rustc --locked --bin cloud-hypervisor -- -D warnings -D clippy::undocumented_unsafe_blocks
|
run: cargo rustc --locked --bin cloud-hypervisor -- -D warnings -D clippy::undocumented_unsafe_blocks
|
||||||
|
|||||||
2
.github/workflows/docker-image.yaml
vendored
2
.github/workflows/docker-image.yaml
vendored
@@ -41,7 +41,7 @@ jobs:
|
|||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
# generate Docker tags based on the following events/attributes
|
# generate Docker tags based on the following events/attributes
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=20240507-0
|
type=raw,value={{date 'YYYYMMDD'}}-0
|
||||||
type=sha
|
type=sha
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
|
|||||||
13
.github/workflows/fuzz-build.yaml
vendored
13
.github/workflows/fuzz-build.yaml
vendored
@@ -14,19 +14,18 @@ jobs:
|
|||||||
- nightly
|
- nightly
|
||||||
target:
|
target:
|
||||||
- x86_64-unknown-linux-gnu
|
- x86_64-unknown-linux-gnu
|
||||||
env:
|
|
||||||
RUSTFLAGS: -D warnings
|
|
||||||
steps:
|
steps:
|
||||||
- name: Code checkout
|
- name: Code checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Install Rust toolchain (${{ matrix.rust }})
|
- name: Install Rust toolchain (${{ matrix.rust }})
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ matrix.rust }}
|
toolchain: ${{ matrix.rust }}
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
|
override: true
|
||||||
- name: Install Cargo fuzz
|
- name: Install Cargo fuzz
|
||||||
run: cargo install cargo-fuzz
|
# Temporary fix for cargo-fuzz on latest nightly: https://github.com/rust-fuzz/cargo-fuzz/issues/276
|
||||||
- name: Fuzz Build
|
#run: cargo install cargo-fuzz
|
||||||
|
run: cargo install --git https://github.com/rust-fuzz/cargo-fuzz --rev b4df3e58f767b5cad8d1aa6753961003f56f3609
|
||||||
|
- name: Cargo Fuzz Build
|
||||||
run: cargo fuzz build
|
run: cargo fuzz build
|
||||||
- name: Fuzz Check
|
|
||||||
run: cargo fuzz check
|
|
||||||
|
|||||||
187
.github/workflows/release.yaml
vendored
187
.github/workflows/release.yaml
vendored
@@ -3,67 +3,135 @@ on: [create, merge_group]
|
|||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
|
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
if: (github.event_name == 'create' && github.event.ref_type == 'tag') || github.event_name == 'merge_group'
|
if: (github.event_name == 'create' && github.event.ref_type == 'tag') || github.event_name == 'merge_group'
|
||||||
name: Release ${{ matrix.platform.target }}
|
name: Release
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
platform:
|
|
||||||
- target: x86_64-unknown-linux-gnu
|
|
||||||
args: --all --release --features mshv
|
|
||||||
name_ch: cloud-hypervisor
|
|
||||||
name_ch_remote: ch-remote
|
|
||||||
- target: x86_64-unknown-linux-musl
|
|
||||||
args: --all --release --features mshv
|
|
||||||
name_ch: cloud-hypervisor-static
|
|
||||||
name_ch_remote: ch-remote-static
|
|
||||||
- target: aarch64-unknown-linux-musl
|
|
||||||
args: --all --release
|
|
||||||
name_ch: cloud-hypervisor-static-aarch64
|
|
||||||
name_ch_remote: ch-remote-static-aarch64
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Code checkout
|
- name: Code checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Install musl-gcc
|
- name: Install musl-gcc
|
||||||
if: contains(matrix.platform.target, 'musl')
|
|
||||||
run: sudo apt install -y musl-tools
|
run: sudo apt install -y musl-tools
|
||||||
- name: Create release directory
|
- name: Create release directory
|
||||||
if: |
|
|
||||||
github.event_name == 'create' && github.event.ref_type == 'tag' &&
|
|
||||||
matrix.platform.target == 'x86_64-unknown-linux-gnu'
|
|
||||||
run: rsync -rv --exclude=.git . ../cloud-hypervisor-${{ github.event.ref }}
|
run: rsync -rv --exclude=.git . ../cloud-hypervisor-${{ github.event.ref }}
|
||||||
- name: Build ${{ matrix.platform.target }}
|
- name: Install Rust toolchain (x86_64-unknown-linux-gnu)
|
||||||
uses: houseabsolute/actions-rust-cross@v0
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
toolchain: "1.70"
|
||||||
|
target: x86_64-unknown-linux-gnu
|
||||||
|
- name: Install Rust toolchain (x86_64-unknown-linux-musl)
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: "1.70"
|
||||||
|
target: x86_64-unknown-linux-musl
|
||||||
|
- name: Build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
toolchain: "1.70"
|
||||||
command: build
|
command: build
|
||||||
target: ${{ matrix.platform.target }}
|
args: --all --release --features mshv --target=x86_64-unknown-linux-gnu
|
||||||
args: ${{ matrix.platform.args }}
|
- name: Static Build
|
||||||
strip: true
|
uses: actions-rs/cargo@v1
|
||||||
toolchain: "1.77.0"
|
|
||||||
- name: Copy Release Binaries
|
|
||||||
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
cp target/${{ matrix.platform.target }}/release/cloud-hypervisor ./${{ matrix.platform.name_ch }}
|
|
||||||
cp target/${{ matrix.platform.target }}/release/ch-remote ./${{ matrix.platform.name_ch_remote }}
|
|
||||||
- name: Upload Release Artifacts
|
|
||||||
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
with:
|
||||||
name: Artifacts for ${{ matrix.platform.target }}
|
toolchain: "1.70"
|
||||||
path: |
|
command: build
|
||||||
./${{ matrix.platform.name_ch }}
|
args: --all --release --features mshv --target=x86_64-unknown-linux-musl
|
||||||
./${{ matrix.platform.name_ch_remote }}
|
- name: Install Rust toolchain (aarch64-unknown-linux-musl)
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: "1.70"
|
||||||
|
target: aarch64-unknown-linux-musl
|
||||||
|
override: true
|
||||||
|
- name: Create Release
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ github.ref }}
|
||||||
|
release_name: ${{ github.ref }}
|
||||||
|
draft: true
|
||||||
|
prerelease: true
|
||||||
|
- name: Upload cloud-hypervisor
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-cloud-hypervisor
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/x86_64-unknown-linux-gnu/release/cloud-hypervisor
|
||||||
|
asset_name: cloud-hypervisor
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload static cloud-hypervisor
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-static-cloud-hypervisor
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/x86_64-unknown-linux-musl/release/cloud-hypervisor
|
||||||
|
asset_name: cloud-hypervisor-static
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload ch-remote
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-ch-remote
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/x86_64-unknown-linux-gnu/release/ch-remote
|
||||||
|
asset_name: ch-remote
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload static-ch-remote
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-static-ch-remote
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/x86_64-unknown-linux-musl/release/ch-remote
|
||||||
|
asset_name: ch-remote-static
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Clean build tree ahead of cross build
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: clean
|
||||||
|
- name: Static Build (AArch64)
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
use-cross: true
|
||||||
|
command: build
|
||||||
|
args: --all --release --target=aarch64-unknown-linux-musl
|
||||||
|
- name: Upload static AArch64 cloud-hypervisor
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-static-aarch64-cloud-hypervisor
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/aarch64-unknown-linux-musl/release/cloud-hypervisor
|
||||||
|
asset_name: cloud-hypervisor-static-aarch64
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
|
- name: Upload static AArch64 ch-remote
|
||||||
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
|
id: upload-release-static-aarch64-ch-remote
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: target/aarch64-unknown-linux-musl/release/ch-remote
|
||||||
|
asset_name: ch-remote-static-aarch64
|
||||||
|
asset_content_type: application/octet-stream
|
||||||
- name: Vendor
|
- name: Vendor
|
||||||
if: |
|
|
||||||
github.event_name == 'create' && github.event.ref_type == 'tag' &&
|
|
||||||
matrix.platform.target == 'x86_64-unknown-linux-gnu'
|
|
||||||
working-directory: ../cloud-hypervisor-${{ github.event.ref }}
|
working-directory: ../cloud-hypervisor-${{ github.event.ref }}
|
||||||
run: |
|
run: |
|
||||||
mkdir ../vendor-cargo-home
|
mkdir ../vendor-cargo-home
|
||||||
@@ -71,25 +139,16 @@ jobs:
|
|||||||
mkdir .cargo
|
mkdir .cargo
|
||||||
cargo vendor > .cargo/config.toml
|
cargo vendor > .cargo/config.toml
|
||||||
- name: Create vendored source archive
|
- name: Create vendored source archive
|
||||||
if: |
|
working-directory: ../
|
||||||
github.event_name == 'create' && github.event.ref_type == 'tag' &&
|
run: tar cJf cloud-hypervisor-${{ github.event.ref }}.tar.xz cloud-hypervisor-${{ github.event.ref }}
|
||||||
matrix.platform.target == 'x86_64-unknown-linux-gnu'
|
|
||||||
run: tar cJf cloud-hypervisor-${{ github.event.ref }}.tar.xz ../cloud-hypervisor-${{ github.event.ref }}
|
|
||||||
- name: Upload cloud-hypervisor vendored source archive
|
- name: Upload cloud-hypervisor vendored source archive
|
||||||
if: |
|
|
||||||
github.event_name == 'create' && github.event.ref_type == 'tag' &&
|
|
||||||
matrix.platform.target == 'x86_64-unknown-linux-gnu'
|
|
||||||
id: upload-release-cloud-hypervisor-vendored-sources
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
path: cloud-hypervisor-${{ github.event.ref }}.tar.xz
|
|
||||||
name: cloud-hypervisor-${{ github.event.ref }}.tar.xz
|
|
||||||
- name: Create GitHub Release
|
|
||||||
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
if: github.event_name == 'create' && github.event.ref_type == 'tag'
|
||||||
uses: softprops/action-gh-release@v1
|
id: upload-release-cloud-hypervisor-vendored-sources
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
draft: true
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
files: |
|
asset_path: ../cloud-hypervisor-${{ github.event.ref }}.tar.xz
|
||||||
./${{ matrix.platform.name_ch }}
|
asset_name: cloud-hypervisor-${{ github.event.ref }}.tar.xz
|
||||||
./${{ matrix.platform.name_ch_remote }}
|
asset_content_type: application/x-xz
|
||||||
./cloud-hypervisor-${{ github.event.ref }}.tar.xz
|
|
||||||
|
|||||||
12
.github/workflows/reuse.yaml
vendored
12
.github/workflows/reuse.yaml
vendored
@@ -1,12 +0,0 @@
|
|||||||
name: REUSE Compliance Check
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
reuse:
|
|
||||||
name: REUSE Compliance Check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: REUSE Compliance Check
|
|
||||||
uses: fsfe/reuse-action@v3
|
|
||||||
20
.github/workflows/shlint.yaml
vendored
20
.github/workflows/shlint.yaml
vendored
@@ -1,20 +0,0 @@
|
|||||||
name: Shell scripts check
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
merge_group:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
sh-checker:
|
|
||||||
name: Check shell scripts
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Run the shell script checkers
|
|
||||||
uses: luizm/action-sh-checker@master
|
|
||||||
env:
|
|
||||||
SHFMT_OPTS: -i 4 -d
|
|
||||||
SHELLCHECK_OPTS: -x --source-path scripts
|
|
||||||
21
.github/workflows/taplo.yaml
vendored
21
.github/workflows/taplo.yaml
vendored
@@ -1,21 +0,0 @@
|
|||||||
name: Cargo.toml Formatting (taplo)
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- '**/Cargo.toml'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
cargo_toml_format:
|
|
||||||
name: Cargo.toml Formatting
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Code checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
- name: Install Rust toolchain
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
- name: Install build dependencies
|
|
||||||
run: sudo apt-get update && sudo apt-get -yqq install build-essential libssl-dev
|
|
||||||
- name: Install taplo
|
|
||||||
run: cargo install taplo-cli --locked
|
|
||||||
- name: Check formatting
|
|
||||||
run: taplo fmt --check
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,4 +6,3 @@
|
|||||||
**/rusty-tags.vi
|
**/rusty-tags.vi
|
||||||
/rpm/SOURCES
|
/rpm/SOURCES
|
||||||
/.vscode
|
/.vscode
|
||||||
/vendor
|
|
||||||
|
|||||||
12
.reuse/dep5
12
.reuse/dep5
@@ -1,12 +0,0 @@
|
|||||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
|
||||||
Upstream-Name: cloud-hypervisor
|
|
||||||
Upstream-Contact: <>
|
|
||||||
Source: https://www.cloudhypervisor.org
|
|
||||||
|
|
||||||
Files: docs/*.md *.md
|
|
||||||
Copyright: 2024
|
|
||||||
License: CC-BY-4.0
|
|
||||||
|
|
||||||
Files: scripts/* test_data/* *.toml .git* fuzz/Cargo.lock fuzz/.gitignore resources/linux-config-* vmm/src/api/openapi/cloud-hypervisor.yaml CODEOWNERS Cargo.lock
|
|
||||||
Copyright: 2024
|
|
||||||
License: Apache-2.0
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
include = ["**/Cargo.toml"]
|
|
||||||
|
|
||||||
[formatting]
|
|
||||||
reorder_arrays = true
|
|
||||||
reorder_keys = true
|
|
||||||
@@ -112,5 +112,5 @@ Fixes #88
|
|||||||
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
|
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, after the corresponding PR is merged, GitHub will automatically close that issue when parsing the
|
Then, after the corresponding PR is merged, Github will automatically close that issue when parsing the
|
||||||
[commit message](https://help.github.com/articles/closing-issues-via-commit-messages/).
|
[commit message](https://help.github.com/articles/closing-issues-via-commit-messages/).
|
||||||
|
|||||||
1216
Cargo.lock
generated
1216
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
111
Cargo.toml
111
Cargo.toml
@@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Cloud Hypervisor Authors"]
|
|
||||||
build = "build.rs"
|
|
||||||
default-run = "cloud-hypervisor"
|
|
||||||
description = "Open source Virtual Machine Monitor (VMM) that runs on top of KVM & MSHV"
|
|
||||||
edition = "2021"
|
|
||||||
homepage = "https://github.com/cloud-hypervisor/cloud-hypervisor"
|
|
||||||
license = "LICENSE-APACHE & LICENSE-BSD-3-Clause"
|
|
||||||
name = "cloud-hypervisor"
|
name = "cloud-hypervisor"
|
||||||
version = "40.0.0"
|
version = "37.1.0"
|
||||||
|
authors = ["The Cloud Hypervisor Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
default-run = "cloud-hypervisor"
|
||||||
|
build = "build.rs"
|
||||||
|
license = "LICENSE-APACHE & LICENSE-BSD-3-Clause"
|
||||||
|
description = "Open source Virtual Machine Monitor (VMM) that runs on top of KVM"
|
||||||
|
homepage = "https://github.com/cloud-hypervisor/cloud-hypervisor"
|
||||||
# Minimum buildable version:
|
# Minimum buildable version:
|
||||||
# Keep in sync with version in .github/workflows/build.yaml
|
# Keep in sync with version in .github/workflows/build.yaml
|
||||||
# Policy on MSRV (see #4318):
|
# Policy on MSRV (see #4318):
|
||||||
@@ -15,87 +15,92 @@ version = "40.0.0"
|
|||||||
# a.) A dependency requires it,
|
# a.) A dependency requires it,
|
||||||
# b.) If we want to use a new feature and that MSRV is at least 6 months old,
|
# b.) If we want to use a new feature and that MSRV is at least 6 months old,
|
||||||
# c.) There is a security issue that is addressed by the toolchain update.
|
# c.) There is a security issue that is addressed by the toolchain update.
|
||||||
rust-version = "1.77.0"
|
rust-version = "1.70"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
|
||||||
lto = true
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
strip = true
|
strip = true
|
||||||
|
|
||||||
[profile.profiling]
|
[profile.profiling]
|
||||||
debug = true
|
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
strip = false
|
strip = false
|
||||||
|
debug = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.75"
|
||||||
api_client = { path = "api_client" }
|
api_client = { path = "api_client" }
|
||||||
clap = { version = "4.5.4", features = ["string"] }
|
clap = { version = "4.4.7", features = ["string"] }
|
||||||
dhat = { version = "0.3.3", optional = true }
|
dhat = { version = "0.3.2", optional = true }
|
||||||
epoll = "4.3.3"
|
epoll = "4.3.3"
|
||||||
event_monitor = { path = "event_monitor" }
|
event_monitor = { path = "event_monitor" }
|
||||||
hypervisor = { path = "hypervisor" }
|
hypervisor = { path = "hypervisor" }
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
log = { version = "0.4.21", features = ["std"] }
|
log = { version = "0.4.20", features = ["std"] }
|
||||||
option_parser = { path = "option_parser" }
|
option_parser = { path = "option_parser" }
|
||||||
seccompiler = "0.4.0"
|
seccompiler = "0.4.0"
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.107"
|
||||||
signal-hook = "0.3.17"
|
signal-hook = "0.3.17"
|
||||||
thiserror = "1.0.60"
|
thiserror = "1.0.40"
|
||||||
tpm = { path = "tpm" }
|
tpm = { path = "tpm"}
|
||||||
tracer = { path = "tracer" }
|
tracer = { path = "tracer" }
|
||||||
vm-memory = "0.14.1"
|
|
||||||
vmm = { path = "vmm" }
|
vmm = { path = "vmm" }
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
zbus = { version = "4.1.2", optional = true }
|
vm-memory = "0.14.0"
|
||||||
|
zbus = { version = "3.11.1", optional = true }
|
||||||
|
|
||||||
|
# List of patched crates
|
||||||
|
[patch.crates-io]
|
||||||
|
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x" }
|
||||||
|
versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.0"
|
||||||
net_util = { path = "net_util" }
|
net_util = { path = "net_util" }
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.18.0"
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.107"
|
||||||
test_infra = { path = "test_infra" }
|
test_infra = { path = "test_infra" }
|
||||||
wait-timeout = "0.2.0"
|
wait-timeout = "0.2.0"
|
||||||
|
|
||||||
# Please adjust `vmm::feature_list()` accordingly when changing the
|
# Please adjust `vmm::feature_list()` accordingly when changing the
|
||||||
# feature list below
|
# feature list below
|
||||||
[features]
|
[features]
|
||||||
dbus_api = ["vmm/dbus_api", "zbus"]
|
default = ["kvm", "io_uring"]
|
||||||
default = ["io_uring", "kvm"]
|
dbus_api = ["zbus", "vmm/dbus_api"]
|
||||||
dhat-heap = ["dhat", "vmm/dhat-heap"] # For heap profiling
|
dhat-heap = ["dhat"] # For heap profiling
|
||||||
guest_debug = ["vmm/guest_debug"]
|
guest_debug = ["vmm/guest_debug"]
|
||||||
igvm = ["mshv", "vmm/igvm"]
|
igvm = ["vmm/igvm", "mshv"]
|
||||||
io_uring = ["vmm/io_uring"]
|
io_uring = ["vmm/io_uring"]
|
||||||
kvm = ["vmm/kvm"]
|
kvm = ["vmm/kvm"]
|
||||||
mshv = ["vmm/mshv"]
|
mshv = ["vmm/mshv"]
|
||||||
sev_snp = ["igvm", "mshv", "vmm/sev_snp"]
|
sev_snp = ["igvm", "vmm/sev_snp", "mshv"]
|
||||||
tdx = ["vmm/tdx"]
|
tdx = ["vmm/tdx"]
|
||||||
tracing = ["tracer/tracing", "vmm/tracing"]
|
tracing = ["vmm/tracing", "tracer/tracing"]
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"api_client",
|
"api_client",
|
||||||
"arch",
|
"arch",
|
||||||
"block",
|
"block",
|
||||||
"devices",
|
"devices",
|
||||||
"event_monitor",
|
"event_monitor",
|
||||||
"hypervisor",
|
"hypervisor",
|
||||||
"net_gen",
|
"net_gen",
|
||||||
"net_util",
|
"net_util",
|
||||||
"option_parser",
|
"option_parser",
|
||||||
"pci",
|
"pci",
|
||||||
"performance-metrics",
|
"performance-metrics",
|
||||||
"rate_limiter",
|
"rate_limiter",
|
||||||
"serial_buffer",
|
"serial_buffer",
|
||||||
"test_infra",
|
"test_infra",
|
||||||
"tracer",
|
"tracer",
|
||||||
"vhost_user_block",
|
"vhost_user_block",
|
||||||
"vhost_user_net",
|
"vhost_user_net",
|
||||||
"virtio-devices",
|
"virtio-devices",
|
||||||
"vm-allocator",
|
"vmm",
|
||||||
"vm-device",
|
"vm-allocator",
|
||||||
"vm-migration",
|
"vm-device",
|
||||||
"vm-virtio",
|
"vm-migration",
|
||||||
"vmm",
|
"vm-virtio"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ do not wish to use the pre-built binaries.
|
|||||||
## Booting Linux
|
## Booting Linux
|
||||||
|
|
||||||
Cloud Hypervisor supports direct kernel boot (the x86-64 kernel requires the kernel
|
Cloud Hypervisor supports direct kernel boot (the x86-64 kernel requires the kernel
|
||||||
built with PVH support or a bzImage) or booting via a firmware (either [Rust Hypervisor
|
built with PVH support) or booting via a firmware (either [Rust Hypervisor
|
||||||
Firmware](https://github.com/cloud-hypervisor/rust-hypervisor-firmware) or an
|
Firmware](https://github.com/cloud-hypervisor/rust-hypervisor-firmware) or an
|
||||||
edk2 UEFI firmware called `CLOUDHV` / `CLOUDHV_EFI`.)
|
edk2 UEFI firmware called `CLOUDHV` / `CLOUDHV_EFI`.)
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ $ ./cloud-hypervisor \
|
|||||||
|
|
||||||
#### Building your Kernel
|
#### Building your Kernel
|
||||||
|
|
||||||
Cloud Hypervisor also supports direct kernel boot. For x86-64, a `vmlinux` ELF kernel (compiled with PVH support) or a regular bzImage are supported. In order to support development there is a custom branch; however provided the required options are enabled any recent kernel will suffice.
|
Cloud Hypervisor also supports direct kernel boot. For x86-64, a `vmlinux` ELF kernel (compiled with PVH support) is needed. In order to support development there is a custom branch; however provided the required options are enabled any recent kernel will suffice.
|
||||||
|
|
||||||
To build the kernel:
|
To build the kernel:
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Cloud Hypervisor Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "api_client"
|
name = "api_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Cloud Hypervisor Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
thiserror = "1.0.61"
|
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
|||||||
@@ -3,27 +3,41 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use thiserror::Error;
|
|
||||||
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
|
use vmm_sys_util::sock_ctrl_msg::ScmSocket;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Error writing to or reading from HTTP socket: {0}")]
|
|
||||||
Socket(std::io::Error),
|
Socket(std::io::Error),
|
||||||
#[error("Error sending file descriptors: {0}")]
|
|
||||||
SocketSendFds(vmm_sys_util::errno::Error),
|
SocketSendFds(vmm_sys_util::errno::Error),
|
||||||
#[error("Error parsing HTTP status code: {0}")]
|
|
||||||
StatusCodeParsing(std::num::ParseIntError),
|
StatusCodeParsing(std::num::ParseIntError),
|
||||||
#[error("HTTP output is missing protocol statement")]
|
|
||||||
MissingProtocol,
|
MissingProtocol,
|
||||||
#[error("Error parsing HTTP Content-Length field: {0}")]
|
|
||||||
ContentLengthParsing(std::num::ParseIntError),
|
ContentLengthParsing(std::num::ParseIntError),
|
||||||
#[error("Server responded with an error: {0:?}")]
|
|
||||||
ServerResponse(StatusCode, Option<String>),
|
ServerResponse(StatusCode, Option<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use Error::*;
|
||||||
|
match self {
|
||||||
|
Socket(e) => write!(f, "Error writing to or reading from HTTP socket: {e}"),
|
||||||
|
SocketSendFds(e) => write!(f, "Error writing to or reading from HTTP socket: {e}"),
|
||||||
|
StatusCodeParsing(e) => write!(f, "Error parsing HTTP status code: {e}"),
|
||||||
|
MissingProtocol => write!(f, "HTTP output is missing protocol statement"),
|
||||||
|
ContentLengthParsing(e) => write!(f, "Error parsing HTTP Content-Length field: {e}"),
|
||||||
|
ServerResponse(s, o) => {
|
||||||
|
if let Some(o) = o {
|
||||||
|
write!(f, "Server responded with an error: {s:?}: {o}")
|
||||||
|
} else {
|
||||||
|
write!(f, "Server responded with an error: {s:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum StatusCode {
|
pub enum StatusCode {
|
||||||
Continue,
|
Continue,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Chromium OS Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "arch"
|
name = "arch"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Chromium OS Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
@@ -10,22 +10,21 @@ sev_snp = []
|
|||||||
tdx = []
|
tdx = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.75"
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.4.3"
|
||||||
hypervisor = { path = "../hypervisor" }
|
hypervisor = { path = "../hypervisor" }
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
linux-loader = { version = "0.11.0", features = ["bzimage", "elf", "pe"] }
|
linux-loader = { version = "0.11.0", features = ["elf", "bzimage", "pe"] }
|
||||||
log = "0.4.21"
|
log = "0.4.20"
|
||||||
serde = { version = "1.0.197", features = ["derive", "rc"] }
|
serde = { version = "1.0.168", features = ["rc", "derive"] }
|
||||||
thiserror = "1.0.60"
|
thiserror = "1.0.40"
|
||||||
uuid = "1.8.0"
|
uuid = "1.3.4"
|
||||||
vm-memory = { version = "0.14.1", features = [
|
versionize = "0.2.0"
|
||||||
"backend-bitmap",
|
versionize_derive = "0.1.6"
|
||||||
"backend-mmap",
|
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-bitmap"] }
|
||||||
] }
|
|
||||||
vm-migration = { path = "../vm-migration" }
|
vm-migration = { path = "../vm-migration" }
|
||||||
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }
|
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
[target.'cfg(target_arch = "aarch64")'.dependencies]
|
||||||
fdt_parser = { version = "0.1.5", package = "fdt" }
|
fdt_parser = { version = "0.1.4", package = "fdt" }
|
||||||
vm-fdt = { git = "https://github.com/rust-vmm/vm-fdt", branch = "main" }
|
vm-fdt = { git = "https://github.com/rust-vmm/vm-fdt", branch = "main" }
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ use super::layout::{
|
|||||||
};
|
};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use thiserror::Error;
|
|
||||||
use vm_fdt::{FdtWriter, FdtWriterResult};
|
use vm_fdt::{FdtWriter, FdtWriterResult};
|
||||||
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion};
|
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion};
|
||||||
|
|
||||||
@@ -81,10 +80,9 @@ pub trait DeviceInfoForFdt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Errors thrown while configuring the Flattened Device Tree for aarch64.
|
/// Errors thrown while configuring the Flattened Device Tree for aarch64.
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failure in writing FDT in memory.
|
/// Failure in writing FDT in memory.
|
||||||
#[error("Failure in writing FDT in memory: {0}")]
|
|
||||||
WriteFdtToMemory(GuestMemoryError),
|
WriteFdtToMemory(GuestMemoryError),
|
||||||
}
|
}
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
@@ -525,7 +523,7 @@ fn create_memory_node(
|
|||||||
let memory_region_size: u64 = memory_region.size() as u64;
|
let memory_region_size: u64 = memory_region.size() as u64;
|
||||||
mem_reg_prop.push(memory_region_start_addr);
|
mem_reg_prop.push(memory_region_start_addr);
|
||||||
mem_reg_prop.push(memory_region_size);
|
mem_reg_prop.push(memory_region_size);
|
||||||
// Set the node address the first non-zero region address
|
// Set the node address the first non-zero regison address
|
||||||
if node_memory_addr == 0 {
|
if node_memory_addr == 0 {
|
||||||
node_memory_addr = memory_region_start_addr;
|
node_memory_addr = memory_region_start_addr;
|
||||||
}
|
}
|
||||||
@@ -571,7 +569,7 @@ fn create_memory_node(
|
|||||||
|
|
||||||
if ram_regions.len() > 2 {
|
if ram_regions.len() > 2 {
|
||||||
panic!(
|
panic!(
|
||||||
"There should be up to two non-continuous regions, divided by the
|
"There should be up to two non-continuous regions, devidided by the
|
||||||
gap at the end of 32bit address space."
|
gap at the end of 32bit address space."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -896,7 +894,7 @@ fn create_pci_nodes(
|
|||||||
for pci_device_info_elem in pci_device_info.iter() {
|
for pci_device_info_elem in pci_device_info.iter() {
|
||||||
// EDK2 requires the PCIe high space above 4G address.
|
// EDK2 requires the PCIe high space above 4G address.
|
||||||
// The actual space in CLH follows the RAM. If the RAM space is small, the PCIe high space
|
// The actual space in CLH follows the RAM. If the RAM space is small, the PCIe high space
|
||||||
// could fall below 4G.
|
// could fall bellow 4G.
|
||||||
// Here we cut off PCI device space below 8G in FDT to workaround the EDK2 check.
|
// Here we cut off PCI device space below 8G in FDT to workaround the EDK2 check.
|
||||||
// But the address written in ACPI is not impacted.
|
// But the address written in ACPI is not impacted.
|
||||||
let (pci_device_base_64bit, pci_device_size_64bit) =
|
let (pci_device_base_64bit, pci_device_size_64bit) =
|
||||||
|
|||||||
@@ -111,9 +111,8 @@ pub const RAM_64BIT_START: GuestAddress = GuestAddress(0x1_0000_0000);
|
|||||||
pub const CMDLINE_MAX_SIZE: usize = 2048;
|
pub const CMDLINE_MAX_SIZE: usize = 2048;
|
||||||
|
|
||||||
/// FDT is at the beginning of RAM.
|
/// FDT is at the beginning of RAM.
|
||||||
|
/// Maximum size of the device tree blob as specified in https://www.kernel.org/doc/Documentation/arm64/booting.txt.
|
||||||
pub const FDT_START: GuestAddress = RAM_START;
|
pub const FDT_START: GuestAddress = RAM_START;
|
||||||
/// Maximum size of the device tree blob as specified in [the kernel
|
|
||||||
/// documentation](https://www.kernel.org/doc/Documentation/arm64/booting.txt).
|
|
||||||
pub const FDT_MAX_SIZE: u64 = 0x20_0000;
|
pub const FDT_MAX_SIZE: u64 = 0x20_0000;
|
||||||
|
|
||||||
/// Put ACPI table above dtb
|
/// Put ACPI table above dtb
|
||||||
|
|||||||
@@ -16,42 +16,35 @@ use crate::{DeviceType, GuestMemoryMmap, NumaNodes, PciSpaceInfo, RegionType};
|
|||||||
use hypervisor::arch::aarch64::gic::Vgic;
|
use hypervisor::arch::aarch64::gic::Vgic;
|
||||||
use log::{log_enabled, Level};
|
use log::{log_enabled, Level};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use thiserror::Error;
|
|
||||||
use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryAtomic};
|
use vm_memory::{Address, GuestAddress, GuestMemory, GuestMemoryAtomic};
|
||||||
|
|
||||||
pub const _NSIG: i32 = 65;
|
pub const _NSIG: i32 = 65;
|
||||||
|
|
||||||
/// Errors thrown while configuring aarch64 system.
|
/// Errors thrown while configuring aarch64 system.
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failed to create a FDT.
|
/// Failed to create a FDT.
|
||||||
#[error("Failed to create a FDT")]
|
|
||||||
SetupFdt,
|
SetupFdt,
|
||||||
|
|
||||||
/// Failed to write FDT to memory.
|
/// Failed to write FDT to memory.
|
||||||
#[error("Failed to write FDT to memory: {0}")]
|
|
||||||
WriteFdtToMemory(fdt::Error),
|
WriteFdtToMemory(fdt::Error),
|
||||||
|
|
||||||
/// Failed to create a GIC.
|
/// Failed to create a GIC.
|
||||||
#[error("Failed to create a GIC")]
|
|
||||||
SetupGic,
|
SetupGic,
|
||||||
|
|
||||||
/// Failed to compute the initramfs address.
|
/// Failed to compute the initramfs address.
|
||||||
#[error("Failed to compute the initramfs address")]
|
|
||||||
InitramfsAddress,
|
InitramfsAddress,
|
||||||
|
|
||||||
/// Error configuring the general purpose registers
|
/// Error configuring the general purpose registers
|
||||||
#[error("Error configuring the general purpose registers: {0}")]
|
|
||||||
RegsConfiguration(hypervisor::HypervisorCpuError),
|
RegsConfiguration(hypervisor::HypervisorCpuError),
|
||||||
|
|
||||||
/// Error configuring the MPIDR register
|
/// Error configuring the MPIDR register
|
||||||
#[error("Error configuring the MPIDR register: {0}")]
|
|
||||||
VcpuRegMpidr(hypervisor::HypervisorCpuError),
|
VcpuRegMpidr(hypervisor::HypervisorCpuError),
|
||||||
|
|
||||||
/// Error initializing PMU for vcpu
|
/// Error initializing PMU for vcpu
|
||||||
#[error("Error initializing PMU for vcpu")]
|
|
||||||
VcpuInitPmu,
|
VcpuInitPmu,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,20 @@
|
|||||||
// Copyright 2020 Arm Limited (or its affiliates). All rights reserved.
|
// Copyright 2020 Arm Limited (or its affiliates). All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
use std::os::fd::AsFd;
|
use std::os::fd::AsFd;
|
||||||
use std::result;
|
use std::result;
|
||||||
use thiserror::Error;
|
|
||||||
use vm_memory::{GuestAddress, GuestMemory};
|
use vm_memory::{GuestAddress, GuestMemory};
|
||||||
|
|
||||||
/// Errors thrown while loading UEFI binary
|
/// Errors thrown while loading UEFI binary
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Unable to seek to UEFI image start.
|
/// Unable to seek to UEFI image start.
|
||||||
#[error("Unable to seek to UEFI image start")]
|
|
||||||
SeekUefiStart,
|
SeekUefiStart,
|
||||||
/// Unable to seek to UEFI image end.
|
/// Unable to seek to UEFI image end.
|
||||||
#[error("Unable to seek to UEFI image end")]
|
|
||||||
SeekUefiEnd,
|
SeekUefiEnd,
|
||||||
/// UEFI image too big.
|
/// UEFI image too big.
|
||||||
#[error("UEFI image too big")]
|
|
||||||
UefiTooBig,
|
UefiTooBig,
|
||||||
/// Unable to read UEFI image
|
/// Unable to read UEFI image
|
||||||
#[error("Unable to read UEFI image")]
|
|
||||||
ReadUefiImage,
|
ReadUefiImage,
|
||||||
}
|
}
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ use std::fmt;
|
|||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeError, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
|
use vm_migration::VersionMapped;
|
||||||
|
|
||||||
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<vm_memory::bitmap::AtomicBitmap>;
|
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<vm_memory::bitmap::AtomicBitmap>;
|
||||||
type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitmap>;
|
type GuestRegionMmap = vm_memory::GuestRegionMmap<vm_memory::bitmap::AtomicBitmap>;
|
||||||
@@ -45,17 +48,13 @@ pub enum Error {
|
|||||||
ModlistSetup(#[source] vm_memory::GuestMemoryError),
|
ModlistSetup(#[source] vm_memory::GuestMemoryError),
|
||||||
#[error("RSDP extends past the end of guest memory")]
|
#[error("RSDP extends past the end of guest memory")]
|
||||||
RsdpPastRamEnd,
|
RsdpPastRamEnd,
|
||||||
#[error("Failed to setup Zero Page for bzImage")]
|
|
||||||
ZeroPageSetup(#[source] vm_memory::GuestMemoryError),
|
|
||||||
#[error("Zero Page for bzImage past RAM end")]
|
|
||||||
ZeroPagePastRamEnd,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type for returning public functions outcome.
|
/// Type for returning public functions outcome.
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
/// Type for memory region types.
|
/// Type for memory region types.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Versionize)]
|
||||||
pub enum RegionType {
|
pub enum RegionType {
|
||||||
/// RAM type
|
/// RAM type
|
||||||
Ram,
|
Ram,
|
||||||
@@ -73,6 +72,8 @@ pub enum RegionType {
|
|||||||
Reserved,
|
Reserved,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionMapped for RegionType {}
|
||||||
|
|
||||||
/// Module for aarch64 related functionality.
|
/// Module for aarch64 related functionality.
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub mod aarch64;
|
pub mod aarch64;
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ use crate::InitramfsConfig;
|
|||||||
use crate::RegionType;
|
use crate::RegionType;
|
||||||
use hypervisor::arch::x86::{CpuIdEntry, CPUID_FLAG_VALID_INDEX};
|
use hypervisor::arch::x86::{CpuIdEntry, CPUID_FLAG_VALID_INDEX};
|
||||||
use hypervisor::{CpuVendor, HypervisorCpuError, HypervisorError};
|
use hypervisor::{CpuVendor, HypervisorCpuError, HypervisorError};
|
||||||
use linux_loader::loader::bootparam::{boot_params, setup_header};
|
|
||||||
use linux_loader::loader::elf::start_info::{
|
use linux_loader::loader::elf::start_info::{
|
||||||
hvm_memmap_table_entry, hvm_modlist_entry, hvm_start_info,
|
hvm_memmap_table_entry, hvm_modlist_entry, hvm_start_info,
|
||||||
};
|
};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use thiserror::Error;
|
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
Address, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
|
Address, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
|
||||||
GuestMemoryRegion, GuestUsize,
|
GuestMemoryRegion, GuestUsize,
|
||||||
@@ -65,8 +63,6 @@ pub const _NSIG: i32 = 65;
|
|||||||
pub struct EntryPoint {
|
pub struct EntryPoint {
|
||||||
/// Address in guest memory where the guest must start execution
|
/// Address in guest memory where the guest must start execution
|
||||||
pub entry_addr: GuestAddress,
|
pub entry_addr: GuestAddress,
|
||||||
/// This field is used for bzImage to fill the zero page
|
|
||||||
pub setup_header: Option<setup_header>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const E820_RAM: u32 = 1;
|
const E820_RAM: u32 = 1;
|
||||||
@@ -128,84 +124,62 @@ pub struct CpuidConfig {
|
|||||||
pub amx: bool,
|
pub amx: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Error writing MP table to memory.
|
/// Error writing MP table to memory.
|
||||||
#[error("Error writing MP table to memory: {0}")]
|
|
||||||
MpTableSetup(mptable::Error),
|
MpTableSetup(mptable::Error),
|
||||||
|
|
||||||
/// Error configuring the general purpose registers
|
/// Error configuring the general purpose registers
|
||||||
#[error("Error configuring the general purpose registers: {0}")]
|
|
||||||
RegsConfiguration(regs::Error),
|
RegsConfiguration(regs::Error),
|
||||||
|
|
||||||
/// Error configuring the special registers
|
/// Error configuring the special registers
|
||||||
#[error("Error configuring the special registers: {0}")]
|
|
||||||
SregsConfiguration(regs::Error),
|
SregsConfiguration(regs::Error),
|
||||||
|
|
||||||
/// Error configuring the floating point related registers
|
/// Error configuring the floating point related registers
|
||||||
#[error("Error configuring the floating point related registers: {0}")]
|
|
||||||
FpuConfiguration(regs::Error),
|
FpuConfiguration(regs::Error),
|
||||||
|
|
||||||
/// Error configuring the MSR registers
|
/// Error configuring the MSR registers
|
||||||
#[error("Error configuring the MSR registers: {0}")]
|
|
||||||
MsrsConfiguration(regs::Error),
|
MsrsConfiguration(regs::Error),
|
||||||
|
|
||||||
/// Failed to set supported CPUs.
|
/// Failed to set supported CPUs.
|
||||||
#[error("Failed to set supported CPUs: {0}")]
|
|
||||||
SetSupportedCpusFailed(anyhow::Error),
|
SetSupportedCpusFailed(anyhow::Error),
|
||||||
|
|
||||||
/// Cannot set the local interruption due to bad configuration.
|
/// Cannot set the local interruption due to bad configuration.
|
||||||
#[error("Cannot set the local interruption due to bad configuration: {0}")]
|
|
||||||
LocalIntConfiguration(anyhow::Error),
|
LocalIntConfiguration(anyhow::Error),
|
||||||
|
|
||||||
/// Error setting up SMBIOS table
|
/// Error setting up SMBIOS table
|
||||||
#[error("Error setting up SMBIOS table: {0}")]
|
|
||||||
SmbiosSetup(smbios::Error),
|
SmbiosSetup(smbios::Error),
|
||||||
|
|
||||||
/// Could not find any SGX EPC section
|
/// Could not find any SGX EPC section
|
||||||
#[error("Could not find any SGX EPC section")]
|
|
||||||
NoSgxEpcSection,
|
NoSgxEpcSection,
|
||||||
|
|
||||||
/// Missing SGX CPU feature
|
/// Missing SGX CPU feature
|
||||||
#[error("Missing SGX CPU feature")]
|
|
||||||
MissingSgxFeature,
|
MissingSgxFeature,
|
||||||
|
|
||||||
/// Missing SGX_LC CPU feature
|
/// Missing SGX_LC CPU feature
|
||||||
#[error("Missing SGX_LC CPU feature")]
|
|
||||||
MissingSgxLaunchControlFeature,
|
MissingSgxLaunchControlFeature,
|
||||||
|
|
||||||
/// Error getting supported CPUID through the hypervisor (kvm/mshv) API
|
/// Error getting supported CPUID through the hypervisor (kvm/mshv) API
|
||||||
#[error("Error getting supported CPUID through the hypervisor API: {0}")]
|
|
||||||
CpuidGetSupported(HypervisorError),
|
CpuidGetSupported(HypervisorError),
|
||||||
|
|
||||||
/// Error populating CPUID with KVM HyperV emulation details
|
/// Error populating CPUID with KVM HyperV emulation details
|
||||||
#[error("Error populating CPUID with KVM HyperV emulation details: {0}")]
|
|
||||||
CpuidKvmHyperV(vmm_sys_util::fam::Error),
|
CpuidKvmHyperV(vmm_sys_util::fam::Error),
|
||||||
|
|
||||||
/// Error populating CPUID with CPU identification
|
/// Error populating CPUID with CPU identification
|
||||||
#[error("Error populating CPUID with CPU identification: {0}")]
|
|
||||||
CpuidIdentification(vmm_sys_util::fam::Error),
|
CpuidIdentification(vmm_sys_util::fam::Error),
|
||||||
|
|
||||||
/// Error checking CPUID compatibility
|
/// Error checking CPUID compatibility
|
||||||
#[error("Error checking CPUID compatibility")]
|
|
||||||
CpuidCheckCompatibility,
|
CpuidCheckCompatibility,
|
||||||
|
|
||||||
// Error writing EBDA address
|
// Error writing EBDA address
|
||||||
#[error("Error writing EBDA address: {0}")]
|
|
||||||
EbdaSetup(vm_memory::GuestMemoryError),
|
EbdaSetup(vm_memory::GuestMemoryError),
|
||||||
|
|
||||||
// Error getting CPU TSC frequency
|
// Error getting CPU TSC frequency
|
||||||
#[error("Error getting CPU TSC frequency: {0}")]
|
|
||||||
GetTscFrequency(HypervisorCpuError),
|
GetTscFrequency(HypervisorCpuError),
|
||||||
|
|
||||||
/// Error retrieving TDX capabilities through the hypervisor (kvm/mshv) API
|
/// Error retrieving TDX capabilities through the hypervisor (kvm/mshv) API
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
#[error("Error retrieving TDX capabilities through the hypervisor API: {0}")]
|
|
||||||
TdxCapabilities(HypervisorError),
|
TdxCapabilities(HypervisorError),
|
||||||
|
|
||||||
/// Failed to configure E820 map for bzImage
|
|
||||||
#[error("Failed to configure E820 map for bzImage")]
|
|
||||||
E820Configuration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Error> for super::Error {
|
impl From<Error> for super::Error {
|
||||||
@@ -577,7 +551,7 @@ impl CpuidFeatureEntry {
|
|||||||
if !entry_compatible {
|
if !entry_compatible {
|
||||||
error!(
|
error!(
|
||||||
"Detected incompatible CPUID entry: leaf={:#02x} (subleaf={:#02x}), register='{:?}', \
|
"Detected incompatible CPUID entry: leaf={:#02x} (subleaf={:#02x}), register='{:?}', \
|
||||||
compatible_check='{:?}', source VM feature='{:#04x}', destination VM feature'{:#04x}'.",
|
compatilbe_check='{:?}', source VM feature='{:#04x}', destination VM feature'{:#04x}'.",
|
||||||
entry.function, entry.index, entry.feature_reg,
|
entry.function, entry.index, entry.feature_reg,
|
||||||
entry.compatible_check, src_vm_feature, dest_vm_feature
|
entry.compatible_check, src_vm_feature, dest_vm_feature
|
||||||
);
|
);
|
||||||
@@ -702,20 +676,6 @@ pub fn generate_common_cpuid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Copy host L1 cache details if not populated by KVM
|
|
||||||
0x8000_0005 => {
|
|
||||||
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
|
||||||
// SAFETY: cpuid called with valid leaves
|
|
||||||
if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 {
|
|
||||||
// SAFETY: cpuid called with valid leaves
|
|
||||||
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) };
|
|
||||||
entry.eax = leaf.eax;
|
|
||||||
entry.ebx = leaf.ebx;
|
|
||||||
entry.ecx = leaf.ecx;
|
|
||||||
entry.edx = leaf.edx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Copy host L2 cache details if not populated by KVM
|
// Copy host L2 cache details if not populated by KVM
|
||||||
0x8000_0006 => {
|
0x8000_0006 => {
|
||||||
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
||||||
@@ -834,17 +794,12 @@ pub fn configure_vcpu(
|
|||||||
CpuidPatch::set_cpuid_reg(&mut cpuid, 0x8000_001e, Some(0), CpuidReg::EAX, x2apic_id);
|
CpuidPatch::set_cpuid_reg(&mut cpuid, 0x8000_001e, Some(0), CpuidReg::EAX, x2apic_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ApicId in cpuid for each vcpu - found in cpuid ebx when eax = 1
|
// Set ApicId in cpuid for each vcpu
|
||||||
let mut apic_id_patched = false;
|
// SAFETY: get host cpuid when eax=1
|
||||||
for entry in &mut cpuid {
|
let mut cpu_ebx = unsafe { core::arch::x86_64::__cpuid(1) }.ebx;
|
||||||
if entry.function == 1 {
|
cpu_ebx &= 0xffffff;
|
||||||
entry.ebx &= 0xffffff;
|
cpu_ebx |= x2apic_id << 24;
|
||||||
entry.ebx |= x2apic_id << 24;
|
CpuidPatch::set_cpuid_reg(&mut cpuid, 0x1, None, CpuidReg::EBX, cpu_ebx);
|
||||||
apic_id_patched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert!(apic_id_patched);
|
|
||||||
|
|
||||||
if let Some(t) = topology {
|
if let Some(t) = topology {
|
||||||
update_cpuid_topology(&mut cpuid, t.0, t.1, t.2, cpu_vendor, id);
|
update_cpuid_topology(&mut cpuid, t.0, t.1, t.2, cpu_vendor, id);
|
||||||
@@ -887,7 +842,8 @@ pub fn configure_vcpu(
|
|||||||
|
|
||||||
regs::setup_msrs(vcpu).map_err(Error::MsrsConfiguration)?;
|
regs::setup_msrs(vcpu).map_err(Error::MsrsConfiguration)?;
|
||||||
if let Some((kernel_entry_point, guest_memory)) = boot_setup {
|
if let Some((kernel_entry_point, guest_memory)) = boot_setup {
|
||||||
regs::setup_regs(vcpu, kernel_entry_point).map_err(Error::RegsConfiguration)?;
|
regs::setup_regs(vcpu, kernel_entry_point.entry_addr.raw_value())
|
||||||
|
.map_err(Error::RegsConfiguration)?;
|
||||||
regs::setup_fpu(vcpu).map_err(Error::FpuConfiguration)?;
|
regs::setup_fpu(vcpu).map_err(Error::FpuConfiguration)?;
|
||||||
regs::setup_sregs(&guest_memory.memory(), vcpu).map_err(Error::SregsConfiguration)?;
|
regs::setup_sregs(&guest_memory.memory(), vcpu).map_err(Error::SregsConfiguration)?;
|
||||||
}
|
}
|
||||||
@@ -936,10 +892,8 @@ pub fn arch_memory_regions() -> Vec<(GuestAddress, usize, RegionType)> {
|
|||||||
pub fn configure_system(
|
pub fn configure_system(
|
||||||
guest_mem: &GuestMemoryMmap,
|
guest_mem: &GuestMemoryMmap,
|
||||||
cmdline_addr: GuestAddress,
|
cmdline_addr: GuestAddress,
|
||||||
cmdline_size: usize,
|
|
||||||
initramfs: &Option<InitramfsConfig>,
|
initramfs: &Option<InitramfsConfig>,
|
||||||
_num_cpus: u8,
|
_num_cpus: u8,
|
||||||
setup_header: Option<setup_header>,
|
|
||||||
rsdp_addr: Option<GuestAddress>,
|
rsdp_addr: Option<GuestAddress>,
|
||||||
sgx_epc_region: Option<SgxEpcRegion>,
|
sgx_epc_region: Option<SgxEpcRegion>,
|
||||||
serial_number: Option<&str>,
|
serial_number: Option<&str>,
|
||||||
@@ -967,31 +921,25 @@ pub fn configure_system(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match setup_header {
|
configure_pvh(
|
||||||
Some(hdr) => configure_32bit_entry(
|
guest_mem,
|
||||||
guest_mem,
|
cmdline_addr,
|
||||||
cmdline_addr,
|
initramfs,
|
||||||
cmdline_size,
|
rsdp_addr,
|
||||||
initramfs,
|
sgx_epc_region,
|
||||||
hdr,
|
)
|
||||||
rsdp_addr,
|
|
||||||
sgx_epc_region,
|
|
||||||
),
|
|
||||||
None => configure_pvh(
|
|
||||||
guest_mem,
|
|
||||||
cmdline_addr,
|
|
||||||
initramfs,
|
|
||||||
rsdp_addr,
|
|
||||||
sgx_epc_region,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RamRange = (u64, u64);
|
type RamRange = (u64, u64);
|
||||||
|
|
||||||
/// Returns usable physical memory ranges for the guest
|
/// Returns usable physical memory ranges for the guest
|
||||||
/// These should be used to create e820_RAM memory maps
|
/// These should be used to create e820_RAM memory maps
|
||||||
pub fn generate_ram_ranges(guest_mem: &GuestMemoryMmap) -> super::Result<Vec<RamRange>> {
|
///
|
||||||
|
/// There are up to two usable physical memory ranges,
|
||||||
|
/// divided by the gap at the end of 32bit address space.
|
||||||
|
pub fn generate_ram_ranges(
|
||||||
|
guest_mem: &GuestMemoryMmap,
|
||||||
|
) -> super::Result<(RamRange, Option<RamRange>)> {
|
||||||
// Merge continuous memory regions into one region.
|
// Merge continuous memory regions into one region.
|
||||||
// Note: memory regions from "GuestMemory" are sorted and non-zero sized.
|
// Note: memory regions from "GuestMemory" are sorted and non-zero sized.
|
||||||
let ram_regions = {
|
let ram_regions = {
|
||||||
@@ -1024,11 +972,15 @@ pub fn generate_ram_ranges(guest_mem: &GuestMemoryMmap) -> super::Result<Vec<Ram
|
|||||||
ram_regions
|
ram_regions
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the memory map entry for memory region before the gap
|
if ram_regions.len() > 2 {
|
||||||
let mut ram_ranges = vec![];
|
error!(
|
||||||
|
"There should be up to two usable physical memory ranges, devidided by the
|
||||||
|
gap at the end of 32bit address space (e.g. between 3G and 4G)."
|
||||||
|
);
|
||||||
|
return Err(super::Error::MemmapTableSetup);
|
||||||
|
}
|
||||||
|
|
||||||
// Generate the first usable physical memory range before the gap. The e820 map
|
// Generate the first usable physical memory range before the gap
|
||||||
// should only report memory above 1MiB.
|
|
||||||
let first_ram_range = {
|
let first_ram_range = {
|
||||||
let (first_region_start, first_region_end) =
|
let (first_region_start, first_region_end) =
|
||||||
ram_regions.first().ok_or(super::Error::MemmapTableSetup)?;
|
ram_regions.first().ok_or(super::Error::MemmapTableSetup)?;
|
||||||
@@ -1055,19 +1007,33 @@ pub fn generate_ram_ranges(guest_mem: &GuestMemoryMmap) -> super::Result<Vec<Ram
|
|||||||
|
|
||||||
(high_ram_start, *first_region_end)
|
(high_ram_start, *first_region_end)
|
||||||
};
|
};
|
||||||
ram_ranges.push(first_ram_range);
|
|
||||||
|
|
||||||
// Generate additional usable physical memory range after the gap if any.
|
// Generate the second usable physical memory range after the gap if any
|
||||||
for ram_region in ram_regions.iter().skip(1) {
|
let second_ram_range = if let Some((second_region_start, second_region_end)) =
|
||||||
|
ram_regions.get(1)
|
||||||
|
{
|
||||||
|
let ram_64bit_start = layout::RAM_64BIT_START.raw_value();
|
||||||
|
|
||||||
|
if second_region_start != &ram_64bit_start {
|
||||||
|
error!(
|
||||||
|
"Unexpected second memory region layout: start: 0x{:08x}, ram_64bit_start: 0x{:08x}",
|
||||||
|
second_region_start, ram_64bit_start
|
||||||
|
);
|
||||||
|
|
||||||
|
return Err(super::Error::MemmapTableSetup);
|
||||||
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"found usable physical memory range, start: 0x{:08x}, end: 0x{:08x}",
|
"Second usable physical memory range, start: 0x{:08x}, end: 0x{:08x}",
|
||||||
ram_region.0, ram_region.1
|
ram_64bit_start, second_region_end
|
||||||
);
|
);
|
||||||
|
|
||||||
ram_ranges.push(*ram_region);
|
Some((ram_64bit_start, *second_region_end))
|
||||||
}
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
Ok(ram_ranges)
|
Ok((first_ram_range, second_ram_range))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_pvh(
|
fn configure_pvh(
|
||||||
@@ -1118,18 +1084,30 @@ fn configure_pvh(
|
|||||||
add_memmap_entry(&mut memmap, 0, layout::EBDA_START.raw_value(), E820_RAM);
|
add_memmap_entry(&mut memmap, 0, layout::EBDA_START.raw_value(), E820_RAM);
|
||||||
|
|
||||||
// Get usable physical memory ranges
|
// Get usable physical memory ranges
|
||||||
let ram_ranges = generate_ram_ranges(guest_mem)?;
|
let (first_ram_range, second_ram_range) = generate_ram_ranges(guest_mem)?;
|
||||||
|
|
||||||
// Create e820 memory map entries
|
// Create e820 memory map entry before the gap
|
||||||
for ram_range in ram_ranges {
|
info!(
|
||||||
|
"create_memmap_entry, start: 0x{:08x}, end: 0x{:08x}",
|
||||||
|
first_ram_range.0, first_ram_range.1
|
||||||
|
);
|
||||||
|
add_memmap_entry(
|
||||||
|
&mut memmap,
|
||||||
|
first_ram_range.0,
|
||||||
|
first_ram_range.1 - first_ram_range.0,
|
||||||
|
E820_RAM,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create e820 memory map after the gap if any
|
||||||
|
if let Some(second_ram_range) = second_ram_range {
|
||||||
info!(
|
info!(
|
||||||
"create_memmap_entry, start: 0x{:08x}, end: 0x{:08x}",
|
"create_memmap_entry, start: 0x{:08x}, end: 0x{:08x}",
|
||||||
ram_range.0, ram_range.1
|
second_ram_range.0, second_ram_range.1
|
||||||
);
|
);
|
||||||
add_memmap_entry(
|
add_memmap_entry(
|
||||||
&mut memmap,
|
&mut memmap,
|
||||||
ram_range.0,
|
second_ram_range.0,
|
||||||
ram_range.1 - ram_range.0,
|
second_ram_range.1 - second_ram_range.0,
|
||||||
E820_RAM,
|
E820_RAM,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1189,113 +1167,6 @@ fn configure_pvh(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure_32bit_entry(
|
|
||||||
guest_mem: &GuestMemoryMmap,
|
|
||||||
cmdline_addr: GuestAddress,
|
|
||||||
cmdline_size: usize,
|
|
||||||
initramfs: &Option<InitramfsConfig>,
|
|
||||||
setup_hdr: setup_header,
|
|
||||||
rsdp_addr: Option<GuestAddress>,
|
|
||||||
sgx_epc_region: Option<SgxEpcRegion>,
|
|
||||||
) -> super::Result<()> {
|
|
||||||
const KERNEL_LOADER_OTHER: u8 = 0xff;
|
|
||||||
|
|
||||||
// Use the provided setup header
|
|
||||||
let mut params = boot_params {
|
|
||||||
hdr: setup_hdr,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Common bootparams settings
|
|
||||||
if params.hdr.type_of_loader == 0 {
|
|
||||||
params.hdr.type_of_loader = KERNEL_LOADER_OTHER;
|
|
||||||
}
|
|
||||||
params.hdr.cmd_line_ptr = cmdline_addr.raw_value() as u32;
|
|
||||||
params.hdr.cmdline_size = cmdline_size as u32;
|
|
||||||
|
|
||||||
if let Some(initramfs_config) = initramfs {
|
|
||||||
params.hdr.ramdisk_image = initramfs_config.address.raw_value() as u32;
|
|
||||||
params.hdr.ramdisk_size = initramfs_config.size as u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_e820_entry(&mut params, 0, layout::EBDA_START.raw_value(), E820_RAM)?;
|
|
||||||
|
|
||||||
let mem_end = guest_mem.last_addr();
|
|
||||||
if mem_end < layout::MEM_32BIT_RESERVED_START {
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
layout::HIGH_RAM_START.raw_value(),
|
|
||||||
mem_end.unchecked_offset_from(layout::HIGH_RAM_START) + 1,
|
|
||||||
E820_RAM,
|
|
||||||
)?;
|
|
||||||
} else {
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
layout::HIGH_RAM_START.raw_value(),
|
|
||||||
layout::MEM_32BIT_RESERVED_START.unchecked_offset_from(layout::HIGH_RAM_START),
|
|
||||||
E820_RAM,
|
|
||||||
)?;
|
|
||||||
if mem_end > layout::RAM_64BIT_START {
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
layout::RAM_64BIT_START.raw_value(),
|
|
||||||
mem_end.unchecked_offset_from(layout::RAM_64BIT_START) + 1,
|
|
||||||
E820_RAM,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
layout::PCI_MMCONFIG_START.0,
|
|
||||||
layout::PCI_MMCONFIG_SIZE,
|
|
||||||
E820_RESERVED,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
if let Some(sgx_epc_region) = sgx_epc_region {
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
sgx_epc_region.start().raw_value(),
|
|
||||||
sgx_epc_region.size(),
|
|
||||||
E820_RESERVED,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(rsdp_addr) = rsdp_addr {
|
|
||||||
params.acpi_rsdp_addr = rsdp_addr.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let zero_page_addr = layout::ZERO_PAGE_START;
|
|
||||||
guest_mem
|
|
||||||
.checked_offset(zero_page_addr, mem::size_of::<boot_params>())
|
|
||||||
.ok_or(super::Error::ZeroPagePastRamEnd)?;
|
|
||||||
guest_mem
|
|
||||||
.write_obj(params, zero_page_addr)
|
|
||||||
.map_err(super::Error::ZeroPageSetup)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add an e820 region to the e820 map.
|
|
||||||
/// Returns Ok(()) if successful, or an error if there is no space left in the map.
|
|
||||||
fn add_e820_entry(
|
|
||||||
params: &mut boot_params,
|
|
||||||
addr: u64,
|
|
||||||
size: u64,
|
|
||||||
mem_type: u32,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
if params.e820_entries >= params.e820_table.len() as u8 {
|
|
||||||
return Err(Error::E820Configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
params.e820_table[params.e820_entries as usize].addr = addr;
|
|
||||||
params.e820_table[params.e820_entries as usize].size = size;
|
|
||||||
params.e820_table[params.e820_entries as usize].type_ = mem_type;
|
|
||||||
params.e820_entries += 1;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_memmap_entry(memmap: &mut Vec<hvm_memmap_table_entry>, addr: u64, size: u64, mem_type: u32) {
|
fn add_memmap_entry(memmap: &mut Vec<hvm_memmap_table_entry>, addr: u64, size: u64, mem_type: u32) {
|
||||||
// Add the table entry to the vector
|
// Add the table entry to the vector
|
||||||
memmap.push(hvm_memmap_table_entry {
|
memmap.push(hvm_memmap_table_entry {
|
||||||
@@ -1542,7 +1413,6 @@ fn update_cpuid_sgx(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use linux_loader::loader::bootparam::boot_e820_entry;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn regions_base_addr() {
|
fn regions_base_addr() {
|
||||||
@@ -1559,10 +1429,8 @@ mod tests {
|
|||||||
let config_err = configure_system(
|
let config_err = configure_system(
|
||||||
&gm,
|
&gm,
|
||||||
GuestAddress(0),
|
GuestAddress(0),
|
||||||
0,
|
|
||||||
&None,
|
&None,
|
||||||
1,
|
1,
|
||||||
None,
|
|
||||||
Some(layout::RSDP_POINTER),
|
Some(layout::RSDP_POINTER),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -1584,7 +1452,6 @@ mod tests {
|
|||||||
configure_system(
|
configure_system(
|
||||||
&gm,
|
&gm,
|
||||||
GuestAddress(0),
|
GuestAddress(0),
|
||||||
0,
|
|
||||||
&None,
|
&None,
|
||||||
no_vcpus,
|
no_vcpus,
|
||||||
None,
|
None,
|
||||||
@@ -1593,7 +1460,6 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -1614,7 +1480,6 @@ mod tests {
|
|||||||
configure_system(
|
configure_system(
|
||||||
&gm,
|
&gm,
|
||||||
GuestAddress(0),
|
GuestAddress(0),
|
||||||
0,
|
|
||||||
&None,
|
&None,
|
||||||
no_vcpus,
|
no_vcpus,
|
||||||
None,
|
None,
|
||||||
@@ -1623,14 +1488,12 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
configure_system(
|
configure_system(
|
||||||
&gm,
|
&gm,
|
||||||
GuestAddress(0),
|
GuestAddress(0),
|
||||||
0,
|
|
||||||
&None,
|
&None,
|
||||||
no_vcpus,
|
no_vcpus,
|
||||||
None,
|
None,
|
||||||
@@ -1639,51 +1502,10 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_add_e820_entry() {
|
|
||||||
let e820_table = [(boot_e820_entry {
|
|
||||||
addr: 0x1,
|
|
||||||
size: 4,
|
|
||||||
type_: 1,
|
|
||||||
}); 128];
|
|
||||||
|
|
||||||
let expected_params = boot_params {
|
|
||||||
e820_table,
|
|
||||||
e820_entries: 1,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut params: boot_params = Default::default();
|
|
||||||
add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
e820_table[0].addr,
|
|
||||||
e820_table[0].size,
|
|
||||||
e820_table[0].type_,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
format!("{:?}", params.e820_table[0]),
|
|
||||||
format!("{:?}", expected_params.e820_table[0])
|
|
||||||
);
|
|
||||||
assert_eq!(params.e820_entries, expected_params.e820_entries);
|
|
||||||
|
|
||||||
// Exercise the scenario where the field storing the length of the e820 entry table is
|
|
||||||
// is bigger than the allocated memory.
|
|
||||||
params.e820_entries = params.e820_table.len() as u8 + 1;
|
|
||||||
assert!(add_e820_entry(
|
|
||||||
&mut params,
|
|
||||||
e820_table[0].addr,
|
|
||||||
e820_table[0].size,
|
|
||||||
e820_table[0].type_
|
|
||||||
)
|
|
||||||
.is_err());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_add_memmap_entry() {
|
fn test_add_memmap_entry() {
|
||||||
let mut memmap: Vec<hvm_memmap_table_entry> = Vec::new();
|
let mut memmap: Vec<hvm_memmap_table_entry> = Vec::new();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
|
|
||||||
@@ -17,7 +15,7 @@ pub const MP_IRQDIR_DEFAULT: ::std::os::raw::c_uint = 0;
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone)]
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
pub struct mpf_intel {
|
pub struct mpf_intel {
|
||||||
pub signature: [::std::os::raw::c_uchar; 4usize],
|
pub signature: [::std::os::raw::c_char; 4usize],
|
||||||
pub physptr: ::std::os::raw::c_uint,
|
pub physptr: ::std::os::raw::c_uint,
|
||||||
pub length: ::std::os::raw::c_uchar,
|
pub length: ::std::os::raw::c_uchar,
|
||||||
pub specification: ::std::os::raw::c_uchar,
|
pub specification: ::std::os::raw::c_uchar,
|
||||||
@@ -32,12 +30,12 @@ pub struct mpf_intel {
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone)]
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
pub struct mpc_table {
|
pub struct mpc_table {
|
||||||
pub signature: [::std::os::raw::c_uchar; 4usize],
|
pub signature: [::std::os::raw::c_char; 4usize],
|
||||||
pub length: ::std::os::raw::c_ushort,
|
pub length: ::std::os::raw::c_ushort,
|
||||||
pub spec: ::std::os::raw::c_uchar,
|
pub spec: ::std::os::raw::c_char,
|
||||||
pub checksum: ::std::os::raw::c_uchar,
|
pub checksum: ::std::os::raw::c_char,
|
||||||
pub oem: [::std::os::raw::c_uchar; 8usize],
|
pub oem: [::std::os::raw::c_char; 8usize],
|
||||||
pub productid: [::std::os::raw::c_uchar; 12usize],
|
pub productid: [::std::os::raw::c_char; 12usize],
|
||||||
pub oemptr: ::std::os::raw::c_uint,
|
pub oemptr: ::std::os::raw::c_uint,
|
||||||
pub oemsize: ::std::os::raw::c_ushort,
|
pub oemsize: ::std::os::raw::c_ushort,
|
||||||
pub oemcount: ::std::os::raw::c_ushort,
|
pub oemcount: ::std::os::raw::c_ushort,
|
||||||
@@ -106,9 +104,9 @@ pub struct mpc_lintsrc {
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone)]
|
#[derive(Debug, Default, Copy, Clone)]
|
||||||
pub struct mpc_oemtable {
|
pub struct mpc_oemtable {
|
||||||
pub signature: [::std::os::raw::c_uchar; 4usize],
|
pub signature: [::std::os::raw::c_char; 4usize],
|
||||||
pub length: ::std::os::raw::c_ushort,
|
pub length: ::std::os::raw::c_ushort,
|
||||||
pub rev: ::std::os::raw::c_uchar,
|
pub rev: ::std::os::raw::c_char,
|
||||||
pub checksum: ::std::os::raw::c_uchar,
|
pub checksum: ::std::os::raw::c_char,
|
||||||
pub mpc: [::std::os::raw::c_uchar; 8usize],
|
pub mpc: [::std::os::raw::c_char; 8usize],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,10 @@
|
|||||||
use crate::layout::{APIC_START, HIGH_RAM_START, IOAPIC_START};
|
use crate::layout::{APIC_START, HIGH_RAM_START, IOAPIC_START};
|
||||||
use crate::x86_64::{get_x2apic_id, mpspec};
|
use crate::x86_64::{get_x2apic_id, mpspec};
|
||||||
use crate::GuestMemoryMmap;
|
use crate::GuestMemoryMmap;
|
||||||
use libc::c_uchar;
|
use libc::c_char;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use thiserror::Error;
|
|
||||||
use vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError};
|
use vm_memory::{Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError};
|
||||||
|
|
||||||
// This is a workaround to the Rust enforcement specifying that any implementation of a foreign
|
// This is a workaround to the Rust enforcement specifying that any implementation of a foreign
|
||||||
@@ -50,40 +49,29 @@ unsafe impl ByteValued for MpcLintsrcWrapper {}
|
|||||||
// SAFETY: see above
|
// SAFETY: see above
|
||||||
unsafe impl ByteValued for MpfIntelWrapper {}
|
unsafe impl ByteValued for MpfIntelWrapper {}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// There was too little guest memory to store the entire MP table.
|
/// There was too little guest memory to store the entire MP table.
|
||||||
#[error("There was too little guest memory to store the entire MP table")]
|
|
||||||
NotEnoughMemory,
|
NotEnoughMemory,
|
||||||
/// The MP table has too little address space to be stored.
|
/// The MP table has too little address space to be stored.
|
||||||
#[error("The MP table has too little address space to be stored")]
|
|
||||||
AddressOverflow,
|
AddressOverflow,
|
||||||
/// Failure while zeroing out the memory for the MP table.
|
/// Failure while zeroing out the memory for the MP table.
|
||||||
#[error("Failure while zeroing out the memory for the MP table: {0}")]
|
|
||||||
Clear(GuestMemoryError),
|
Clear(GuestMemoryError),
|
||||||
/// Number of CPUs exceeds the maximum supported CPUs
|
/// Number of CPUs exceeds the maximum supported CPUs
|
||||||
#[error("Number of CPUs exceeds the maximum supported CPUs")]
|
|
||||||
TooManyCpus,
|
TooManyCpus,
|
||||||
/// Failure to write the MP floating pointer.
|
/// Failure to write the MP floating pointer.
|
||||||
#[error("Failure to write the MP floating pointer: {0}")]
|
|
||||||
WriteMpfIntel(GuestMemoryError),
|
WriteMpfIntel(GuestMemoryError),
|
||||||
/// Failure to write MP CPU entry.
|
/// Failure to write MP CPU entry.
|
||||||
#[error("Failure to write MP CPU entry: {0}")]
|
|
||||||
WriteMpcCpu(GuestMemoryError),
|
WriteMpcCpu(GuestMemoryError),
|
||||||
/// Failure to write MP ioapic entry.
|
/// Failure to write MP ioapic entry.
|
||||||
#[error("Failure to write MP ioapic entry: {0}")]
|
|
||||||
WriteMpcIoapic(GuestMemoryError),
|
WriteMpcIoapic(GuestMemoryError),
|
||||||
/// Failure to write MP bus entry.
|
/// Failure to write MP bus entry.
|
||||||
#[error("Failure to write MP bus entry: {0}")]
|
|
||||||
WriteMpcBus(GuestMemoryError),
|
WriteMpcBus(GuestMemoryError),
|
||||||
/// Failure to write MP interrupt source entry.
|
/// Failure to write MP interrupt source entry.
|
||||||
#[error("Failure to write MP interrupt source entry: {0}")]
|
|
||||||
WriteMpcIntsrc(GuestMemoryError),
|
WriteMpcIntsrc(GuestMemoryError),
|
||||||
/// Failure to write MP local interrupt source entry.
|
/// Failure to write MP local interrupt source entry.
|
||||||
#[error("Failure to write MP local interrupt source entry: {0}")]
|
|
||||||
WriteMpcLintsrc(GuestMemoryError),
|
WriteMpcLintsrc(GuestMemoryError),
|
||||||
/// Failure to write MP table header.
|
/// Failure to write MP table header.
|
||||||
#[error("Failure to write MP table header: {0}")]
|
|
||||||
WriteMpcTable(GuestMemoryError),
|
WriteMpcTable(GuestMemoryError),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,13 +82,18 @@ pub type Result<T> = result::Result<T, Error>;
|
|||||||
// a large number for FC usecases.
|
// a large number for FC usecases.
|
||||||
pub const MAX_SUPPORTED_CPUS: u32 = 254;
|
pub const MAX_SUPPORTED_CPUS: u32 = 254;
|
||||||
|
|
||||||
|
// Convenience macro for making arrays of diverse character types.
|
||||||
|
macro_rules! char_array {
|
||||||
|
($t:ty; $( $c:expr ),*) => ( [ $( $c as $t ),* ] )
|
||||||
|
}
|
||||||
|
|
||||||
// Most of these variables are sourced from the Intel MP Spec 1.4.
|
// Most of these variables are sourced from the Intel MP Spec 1.4.
|
||||||
const SMP_MAGIC_IDENT: &[c_uchar; 4] = b"_MP_";
|
const SMP_MAGIC_IDENT: [c_char; 4] = char_array!(c_char; '_', 'M', 'P', '_');
|
||||||
const MPC_SIGNATURE: &[c_uchar; 4] = b"PCMP";
|
const MPC_SIGNATURE: [c_char; 4] = char_array!(c_char; 'P', 'C', 'M', 'P');
|
||||||
const MPC_SPEC: u8 = 4;
|
const MPC_SPEC: i8 = 4;
|
||||||
const MPC_OEM: &[c_uchar; 8] = b"FC ";
|
const MPC_OEM: [c_char; 8] = char_array!(c_char; 'F', 'C', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||||
const MPC_PRODUCT_ID: &[c_uchar; 12] = &[b'0'; 12];
|
const MPC_PRODUCT_ID: [c_char; 12] = ['0' as c_char; 12];
|
||||||
const BUS_TYPE_ISA: &[c_uchar; 6] = b"ISA ";
|
const BUS_TYPE_ISA: [u8; 6] = char_array!(u8; 'I', 'S', 'A', ' ', ' ', ' ');
|
||||||
const APIC_VERSION: u8 = 0x14;
|
const APIC_VERSION: u8 = 0x14;
|
||||||
const CPU_STEPPING: u32 = 0x600;
|
const CPU_STEPPING: u32 = 0x600;
|
||||||
const CPU_FEATURE_APIC: u32 = 0x200;
|
const CPU_FEATURE_APIC: u32 = 0x200;
|
||||||
@@ -175,7 +168,7 @@ pub fn setup_mptable(
|
|||||||
{
|
{
|
||||||
let mut mpf_intel = MpfIntelWrapper(mpspec::mpf_intel::default());
|
let mut mpf_intel = MpfIntelWrapper(mpspec::mpf_intel::default());
|
||||||
let size = mem::size_of::<MpfIntelWrapper>() as u64;
|
let size = mem::size_of::<MpfIntelWrapper>() as u64;
|
||||||
mpf_intel.0.signature = *SMP_MAGIC_IDENT;
|
mpf_intel.0.signature = SMP_MAGIC_IDENT;
|
||||||
mpf_intel.0.length = 1;
|
mpf_intel.0.length = 1;
|
||||||
mpf_intel.0.specification = 4;
|
mpf_intel.0.specification = 4;
|
||||||
mpf_intel.0.physptr = (base_mp.raw_value() + size) as u32;
|
mpf_intel.0.physptr = (base_mp.raw_value() + size) as u32;
|
||||||
@@ -216,7 +209,7 @@ pub fn setup_mptable(
|
|||||||
let mut mpc_bus = MpcBusWrapper(mpspec::mpc_bus::default());
|
let mut mpc_bus = MpcBusWrapper(mpspec::mpc_bus::default());
|
||||||
mpc_bus.0.type_ = mpspec::MP_BUS as u8;
|
mpc_bus.0.type_ = mpspec::MP_BUS as u8;
|
||||||
mpc_bus.0.busid = 0;
|
mpc_bus.0.busid = 0;
|
||||||
mpc_bus.0.bustype = *BUS_TYPE_ISA;
|
mpc_bus.0.bustype = BUS_TYPE_ISA;
|
||||||
mem.write_obj(mpc_bus, base_mp)
|
mem.write_obj(mpc_bus, base_mp)
|
||||||
.map_err(Error::WriteMpcBus)?;
|
.map_err(Error::WriteMpcBus)?;
|
||||||
base_mp = base_mp.unchecked_add(size as u64);
|
base_mp = base_mp.unchecked_add(size as u64);
|
||||||
@@ -287,14 +280,14 @@ pub fn setup_mptable(
|
|||||||
|
|
||||||
{
|
{
|
||||||
let mut mpc_table = MpcTableWrapper(mpspec::mpc_table::default());
|
let mut mpc_table = MpcTableWrapper(mpspec::mpc_table::default());
|
||||||
mpc_table.0.signature = *MPC_SIGNATURE;
|
mpc_table.0.signature = MPC_SIGNATURE;
|
||||||
mpc_table.0.length = table_end.unchecked_offset_from(table_base) as u16;
|
mpc_table.0.length = table_end.unchecked_offset_from(table_base) as u16;
|
||||||
mpc_table.0.spec = MPC_SPEC;
|
mpc_table.0.spec = MPC_SPEC;
|
||||||
mpc_table.0.oem = *MPC_OEM;
|
mpc_table.0.oem = MPC_OEM;
|
||||||
mpc_table.0.productid = *MPC_PRODUCT_ID;
|
mpc_table.0.productid = MPC_PRODUCT_ID;
|
||||||
mpc_table.0.lapic = APIC_START.0 as u32;
|
mpc_table.0.lapic = APIC_START.0 as u32;
|
||||||
checksum = checksum.wrapping_add(compute_checksum(&mpc_table.0));
|
checksum = checksum.wrapping_add(compute_checksum(&mpc_table.0));
|
||||||
mpc_table.0.checksum = (!checksum).wrapping_add(1);
|
mpc_table.0.checksum = (!checksum).wrapping_add(1) as i8;
|
||||||
mem.write_obj(mpc_table, table_base)
|
mem.write_obj(mpc_table, table_base)
|
||||||
.map_err(Error::WriteMpcTable)?;
|
.map_err(Error::WriteMpcTable)?;
|
||||||
}
|
}
|
||||||
@@ -307,7 +300,8 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::layout::MPTABLE_START;
|
use crate::layout::MPTABLE_START;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
bitmap::BitmapSlice, GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile,
|
bitmap::BitmapSlice, GuestAddress, GuestUsize, VolatileMemoryError, VolatileSlice,
|
||||||
|
WriteVolatile,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn table_entry_size(type_: u8) -> usize {
|
fn table_entry_size(type_: u8) -> usize {
|
||||||
|
|||||||
@@ -6,55 +6,40 @@
|
|||||||
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
use crate::layout::{
|
use crate::layout::{BOOT_GDT_START, BOOT_IDT_START, PVH_INFO_START};
|
||||||
BOOT_GDT_START, BOOT_IDT_START, BOOT_STACK_POINTER, PVH_INFO_START, ZERO_PAGE_START,
|
use crate::GuestMemoryMmap;
|
||||||
};
|
|
||||||
use crate::{EntryPoint, GuestMemoryMmap};
|
|
||||||
use hypervisor::arch::x86::gdt::{gdt_entry, segment_from_gdt};
|
use hypervisor::arch::x86::gdt::{gdt_entry, segment_from_gdt};
|
||||||
use hypervisor::arch::x86::regs::CR0_PE;
|
use hypervisor::arch::x86::regs::CR0_PE;
|
||||||
use hypervisor::arch::x86::{FpuState, SpecialRegisters, StandardRegisters};
|
use hypervisor::arch::x86::{FpuState, SpecialRegisters, StandardRegisters};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{mem, result};
|
use std::{mem, result};
|
||||||
use thiserror::Error;
|
|
||||||
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError};
|
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failed to get SREGs for this CPU.
|
/// Failed to get SREGs for this CPU.
|
||||||
#[error("Failed to get SREGs for this CPU: {0}")]
|
|
||||||
GetStatusRegisters(hypervisor::HypervisorCpuError),
|
GetStatusRegisters(hypervisor::HypervisorCpuError),
|
||||||
/// Failed to set base registers for this CPU.
|
/// Failed to set base registers for this CPU.
|
||||||
#[error("Failed to set base registers for this CPU: {0}")]
|
|
||||||
SetBaseRegisters(hypervisor::HypervisorCpuError),
|
SetBaseRegisters(hypervisor::HypervisorCpuError),
|
||||||
/// Failed to configure the FPU.
|
/// Failed to configure the FPU.
|
||||||
#[error("Failed to configure the FPU: {0}")]
|
|
||||||
SetFpuRegisters(hypervisor::HypervisorCpuError),
|
SetFpuRegisters(hypervisor::HypervisorCpuError),
|
||||||
/// Setting up MSRs failed.
|
/// Setting up MSRs failed.
|
||||||
#[error("Setting up MSRs failed: {0}")]
|
|
||||||
SetModelSpecificRegisters(hypervisor::HypervisorCpuError),
|
SetModelSpecificRegisters(hypervisor::HypervisorCpuError),
|
||||||
/// Failed to set SREGs for this CPU.
|
/// Failed to set SREGs for this CPU.
|
||||||
#[error("Failed to set SREGs for this CPU: {0}")]
|
|
||||||
SetStatusRegisters(hypervisor::HypervisorCpuError),
|
SetStatusRegisters(hypervisor::HypervisorCpuError),
|
||||||
/// Checking the GDT address failed.
|
/// Checking the GDT address failed.
|
||||||
#[error("Checking the GDT address failed")]
|
|
||||||
CheckGdtAddr,
|
CheckGdtAddr,
|
||||||
/// Writing the GDT to RAM failed.
|
/// Writing the GDT to RAM failed.
|
||||||
#[error("Writing the GDT to RAM failed: {0}")]
|
|
||||||
WriteGdt(GuestMemoryError),
|
WriteGdt(GuestMemoryError),
|
||||||
/// Writing the IDT to RAM failed.
|
/// Writing the IDT to RAM failed.
|
||||||
#[error("Writing the IDT to RAM failed: {0}")]
|
|
||||||
WriteIdt(GuestMemoryError),
|
WriteIdt(GuestMemoryError),
|
||||||
/// Writing PDPTE to RAM failed.
|
/// Writing PDPTE to RAM failed.
|
||||||
#[error("Writing PDPTE to RAM failed: {0}")]
|
|
||||||
WritePdpteAddress(GuestMemoryError),
|
WritePdpteAddress(GuestMemoryError),
|
||||||
/// Writing PDE to RAM failed.
|
/// Writing PDE to RAM failed.
|
||||||
#[error("Writing PDE to RAM failed: {0}")]
|
|
||||||
WritePdeAddress(GuestMemoryError),
|
WritePdeAddress(GuestMemoryError),
|
||||||
/// Writing PML4 to RAM failed.
|
/// Writing PML4 to RAM failed.
|
||||||
#[error("Writing PML4 to RAM failed: {0}")]
|
|
||||||
WritePml4Address(GuestMemoryError),
|
WritePml4Address(GuestMemoryError),
|
||||||
/// Writing PML5 to RAM failed.
|
/// Writing PML5 to RAM failed.
|
||||||
#[error("Writing PML5 to RAM failed: {0}")]
|
|
||||||
WritePml5Address(GuestMemoryError),
|
WritePml5Address(GuestMemoryError),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,22 +77,13 @@ pub fn setup_msrs(vcpu: &Arc<dyn hypervisor::Vcpu>) -> Result<()> {
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
|
/// * `vcpu` - Structure for the VCPU that holds the VCPU's fd.
|
||||||
/// * `entry_point` - Description of the boot entry to set up.
|
/// * `boot_ip` - Starting instruction pointer.
|
||||||
pub fn setup_regs(vcpu: &Arc<dyn hypervisor::Vcpu>, entry_point: EntryPoint) -> Result<()> {
|
pub fn setup_regs(vcpu: &Arc<dyn hypervisor::Vcpu>, boot_ip: u64) -> Result<()> {
|
||||||
let regs = match entry_point.setup_header {
|
let regs = StandardRegisters {
|
||||||
None => StandardRegisters {
|
rflags: 0x0000000000000002u64,
|
||||||
rflags: 0x0000000000000002u64,
|
rbx: PVH_INFO_START.raw_value(),
|
||||||
rip: entry_point.entry_addr.raw_value(),
|
rip: boot_ip,
|
||||||
rbx: PVH_INFO_START.raw_value(),
|
..Default::default()
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
Some(_) => StandardRegisters {
|
|
||||||
rflags: 0x0000000000000002u64,
|
|
||||||
rip: entry_point.entry_addr.raw_value(),
|
|
||||||
rsp: BOOT_STACK_POINTER.raw_value(),
|
|
||||||
rsi: ZERO_PAGE_START.raw_value(),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
vcpu.set_regs(®s).map_err(Error::SetBaseRegisters)
|
vcpu.set_regs(®s).map_err(Error::SetBaseRegisters)
|
||||||
}
|
}
|
||||||
@@ -188,6 +164,7 @@ pub fn configure_segments_and_sregs(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::GuestMemoryMmap;
|
||||||
use vm_memory::GuestAddress;
|
use vm_memory::GuestAddress;
|
||||||
|
|
||||||
fn create_guest_mem() -> GuestMemoryMmap {
|
fn create_guest_mem() -> GuestMemoryMmap {
|
||||||
|
|||||||
@@ -8,36 +8,53 @@
|
|||||||
|
|
||||||
use crate::layout::SMBIOS_START;
|
use crate::layout::SMBIOS_START;
|
||||||
use crate::GuestMemoryMmap;
|
use crate::GuestMemoryMmap;
|
||||||
|
use std::fmt::{self, Display};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use thiserror::Error;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use vm_memory::ByteValued;
|
use vm_memory::ByteValued;
|
||||||
use vm_memory::{Address, Bytes, GuestAddress};
|
use vm_memory::{Address, Bytes, GuestAddress};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// There was too little guest memory to store the entire SMBIOS table.
|
/// There was too little guest memory to store the entire SMBIOS table.
|
||||||
#[error("There was too little guest memory to store the SMBIOS table")]
|
|
||||||
NotEnoughMemory,
|
NotEnoughMemory,
|
||||||
/// The SMBIOS table has too little address space to be stored.
|
/// The SMBIOS table has too little address space to be stored.
|
||||||
#[error("The SMBIOS table has too little address space to be stored")]
|
|
||||||
AddressOverflow,
|
AddressOverflow,
|
||||||
/// Failure while zeroing out the memory for the SMBIOS table.
|
/// Failure while zeroing out the memory for the SMBIOS table.
|
||||||
#[error("Failure while zeroing out the memory for the SMBIOS table")]
|
|
||||||
Clear,
|
Clear,
|
||||||
/// Failure to write SMBIOS entrypoint structure
|
/// Failure to write SMBIOS entrypoint structure
|
||||||
#[error("Failure to write SMBIOS entrypoint structure")]
|
|
||||||
WriteSmbiosEp,
|
WriteSmbiosEp,
|
||||||
/// Failure to write additional data to memory
|
/// Failure to write additional data to memory
|
||||||
#[error("Failure to write additional data to memory")]
|
|
||||||
WriteData,
|
WriteData,
|
||||||
/// Failure to parse uuid, uuid format may be error
|
/// Failure to parse uuid, uuid format may be error
|
||||||
#[error("Failure to parse uuid: {0}")]
|
|
||||||
ParseUuid(uuid::Error),
|
ParseUuid(uuid::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use self::Error::*;
|
||||||
|
|
||||||
|
let description = match self {
|
||||||
|
NotEnoughMemory => {
|
||||||
|
"There was too little guest memory to store the SMBIOS table".to_string()
|
||||||
|
}
|
||||||
|
AddressOverflow => {
|
||||||
|
"The SMBIOS table has too little address space to be stored".to_string()
|
||||||
|
}
|
||||||
|
Clear => "Failure while zeroing out the memory for the SMBIOS table".to_string(),
|
||||||
|
WriteSmbiosEp => "Failure to write SMBIOS entrypoint structure".to_string(),
|
||||||
|
WriteData => "Failure to write additional data to memory".to_string(),
|
||||||
|
ParseUuid(e) => format!("Failure to parse uuid: {e}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
write!(f, "SMBIOS error: {description}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
// Constants sourced from SMBIOS Spec 3.2.0.
|
// Constants sourced from SMBIOS Spec 3.2.0.
|
||||||
|
|||||||
@@ -1,30 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Chromium OS Authors", "The Cloud Hypervisor Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "block"
|
name = "block"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
authors = ["The Cloud Hypervisor Authors", "The Chromium OS Authors"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
io_uring = ["dep:io-uring"]
|
io_uring = ["dep:io-uring"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.4.3"
|
||||||
crc-any = "2.4.4"
|
crc-any = "2.4.4"
|
||||||
io-uring = { version = "0.6.3", optional = true }
|
io-uring = { version = "0.6.2", optional = true }
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
log = "0.4.21"
|
log = "0.4.20"
|
||||||
remain = "0.2.13"
|
remain = "0.2.11"
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
smallvec = "1.11.0"
|
||||||
smallvec = "1.13.2"
|
thiserror = "1.0.40"
|
||||||
thiserror = "1.0.60"
|
uuid = { version = "1.3.4", features = ["v4"] }
|
||||||
uuid = { version = "1.8.0", features = ["v4"] }
|
versionize = "0.2.0"
|
||||||
virtio-bindings = { version = "0.2.2", features = ["virtio-v5_0_0"] }
|
versionize_derive = "0.1.6"
|
||||||
virtio-queue = "0.12.0"
|
virtio-bindings = { version = "0.2.0", features = ["virtio-v5_0_0"] }
|
||||||
vm-memory = { version = "0.14.1", features = [
|
virtio-queue = "0.11.0"
|
||||||
"backend-atomic",
|
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
|
||||||
"backend-bitmap",
|
|
||||||
"backend-mmap",
|
|
||||||
] }
|
|
||||||
vm-virtio = { path = "../vm-virtio" }
|
vm-virtio = { path = "../vm-virtio" }
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ use crate::vhdx::{Vhdx, VhdxError};
|
|||||||
#[cfg(feature = "io_uring")]
|
#[cfg(feature = "io_uring")]
|
||||||
use io_uring::{opcode, IoUring, Probe};
|
use io_uring::{opcode, IoUring, Probe};
|
||||||
use libc::{ioctl, S_IFBLK, S_IFMT};
|
use libc::{ioctl, S_IFBLK, S_IFMT};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
|
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
|
||||||
@@ -53,17 +53,21 @@ use std::sync::Arc;
|
|||||||
use std::sync::MutexGuard;
|
use std::sync::MutexGuard;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use virtio_bindings::virtio_blk::*;
|
use virtio_bindings::virtio_blk::*;
|
||||||
use virtio_queue::DescriptorChain;
|
use virtio_queue::DescriptorChain;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError,
|
bitmap::AtomicBitmap, bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory,
|
||||||
GuestMemoryLoadGuard,
|
GuestMemoryError, GuestMemoryLoadGuard,
|
||||||
};
|
};
|
||||||
use vm_virtio::{AccessPlatform, Translatable};
|
use vm_virtio::{AccessPlatform, Translatable};
|
||||||
use vmm_sys_util::aio;
|
use vmm_sys_util::aio;
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr};
|
use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr};
|
||||||
|
|
||||||
|
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
|
||||||
|
|
||||||
const SECTOR_SHIFT: u8 = 9;
|
const SECTOR_SHIFT: u8 = 9;
|
||||||
pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT;
|
pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT;
|
||||||
|
|
||||||
@@ -193,8 +197,8 @@ pub enum RequestType {
|
|||||||
Unsupported(u32),
|
Unsupported(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn request_type<B: Bitmap + 'static>(
|
pub fn request_type(
|
||||||
mem: &vm_memory::GuestMemoryMmap<B>,
|
mem: &GuestMemoryMmap,
|
||||||
desc_addr: GuestAddress,
|
desc_addr: GuestAddress,
|
||||||
) -> result::Result<RequestType, Error> {
|
) -> result::Result<RequestType, Error> {
|
||||||
let type_ = mem.read_obj(desc_addr).map_err(Error::GuestMemory)?;
|
let type_ = mem.read_obj(desc_addr).map_err(Error::GuestMemory)?;
|
||||||
@@ -207,10 +211,7 @@ pub fn request_type<B: Bitmap + 'static>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sector<B: Bitmap + 'static>(
|
fn sector(mem: &GuestMemoryMmap, desc_addr: GuestAddress) -> result::Result<u64, Error> {
|
||||||
mem: &vm_memory::GuestMemoryMmap<B>,
|
|
||||||
desc_addr: GuestAddress,
|
|
||||||
) -> result::Result<u64, Error> {
|
|
||||||
const SECTOR_OFFSET: usize = 8;
|
const SECTOR_OFFSET: usize = 8;
|
||||||
let addr = match mem.checked_offset(desc_addr, SECTOR_OFFSET) {
|
let addr = match mem.checked_offset(desc_addr, SECTOR_OFFSET) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
@@ -240,8 +241,8 @@ pub struct Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
pub fn parse<B: Bitmap + 'static>(
|
pub fn parse(
|
||||||
desc_chain: &mut DescriptorChain<GuestMemoryLoadGuard<vm_memory::GuestMemoryMmap<B>>>,
|
desc_chain: &mut DescriptorChain<GuestMemoryLoadGuard<GuestMemoryMmap>>,
|
||||||
access_platform: Option<&Arc<dyn AccessPlatform>>,
|
access_platform: Option<&Arc<dyn AccessPlatform>>,
|
||||||
) -> result::Result<Request, Error> {
|
) -> result::Result<Request, Error> {
|
||||||
let hdr_desc = desc_chain
|
let hdr_desc = desc_chain
|
||||||
@@ -332,11 +333,11 @@ impl Request {
|
|||||||
Ok(req)
|
Ok(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute<T: Seek + Read + Write, B: Bitmap + 'static>(
|
pub fn execute<T: Seek + Read + Write>(
|
||||||
&self,
|
&self,
|
||||||
disk: &mut T,
|
disk: &mut T,
|
||||||
disk_nsectors: u64,
|
disk_nsectors: u64,
|
||||||
mem: &vm_memory::GuestMemoryMmap<B>,
|
mem: &GuestMemoryMmap,
|
||||||
serial: &[u8],
|
serial: &[u8],
|
||||||
) -> result::Result<u32, ExecuteError> {
|
) -> result::Result<u32, ExecuteError> {
|
||||||
disk.seek(SeekFrom::Start(self.sector << SECTOR_SHIFT))
|
disk.seek(SeekFrom::Start(self.sector << SECTOR_SHIFT))
|
||||||
@@ -389,9 +390,9 @@ impl Request {
|
|||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_async<B: Bitmap + 'static>(
|
pub fn execute_async(
|
||||||
&mut self,
|
&mut self,
|
||||||
mem: &vm_memory::GuestMemoryMmap<B>,
|
mem: &GuestMemoryMmap,
|
||||||
disk_nsectors: u64,
|
disk_nsectors: u64,
|
||||||
disk_image: &mut dyn AsyncIo,
|
disk_image: &mut dyn AsyncIo,
|
||||||
serial: &[u8],
|
serial: &[u8],
|
||||||
@@ -544,7 +545,7 @@ impl Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Default, Versionize)]
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
pub struct VirtioBlockConfig {
|
pub struct VirtioBlockConfig {
|
||||||
pub capacity: u64,
|
pub capacity: u64,
|
||||||
@@ -567,7 +568,7 @@ pub struct VirtioBlockConfig {
|
|||||||
pub write_zeroes_may_unmap: u8,
|
pub write_zeroes_may_unmap: u8,
|
||||||
pub unused1: [u8; 3],
|
pub unused1: [u8; 3],
|
||||||
}
|
}
|
||||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, Default, Versionize)]
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
pub struct VirtioBlockGeometry {
|
pub struct VirtioBlockGeometry {
|
||||||
pub cylinders: u16,
|
pub cylinders: u16,
|
||||||
@@ -659,9 +660,7 @@ where
|
|||||||
let mut slices: SmallVec<[IoSliceMut; 1]> = SmallVec::with_capacity(iovecs.len());
|
let mut slices: SmallVec<[IoSliceMut; 1]> = SmallVec::with_capacity(iovecs.len());
|
||||||
for iovec in iovecs.iter() {
|
for iovec in iovecs.iter() {
|
||||||
// SAFETY: on Linux IoSliceMut wraps around libc::iovec
|
// SAFETY: on Linux IoSliceMut wraps around libc::iovec
|
||||||
slices.push(IoSliceMut::new(unsafe {
|
slices.push(IoSliceMut::new(unsafe { std::mem::transmute(*iovec) }));
|
||||||
std::mem::transmute::<libc::iovec, &mut [u8]>(*iovec)
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
@@ -694,9 +693,7 @@ where
|
|||||||
let mut slices: SmallVec<[IoSlice; 1]> = SmallVec::with_capacity(iovecs.len());
|
let mut slices: SmallVec<[IoSlice; 1]> = SmallVec::with_capacity(iovecs.len());
|
||||||
for iovec in iovecs.iter() {
|
for iovec in iovecs.iter() {
|
||||||
// SAFETY: on Linux IoSlice wraps around libc::iovec
|
// SAFETY: on Linux IoSlice wraps around libc::iovec
|
||||||
slices.push(IoSlice::new(unsafe {
|
slices.push(IoSlice::new(unsafe { std::mem::transmute(*iovec) }));
|
||||||
std::mem::transmute::<libc::iovec, &mut [u8]>(*iovec)
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = {
|
let result = {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
mod qcow_raw_file;
|
mod qcow_raw_file;
|
||||||
mod raw_file;
|
mod raw_file;
|
||||||
@@ -19,11 +17,11 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
|||||||
use libc::{EINVAL, ENOSPC, ENOTSUP};
|
use libc::{EINVAL, ENOSPC, ENOTSUP};
|
||||||
use remain::sorted;
|
use remain::sorted;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
use std::fmt::{self, Display};
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::str;
|
use std::str;
|
||||||
use thiserror::Error;
|
|
||||||
use vmm_sys_util::{
|
use vmm_sys_util::{
|
||||||
file_traits::FileSetLen, file_traits::FileSync, seek_hole::SeekHole, write_zeroes::PunchHole,
|
file_traits::FileSetLen, file_traits::FileSync, seek_hole::SeekHole, write_zeroes::PunchHole,
|
||||||
write_zeroes::WriteZeroesAt,
|
write_zeroes::WriteZeroesAt,
|
||||||
@@ -31,98 +29,106 @@ use vmm_sys_util::{
|
|||||||
|
|
||||||
pub use crate::qcow::raw_file::RawFile;
|
pub use crate::qcow::raw_file::RawFile;
|
||||||
|
|
||||||
/// Nesting depth limit for disk formats that can open other disk files.
|
|
||||||
const MAX_NESTING_DEPTH: u32 = 10;
|
|
||||||
|
|
||||||
#[sorted]
|
#[sorted]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Backing file io error: {0}")]
|
|
||||||
BackingFileIo(io::Error),
|
BackingFileIo(io::Error),
|
||||||
#[error("Backing file open error: {0}")]
|
BackingFileOpen(Box<crate::Error>),
|
||||||
BackingFileOpen(Box<Error>),
|
|
||||||
#[error("Backing file name is too long: {0} bytes over")]
|
|
||||||
BackingFileTooLong(usize),
|
BackingFileTooLong(usize),
|
||||||
#[error("Compressed blocks not supported")]
|
|
||||||
CompressedBlocksNotSupported,
|
CompressedBlocksNotSupported,
|
||||||
#[error("Failed to evict cache: {0}")]
|
|
||||||
EvictingCache(io::Error),
|
EvictingCache(io::Error),
|
||||||
#[error("File larger than max of {}: {0}", MAX_QCOW_FILE_SIZE)]
|
|
||||||
FileTooBig(u64),
|
FileTooBig(u64),
|
||||||
#[error("Failed to get file size: {0}")]
|
|
||||||
GettingFileSize(io::Error),
|
GettingFileSize(io::Error),
|
||||||
#[error("Failed to get refcount: {0}")]
|
|
||||||
GettingRefcount(refcount::Error),
|
GettingRefcount(refcount::Error),
|
||||||
#[error("Failed to parse filename: {0}")]
|
|
||||||
InvalidBackingFileName(str::Utf8Error),
|
InvalidBackingFileName(str::Utf8Error),
|
||||||
#[error("Invalid cluster index")]
|
|
||||||
InvalidClusterIndex,
|
InvalidClusterIndex,
|
||||||
#[error("Invalid cluster size")]
|
|
||||||
InvalidClusterSize,
|
InvalidClusterSize,
|
||||||
#[error("Invalid index")]
|
|
||||||
InvalidIndex,
|
InvalidIndex,
|
||||||
#[error("Invalid L1 table offset")]
|
|
||||||
InvalidL1TableOffset,
|
InvalidL1TableOffset,
|
||||||
#[error("Invalid L1 table size: {0}")]
|
|
||||||
InvalidL1TableSize(u32),
|
InvalidL1TableSize(u32),
|
||||||
#[error("Invalid magic")]
|
|
||||||
InvalidMagic,
|
InvalidMagic,
|
||||||
#[error("Invalid offset: {0}")]
|
|
||||||
InvalidOffset(u64),
|
InvalidOffset(u64),
|
||||||
#[error("Invalid refcount table offset")]
|
|
||||||
InvalidRefcountTableOffset,
|
InvalidRefcountTableOffset,
|
||||||
#[error("Invalid refcount table size: {0}")]
|
|
||||||
InvalidRefcountTableSize(u64),
|
InvalidRefcountTableSize(u64),
|
||||||
#[error("Maximum disk nesting depth exceeded")]
|
|
||||||
MaxNestingDepthExceeded,
|
|
||||||
#[error("No free clusters")]
|
|
||||||
NoFreeClusters,
|
NoFreeClusters,
|
||||||
#[error("No refcount clusters")]
|
|
||||||
NoRefcountClusters,
|
NoRefcountClusters,
|
||||||
#[error("Not enough space for refcounts")]
|
|
||||||
NotEnoughSpaceForRefcounts,
|
NotEnoughSpaceForRefcounts,
|
||||||
#[error("Failed to open file {0}")]
|
|
||||||
OpeningFile(io::Error),
|
OpeningFile(io::Error),
|
||||||
#[error("Failed to read data: {0}")]
|
|
||||||
ReadingData(io::Error),
|
ReadingData(io::Error),
|
||||||
#[error("Failed to read header: {0}")]
|
|
||||||
ReadingHeader(io::Error),
|
ReadingHeader(io::Error),
|
||||||
#[error("Failed to read pointers: {0}")]
|
|
||||||
ReadingPointers(io::Error),
|
ReadingPointers(io::Error),
|
||||||
#[error("Failed to read ref count block: {0}")]
|
|
||||||
ReadingRefCountBlock(refcount::Error),
|
ReadingRefCountBlock(refcount::Error),
|
||||||
#[error("Failed to read ref counts: {0}")]
|
|
||||||
ReadingRefCounts(io::Error),
|
ReadingRefCounts(io::Error),
|
||||||
#[error("Failed to rebuild ref counts: {0}")]
|
|
||||||
RebuildingRefCounts(io::Error),
|
RebuildingRefCounts(io::Error),
|
||||||
#[error("Refcount table offset past file end")]
|
|
||||||
RefcountTableOffEnd,
|
RefcountTableOffEnd,
|
||||||
#[error("Too many clusters specified for refcount")]
|
|
||||||
RefcountTableTooLarge,
|
RefcountTableTooLarge,
|
||||||
#[error("Failed to seek file: {0}")]
|
|
||||||
SeekingFile(io::Error),
|
SeekingFile(io::Error),
|
||||||
#[error("Failed to set file size: {0}")]
|
|
||||||
SettingFileSize(io::Error),
|
SettingFileSize(io::Error),
|
||||||
#[error("Failed to set refcount refcount: {0}")]
|
|
||||||
SettingRefcountRefcount(io::Error),
|
SettingRefcountRefcount(io::Error),
|
||||||
#[error("Size too small for number of clusters")]
|
|
||||||
SizeTooSmallForNumberOfClusters,
|
SizeTooSmallForNumberOfClusters,
|
||||||
#[error("L1 entry table too large: {0}")]
|
|
||||||
TooManyL1Entries(u64),
|
TooManyL1Entries(u64),
|
||||||
#[error("Ref count table too large: {0}")]
|
|
||||||
TooManyRefcounts(u64),
|
TooManyRefcounts(u64),
|
||||||
#[error("Unsupported refcount order")]
|
|
||||||
UnsupportedRefcountOrder,
|
UnsupportedRefcountOrder,
|
||||||
#[error("Unsupported version: {0}")]
|
|
||||||
UnsupportedVersion(u32),
|
UnsupportedVersion(u32),
|
||||||
#[error("Failed to write data: {0}")]
|
|
||||||
WritingData(io::Error),
|
WritingData(io::Error),
|
||||||
#[error("Failed to write header: {0}")]
|
|
||||||
WritingHeader(io::Error),
|
WritingHeader(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
#[remain::check]
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use self::Error::*;
|
||||||
|
|
||||||
|
#[sorted]
|
||||||
|
match self {
|
||||||
|
BackingFileIo(e) => write!(f, "backing file io error: {}", e),
|
||||||
|
BackingFileOpen(e) => write!(f, "backing file open error: {}", *e),
|
||||||
|
BackingFileTooLong(len) => {
|
||||||
|
write!(f, "backing file name is too long: {} bytes over", len)
|
||||||
|
}
|
||||||
|
CompressedBlocksNotSupported => write!(f, "compressed blocks not supported"),
|
||||||
|
EvictingCache(e) => write!(f, "failed to evict cache: {e}"),
|
||||||
|
FileTooBig(size) => write!(f, "file larger than max of {MAX_QCOW_FILE_SIZE}: {size}"),
|
||||||
|
GettingFileSize(e) => write!(f, "failed to get file size: {e}"),
|
||||||
|
GettingRefcount(e) => write!(f, "failed to get refcount: {e}"),
|
||||||
|
InvalidBackingFileName(e) => write!(f, "failed to parse filename: {}", e),
|
||||||
|
InvalidClusterIndex => write!(f, "invalid cluster index"),
|
||||||
|
InvalidClusterSize => write!(f, "invalid cluster size"),
|
||||||
|
InvalidIndex => write!(f, "invalid index"),
|
||||||
|
InvalidL1TableOffset => write!(f, "invalid L1 table offset"),
|
||||||
|
InvalidL1TableSize(size) => write!(f, "invalid L1 table size {size}"),
|
||||||
|
InvalidMagic => write!(f, "invalid magic"),
|
||||||
|
InvalidOffset(_) => write!(f, "invalid offset"),
|
||||||
|
InvalidRefcountTableOffset => write!(f, "invalid refcount table offset"),
|
||||||
|
InvalidRefcountTableSize(size) => write!(f, "invalid refcount table size: {size}"),
|
||||||
|
NoFreeClusters => write!(f, "no free clusters"),
|
||||||
|
NoRefcountClusters => write!(f, "no refcount clusters"),
|
||||||
|
NotEnoughSpaceForRefcounts => write!(f, "not enough space for refcounts"),
|
||||||
|
OpeningFile(e) => write!(f, "failed to open file: {e}"),
|
||||||
|
ReadingData(e) => write!(f, "failed to read data: {e}"),
|
||||||
|
ReadingHeader(e) => write!(f, "failed to read header: {e}"),
|
||||||
|
ReadingPointers(e) => write!(f, "failed to read pointers: {e}"),
|
||||||
|
ReadingRefCountBlock(e) => write!(f, "failed to read ref count block: {e}"),
|
||||||
|
ReadingRefCounts(e) => write!(f, "failed to read ref counts: {e}"),
|
||||||
|
RebuildingRefCounts(e) => write!(f, "failed to rebuild ref counts: {e}"),
|
||||||
|
RefcountTableOffEnd => write!(f, "refcount table offset past file end"),
|
||||||
|
RefcountTableTooLarge => write!(f, "too many clusters specified for refcount table"),
|
||||||
|
SeekingFile(e) => write!(f, "failed to seek file: {e}"),
|
||||||
|
SettingFileSize(e) => write!(f, "failed to set file size: {e}"),
|
||||||
|
SettingRefcountRefcount(e) => write!(f, "failed to set refcount refcount: {e}"),
|
||||||
|
SizeTooSmallForNumberOfClusters => write!(f, "size too small for number of clusters"),
|
||||||
|
TooManyL1Entries(count) => write!(f, "l1 entry table too large: {count}"),
|
||||||
|
TooManyRefcounts(count) => write!(f, "ref count table too large: {count}"),
|
||||||
|
UnsupportedRefcountOrder => write!(f, "unsupported refcount order"),
|
||||||
|
UnsupportedVersion(v) => write!(f, "unsupported version: {v}"),
|
||||||
|
WritingData(e) => write!(f, "failed to write data: {e}"),
|
||||||
|
WritingHeader(e) => write!(f, "failed to write header: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum ImageType {
|
pub enum ImageType {
|
||||||
Raw,
|
Raw,
|
||||||
Qcow2,
|
Qcow2,
|
||||||
@@ -439,20 +445,12 @@ pub struct QcowFile {
|
|||||||
// List of unreferenced clusters available to be used. unref clusters become available once the
|
// List of unreferenced clusters available to be used. unref clusters become available once the
|
||||||
// removal of references to them have been synced to disk.
|
// removal of references to them have been synced to disk.
|
||||||
avail_clusters: Vec<u64>,
|
avail_clusters: Vec<u64>,
|
||||||
backing_file: Option<Box<Self>>,
|
backing_file: Option<Box<dyn BlockBackend>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QcowFile {
|
impl QcowFile {
|
||||||
/// Creates a QcowFile from `file`. File must be a valid qcow2 image.
|
/// Creates a QcowFile from `file`. File must be a valid qcow2 image.
|
||||||
///
|
pub fn from(mut file: RawFile) -> Result<QcowFile> {
|
||||||
/// Additionally, max nesting depth of this qcow2 image will be set to default value 10.
|
|
||||||
pub fn from(file: RawFile) -> Result<QcowFile> {
|
|
||||||
Self::from_with_nesting_depth(file, MAX_NESTING_DEPTH)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a QcowFile from `file` and with a max nesting depth. File must be a valid qcow2
|
|
||||||
/// image.
|
|
||||||
pub fn from_with_nesting_depth(mut file: RawFile, max_nesting_depth: u32) -> Result<QcowFile> {
|
|
||||||
let header = QcowHeader::new(&mut file)?;
|
let header = QcowHeader::new(&mut file)?;
|
||||||
|
|
||||||
// Only v2 and v3 files are supported.
|
// Only v2 and v3 files are supported.
|
||||||
@@ -479,20 +477,14 @@ impl QcowFile {
|
|||||||
let direct_io = file.is_direct();
|
let direct_io = file.is_direct();
|
||||||
|
|
||||||
let backing_file = if let Some(backing_file_path) = header.backing_file_path.as_ref() {
|
let backing_file = if let Some(backing_file_path) = header.backing_file_path.as_ref() {
|
||||||
if max_nesting_depth == 0 {
|
|
||||||
return Err(Error::MaxNestingDepthExceeded);
|
|
||||||
}
|
|
||||||
let path = backing_file_path.clone();
|
let path = backing_file_path.clone();
|
||||||
let backing_raw_file = OpenOptions::new()
|
let backing_raw_file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(path)
|
.open(path)
|
||||||
.map_err(Error::BackingFileIo)?;
|
.map_err(Error::BackingFileIo)?;
|
||||||
let backing_file = Self::from_with_nesting_depth(
|
let backing_file = crate::create_disk_file(backing_raw_file, direct_io)
|
||||||
RawFile::new(backing_raw_file, direct_io),
|
.map_err(|e| Error::BackingFileOpen(Box::new(e)))?;
|
||||||
max_nesting_depth - 1,
|
Some(backing_file)
|
||||||
)
|
|
||||||
.map_err(|e| Error::BackingFileOpen(Box::new(e)))?;
|
|
||||||
Some(Box::new(backing_file))
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -640,22 +632,20 @@ impl QcowFile {
|
|||||||
file: RawFile,
|
file: RawFile,
|
||||||
version: u32,
|
version: u32,
|
||||||
backing_file_name: &str,
|
backing_file_name: &str,
|
||||||
backing_file_max_nesting_depth: u32,
|
|
||||||
) -> Result<QcowFile> {
|
) -> Result<QcowFile> {
|
||||||
let direct_io = file.is_direct();
|
let direct_io = file.is_direct();
|
||||||
let backing_raw_file = OpenOptions::new()
|
let backing_raw_file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.open(backing_file_name)
|
.open(backing_file_name)
|
||||||
.map_err(Error::BackingFileIo)?;
|
.map_err(Error::BackingFileIo)?;
|
||||||
let backing_file = Self::from_with_nesting_depth(
|
let backing_file = crate::create_disk_file(backing_raw_file, direct_io)
|
||||||
RawFile::new(backing_raw_file, direct_io),
|
.map_err(|e| Error::BackingFileOpen(Box::new(e)))?;
|
||||||
backing_file_max_nesting_depth,
|
let size = backing_file
|
||||||
)
|
.size()
|
||||||
.map_err(|e| Error::BackingFileOpen(Box::new(e)))?;
|
.map_err(|e| Error::BackingFileOpen(Box::new(e)))?;
|
||||||
let size = backing_file.virtual_size();
|
|
||||||
let header = QcowHeader::create_for_size_and_path(version, size, Some(backing_file_name))?;
|
let header = QcowHeader::create_for_size_and_path(version, size, Some(backing_file_name))?;
|
||||||
let mut result = QcowFile::new_from_header(file, header)?;
|
let mut result = QcowFile::new_from_header(file, header)?;
|
||||||
result.backing_file = Some(Box::new(backing_file));
|
result.backing_file = Some(backing_file);
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,7 +673,7 @@ impl QcowFile {
|
|||||||
Ok(qcow)
|
Ok(qcow)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_backing_file(&mut self, backing: Option<Box<Self>>) {
|
pub fn set_backing_file(&mut self, backing: Option<Box<dyn BlockBackend>>) {
|
||||||
self.backing_file = backing;
|
self.backing_file = backing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1221,7 +1211,7 @@ impl QcowFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate and initialize a new data cluster. Returns the offset of the
|
// Allocate and initialize a new data cluster. Returns the offset of the
|
||||||
// cluster into the file on success.
|
// cluster in to the file on success.
|
||||||
fn append_data_cluster(&mut self, initial_data: Option<Vec<u8>>) -> std::io::Result<u64> {
|
fn append_data_cluster(&mut self, initial_data: Option<Vec<u8>>) -> std::io::Result<u64> {
|
||||||
let new_addr: u64 = self.get_new_cluster(initial_data)?;
|
let new_addr: u64 = self.get_new_cluster(initial_data)?;
|
||||||
// The cluster refcount starts at one indicating it is used but doesn't need COW.
|
// The cluster refcount starts at one indicating it is used but doesn't need COW.
|
||||||
@@ -1639,7 +1629,7 @@ impl PunchHole for QcowFile {
|
|||||||
let mut remaining = length;
|
let mut remaining = length;
|
||||||
let mut offset = offset;
|
let mut offset = offset;
|
||||||
while remaining > 0 {
|
while remaining > 0 {
|
||||||
let chunk_length = min(remaining, usize::MAX as u64) as usize;
|
let chunk_length = min(remaining, std::usize::MAX as u64) as usize;
|
||||||
self.deallocate_bytes(offset, chunk_length)?;
|
self.deallocate_bytes(offset, chunk_length)?;
|
||||||
remaining -= chunk_length as u64;
|
remaining -= chunk_length as u64;
|
||||||
offset += chunk_length as u64;
|
offset += chunk_length as u64;
|
||||||
@@ -1799,17 +1789,11 @@ where
|
|||||||
/// Copy the contents of a disk image in `src_file` into `dst_file`.
|
/// Copy the contents of a disk image in `src_file` into `dst_file`.
|
||||||
/// The type of `src_file` is automatically detected, and the output file type is
|
/// The type of `src_file` is automatically detected, and the output file type is
|
||||||
/// determined by `dst_type`.
|
/// determined by `dst_type`.
|
||||||
pub fn convert(
|
pub fn convert(mut src_file: RawFile, dst_file: RawFile, dst_type: ImageType) -> Result<()> {
|
||||||
mut src_file: RawFile,
|
|
||||||
dst_file: RawFile,
|
|
||||||
dst_type: ImageType,
|
|
||||||
src_max_nesting_depth: u32,
|
|
||||||
) -> Result<()> {
|
|
||||||
let src_type = detect_image_type(&mut src_file)?;
|
let src_type = detect_image_type(&mut src_file)?;
|
||||||
match src_type {
|
match src_type {
|
||||||
ImageType::Qcow2 => {
|
ImageType::Qcow2 => {
|
||||||
let mut src_reader =
|
let mut src_reader = QcowFile::from(src_file)?;
|
||||||
QcowFile::from_with_nesting_depth(src_file, src_max_nesting_depth)?;
|
|
||||||
convert_reader(&mut src_reader, dst_file, dst_type)
|
convert_reader(&mut src_reader, dst_file, dst_type)
|
||||||
}
|
}
|
||||||
ImageType::Raw => {
|
ImageType::Raw => {
|
||||||
@@ -1838,9 +1822,7 @@ pub fn detect_image_type(file: &mut RawFile) -> Result<ImageType> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fs::File;
|
use std::io::{Read, Seek, SeekFrom, Write};
|
||||||
use std::path::Path;
|
|
||||||
use vmm_sys_util::tempdir::TempDir;
|
|
||||||
use vmm_sys_util::tempfile::TempFile;
|
use vmm_sys_util::tempfile::TempFile;
|
||||||
use vmm_sys_util::write_zeroes::WriteZeroes;
|
use vmm_sys_util::write_zeroes::WriteZeroes;
|
||||||
|
|
||||||
@@ -2040,82 +2022,6 @@ mod tests {
|
|||||||
assert_eq!(read_header.backing_file_path, header.backing_file_path);
|
assert_eq!(read_header.backing_file_path, header.backing_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn no_backing_file() {
|
|
||||||
// `backing_file` is `None`
|
|
||||||
let header = QcowHeader::create_for_size_and_path(3, 0x10_0000, None)
|
|
||||||
.expect("Failed to create header.");
|
|
||||||
let mut disk_file: RawFile = RawFile::new(TempFile::new().unwrap().into_file(), false);
|
|
||||||
header
|
|
||||||
.write_to(&mut disk_file)
|
|
||||||
.expect("Failed to write header to shm.");
|
|
||||||
disk_file.rewind().unwrap();
|
|
||||||
// The maximum nesting depth is 0, which means backing file is not allowed.
|
|
||||||
let res = QcowFile::from_with_nesting_depth(disk_file, 0);
|
|
||||||
assert!(res.is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn disable_backing_file() {
|
|
||||||
// `backing_file` is `Some`
|
|
||||||
let header =
|
|
||||||
QcowHeader::create_for_size_and_path(3, 0x10_0000, Some("/path/to/backing/file"))
|
|
||||||
.expect("Failed to create header.");
|
|
||||||
let mut disk_file: RawFile = RawFile::new(TempFile::new().unwrap().into_file(), false);
|
|
||||||
header
|
|
||||||
.write_to(&mut disk_file)
|
|
||||||
.expect("Failed to write header to shm.");
|
|
||||||
disk_file.rewind().unwrap();
|
|
||||||
// The maximum nesting depth is 0, which means backing file is not allowed.
|
|
||||||
let res = QcowFile::from_with_nesting_depth(disk_file, 0);
|
|
||||||
assert!(res.is_err());
|
|
||||||
assert!(matches!(res.unwrap_err(), Error::MaxNestingDepthExceeded));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a qcow2 file with itself as its backing file.
|
|
||||||
///
|
|
||||||
/// Without configuration `max_nesting_depth`, this will cause infinite recursion when loading
|
|
||||||
/// the file until stack overflow.
|
|
||||||
fn new_self_referential_qcow(path: &Path) -> Result<()> {
|
|
||||||
let header = QcowHeader::create_for_size_and_path(3, 0x10_0000, path.to_str())?;
|
|
||||||
let mut disk_file = RawFile::new(
|
|
||||||
File::create(path).expect("Failed to create image file."),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
header.write_to(&mut disk_file)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn max_nesting_backing() {
|
|
||||||
let test_dir = TempDir::new_with_prefix("/tmp/ch").unwrap();
|
|
||||||
let img_path = test_dir.as_path().join("test.img");
|
|
||||||
|
|
||||||
new_self_referential_qcow(img_path.as_path()).unwrap();
|
|
||||||
|
|
||||||
let err = QcowFile::from_with_nesting_depth(
|
|
||||||
RawFile::new(
|
|
||||||
File::open(img_path.as_path()).expect("Failed to open qcow image file"),
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
MAX_NESTING_DEPTH,
|
|
||||||
)
|
|
||||||
.expect_err("Opening qcow file with itself as backing file should fail.");
|
|
||||||
|
|
||||||
// This type of error is complex. For comparing easily, we can check if it contains the
|
|
||||||
// type name after formatting.
|
|
||||||
assert!(format!("{err:?}").contains(&format!("{:?}", Error::MaxNestingDepthExceeded)));
|
|
||||||
// This should recursively call the function ten times before throwing an error, and the
|
|
||||||
// error `BackingFileOpen` should also be repeated ten times.
|
|
||||||
assert_eq!(
|
|
||||||
format!("{err:?}")
|
|
||||||
.matches("BackingFileOpen")
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.len() as u32,
|
|
||||||
MAX_NESTING_DEPTH,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_magic() {
|
fn invalid_magic() {
|
||||||
let invalid_header = vec![0x51u8, 0x46, 0x4a, 0xfb];
|
let invalid_header = vec![0x51u8, 0x46, 0x4a, 0xfb];
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
use super::RawFile;
|
use super::RawFile;
|
||||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
use crate::BlockBackend;
|
use crate::BlockBackend;
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
use std::alloc::{alloc_zeroed, dealloc, Layout};
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fs::{File, Metadata};
|
use std::fs::{File, Metadata};
|
||||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
|
|||||||
@@ -1,40 +1,51 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
|
use std::fmt::{self, Display};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use libc::EINVAL;
|
use libc::EINVAL;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use crate::qcow::{
|
use crate::qcow::{
|
||||||
qcow_raw_file::QcowRawFile,
|
qcow_raw_file::QcowRawFile,
|
||||||
vec_cache::{CacheMap, Cacheable, VecCache},
|
vec_cache::{CacheMap, Cacheable, VecCache},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// `EvictingCache` - Error writing a refblock from the cache to disk.
|
/// `EvictingCache` - Error writing a refblock from the cache to disk.
|
||||||
#[error("Failed to write a refblock from the cache to disk: {0}")]
|
|
||||||
EvictingRefCounts(io::Error),
|
EvictingRefCounts(io::Error),
|
||||||
/// `InvalidIndex` - Address requested isn't within the range of the disk.
|
/// `InvalidIndex` - Address requested isn't within the range of the disk.
|
||||||
#[error("Address requested is not within the range of the disk")]
|
|
||||||
InvalidIndex,
|
InvalidIndex,
|
||||||
/// `NeedCluster` - Handle this error by reading the cluster and calling the function again.
|
/// `NeedCluster` - Handle this error by reading the cluster and calling the function again.
|
||||||
#[error("Cluster with addr={0} needs to be read")]
|
|
||||||
NeedCluster(u64),
|
NeedCluster(u64),
|
||||||
/// `NeedNewCluster` - Handle this error by allocating a cluster and calling the function again.
|
/// `NeedNewCluster` - Handle this error by allocating a cluster and calling the function again.
|
||||||
#[error("New cluster needs to be allocated for refcounts")]
|
|
||||||
NeedNewCluster,
|
NeedNewCluster,
|
||||||
/// `ReadingRefCounts` - Error reading the file into the refcount cache.
|
/// `ReadingRefCounts` - Error reading the file in to the refcount cache.
|
||||||
#[error("Failed to read the file into the refcount cache: {0}")]
|
|
||||||
ReadingRefCounts(io::Error),
|
ReadingRefCounts(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
use self::Error::*;
|
||||||
|
|
||||||
|
match self {
|
||||||
|
EvictingRefCounts(e) => {
|
||||||
|
write!(f, "failed to write a refblock from the cache to disk: {e}")
|
||||||
|
}
|
||||||
|
InvalidIndex => write!(f, "address requested is not within the range of the disk"),
|
||||||
|
NeedCluster(addr) => write!(f, "cluster with addr={addr} needs to be read"),
|
||||||
|
NeedNewCluster => write!(f, "new cluster needs to be allocated for refcounts"),
|
||||||
|
ReadingRefCounts(e) => {
|
||||||
|
write!(f, "failed to read the file into the refcount cache: {e}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents the refcount entries for an open qcow file.
|
/// Represents the refcount entries for an open qcow file.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RefCount {
|
pub struct RefCount {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
use std::collections::hash_map::IterMut;
|
use std::collections::hash_map::IterMut;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use crate::{read_aligned_block_size, DiskTopology};
|
use crate::{read_aligned_block_size, DiskTopology};
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Seek, SeekFrom};
|
use std::io::{Seek, SeekFrom};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ extern crate log;
|
|||||||
use byteorder::{ByteOrder, LittleEndian, ReadBytesExt};
|
use byteorder::{ByteOrder, LittleEndian, ReadBytesExt};
|
||||||
use remain::sorted;
|
use remain::sorted;
|
||||||
use std::collections::btree_map::BTreeMap;
|
use std::collections::btree_map::BTreeMap;
|
||||||
|
use std::convert::TryInto;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
@@ -90,7 +91,7 @@ pub type Result<T> = std::result::Result<T, VhdxHeaderError>;
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct FileTypeIdentifier {
|
pub struct FileTypeIdentifier {
|
||||||
pub _signature: u64,
|
pub signature: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileTypeIdentifier {
|
impl FileTypeIdentifier {
|
||||||
@@ -98,14 +99,14 @@ impl FileTypeIdentifier {
|
|||||||
pub fn new(f: &mut File) -> Result<FileTypeIdentifier> {
|
pub fn new(f: &mut File) -> Result<FileTypeIdentifier> {
|
||||||
f.seek(SeekFrom::Start(FILE_START))
|
f.seek(SeekFrom::Start(FILE_START))
|
||||||
.map_err(VhdxHeaderError::SeekFileTypeIdentifier)?;
|
.map_err(VhdxHeaderError::SeekFileTypeIdentifier)?;
|
||||||
let _signature = f
|
let signature = f
|
||||||
.read_u64::<LittleEndian>()
|
.read_u64::<LittleEndian>()
|
||||||
.map_err(VhdxHeaderError::ReadFileTypeIdentifier)?;
|
.map_err(VhdxHeaderError::ReadFileTypeIdentifier)?;
|
||||||
if _signature != VHDX_SIGN {
|
if signature != VHDX_SIGN {
|
||||||
return Err(VhdxHeaderError::InvalidVHDXSign);
|
return Err(VhdxHeaderError::InvalidVHDXSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(FileTypeIdentifier { _signature })
|
Ok(FileTypeIdentifier { signature })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ pub struct Header {
|
|||||||
impl Header {
|
impl Header {
|
||||||
/// Reads the Header structure from a reference VHDx file
|
/// Reads the Header structure from a reference VHDx file
|
||||||
pub fn new(f: &mut File, start: u64) -> Result<Header> {
|
pub fn new(f: &mut File, start: u64) -> Result<Header> {
|
||||||
// Read the whole header into a buffer. We will need it for
|
// Read the whole header in to a buffer. We will need it for
|
||||||
// calculating checksum.
|
// calculating checksum.
|
||||||
let mut buffer = [0; HEADER_SIZE as usize];
|
let mut buffer = [0; HEADER_SIZE as usize];
|
||||||
f.seek(SeekFrom::Start(start))
|
f.seek(SeekFrom::Start(start))
|
||||||
@@ -352,6 +353,12 @@ impl RegionTableEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
struct RegionEntry {
|
||||||
|
_start: u64,
|
||||||
|
_end: u64,
|
||||||
|
}
|
||||||
|
|
||||||
enum HeaderNo {
|
enum HeaderNo {
|
||||||
First,
|
First,
|
||||||
Second,
|
Second,
|
||||||
@@ -470,7 +477,7 @@ impl VhdxHeader {
|
|||||||
pub fn calculate_checksum(buffer: &mut [u8], csum_offset: usize) -> Result<u32> {
|
pub fn calculate_checksum(buffer: &mut [u8], csum_offset: usize) -> Result<u32> {
|
||||||
// Read the checksum into a mutable slice
|
// Read the checksum into a mutable slice
|
||||||
let csum_buf = &mut buffer[csum_offset..csum_offset + 4];
|
let csum_buf = &mut buffer[csum_offset..csum_offset + 4];
|
||||||
// Convert the checksum chunk into a u32 integer
|
// Convert the checksum chunk in to a u32 integer
|
||||||
let orig_csum = LittleEndian::read_u32(csum_buf);
|
let orig_csum = LittleEndian::read_u32(csum_buf);
|
||||||
// Zero the checksum in the buffer
|
// Zero the checksum in the buffer
|
||||||
LittleEndian::write_u32(csum_buf, 0);
|
LittleEndian::write_u32(csum_buf, 0);
|
||||||
|
|||||||
@@ -1,26 +1,27 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Chromium OS Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "devices"
|
name = "devices"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Chromium OS Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
acpi_tables = { git = "https://github.com/rust-vmm/acpi_tables", branch = "main" }
|
acpi_tables = { git = "https://github.com/rust-vmm/acpi_tables", branch = "main" }
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.75"
|
||||||
arch = { path = "../arch" }
|
arch = { path = "../arch" }
|
||||||
bitflags = "2.5.0"
|
bitflags = "2.4.1"
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.4.3"
|
||||||
event_monitor = { path = "../event_monitor" }
|
event_monitor = { path = "../event_monitor" }
|
||||||
hypervisor = { path = "../hypervisor" }
|
hypervisor = { path = "../hypervisor" }
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
log = "0.4.21"
|
log = "0.4.20"
|
||||||
pci = { path = "../pci" }
|
pci = { path = "../pci" }
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
thiserror = "1.0.40"
|
||||||
thiserror = "1.0.60"
|
|
||||||
tpm = { path = "../tpm" }
|
tpm = { path = "../tpm" }
|
||||||
|
versionize = "0.2.0"
|
||||||
|
versionize_derive = "0.1.6"
|
||||||
vm-allocator = { path = "../vm-allocator" }
|
vm-allocator = { path = "../vm-allocator" }
|
||||||
vm-device = { path = "../vm-device" }
|
vm-device = { path = "../vm-device" }
|
||||||
vm-memory = "0.14.1"
|
vm-memory = "0.14.0"
|
||||||
vm-migration = { path = "../vm-migration" }
|
vm-migration = { path = "../vm-migration" }
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
// Copyright © 2023 Cyberus Technology
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
//! Module for [`DebugconState`].
|
|
||||||
|
|
||||||
use std::io;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::sync::{Arc, Barrier};
|
|
||||||
use vm_device::BusDevice;
|
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
|
||||||
|
|
||||||
/// I/O-port.
|
|
||||||
pub const DEFAULT_PORT: u64 = 0xe9;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DebugconState {}
|
|
||||||
|
|
||||||
/// Emulates a debug console similar to the QEMU debugcon device. This device
|
|
||||||
/// is stateless and only prints the bytes (usually text) that are written to
|
|
||||||
/// it.
|
|
||||||
///
|
|
||||||
/// This device is only available on x86.
|
|
||||||
///
|
|
||||||
/// Reference:
|
|
||||||
/// - https://github.com/qemu/qemu/blob/master/hw/char/debugcon.c
|
|
||||||
/// - https://phip1611.de/blog/how-to-use-qemus-debugcon-feature-and-write-to-a-file/
|
|
||||||
pub struct DebugConsole {
|
|
||||||
id: String,
|
|
||||||
out: Box<dyn io::Write + Send>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DebugConsole {
|
|
||||||
pub fn new(id: String, out: Box<dyn io::Write + Send>) -> Self {
|
|
||||||
Self { id, out }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BusDevice for DebugConsole {
|
|
||||||
fn read(&mut self, _base: u64, _offset: u64, _data: &mut [u8]) {}
|
|
||||||
|
|
||||||
fn write(&mut self, _base: u64, _offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
|
|
||||||
if let Err(e) = self.out.write_all(data) {
|
|
||||||
// unlikely
|
|
||||||
error!("debug-console: failed writing data: {e:?}");
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Snapshottable for DebugConsole {
|
|
||||||
fn id(&self) -> String {
|
|
||||||
self.id.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn snapshot(&mut self) -> Result<Snapshot, MigratableError> {
|
|
||||||
Snapshot::new_from_state(&())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Pausable for DebugConsole {}
|
|
||||||
impl Transportable for DebugConsole {}
|
|
||||||
impl Migratable for DebugConsole {}
|
|
||||||
@@ -4,42 +4,31 @@
|
|||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::result;
|
use std::result;
|
||||||
use thiserror::Error;
|
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Invalid trigger mode.
|
/// Invalid trigger mode.
|
||||||
#[error("Invalid trigger mode")]
|
|
||||||
InvalidTriggerMode,
|
InvalidTriggerMode,
|
||||||
/// Invalid delivery mode.
|
/// Invalid delivery mode.
|
||||||
#[error("Invalid delivery mode")]
|
|
||||||
InvalidDeliveryMode,
|
InvalidDeliveryMode,
|
||||||
/// Failed creating the interrupt source group.
|
/// Failed creating the interrupt source group.
|
||||||
#[error("Failed creating the interrupt source group: {0}")]
|
|
||||||
CreateInterruptSourceGroup(io::Error),
|
CreateInterruptSourceGroup(io::Error),
|
||||||
/// Failed triggering the interrupt.
|
/// Failed triggering the interrupt.
|
||||||
#[error("Failed triggering the interrupt: {0}")]
|
|
||||||
TriggerInterrupt(io::Error),
|
TriggerInterrupt(io::Error),
|
||||||
/// Failed masking the interrupt.
|
/// Failed masking the interrupt.
|
||||||
#[error("Failed masking the interrupt: {0}")]
|
|
||||||
MaskInterrupt(io::Error),
|
MaskInterrupt(io::Error),
|
||||||
/// Failed unmasking the interrupt.
|
/// Failed unmasking the interrupt.
|
||||||
#[error("Failed unmasking the interrupt: {0}")]
|
|
||||||
UnmaskInterrupt(io::Error),
|
UnmaskInterrupt(io::Error),
|
||||||
/// Failed updating the interrupt.
|
/// Failed updating the interrupt.
|
||||||
#[error("Failed updating the interrupt: {0}")]
|
|
||||||
UpdateInterrupt(io::Error),
|
UpdateInterrupt(io::Error),
|
||||||
/// Failed enabling the interrupt.
|
/// Failed enabling the interrupt.
|
||||||
#[error("Failed enabling the interrupt: {0}")]
|
|
||||||
EnableInterrupt(io::Error),
|
EnableInterrupt(io::Error),
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
/// Failed creating GIC device.
|
/// Failed creating GIC device.
|
||||||
#[error("Failed creating GIC device: {0}")]
|
|
||||||
CreateGic(hypervisor::HypervisorVmError),
|
CreateGic(hypervisor::HypervisorVmError),
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
/// Failed restoring GIC device.
|
/// Failed restoring GIC device.
|
||||||
#[error("Failed restoring GIC device: {0}")]
|
|
||||||
RestoreGic(hypervisor::arch::aarch64::gic::Error),
|
RestoreGic(hypervisor::arch::aarch64::gic::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,19 @@
|
|||||||
|
|
||||||
use super::interrupt_controller::{Error, InterruptController};
|
use super::interrupt_controller::{Error, InterruptController};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_device::interrupt::{
|
use vm_device::interrupt::{
|
||||||
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
|
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
|
||||||
MsiIrqGroupConfig, MsiIrqSourceConfig,
|
MsiIrqGroupConfig, MsiIrqSourceConfig,
|
||||||
};
|
};
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
use vm_memory::GuestAddress;
|
use vm_memory::GuestAddress;
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
@@ -133,7 +136,7 @@ pub struct Ioapic {
|
|||||||
interrupt_source_group: Arc<dyn InterruptSourceGroup>,
|
interrupt_source_group: Arc<dyn InterruptSourceGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
pub struct IoapicState {
|
pub struct IoapicState {
|
||||||
id_reg: u32,
|
id_reg: u32,
|
||||||
reg_sel: u32,
|
reg_sel: u32,
|
||||||
@@ -141,6 +144,7 @@ pub struct IoapicState {
|
|||||||
used_entries: [bool; NUM_IOAPIC_PINS],
|
used_entries: [bool; NUM_IOAPIC_PINS],
|
||||||
apic_address: u64,
|
apic_address: u64,
|
||||||
}
|
}
|
||||||
|
impl VersionMapped for IoapicState {}
|
||||||
|
|
||||||
impl BusDevice for Ioapic {
|
impl BusDevice for Ioapic {
|
||||||
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
||||||
@@ -416,7 +420,7 @@ impl InterruptController for Ioapic {
|
|||||||
self.interrupt_source_group
|
self.interrupt_source_group
|
||||||
.trigger(irq as InterruptIndex)
|
.trigger(irq as InterruptIndex)
|
||||||
.map_err(Error::TriggerInterrupt)?;
|
.map_err(Error::TriggerInterrupt)?;
|
||||||
debug!("Interrupt {irq} successfully delivered");
|
debug!("Interrupt successfully delivered");
|
||||||
|
|
||||||
// If trigger mode is level sensitive, set the Remote IRR bit.
|
// If trigger mode is level sensitive, set the Remote IRR bit.
|
||||||
// It will be cleared when the EOI is received.
|
// It will be cleared when the EOI is received.
|
||||||
@@ -440,7 +444,7 @@ impl Snapshottable for Ioapic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
Snapshot::new_from_state(&self.state())
|
Snapshot::new_from_versioned_state(&self.state())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
use libc::{clock_gettime, gmtime_r, timespec, tm, CLOCK_REALTIME};
|
use libc::{clock_gettime, gmtime_r, timespec, tm, CLOCK_REALTIME};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|||||||
@@ -8,14 +8,16 @@
|
|||||||
//!
|
//!
|
||||||
|
|
||||||
use crate::{read_le_u32, write_le_u32};
|
use crate::{read_le_u32, write_le_u32};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::io;
|
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
use thiserror::Error;
|
use std::{fmt, io};
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
|
|
||||||
const OFS_DATA: u64 = 0x400; // Data Register
|
const OFS_DATA: u64 = 0x400; // Data Register
|
||||||
const GPIODIR: u64 = 0x400; // Direction Register
|
const GPIODIR: u64 = 0x400; // Direction Register
|
||||||
@@ -38,18 +40,29 @@ const GPIO_ID_HIGH: u64 = 0x1000;
|
|||||||
|
|
||||||
const N_GPIOS: u32 = 8;
|
const N_GPIOS: u32 = 8;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Bad Write Offset: {0}")]
|
|
||||||
BadWriteOffset(u64),
|
BadWriteOffset(u64),
|
||||||
#[error("GPIO interrupt disabled by guest driver.")]
|
|
||||||
GpioInterruptDisabled,
|
GpioInterruptDisabled,
|
||||||
#[error("Could not trigger GPIO interrupt: {0}.")]
|
|
||||||
GpioInterruptFailure(io::Error),
|
GpioInterruptFailure(io::Error),
|
||||||
#[error("Invalid GPIO Input key triggered: {0}.")]
|
|
||||||
GpioTriggerKeyFailure(u32),
|
GpioTriggerKeyFailure(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::BadWriteOffset(offset) => write!(f, "Bad Write Offset: {offset}"),
|
||||||
|
Error::GpioInterruptDisabled => write!(f, "GPIO interrupt disabled by guest driver.",),
|
||||||
|
Error::GpioInterruptFailure(ref e) => {
|
||||||
|
write!(f, "Could not trigger GPIO interrupt: {e}.")
|
||||||
|
}
|
||||||
|
Error::GpioTriggerKeyFailure(key) => {
|
||||||
|
write!(f, "Invalid GPIO Input key triggered: {key}.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
/// A GPIO device following the PL061 specification.
|
/// A GPIO device following the PL061 specification.
|
||||||
@@ -76,7 +89,7 @@ pub struct Gpio {
|
|||||||
interrupt: Arc<dyn InterruptSourceGroup>,
|
interrupt: Arc<dyn InterruptSourceGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
pub struct GpioState {
|
pub struct GpioState {
|
||||||
data: u32,
|
data: u32,
|
||||||
old_in_data: u32,
|
old_in_data: u32,
|
||||||
@@ -89,6 +102,8 @@ pub struct GpioState {
|
|||||||
afsel: u32,
|
afsel: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionMapped for GpioState {}
|
||||||
|
|
||||||
impl Gpio {
|
impl Gpio {
|
||||||
/// Constructs an PL061 GPIO device.
|
/// Constructs an PL061 GPIO device.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@@ -313,7 +328,7 @@ impl Snapshottable for Gpio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
Snapshot::new_from_state(&self.state())
|
Snapshot::new_from_versioned_state(&self.state())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +339,8 @@ impl Migratable for Gpio {}
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::{read_le_u32, write_le_u32};
|
||||||
|
use std::sync::Arc;
|
||||||
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
//! a real-time clock input.
|
//! a real-time clock input.
|
||||||
//!
|
//!
|
||||||
use crate::{read_le_u32, write_le_u32};
|
use crate::{read_le_u32, write_le_u32};
|
||||||
|
use std::fmt;
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
use thiserror::Error;
|
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
|
|
||||||
@@ -39,14 +39,21 @@ const AMBA_ID_HIGH: u64 = 0x1000;
|
|||||||
/// Constant to convert seconds to nanoseconds.
|
/// Constant to convert seconds to nanoseconds.
|
||||||
pub const NANOS_PER_SECOND: u64 = 1_000_000_000;
|
pub const NANOS_PER_SECOND: u64 = 1_000_000_000;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Bad Write Offset: {0}")]
|
|
||||||
BadWriteOffset(u64),
|
BadWriteOffset(u64),
|
||||||
#[error("Failed to trigger interrupt: {0}")]
|
|
||||||
InterruptFailure(io::Error),
|
InterruptFailure(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::BadWriteOffset(offset) => write!(f, "Bad Write Offset: {offset}"),
|
||||||
|
Error::InterruptFailure(e) => write!(f, "Failed to trigger interrupt: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
/// Wrapper over `libc::clockid_t` to specify Linux Kernel clock source.
|
/// Wrapper over `libc::clockid_t` to specify Linux Kernel clock source.
|
||||||
@@ -72,6 +79,98 @@ impl From<ClockType> for libc::clockid_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Structure representing the date in local time with nanosecond precision.
|
||||||
|
pub struct LocalTime {
|
||||||
|
/// Seconds in current minute.
|
||||||
|
sec: i32,
|
||||||
|
/// Minutes in current hour.
|
||||||
|
min: i32,
|
||||||
|
/// Hours in current day, 24H format.
|
||||||
|
hour: i32,
|
||||||
|
/// Days in current month.
|
||||||
|
mday: i32,
|
||||||
|
/// Months in current year.
|
||||||
|
mon: i32,
|
||||||
|
/// Years passed since 1900 BC.
|
||||||
|
year: i32,
|
||||||
|
/// Nanoseconds in current second.
|
||||||
|
nsec: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocalTime {
|
||||||
|
/// Returns the [LocalTime](struct.LocalTime.html) structure for the calling moment.
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn now() -> LocalTime {
|
||||||
|
let mut timespec = libc::timespec {
|
||||||
|
tv_sec: 0,
|
||||||
|
tv_nsec: 0,
|
||||||
|
};
|
||||||
|
let mut tm: libc::tm = libc::tm {
|
||||||
|
tm_sec: 0,
|
||||||
|
tm_min: 0,
|
||||||
|
tm_hour: 0,
|
||||||
|
tm_mday: 0,
|
||||||
|
tm_mon: 0,
|
||||||
|
tm_year: 0,
|
||||||
|
tm_wday: 0,
|
||||||
|
tm_yday: 0,
|
||||||
|
tm_isdst: 0,
|
||||||
|
tm_gmtoff: 0,
|
||||||
|
tm_zone: std::ptr::null(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// SAFETY: the parameters are valid.
|
||||||
|
unsafe {
|
||||||
|
libc::clock_gettime(libc::CLOCK_REALTIME, &mut timespec);
|
||||||
|
libc::localtime_r(×pec.tv_sec, &mut tm);
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalTime {
|
||||||
|
sec: tm.tm_sec,
|
||||||
|
min: tm.tm_min,
|
||||||
|
hour: tm.tm_hour,
|
||||||
|
mday: tm.tm_mday,
|
||||||
|
mon: tm.tm_mon,
|
||||||
|
year: tm.tm_year,
|
||||||
|
nsec: timespec.tv_nsec,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for LocalTime {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}-{:02}-{:02}T{:02}:{:02}:{:02}.{:09}",
|
||||||
|
self.year + 1900,
|
||||||
|
self.mon + 1,
|
||||||
|
self.mday,
|
||||||
|
self.hour,
|
||||||
|
self.min,
|
||||||
|
self.sec,
|
||||||
|
self.nsec
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Holds a micro-second resolution timestamp with both the real time and cpu time.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct TimestampUs {
|
||||||
|
/// Real time in microseconds.
|
||||||
|
pub time_us: u64,
|
||||||
|
/// Cpu time in microseconds.
|
||||||
|
pub cputime_us: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for TimestampUs {
|
||||||
|
fn default() -> TimestampUs {
|
||||||
|
TimestampUs {
|
||||||
|
time_us: get_time(ClockType::Monotonic) / 1000,
|
||||||
|
cputime_us: get_time(ClockType::ProcessCpu) / 1000,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a timestamp in nanoseconds based on the provided clock type.
|
/// Returns a timestamp in nanoseconds based on the provided clock type.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
@@ -230,78 +329,15 @@ impl BusDevice for Rtc {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
read_be_u16, read_be_u32, read_le_i32, read_le_u16, read_le_u64, write_be_u16,
|
read_be_u16, read_be_u32, read_le_i32, read_le_u16, read_le_u32, read_le_u64, write_be_u16,
|
||||||
write_be_u32, write_le_i32, write_le_u16, write_le_u64,
|
write_be_u32, write_le_i32, write_le_u16, write_le_u32, write_le_u64,
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
const LEGACY_RTC_MAPPED_IO_START: u64 = 0x0901_0000;
|
const LEGACY_RTC_MAPPED_IO_START: u64 = 0x0901_0000;
|
||||||
|
|
||||||
struct LocalTime {
|
|
||||||
sec: i32,
|
|
||||||
min: i32,
|
|
||||||
hour: i32,
|
|
||||||
mday: i32,
|
|
||||||
mon: i32,
|
|
||||||
year: i32,
|
|
||||||
nsec: i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LocalTime {
|
|
||||||
fn now() -> LocalTime {
|
|
||||||
let mut timespec = libc::timespec {
|
|
||||||
tv_sec: 0,
|
|
||||||
tv_nsec: 0,
|
|
||||||
};
|
|
||||||
let mut tm: libc::tm = libc::tm {
|
|
||||||
tm_sec: 0,
|
|
||||||
tm_min: 0,
|
|
||||||
tm_hour: 0,
|
|
||||||
tm_mday: 0,
|
|
||||||
tm_mon: 0,
|
|
||||||
tm_year: 0,
|
|
||||||
tm_wday: 0,
|
|
||||||
tm_yday: 0,
|
|
||||||
tm_isdst: 0,
|
|
||||||
tm_gmtoff: 0,
|
|
||||||
tm_zone: std::ptr::null(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// SAFETY: the parameters are valid.
|
|
||||||
unsafe {
|
|
||||||
libc::clock_gettime(libc::CLOCK_REALTIME, &mut timespec);
|
|
||||||
libc::localtime_r(×pec.tv_sec, &mut tm);
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalTime {
|
|
||||||
sec: tm.tm_sec,
|
|
||||||
min: tm.tm_min,
|
|
||||||
hour: tm.tm_hour,
|
|
||||||
mday: tm.tm_mday,
|
|
||||||
mon: tm.tm_mon,
|
|
||||||
year: tm.tm_year,
|
|
||||||
nsec: timespec.tv_nsec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for LocalTime {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}-{:02}-{:02}T{:02}:{:02}:{:02}.{:09}",
|
|
||||||
self.year + 1900,
|
|
||||||
self.mon + 1,
|
|
||||||
self.mday,
|
|
||||||
self.hour,
|
|
||||||
self.min,
|
|
||||||
self.sec,
|
|
||||||
self.nsec
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_time() {
|
fn test_get_time() {
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
|
|||||||
@@ -5,13 +5,16 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
use vmm_sys_util::errno::Result;
|
use vmm_sys_util::errno::Result;
|
||||||
|
|
||||||
const LOOP_SIZE: usize = 0x40;
|
const LOOP_SIZE: usize = 0x40;
|
||||||
@@ -71,7 +74,7 @@ pub struct Serial {
|
|||||||
out: Option<Box<dyn io::Write + Send>>,
|
out: Option<Box<dyn io::Write + Send>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
pub struct SerialState {
|
pub struct SerialState {
|
||||||
interrupt_enable: u8,
|
interrupt_enable: u8,
|
||||||
interrupt_identification: u8,
|
interrupt_identification: u8,
|
||||||
@@ -83,6 +86,7 @@ pub struct SerialState {
|
|||||||
baud_divisor: u16,
|
baud_divisor: u16,
|
||||||
in_buffer: Vec<u8>,
|
in_buffer: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
impl VersionMapped for SerialState {}
|
||||||
|
|
||||||
impl Serial {
|
impl Serial {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@@ -330,7 +334,7 @@ impl Snapshottable for Serial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
Snapshot::new_from_state(&self.state())
|
Snapshot::new_from_versioned_state(&self.state())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +345,8 @@ impl Migratable for Serial {}
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::sync::Mutex;
|
use std::io;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,18 @@
|
|||||||
//!
|
//!
|
||||||
|
|
||||||
use crate::{read_le_u32, write_le_u32};
|
use crate::{read_le_u32, write_le_u32};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::fmt;
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
use thiserror::Error;
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
|
|
||||||
/* Registers */
|
/* Registers */
|
||||||
const UARTDR: u64 = 0;
|
const UARTDR: u64 = 0;
|
||||||
@@ -45,20 +48,27 @@ const PL011_ID: [u8; 8] = [0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1];
|
|||||||
const AMBA_ID_LOW: u64 = 0x3f8;
|
const AMBA_ID_LOW: u64 = 0x3f8;
|
||||||
const AMBA_ID_HIGH: u64 = 0x401;
|
const AMBA_ID_HIGH: u64 = 0x401;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("pl011_write: Bad Write Offset: {0}")]
|
|
||||||
BadWriteOffset(u64),
|
BadWriteOffset(u64),
|
||||||
#[error("pl011: DMA not implemented.")]
|
|
||||||
DmaNotImplemented,
|
DmaNotImplemented,
|
||||||
#[error("Failed to trigger interrupt: {0}")]
|
|
||||||
InterruptFailure(io::Error),
|
InterruptFailure(io::Error),
|
||||||
#[error("Failed to write: {0}")]
|
|
||||||
WriteAllFailure(io::Error),
|
WriteAllFailure(io::Error),
|
||||||
#[error("Failed to flush: {0}")]
|
|
||||||
FlushFailure(io::Error),
|
FlushFailure(io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Error::BadWriteOffset(offset) => write!(f, "pl011_write: Bad Write Offset: {offset}"),
|
||||||
|
Error::DmaNotImplemented => write!(f, "pl011: DMA not implemented."),
|
||||||
|
Error::InterruptFailure(e) => write!(f, "Failed to trigger interrupt: {e}"),
|
||||||
|
Error::WriteAllFailure(e) => write!(f, "Failed to write: {e}"),
|
||||||
|
Error::FlushFailure(e) => write!(f, "Failed to flush: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
/// A PL011 device following the PL011 specification.
|
/// A PL011 device following the PL011 specification.
|
||||||
@@ -84,7 +94,7 @@ pub struct Pl011 {
|
|||||||
timestamp: std::time::Instant,
|
timestamp: std::time::Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
pub struct Pl011State {
|
pub struct Pl011State {
|
||||||
flags: u32,
|
flags: u32,
|
||||||
lcr: u32,
|
lcr: u32,
|
||||||
@@ -103,6 +113,8 @@ pub struct Pl011State {
|
|||||||
read_trigger: u32,
|
read_trigger: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionMapped for Pl011State {}
|
||||||
|
|
||||||
impl Pl011 {
|
impl Pl011 {
|
||||||
/// Constructs an AMBA PL011 UART device.
|
/// Constructs an AMBA PL011 UART device.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
@@ -442,7 +454,7 @@ impl Snapshottable for Pl011 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
Snapshot::new_from_state(&self.state())
|
Snapshot::new_from_versioned_state(&self.state())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +465,8 @@ impl Migratable for Pl011 {}
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::sync::Mutex;
|
use std::io;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
use vm_device::interrupt::{InterruptIndex, InterruptSourceConfig};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ extern crate event_monitor;
|
|||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
pub mod acpi;
|
pub mod acpi;
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
pub mod debug_console;
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub mod gic;
|
pub mod gic;
|
||||||
pub mod interrupt_controller;
|
pub mod interrupt_controller;
|
||||||
|
|||||||
@@ -9,15 +9,18 @@ use pci::{
|
|||||||
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
|
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
|
||||||
PCI_CONFIGURATION_ID,
|
PCI_CONFIGURATION_ID,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||||
|
use versionize_derive::Versionize;
|
||||||
use vm_allocator::{AddressAllocator, SystemAllocator};
|
use vm_allocator::{AddressAllocator, SystemAllocator};
|
||||||
use vm_device::{BusDevice, Resource};
|
use vm_device::{BusDevice, Resource};
|
||||||
use vm_memory::{Address, GuestAddress};
|
use vm_memory::{Address, GuestAddress};
|
||||||
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
use vm_migration::{
|
||||||
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
|
};
|
||||||
|
|
||||||
const PVPANIC_VENDOR_ID: u16 = 0x1b36;
|
const PVPANIC_VENDOR_ID: u16 = 0x1b36;
|
||||||
const PVPANIC_DEVICE_ID: u16 = 0x0011;
|
const PVPANIC_DEVICE_ID: u16 = 0x0011;
|
||||||
@@ -57,20 +60,23 @@ pub struct PvPanicDevice {
|
|||||||
bar_regions: Vec<PciBarConfiguration>,
|
bar_regions: Vec<PciBarConfiguration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Versionize)]
|
||||||
pub struct PvPanicDeviceState {
|
pub struct PvPanicDeviceState {
|
||||||
events: u8,
|
events: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl VersionMapped for PvPanicDeviceState {}
|
||||||
|
|
||||||
impl PvPanicDevice {
|
impl PvPanicDevice {
|
||||||
pub fn new(id: String, snapshot: Option<Snapshot>) -> Result<Self, PvPanicError> {
|
pub fn new(id: String, snapshot: Option<Snapshot>) -> Result<Self, PvPanicError> {
|
||||||
let pci_configuration_state =
|
let pci_configuration_state =
|
||||||
vm_migration::state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID).map_err(|e| {
|
vm_migration::versioned_state_from_id(snapshot.as_ref(), PCI_CONFIGURATION_ID)
|
||||||
PvPanicError::RetrievePciConfigurationState(anyhow!(
|
.map_err(|e| {
|
||||||
"Failed to get PciConfigurationState from Snapshot: {}",
|
PvPanicError::RetrievePciConfigurationState(anyhow!(
|
||||||
e
|
"Failed to get PciConfigurationState from Snapshot: {}",
|
||||||
))
|
e
|
||||||
})?;
|
))
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut configuration = PciConfiguration::new(
|
let mut configuration = PciConfiguration::new(
|
||||||
PVPANIC_VENDOR_ID,
|
PVPANIC_VENDOR_ID,
|
||||||
@@ -91,7 +97,7 @@ impl PvPanicDevice {
|
|||||||
|
|
||||||
let state: Option<PvPanicDeviceState> = snapshot
|
let state: Option<PvPanicDeviceState> = snapshot
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.to_state())
|
.map(|s| s.to_versioned_state())
|
||||||
.transpose()
|
.transpose()
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
PvPanicError::CreatePvPanicDevice(anyhow!(
|
PvPanicError::CreatePvPanicDevice(anyhow!(
|
||||||
@@ -204,7 +210,7 @@ impl PciDevice for PvPanicDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bars.push(bar);
|
bars.push(bar);
|
||||||
self.bar_regions.clone_from(&bars);
|
self.bar_regions = bars.clone();
|
||||||
|
|
||||||
Ok(bars)
|
Ok(bars)
|
||||||
}
|
}
|
||||||
@@ -253,7 +259,7 @@ impl Snapshottable for PvPanicDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||||
let mut snapshot = Snapshot::new_from_state(&self.state())?;
|
let mut snapshot = Snapshot::new_from_versioned_state(&self.state())?;
|
||||||
|
|
||||||
// Snapshot PciConfiguration
|
// Snapshot PciConfiguration
|
||||||
snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?);
|
snapshot.add_snapshot(self.configuration.id(), self.configuration.snapshot()?);
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ impl BusDevice for Tpm {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Invalid value passed to CTRL_REQ register");
|
error!("Invalid value passed to CRTL_REQ register");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
All documentations (e.g. files with extension `.md`) in this repository is
|
The documentation in this directory is covered by the following license:
|
||||||
covered by the following license:
|
|
||||||
|
|
||||||
Attribution 4.0 International
|
Attribution 4.0 International
|
||||||
|
|
||||||
15
docs/api.md
15
docs/api.md
@@ -110,7 +110,6 @@ The Cloud Hypervisor API exposes the following actions through its endpoints:
|
|||||||
| Add vsock device to the VM | `/vm.add-vsock` | `/schemas/VsockConfig` | `/schemas/PciDeviceInfo` | The VM is booted |
|
| Add vsock device to the VM | `/vm.add-vsock` | `/schemas/VsockConfig` | `/schemas/PciDeviceInfo` | The VM is booted |
|
||||||
| Remove device from the VM | `/vm.remove-device` | `/schemas/VmRemoveDevice` | N/A | The VM is booted |
|
| Remove device from the VM | `/vm.remove-device` | `/schemas/VmRemoveDevice` | N/A | The VM is booted |
|
||||||
| Dump the VM counters | `/vm.counters` | N/A | `/schemas/VmCounters` | The VM is booted |
|
| Dump the VM counters | `/vm.counters` | N/A | `/schemas/VmCounters` | The VM is booted |
|
||||||
| Inject an NMI | `/vm.nmi` | N/A | N/A | The VM is booted |
|
|
||||||
| Prepare to receive a migration | `/vm.receive-migration` | `/schemas/ReceiveMigrationData` | N/A | N/A |
|
| Prepare to receive a migration | `/vm.receive-migration` | `/schemas/ReceiveMigrationData` | N/A | N/A |
|
||||||
| Start to send migration to target | `/vm.send-migration` | `/schemas/SendMigrationData` | N/A | The VM is booted and (shared mem or hugepages enabled) |
|
| Start to send migration to target | `/vm.send-migration` | `/schemas/SendMigrationData` | N/A | The VM is booted and (shared mem or hugepages enabled) |
|
||||||
|
|
||||||
@@ -148,7 +147,7 @@ We want to create a virtual machine with the following characteristics:
|
|||||||
`/opt/clh/images/focal-server-cloudimg-amd64.raw`
|
`/opt/clh/images/focal-server-cloudimg-amd64.raw`
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
||||||
-X PUT 'http://localhost/api/v1/vm.create' \
|
-X PUT 'http://localhost/api/v1/vm.create' \
|
||||||
@@ -168,7 +167,7 @@ curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
|||||||
Once the VM is created, we can boot it:
|
Once the VM is created, we can boot it:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.boot'
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.boot'
|
||||||
```
|
```
|
||||||
@@ -178,7 +177,7 @@ curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1
|
|||||||
We can fetch information about any VM, as soon as it's created:
|
We can fetch information about any VM, as soon as it's created:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
||||||
-X GET 'http://localhost/api/v1/vm.info' \
|
-X GET 'http://localhost/api/v1/vm.info' \
|
||||||
@@ -190,7 +189,7 @@ curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
|||||||
We can reboot a VM that's already booted:
|
We can reboot a VM that's already booted:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.reboot'
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.reboot'
|
||||||
```
|
```
|
||||||
@@ -200,7 +199,7 @@ curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1
|
|||||||
Once booted, we can shut a VM down from the REST API:
|
Once booted, we can shut a VM down from the REST API:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.shutdown'
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i -X PUT 'http://localhost/api/v1/vm.shutdown'
|
||||||
```
|
```
|
||||||
@@ -270,7 +269,7 @@ definition in XML format:
|
|||||||
### Command Line Interface
|
### Command Line Interface
|
||||||
|
|
||||||
The Cloud Hypervisor Command Line Interface (CLI) can only be used for launching
|
The Cloud Hypervisor Command Line Interface (CLI) can only be used for launching
|
||||||
the Cloud Hypervisor binary, i.e. it cannot be used for controlling the VMM or
|
the Cloud Hypervisor binary, i.e. it can not be used for controlling the VMM or
|
||||||
the launched VM once they're up and running.
|
the launched VM once they're up and running.
|
||||||
|
|
||||||
If you want to inspect the VMM, or control the VM after launching Cloud
|
If you want to inspect the VMM, or control the VM after launching Cloud
|
||||||
@@ -386,7 +385,7 @@ APIs work together, let's look at a complete VM creation flow, from the
|
|||||||
[REST API](#rest-api) in order to creates a virtual machine:
|
[REST API](#rest-api) in order to creates a virtual machine:
|
||||||
```
|
```
|
||||||
shell
|
shell
|
||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
curl --unix-socket /tmp/cloud-hypervisor.sock -i \
|
||||||
-X PUT 'http://localhost/api/v1/vm.create' \
|
-X PUT 'http://localhost/api/v1/vm.create' \
|
||||||
|
|||||||
@@ -159,10 +159,10 @@ as we might need to update the direct kernel boot command line, replacing
|
|||||||
|
|
||||||
Update all references to the previous image name to the new one.
|
Update all references to the previous image name to the new one.
|
||||||
|
|
||||||
## NVIDIA image for VFIO bare-metal CI
|
## NVIDIA image for VFIO baremetal CI
|
||||||
|
|
||||||
Here we are going to describe how to create a cloud image that contains the
|
Here we are going to describe how to create a cloud image that contains the
|
||||||
necessary NVIDIA drivers for our VFIO bare-metal CI.
|
necessary NVIDIA drivers for our VFIO baremetal CI.
|
||||||
|
|
||||||
### Download base image
|
### Download base image
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
# `cloud-hypervisor` debug IO ports
|
# `cloud-hypervisor` debug IO port
|
||||||
|
|
||||||
When running x86 guests, `cloud-hypervisor` provides different kinds of debug ports:
|
`cloud-hypervisor` uses the [`0x80`](https://www.intel.com/content/www/us/en/support/articles/000005500/boards-and-kits.html)
|
||||||
- [`0x80` debug port](https://www.intel.com/content/www/us/en/support/articles/000005500/boards-and-kits.html)
|
I/O port to trace user defined guest events.
|
||||||
- Debug console (by default at `0xe9`).
|
|
||||||
- Firmware debug port at `0x402`.
|
|
||||||
|
|
||||||
All of them can be used to trace user-defined guest events and all of them can
|
|
||||||
be used simultaneously.
|
|
||||||
|
|
||||||
## Debug Ports Overview
|
|
||||||
|
|
||||||
### `0x80` I/O port
|
|
||||||
|
|
||||||
Whenever the guest write one byte between `0x0` and `0xF` on this particular
|
Whenever the guest write one byte between `0x0` and `0xF` on this particular
|
||||||
I/O port, `cloud-hypervisor` will log and timestamp that event at the `debug`
|
I/O port, `cloud-hypervisor` will log and timestamp that event at the `debug`
|
||||||
@@ -39,7 +30,7 @@ guest will have `cloud-hypervisor` generate timestamped logs of all those steps.
|
|||||||
That provides a basic but convenient way of measuring not only the overall guest
|
That provides a basic but convenient way of measuring not only the overall guest
|
||||||
boot time but all intermediate steps as well.
|
boot time but all intermediate steps as well.
|
||||||
|
|
||||||
#### Logging
|
## Logging
|
||||||
|
|
||||||
Assuming parts of the guest software stack have been instrumented to use the
|
Assuming parts of the guest software stack have been instrumented to use the
|
||||||
`cloud-hypervisor` debug I/O port, we may want to gather the related logs.
|
`cloud-hypervisor` debug I/O port, we may want to gather the related logs.
|
||||||
@@ -68,29 +59,3 @@ $ grep "Debug I/O port" /tmp/ch-fw.log
|
|||||||
cloud-hypervisor: 19.762449ms: DEBUG:vmm/src/vm.rs:510 -- [Debug I/O port: Firmware code 0x0] 0.019004 seconds
|
cloud-hypervisor: 19.762449ms: DEBUG:vmm/src/vm.rs:510 -- [Debug I/O port: Firmware code 0x0] 0.019004 seconds
|
||||||
cloud-hypervisor: 403.499628ms: DEBUG:vmm/src/vm.rs:510 -- [Debug I/O port: Firmware code 0x1] 0.402744 seconds
|
cloud-hypervisor: 403.499628ms: DEBUG:vmm/src/vm.rs:510 -- [Debug I/O port: Firmware code 0x1] 0.402744 seconds
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debug console port
|
|
||||||
|
|
||||||
The debug console is inspired by QEMU and Bochs, which have a similar feature.
|
|
||||||
By default, the I/O port `0xe9` is used. This port can be configured like a
|
|
||||||
console. Thus, it can print to a tty, a file, or a pty, for example.
|
|
||||||
|
|
||||||
### Firmware debug port
|
|
||||||
|
|
||||||
The firmware debug port is also a simple port that prints all bytes written to
|
|
||||||
it. The firmware debug port only prints to stdout.
|
|
||||||
|
|
||||||
## When do I need these ports?
|
|
||||||
|
|
||||||
The ports are on the one hand interesting for firmware or kernel developers, as
|
|
||||||
they provide an easy way to print debug information from within a guest.
|
|
||||||
Furthermore, you can patch "normal" software to measure certain events, such as
|
|
||||||
the boot time of a guest.
|
|
||||||
|
|
||||||
## Which port should I choose?
|
|
||||||
|
|
||||||
The `0x80` debug port and the port of the firmware debug device are always
|
|
||||||
available. The debug console must be activated via the command line, but
|
|
||||||
provides more configuration options.
|
|
||||||
|
|
||||||
You can use different ports for different aspect of your logging messages.
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Cloud Hypervisor uses [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz) for fuzzing individual components.
|
Cloud Hypervisor uses [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz) for fuzzing individual components.
|
||||||
|
|
||||||
The fuzzers are in the `fuzz/fuzz_targets` directory
|
The fuzzers are are in the `fuzz/fuzz_targets` directory
|
||||||
|
|
||||||
## Preparation
|
## Preparation
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ On-line CPU(s) list: 0-7
|
|||||||
|
|
||||||
After a reboot the added CPUs will remain.
|
After a reboot the added CPUs will remain.
|
||||||
|
|
||||||
Removing CPUs works similarly by reducing the number in the "desired_vcpus" field of the resize API. The CPUs will be automatically offlined inside the guest so there is no need to run any commands inside the guest:
|
Removing CPUs works similarly by reducing the number in the "desired_vcpus" field of the reisze API. The CPUs will be automatically offlined inside the guest so there is no need to run any commands inside the guest:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
./ch-remote --api-socket=/tmp/ch-socket resize --cpus 2
|
./ch-remote --api-socket=/tmp/ch-socket resize --cpus 2
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ firmware:
|
|||||||
### TDShim
|
### TDShim
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
> The latest version of TDShim being tested is [_v0.8.0_](https://github.com/confidential-containers/td-shim/releases/tag/v0.8.0).
|
> The latest version of TDShim being tested is [_66bb334_](https://github.com/confidential-containers/td-shim/tree/66bb33451befbf1291abe3cfea7ee9e99d922b0d).
|
||||||
|
|
||||||
This is a lightweight version of the TDVF, written in Rust and designed for
|
This is a lightweight version of the TDVF, written in Rust and designed for
|
||||||
direct kernel boot, which is useful for containers use cases.
|
direct kernel boot, which is useful for containers use cases.
|
||||||
@@ -113,7 +113,7 @@ and `LLVM` first. The TDshim can be build as follows:
|
|||||||
```bash
|
```bash
|
||||||
git clone https://github.com/confidential-containers/td-shim
|
git clone https://github.com/confidential-containers/td-shim
|
||||||
cd td-shim
|
cd td-shim
|
||||||
git checkout v0.8.0
|
git checkout 66bb33451befbf1291abe3cfea7ee9e99d922b0d
|
||||||
cargo install cargo-xbuild
|
cargo install cargo-xbuild
|
||||||
export CC=clang
|
export CC=clang
|
||||||
export AR=llvm-ar
|
export AR=llvm-ar
|
||||||
@@ -121,13 +121,15 @@ export CC_x86_64_unknown_none=clang
|
|||||||
export AR_x86_64_unknown_none=llvm-ar
|
export AR_x86_64_unknown_none=llvm-ar
|
||||||
git submodule update --init --recursive
|
git submodule update --init --recursive
|
||||||
./sh_script/preparation.sh
|
./sh_script/preparation.sh
|
||||||
cargo image --release
|
cargo xbuild -p td-shim --target x86_64-unknown-none --release --features=main,tdx
|
||||||
|
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/release/ResetVector.bin target/x86_64-unknown-none/release/td-shim -o target/release/final.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
If debug logs from the TDShim is needed, here are the alternative
|
If debug logs from the TDShim is needed, here are the alternative
|
||||||
commands:
|
commands:
|
||||||
```bash
|
```bash
|
||||||
cargo image
|
cargo xbuild -p td-shim --target x86_64-unknown-none --features=main,tdx
|
||||||
|
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/debug/ResetVector.bin target/x86_64-unknown-none/debug/td-shim -o target/debug/final.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
And run a TDX VM by providing the firmware previously built, along with a guest
|
And run a TDX VM by providing the firmware previously built, along with a guest
|
||||||
|
|||||||
@@ -42,14 +42,3 @@ actual rate limit users get can be as low as
|
|||||||
generally advisable to keep `bw/ops_refill_time` larger than `100 ms`
|
generally advisable to keep `bw/ops_refill_time` larger than `100 ms`
|
||||||
(`cool_down_time`) to make sure the actual rate limit is close to users'
|
(`cool_down_time`) to make sure the actual rate limit is close to users'
|
||||||
expectation ("refill-rate").
|
expectation ("refill-rate").
|
||||||
|
|
||||||
## Rate Limit Groups
|
|
||||||
It is possible to throttle the aggregate bandwidth or operations
|
|
||||||
of multiple virtio-blk devices using a `rate_limit_group`. virtio-blk devices may be
|
|
||||||
dynamically added and removed from a `rate_limit_group`. The following example
|
|
||||||
demonstrates how to throttle the aggregate bandwidth of two disks to 10 MiB/s.
|
|
||||||
```
|
|
||||||
--disk path=disk0.raw,rate_limit_group=group0 \
|
|
||||||
path=disk1.raw,rate_limit_group=group0 \
|
|
||||||
--rate-limit-group bw_size=1048576,bw_refill_time,bw_refill_time=100
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Another reason for having a virtual IOMMU is to allow passing physical devices
|
|||||||
from the host through multiple layers of virtualization. Let's take as example
|
from the host through multiple layers of virtualization. Let's take as example
|
||||||
a system with a physical IOMMU running a VM with a virtual IOMMU. The
|
a system with a physical IOMMU running a VM with a virtual IOMMU. The
|
||||||
implementation of the virtual IOMMU is responsible for updating the physical
|
implementation of the virtual IOMMU is responsible for updating the physical
|
||||||
DMA Remapping table (DMAR) every time the DMA mapping changes. This must happen
|
DMA Remapping table (DMAR) everytime the DMA mapping changes. This must happen
|
||||||
through the VFIO framework on the host as this is the only userspace interface
|
through the VFIO framework on the host as this is the only userspace interface
|
||||||
to interact with a physical IOMMU.
|
to interact with a physical IOMMU.
|
||||||
|
|
||||||
@@ -60,7 +60,10 @@ implement a full emulation of a physical IOMMU.
|
|||||||
|
|
||||||
### Kernel
|
### Kernel
|
||||||
|
|
||||||
As of Kernel 5.14, virtio-iommu is available for both X86-64 and Aarch64.
|
Since virtio-iommu has landed partially into the version 5.3 of the Linux
|
||||||
|
kernel, a special branch is needed to get things working with Cloud Hypervisor.
|
||||||
|
By partially, we are talking about x86 specifically, as it is already fully
|
||||||
|
functional for ARM architectures.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -124,7 +127,7 @@ On AArch64 architecture, the virtual IOMMU can still be used even if ACPI is not
|
|||||||
enabled. But the effect is different with what the aforementioned test showed.
|
enabled. But the effect is different with what the aforementioned test showed.
|
||||||
|
|
||||||
When ACPI is disabled, virtual IOMMU is supported through Flattened Device Tree
|
When ACPI is disabled, virtual IOMMU is supported through Flattened Device Tree
|
||||||
(FDT). In this case, the guest kernel cannot tell which device should be
|
(FDT). In this case, the guest kernel can not tell which device should be
|
||||||
IOMMU-attached and which should not. No matter how many devices you attached to
|
IOMMU-attached and which should not. No matter how many devices you attached to
|
||||||
the virtual IOMMU by setting `iommu=on` option, all the devices on the PCI bus
|
the virtual IOMMU by setting `iommu=on` option, all the devices on the PCI bus
|
||||||
will be attached to the virtual IOMMU (except the IOMMU itself). Each of the
|
will be attached to the virtual IOMMU (except the IOMMU itself). Each of the
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ List of virtual CPUs attached to the guest NUMA node identified by the
|
|||||||
`guest_numa_id` option. This allows for describing a list of CPUs which
|
`guest_numa_id` option. This allows for describing a list of CPUs which
|
||||||
must be seen by the guest as belonging to the NUMA node `guest_numa_id`.
|
must be seen by the guest as belonging to the NUMA node `guest_numa_id`.
|
||||||
|
|
||||||
One can use this option for a fine-grained description of the NUMA topology
|
One can use this option for a fine grained description of the NUMA topology
|
||||||
regarding the CPUs associated with it, which might help the guest run more
|
regarding the CPUs associated with it, which might help the guest run more
|
||||||
efficiently.
|
efficiently.
|
||||||
|
|
||||||
@@ -573,7 +573,7 @@ _Example_
|
|||||||
### PCI bus
|
### PCI bus
|
||||||
|
|
||||||
Cloud Hypervisor supports guests with one or more PCI segments. The default PCI segment always
|
Cloud Hypervisor supports guests with one or more PCI segments. The default PCI segment always
|
||||||
has affinity to NUMA node 0. Be default, all other PCI segments have affinity to NUMA node 0.
|
has affinity to NUMA node 0. Be default, all other PCI segments have afffinity to NUMA node 0.
|
||||||
The user may configure the NUMA affinity for any additional PCI segments.
|
The user may configure the NUMA affinity for any additional PCI segments.
|
||||||
|
|
||||||
_Example_
|
_Example_
|
||||||
|
|||||||
2
docs/releases.md
Normal file → Executable file
2
docs/releases.md
Normal file → Executable file
@@ -95,7 +95,7 @@ E - EOL
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### LTS Stability Considerations
|
### LTS Stablity Considerations
|
||||||
|
|
||||||
An LTS release is just a `MAJOR` release for which point releases are made for
|
An LTS release is just a `MAJOR` release for which point releases are made for
|
||||||
longer following the same rules for what can be backported to a `POINT` release.
|
longer following the same rules for what can be backported to a `POINT` release.
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ component in the state it was left before the snapshot occurred.
|
|||||||
## Restore a Cloud Hypervisor VM
|
## Restore a Cloud Hypervisor VM
|
||||||
|
|
||||||
Given that one has access to an existing snapshot in `/home/foo/snapshot`,
|
Given that one has access to an existing snapshot in `/home/foo/snapshot`,
|
||||||
it is possible to create a new VM based on this snapshot with the following
|
it is possible to create a new VM based on this snapshot with the following
|
||||||
command:
|
command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -93,21 +93,6 @@ start using it.
|
|||||||
At this point, the VM is fully restored and is identical to the VM which was
|
At this point, the VM is fully restored and is identical to the VM which was
|
||||||
snapshot earlier.
|
snapshot earlier.
|
||||||
|
|
||||||
## Restore a VM with new Net FDs
|
|
||||||
For a VM created with FDs explicitly passed to NetConfig, a set of valid FDs
|
|
||||||
need to be provided along with the VM restore command in the following syntax:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# First terminal
|
|
||||||
./cloud-hypervisor --api-socket /tmp/cloud-hypervisor.sock
|
|
||||||
|
|
||||||
# Second terminal
|
|
||||||
./ch-remote --api-socket=/tmp/cloud-hypervisor.sock restore source_url=file:///home/foo/snapshot net_fds=[net1@[23,24],net2@[25,26]]
|
|
||||||
```
|
|
||||||
In the example above, the net device with id `net1` will be backed by FDs '23'
|
|
||||||
and '24', and the net device with id `net2` will be backed by FDs '25' and '26'
|
|
||||||
from the restored VM.
|
|
||||||
|
|
||||||
## Limitations
|
## Limitations
|
||||||
|
|
||||||
VFIO devices and Intel SGX are out of scope.
|
VFIO devices and Intel SGX are out of scope.
|
||||||
|
|||||||
@@ -37,6 +37,6 @@ generating traces of the boot. These can be relocated for focus tracing on a
|
|||||||
narrow part of the code base.
|
narrow part of the code base.
|
||||||
|
|
||||||
A `tracer::trace_point!()` macro is also provided for an instantaneous trace
|
A `tracer::trace_point!()` macro is also provided for an instantaneous trace
|
||||||
point however this is neither in use in the code base currently nor is handled by
|
point however this is not in use in the code base currently nor is handled by
|
||||||
the visualisation script due to the difficulty in representation in the SVG.
|
the visualisation script due to the difficulty in representation in the SVG.
|
||||||
|
|
||||||
|
|||||||
62
docs/vfio.md
62
docs/vfio.md
@@ -122,64 +122,4 @@ $ ls /sys/kernel/iommu_groups/22/devices/
|
|||||||
|
|
||||||
This means these two devices are under the same IOMMU group 22. In such case,
|
This means these two devices are under the same IOMMU group 22. In such case,
|
||||||
it is important to bind both devices to VFIO and pass them both through the
|
it is important to bind both devices to VFIO and pass them both through the
|
||||||
VM, otherwise this could cause some functional and security issues.
|
VM, otherwise this could cause some functional and security issues.
|
||||||
|
|
||||||
### Advanced Configuration Options
|
|
||||||
|
|
||||||
When using NVIDIA GPUs in a VFIO passthrough configuration, advanced
|
|
||||||
configuration options are supported to enable GPUDirect P2P DMA over
|
|
||||||
PCIe. When enabled, loads and stores between GPUs use native PCIe
|
|
||||||
peer-to-peer transactions instead of a shared memory buffer. This drastically
|
|
||||||
decreases P2P latency between GPUs. This functionality is supported by
|
|
||||||
cloud-hypervisor on NVIDIA Turing, Ampere, Hopper, and Lovelace GPUs.
|
|
||||||
|
|
||||||
The NVIDIA driver does not enable GPUDirect P2P over PCIe within guests
|
|
||||||
by default because hardware support for routing P2P TLP between PCIe root
|
|
||||||
ports is optional. PCIe P2P should always be supported between devices
|
|
||||||
on the same PCIe switch. The `x_nv_gpudirect_clique` config argument may
|
|
||||||
be used to signal support for PCIe P2P traffic between NVIDIA VFIO endpoints.
|
|
||||||
The guest driver assumes that P2P traffic is supported between all endpoints
|
|
||||||
that are part of the same clique.
|
|
||||||
```
|
|
||||||
--device path=/sys/bus/pci/devices/0000:01:00.0/,x_nv_gpudirect_clique=0
|
|
||||||
```
|
|
||||||
|
|
||||||
The following command can be run on the guest to verify that GPUDirect P2P is
|
|
||||||
correctly enabled.
|
|
||||||
```
|
|
||||||
nvidia-smi topo -p2p r
|
|
||||||
GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7
|
|
||||||
GPU0 X OK OK OK OK OK OK OK
|
|
||||||
GPU1 OK X OK OK OK OK OK OK
|
|
||||||
GPU2 OK OK X OK OK OK OK OK
|
|
||||||
GPU3 OK OK OK X OK OK OK OK
|
|
||||||
GPU4 OK OK OK OK X OK OK OK
|
|
||||||
GPU5 OK OK OK OK OK X OK OK
|
|
||||||
GPU6 OK OK OK OK OK OK X OK
|
|
||||||
GPU7 OK OK OK OK OK OK OK X
|
|
||||||
```
|
|
||||||
|
|
||||||
Some VFIO devices have a 32-bit mmio BAR. When using many such devices, it is
|
|
||||||
possible to exhaust the 32-bit mmio space available on a PCI segment. The
|
|
||||||
following example demonstrates an example device with a 16 MiB 32-bit mmio BAR.
|
|
||||||
```
|
|
||||||
lspci -s 0000:01:00.0 -v
|
|
||||||
0000:01:00.0 3D controller: NVIDIA Corporation Device 26b9 (rev a1)
|
|
||||||
[...]
|
|
||||||
Memory at f9000000 (32-bit, non-prefetchable) [size=16M]
|
|
||||||
Memory at 46000000000 (64-bit, prefetchable) [size=64G]
|
|
||||||
Memory at 48040000000 (64-bit, prefetchable) [size=32M]
|
|
||||||
[...]
|
|
||||||
```
|
|
||||||
|
|
||||||
When using multiple PCI segments, the 32-bit mmio address space available to
|
|
||||||
be allocated to VFIO devices is equally split between all PCI segments by
|
|
||||||
default. This can be tuned with the `--pci-segment` flag. The following example
|
|
||||||
demonstrates a guest with two PCI segments. 2/3 of the 32-bit mmio address
|
|
||||||
space is available for use by devices on PCI segment 0 and 1/3 of the 32-bit
|
|
||||||
mmio address space is available for use by devices on PCI segment 1.
|
|
||||||
```
|
|
||||||
--platform num_pci_segments=2
|
|
||||||
--pci-segment pci_segment=0,mmio32_aperture_weight=2
|
|
||||||
--pci-segment pci_segment=1,mmio32_aperture_weight=1
|
|
||||||
```
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
The purpose of this document is to illustrate how to test vhost-user-net
|
The purpose of this document is to illustrate how to test vhost-user-net
|
||||||
in cloud-hypervisor with OVS/DPDK as the backend. This document was
|
in cloud-hypervisor with OVS/DPDK as the backend. This document was
|
||||||
tested with Open vSwitch v2.17.8, DPDK v21.11.4, and Cloud Hypervisor
|
tested with Open vSwitch v2.13.1, DPDK v19.11.3, and Cloud Hypervisor
|
||||||
v37.0 on Ubuntu 22.04.3 (host kernel v5.15.0).
|
v15.0 on Ubuntu 20.04.1 (host kernel v5.4.0).
|
||||||
|
|
||||||
## Framework
|
## Framework
|
||||||
|
|
||||||
@@ -74,8 +74,8 @@ Here is an example how to create a bridge and add two DPDK ports to it
|
|||||||
# create a bridge
|
# create a bridge
|
||||||
ovs-vsctl add-br ovsbr0 -- set bridge ovsbr0 datapath_type=netdev
|
ovs-vsctl add-br ovsbr0 -- set bridge ovsbr0 datapath_type=netdev
|
||||||
# create two DPDK ports and add them to the bridge
|
# create two DPDK ports and add them to the bridge
|
||||||
ovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost-user1
|
ovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuser
|
||||||
ovs-vsctl add-port ovsbr0 vhost-user2 -- set Interface vhost-user2 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost-user2
|
ovs-vsctl add-port ovsbr0 vhost-user2 -- set Interface vhost-user2 type=dpdkvhostuser
|
||||||
# set the number of rx queues
|
# set the number of rx queues
|
||||||
ovs-vsctl set Interface vhost-user1 options:n_rxq=2
|
ovs-vsctl set Interface vhost-user1 options:n_rxq=2
|
||||||
ovs-vsctl set Interface vhost-user2 options:n_rxq=2
|
ovs-vsctl set Interface vhost-user2 options:n_rxq=2
|
||||||
@@ -92,7 +92,7 @@ VMs run in client mode. They connect to the socket created by the `dpdkvhostuser
|
|||||||
--kernel vmlinux \
|
--kernel vmlinux \
|
||||||
--cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \
|
--cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \
|
||||||
--disk path=focal-server-cloudimg-amd64.raw \
|
--disk path=focal-server-cloudimg-amd64.raw \
|
||||||
--net mac=52:54:00:02:d9:01,vhost_user=true,socket=/tmp/vhost-user1,num_queues=4,vhost_mode=server
|
--net mac=52:54:00:02:d9:01,vhost_user=true,socket=/var/run/openvswitch/vhost-user1,num_queues=4
|
||||||
|
|
||||||
# From another terminal. We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host.
|
# From another terminal. We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host.
|
||||||
./cloud-hypervisor \
|
./cloud-hypervisor \
|
||||||
@@ -101,21 +101,21 @@ VMs run in client mode. They connect to the socket created by the `dpdkvhostuser
|
|||||||
--kernel vmlinux \
|
--kernel vmlinux \
|
||||||
--cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \
|
--cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \
|
||||||
--disk path=focal-server-cloudimg-amd64.raw \
|
--disk path=focal-server-cloudimg-amd64.raw \
|
||||||
--net mac=52:54:20:11:C5:02,vhost_user=true,socket=/tmp/vhost-user2,num_queues=4,vhost_mode=server
|
--net mac=52:54:20:11:C5:02,vhost_user=true,socket=/var/run/openvswitch/vhost-user2,num_queues=4
|
||||||
```
|
```
|
||||||
|
|
||||||
_Setup VM1_
|
_Setup VM1_
|
||||||
```bash
|
```bash
|
||||||
# From inside the guest
|
# From inside the guest
|
||||||
sudo ip addr add 172.100.0.1/24 dev ens3
|
sudo ip addr add 172.100.0.1/24 dev ens2
|
||||||
sudo ip link set up dev ens3
|
sudo ip link set up dev ens2
|
||||||
```
|
```
|
||||||
|
|
||||||
_Setup VM2_
|
_Setup VM2_
|
||||||
```bash
|
```bash
|
||||||
# From inside the guest
|
# From inside the guest
|
||||||
sudo ip addr add 172.100.0.2/24 dev ens3
|
sudo ip addr add 172.100.0.2/24 dev ens2
|
||||||
sudo ip link set up dev ens3
|
sudo ip link set up dev ens2
|
||||||
```
|
```
|
||||||
|
|
||||||
_Ping VM1 from VM2_
|
_Ping VM1 from VM2_
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# VSOCK support
|
# VSOCK support
|
||||||
|
|
||||||
VSOCK provides a way for guest and host to communicate through a socket. `cloud-hypervisor` only supports stream VSOCK sockets.
|
VSOCK provides a way for guest and host to communicate through a socket. VSOCK sockets support both stream and datagram types.
|
||||||
|
|
||||||
The `virtio-vsock` is based on the [Firecracker](https://github.com/firecracker-microvm/firecracker/blob/main/docs/vsock.md) implementation, where additional details can be found.
|
The `virtio-vsock` is based on the [Firecracker](https://github.com/firecracker-microvm/firecracker/blob/main/docs/vsock.md) implementation, where additional details can be found.
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Cloud Hypervisor Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "event_monitor"
|
name = "event_monitor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Cloud Hypervisor Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
flume = "0.11.0"
|
flume = "0.10.14"
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.18.0"
|
||||||
serde = { version = "1.0.197", features = ["derive", "rc"] }
|
serde = { version = "1.0.168", features = ["rc", "derive"] }
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.107"
|
||||||
|
|||||||
490
fuzz/Cargo.lock
generated
490
fuzz/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["Automatically generated"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "cloud-hypervisor-fuzz"
|
name = "cloud-hypervisor-fuzz"
|
||||||
publish = false
|
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
authors = ["Automatically generated"]
|
||||||
|
publish = false
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
cargo-fuzz = true
|
cargo-fuzz = true
|
||||||
@@ -14,119 +14,126 @@ igvm = []
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
block = { path = "../block" }
|
block = { path = "../block" }
|
||||||
devices = { path = "../devices" }
|
devices = { path = "../devices" }
|
||||||
epoll = "4.3.3"
|
epoll = "4.3.1"
|
||||||
libc = "0.2.155"
|
libc = "0.2.152"
|
||||||
libfuzzer-sys = "0.4.7"
|
libfuzzer-sys = "0.4.7"
|
||||||
linux-loader = { version = "0.11.0", features = ["bzimage", "elf", "pe"] }
|
linux-loader = { version = "0.11.0", features = ["elf", "bzimage", "pe"] }
|
||||||
micro_http = { git = "https://github.com/firecracker-microvm/micro-http", branch = "main" }
|
micro_http = { git = "https://github.com/firecracker-microvm/micro-http", branch = "main" }
|
||||||
net_util = { path = "../net_util" }
|
net_util = { path = "../net_util" }
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
seccompiler = "0.4.0"
|
seccompiler = "0.4.0"
|
||||||
virtio-devices = { path = "../virtio-devices" }
|
virtio-devices = { path = "../virtio-devices" }
|
||||||
virtio-queue = "0.12.0"
|
virtio-queue = "0.11.0"
|
||||||
vm-device = { path = "../vm-device" }
|
vmm = { path = "../vmm" }
|
||||||
vm-memory = "0.14.1"
|
|
||||||
vm-migration = { path = "../vm-migration" }
|
|
||||||
vm-virtio = { path = "../vm-virtio" }
|
|
||||||
vmm = { path = "../vmm", features = ["guest_debug"] }
|
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
vm-memory = "0.14.0"
|
||||||
|
vm-migration = { path = "../vm-migration" }
|
||||||
|
vm-device = { path = "../vm-device" }
|
||||||
|
vm-virtio = { path = "../vm-virtio" }
|
||||||
|
|
||||||
|
[dependencies.cloud-hypervisor]
|
||||||
|
path = ".."
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x" }
|
||||||
|
versionize_derive = { git = "https://github.com/cloud-hypervisor/versionize_derive", branch = "ch-0.1.6" }
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
# Prevent this from interfering with workspaces
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["."]
|
members = ["."]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "balloon"
|
name = "balloon"
|
||||||
path = "fuzz_targets/balloon.rs"
|
path = "fuzz_targets/balloon.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "block"
|
name = "block"
|
||||||
path = "fuzz_targets/block.rs"
|
path = "fuzz_targets/block.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "cmos"
|
name = "cmos"
|
||||||
path = "fuzz_targets/cmos.rs"
|
path = "fuzz_targets/cmos.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "console"
|
name = "console"
|
||||||
path = "fuzz_targets/console.rs"
|
path = "fuzz_targets/console.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "http_api"
|
name = "http_api"
|
||||||
path = "fuzz_targets/http_api.rs"
|
path = "fuzz_targets/http_api.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "iommu"
|
name = "iommu"
|
||||||
path = "fuzz_targets/iommu.rs"
|
path = "fuzz_targets/iommu.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "linux_loader"
|
name = "linux_loader"
|
||||||
path = "fuzz_targets/linux_loader.rs"
|
path = "fuzz_targets/linux_loader.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "linux_loader_cmdline"
|
name = "linux_loader_cmdline"
|
||||||
path = "fuzz_targets/linux_loader_cmdline.rs"
|
path = "fuzz_targets/linux_loader_cmdline.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "mem"
|
name = "mem"
|
||||||
path = "fuzz_targets/mem.rs"
|
path = "fuzz_targets/mem.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "net"
|
name = "net"
|
||||||
path = "fuzz_targets/net.rs"
|
path = "fuzz_targets/net.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "pmem"
|
name = "pmem"
|
||||||
path = "fuzz_targets/pmem.rs"
|
path = "fuzz_targets/pmem.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "qcow"
|
name = "qcow"
|
||||||
path = "fuzz_targets/qcow.rs"
|
path = "fuzz_targets/qcow.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "rng"
|
name = "rng"
|
||||||
path = "fuzz_targets/rng.rs"
|
path = "fuzz_targets/rng.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "serial"
|
name = "serial"
|
||||||
path = "fuzz_targets/serial.rs"
|
path = "fuzz_targets/serial.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "vhdx"
|
name = "vhdx"
|
||||||
path = "fuzz_targets/vhdx.rs"
|
path = "fuzz_targets/vhdx.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
doc = false
|
|
||||||
name = "watchdog"
|
name = "watchdog"
|
||||||
path = "fuzz_targets/watchdog.rs"
|
path = "fuzz_targets/watchdog.rs"
|
||||||
test = false
|
test = false
|
||||||
|
doc = false
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
|
|||||||
use virtio_queue::{Queue, QueueT};
|
use virtio_queue::{Queue, QueueT};
|
||||||
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
|
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
|
||||||
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
|
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
|
||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
|
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;
|
||||||
|
|
||||||
@@ -50,7 +49,6 @@ fuzz_target!(|bytes| {
|
|||||||
let shm = memfd_create(&ffi::CString::new("fuzz").unwrap(), 0).unwrap();
|
let shm = memfd_create(&ffi::CString::new("fuzz").unwrap(), 0).unwrap();
|
||||||
let disk_file: File = unsafe { File::from_raw_fd(shm) };
|
let disk_file: File = unsafe { File::from_raw_fd(shm) };
|
||||||
let qcow_disk = Box::new(RawFileDiskSync::new(disk_file)) as Box<dyn DiskFile>;
|
let qcow_disk = Box::new(RawFileDiskSync::new(disk_file)) as Box<dyn DiskFile>;
|
||||||
let queue_affinity = BTreeMap::new();
|
|
||||||
let mut block = Block::new(
|
let mut block = Block::new(
|
||||||
"tmp".to_owned(),
|
"tmp".to_owned(),
|
||||||
qcow_disk,
|
qcow_disk,
|
||||||
@@ -64,7 +62,6 @@ fuzz_target!(|bytes| {
|
|||||||
None,
|
None,
|
||||||
EventFd::new(EFD_NONBLOCK).unwrap(),
|
EventFd::new(EFD_NONBLOCK).unwrap(),
|
||||||
None,
|
None,
|
||||||
queue_affinity,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
use devices::legacy::Cmos;
|
use devices::legacy::Cmos;
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use libfuzzer_sys::fuzz_target;
|
use libfuzzer_sys::fuzz_target;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
use std::sync::Arc;
|
||||||
use vm_device::BusDevice;
|
use vm_device::BusDevice;
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
|
|||||||
@@ -7,18 +7,9 @@ use libfuzzer_sys::fuzz_target;
|
|||||||
use micro_http::Request;
|
use micro_http::Request;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use vm_migration::MigratableError;
|
use vmm::api::{http::*, ApiRequest, ApiResponsePayload};
|
||||||
use vmm::api::{
|
|
||||||
http::*, ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData,
|
|
||||||
VmSendMigrationData, VmmPingResponse,
|
|
||||||
};
|
|
||||||
use vmm::config::RestoreConfig;
|
|
||||||
use vmm::vm::{Error as VmError, VmState};
|
|
||||||
use vmm::vm_config::*;
|
|
||||||
use vmm::{EpollContext, EpollDispatch};
|
use vmm::{EpollContext, EpollDispatch};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
@@ -78,207 +69,6 @@ fn generate_request(bytes: &[u8]) -> Option<Request> {
|
|||||||
Request::try_from(&request, None).ok()
|
Request::try_from(&request, None).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StubApiRequestHandler;
|
|
||||||
|
|
||||||
impl RequestHandler for StubApiRequestHandler {
|
|
||||||
fn vm_create(&mut self, _: Arc<Mutex<VmConfig>>) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_boot(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_pause(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_resume(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_snapshot(&mut self, _: &str) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_restore(&mut self, _: RestoreConfig) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fn vm_coredump(&mut self, _: &str) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_shutdown(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_reboot(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_info(&self) -> Result<VmInfoResponse, VmError> {
|
|
||||||
Ok(VmInfoResponse {
|
|
||||||
config: Arc::new(Mutex::new(VmConfig {
|
|
||||||
cpus: CpusConfig {
|
|
||||||
boot_vcpus: 1,
|
|
||||||
max_vcpus: 1,
|
|
||||||
topology: None,
|
|
||||||
kvm_hyperv: false,
|
|
||||||
max_phys_bits: 46,
|
|
||||||
affinity: None,
|
|
||||||
features: CpuFeatures::default(),
|
|
||||||
},
|
|
||||||
memory: MemoryConfig {
|
|
||||||
size: 536_870_912,
|
|
||||||
mergeable: false,
|
|
||||||
hotplug_method: HotplugMethod::Acpi,
|
|
||||||
hotplug_size: None,
|
|
||||||
hotplugged_size: None,
|
|
||||||
shared: false,
|
|
||||||
hugepages: false,
|
|
||||||
hugepage_size: None,
|
|
||||||
prefault: false,
|
|
||||||
zones: None,
|
|
||||||
thp: true,
|
|
||||||
},
|
|
||||||
payload: Some(PayloadConfig {
|
|
||||||
kernel: Some(PathBuf::from("/path/to/kernel")),
|
|
||||||
firmware: None,
|
|
||||||
cmdline: None,
|
|
||||||
initramfs: None,
|
|
||||||
#[cfg(feature = "igvm")]
|
|
||||||
igvm: None,
|
|
||||||
}),
|
|
||||||
rate_limit_groups: None,
|
|
||||||
disks: None,
|
|
||||||
net: None,
|
|
||||||
rng: RngConfig {
|
|
||||||
src: PathBuf::from("/dev/urandom"),
|
|
||||||
iommu: false,
|
|
||||||
},
|
|
||||||
balloon: None,
|
|
||||||
fs: None,
|
|
||||||
pmem: None,
|
|
||||||
serial: ConsoleConfig {
|
|
||||||
file: None,
|
|
||||||
mode: ConsoleOutputMode::Null,
|
|
||||||
iommu: false,
|
|
||||||
socket: None,
|
|
||||||
},
|
|
||||||
console: ConsoleConfig {
|
|
||||||
file: None,
|
|
||||||
mode: ConsoleOutputMode::Tty,
|
|
||||||
iommu: false,
|
|
||||||
socket: None,
|
|
||||||
},
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
debug_console: DebugConsoleConfig::default(),
|
|
||||||
devices: None,
|
|
||||||
user_devices: None,
|
|
||||||
vdpa: None,
|
|
||||||
vsock: None,
|
|
||||||
pvpanic: false,
|
|
||||||
iommu: false,
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
sgx_epc: None,
|
|
||||||
numa: None,
|
|
||||||
watchdog: false,
|
|
||||||
gdb: false,
|
|
||||||
pci_segments: None,
|
|
||||||
platform: None,
|
|
||||||
tpm: None,
|
|
||||||
preserved_fds: None,
|
|
||||||
})),
|
|
||||||
state: VmState::Running,
|
|
||||||
memory_actual_size: 0,
|
|
||||||
device_tree: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vmm_ping(&self) -> VmmPingResponse {
|
|
||||||
VmmPingResponse {
|
|
||||||
build_version: String::new(),
|
|
||||||
version: String::new(),
|
|
||||||
pid: 0,
|
|
||||||
features: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_delete(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vmm_shutdown(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_resize(&mut self, _: Option<u8>, _: Option<u64>, _: Option<u64>) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_resize_zone(&mut self, _: String, _: u64) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_device(&mut self, _: DeviceConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_user_device(&mut self, _: UserDeviceConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_remove_device(&mut self, _: String) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_disk(&mut self, _: DiskConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_fs(&mut self, _: FsConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_pmem(&mut self, _: PmemConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_net(&mut self, _: NetConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_vdpa(&mut self, _: VdpaConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_add_vsock(&mut self, _: VsockConfig) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_counters(&mut self) -> Result<Option<Vec<u8>>, VmError> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_power_button(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_receive_migration(&mut self, _: VmReceiveMigrationData) -> Result<(), MigratableError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_send_migration(&mut self, _: VmSendMigrationData) -> Result<(), MigratableError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_nmi(&mut self) -> Result<(), VmError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn http_receiver_stub(exit_evt: EventFd, api_evt: EventFd, api_receiver: Receiver<ApiRequest>) {
|
fn http_receiver_stub(exit_evt: EventFd, api_evt: EventFd, api_receiver: Receiver<ApiRequest>) {
|
||||||
let mut epoll = EpollContext::new().unwrap();
|
let mut epoll = EpollContext::new().unwrap();
|
||||||
epoll.add_event(&exit_evt, EpollDispatch::Exit).unwrap();
|
epoll.add_event(&exit_evt, EpollDispatch::Exit).unwrap();
|
||||||
@@ -308,7 +98,89 @@ fn http_receiver_stub(exit_evt: EventFd, api_evt: EventFd, api_receiver: Receive
|
|||||||
EpollDispatch::Api => {
|
EpollDispatch::Api => {
|
||||||
for _ in 0..api_evt.read().unwrap() {
|
for _ in 0..api_evt.read().unwrap() {
|
||||||
let api_request = api_receiver.recv().unwrap();
|
let api_request = api_receiver.recv().unwrap();
|
||||||
api_request(&mut StubApiRequestHandler).unwrap();
|
match api_request {
|
||||||
|
ApiRequest::VmCreate(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmDelete(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmBoot(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmShutdown(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmReboot(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmInfo(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmmPing(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmPause(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmResume(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmSnapshot(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmRestore(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmmShutdown(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmResize(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmResizeZone(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddDevice(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddUserDevice(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmRemoveDevice(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddDisk(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddFs(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddPmem(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddNet(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddVdpa(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmAddVsock(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmCounters(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmReceiveMigration(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmSendMigration(_, sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
ApiRequest::VmPowerButton(sender) => {
|
||||||
|
sender.send(Ok(ApiResponsePayload::Empty)).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
use libfuzzer_sys::fuzz_target;
|
use libfuzzer_sys::fuzz_target;
|
||||||
|
|||||||
@@ -1,47 +1,39 @@
|
|||||||
[package]
|
[package]
|
||||||
|
name = "hypervisor"
|
||||||
|
version = "0.1.0"
|
||||||
authors = ["Microsoft Authors"]
|
authors = ["Microsoft Authors"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "Apache-2.0 OR BSD-3-Clause"
|
license = "Apache-2.0 OR BSD-3-Clause"
|
||||||
name = "hypervisor"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
kvm = ["kvm-bindings", "kvm-ioctls", "vfio-ioctls/kvm"]
|
kvm = ["kvm-ioctls", "kvm-bindings", "vfio-ioctls/kvm"]
|
||||||
mshv = ["iced-x86", "mshv-bindings", "mshv-ioctls", "vfio-ioctls/mshv"]
|
mshv = ["mshv-ioctls", "mshv-bindings", "vfio-ioctls/mshv", "iced-x86"]
|
||||||
sev_snp = ["igvm", "igvm_defs"]
|
sev_snp = ["igvm_parser", "igvm_defs"]
|
||||||
tdx = []
|
tdx = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.81"
|
anyhow = "1.0.75"
|
||||||
byteorder = "1.5.0"
|
byteorder = "1.4.3"
|
||||||
igvm = { version = "0.3.1", optional = true }
|
igvm_defs = { git = "https://github.com/microsoft/igvm", branch = "main", package = "igvm_defs", optional = true }
|
||||||
igvm_defs = { version = "0.3.1", optional = true }
|
igvm_parser = { git = "https://github.com/microsoft/igvm", branch = "main", package = "igvm", optional = true }
|
||||||
kvm-bindings = { version = "0.8.1", optional = true, features = ["serde"] }
|
libc = "0.2.147"
|
||||||
kvm-ioctls = { version = "0.17.0", optional = true }
|
log = "0.4.20"
|
||||||
libc = "0.2.153"
|
kvm-ioctls = { version = "0.16.0", optional = true }
|
||||||
log = "0.4.21"
|
kvm-bindings = { git = "https://github.com/cloud-hypervisor/kvm-bindings", branch = "ch-live-upgrade-stable-37.x", features = ["with-serde", "fam-wrappers"], optional = true }
|
||||||
mshv-bindings = { git = "https://github.com/rust-vmm/mshv", tag = "v0.2.0", features = [
|
mshv-bindings = { git = "https://github.com/rust-vmm/mshv", branch = "main", features = ["with-serde", "fam-wrappers"], optional = true }
|
||||||
"fam-wrappers",
|
mshv-ioctls = { git = "https://github.com/rust-vmm/mshv", branch = "main", optional = true}
|
||||||
"with-serde",
|
serde = { version = "1.0.168", features = ["rc", "derive"] }
|
||||||
], optional = true }
|
serde_with = { version = "3.4.0", default-features = false, features = ["macros"] }
|
||||||
mshv-ioctls = { git = "https://github.com/rust-vmm/mshv", tag = "v0.2.0", optional = true }
|
|
||||||
serde = { version = "1.0.197", features = ["derive", "rc"] }
|
|
||||||
serde_with = { version = "3.7.0", default-features = false, features = [
|
|
||||||
"macros",
|
|
||||||
] }
|
|
||||||
thiserror = "1.0.60"
|
|
||||||
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio", branch = "main", default-features = false }
|
vfio-ioctls = { git = "https://github.com/rust-vmm/vfio", branch = "main", default-features = false }
|
||||||
vm-memory = { version = "0.14.1", features = [
|
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-atomic"] }
|
||||||
"backend-atomic",
|
|
||||||
"backend-mmap",
|
|
||||||
] }
|
|
||||||
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }
|
vmm-sys-util = { version = "0.12.1", features = ["with-serde"] }
|
||||||
|
thiserror = "1.0.52"
|
||||||
|
|
||||||
[target.'cfg(target_arch = "x86_64")'.dependencies.iced-x86]
|
[target.'cfg(target_arch = "x86_64")'.dependencies.iced-x86]
|
||||||
default-features = false
|
|
||||||
features = ["decoder", "fast_fmt", "instr_info", "op_code_info", "std"]
|
|
||||||
optional = true
|
optional = true
|
||||||
version = "1.21.0"
|
version = "1.20.0"
|
||||||
|
default-features = false
|
||||||
|
features = ["std", "decoder", "op_code_info", "instr_info", "fast_fmt"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.10.0"
|
||||||
|
|||||||
@@ -1,23 +1,17 @@
|
|||||||
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
use crate::{CpuState, GicState, HypervisorDeviceError, HypervisorVmError};
|
use crate::{CpuState, GicState, HypervisorDeviceError, HypervisorVmError};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::result;
|
use std::result;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
/// Errors thrown while setting up the VGIC.
|
/// Errors thrown while setting up the VGIC.
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Error while calling KVM ioctl for setting up the global interrupt controller.
|
/// Error while calling KVM ioctl for setting up the global interrupt controller.
|
||||||
#[error("Failed creating GIC device: {0}")]
|
|
||||||
CreateGic(HypervisorVmError),
|
CreateGic(HypervisorVmError),
|
||||||
/// Error while setting device attributes for the GIC.
|
/// Error while setting device attributes for the GIC.
|
||||||
#[error("Failed setting device attributes for the GIC: {0}")]
|
|
||||||
SetDeviceAttribute(HypervisorDeviceError),
|
SetDeviceAttribute(HypervisorDeviceError),
|
||||||
/// Error while getting device attributes for the GIC.
|
/// Error while getting device attributes for the GIC.
|
||||||
#[error("Failed getting device attributes for the GIC: {0}")]
|
|
||||||
GetDeviceAttribute(HypervisorDeviceError),
|
GetDeviceAttribute(HypervisorDeviceError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
pub mod gic;
|
pub mod gic;
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
// CMP-Compare Two Operands
|
// CMP-Compare Two Operands
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use crate::arch::emulator::{EmulationError, PlatformEmulator};
|
||||||
use crate::arch::x86::emulator::instructions::*;
|
use crate::arch::x86::emulator::instructions::*;
|
||||||
use crate::arch::x86::regs::*;
|
use crate::arch::x86::regs::*;
|
||||||
|
use crate::arch::x86::Exception;
|
||||||
|
|
||||||
// CMP affects OF, SF, ZF, AF, PF and CF
|
// CMP affects OF, SF, ZF, AF, PF and CF
|
||||||
const FLAGS_MASK: u64 = CF | PF | AF | ZF | SF | OF;
|
const FLAGS_MASK: u64 = CF | PF | AF | ZF | SF | OF;
|
||||||
@@ -209,6 +211,8 @@ impl<T: CpuStateManager> InstructionHandler<T> for Cmp_rm64_imm8 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(unused_mut)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::arch::x86::emulator::mock_vmm::*;
|
use crate::arch::x86::emulator::mock_vmm::*;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
// Copies the second operand (source operand) to the first operand (destination operand).
|
// Copies the second operand (source operand) to the first operand (destination operand).
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use crate::arch::emulator::{EmulationError, PlatformEmulator};
|
||||||
use crate::arch::x86::emulator::instructions::*;
|
use crate::arch::x86::emulator::instructions::*;
|
||||||
|
use crate::arch::x86::Exception;
|
||||||
|
|
||||||
macro_rules! mov_rm_r {
|
macro_rules! mov_rm_r {
|
||||||
($bound:ty) => {
|
($bound:ty) => {
|
||||||
@@ -269,6 +271,7 @@ impl<T: CpuStateManager> InstructionHandler<T> for Mov_RAX_moffs64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(unused_mut)]
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::arch::x86::emulator::mock_vmm::*;
|
use crate::arch::x86::emulator::mock_vmm::*;
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
// MOVS - Move Data from String to String
|
// MOVS - Move Data from String to String
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use crate::arch::emulator::{EmulationError, PlatformEmulator};
|
||||||
use crate::arch::x86::emulator::instructions::*;
|
use crate::arch::x86::emulator::instructions::*;
|
||||||
use crate::arch::x86::regs::DF;
|
use crate::arch::x86::regs::DF;
|
||||||
|
use crate::arch::x86::Exception;
|
||||||
|
|
||||||
macro_rules! movs {
|
macro_rules! movs {
|
||||||
($bound:ty) => {
|
($bound:ty) => {
|
||||||
@@ -100,6 +102,7 @@ impl<T: CpuStateManager> InstructionHandler<T> for Movsb_m8_m8 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(unused_mut)]
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::arch::x86::emulator::mock_vmm::*;
|
use crate::arch::x86::emulator::mock_vmm::*;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
// OR - Logical inclusive OR
|
// OR - Logical inclusive OR
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use crate::arch::emulator::{EmulationError, PlatformEmulator};
|
||||||
use crate::arch::x86::emulator::instructions::*;
|
use crate::arch::x86::emulator::instructions::*;
|
||||||
|
use crate::arch::x86::Exception;
|
||||||
|
|
||||||
macro_rules! or_rm_r {
|
macro_rules! or_rm_r {
|
||||||
($bound:ty) => {
|
($bound:ty) => {
|
||||||
@@ -50,6 +52,7 @@ impl<T: CpuStateManager> InstructionHandler<T> for Or_rm8_r8 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(unused_mut)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::arch::x86::emulator::mock_vmm::*;
|
use crate::arch::x86::emulator::mock_vmm::*;
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ pub trait CpuStateManager: Clone {
|
|||||||
.checked_add(segment_register.base)
|
.checked_add(segment_register.base)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
PlatformError::InvalidAddress(anyhow!(
|
PlatformError::InvalidAddress(anyhow!(
|
||||||
"Logical address {:#x} cannot be linearized with segment {:#x?}",
|
"Logical address {:#x} can not be linearized with segment {:#x?}",
|
||||||
logical_addr,
|
logical_addr,
|
||||||
segment_register
|
segment_register
|
||||||
))
|
))
|
||||||
@@ -148,7 +148,7 @@ pub trait CpuStateManager: Clone {
|
|||||||
// Must not write to a read-only segment.
|
// Must not write to a read-only segment.
|
||||||
if segment_type_ro(segment_type) && write {
|
if segment_type_ro(segment_type) && write {
|
||||||
return Err(PlatformError::InvalidAddress(anyhow!(
|
return Err(PlatformError::InvalidAddress(anyhow!(
|
||||||
"Cannot write to a read-only segment"
|
"Can not write to a read-only segment"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,9 +648,13 @@ impl<'a, T: CpuStateManager> Emulator<'a, T> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod mock_vmm {
|
mod mock_vmm {
|
||||||
|
#![allow(unused_mut)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::arch::x86::emulator::EmulatorCpuState as CpuState;
|
use crate::arch::emulator::{EmulationError, PlatformEmulator};
|
||||||
|
use crate::arch::x86::emulator::{Emulator, EmulatorCpuState as CpuState};
|
||||||
use crate::arch::x86::gdt::{gdt_entry, segment_from_gdt};
|
use crate::arch::x86::gdt::{gdt_entry, segment_from_gdt};
|
||||||
|
use crate::arch::x86::Exception;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -768,6 +772,7 @@ mod mock_vmm {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(unused_mut)]
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::arch::x86::emulator::mock_vmm::*;
|
use crate::arch::x86::emulator::mock_vmm::*;
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ pub enum Exception {
|
|||||||
pub mod regs;
|
pub mod regs;
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
|
||||||
pub struct SegmentRegister {
|
pub struct SegmentRegister {
|
||||||
pub base: u64,
|
pub base: u64,
|
||||||
pub limit: u32,
|
pub limit: u32,
|
||||||
@@ -173,6 +174,7 @@ macro_rules! msr_data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
|
||||||
pub struct StandardRegisters {
|
pub struct StandardRegisters {
|
||||||
pub rax: u64,
|
pub rax: u64,
|
||||||
pub rbx: u64,
|
pub rbx: u64,
|
||||||
@@ -195,12 +197,14 @@ pub struct StandardRegisters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
|
||||||
pub struct DescriptorTable {
|
pub struct DescriptorTable {
|
||||||
pub base: u64,
|
pub base: u64,
|
||||||
pub limit: u16,
|
pub limit: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
||||||
|
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
|
||||||
pub struct SpecialRegisters {
|
pub struct SpecialRegisters {
|
||||||
pub cs: SegmentRegister,
|
pub cs: SegmentRegister,
|
||||||
pub ds: SegmentRegister,
|
pub ds: SegmentRegister,
|
||||||
@@ -308,10 +312,10 @@ pub struct MsrEntry {
|
|||||||
pub data: u64,
|
pub data: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
#[serde_with::serde_as]
|
#[serde_with::serde_as]
|
||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct XsaveState {
|
pub struct XsaveState {
|
||||||
#[serde_as(as = "[_; 1024usize]")]
|
|
||||||
pub region: [u32; 1024usize],
|
pub region: [u32; 1024usize],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,3 +325,26 @@ impl Default for XsaveState {
|
|||||||
unsafe { ::std::mem::zeroed() }
|
unsafe { ::std::mem::zeroed() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'de> serde::Deserialize<'de> for XsaveState {
|
||||||
|
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let region: Vec<u32> = Vec::deserialize(deserializer)?;
|
||||||
|
let mut val: XsaveState = XsaveState::default();
|
||||||
|
// This panics if the source and destination have different lengths.
|
||||||
|
val.region.copy_from_slice(®ion[..]);
|
||||||
|
Ok(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serde::Serialize for XsaveState {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let region = &self.region[..];
|
||||||
|
region.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
// Copyright 2017 The Chromium OS Authors. All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
|
|
||||||
|
|||||||
@@ -107,28 +107,14 @@ pub enum HypervisorCpuError {
|
|||||||
///
|
///
|
||||||
/// Setting Saved Processor Extended States error
|
/// Setting Saved Processor Extended States error
|
||||||
///
|
///
|
||||||
#[cfg(feature = "kvm")]
|
|
||||||
#[error("Failed to set Saved Processor Extended States: {0}")]
|
#[error("Failed to set Saved Processor Extended States: {0}")]
|
||||||
SetXsaveState(#[source] anyhow::Error),
|
SetXsaveState(#[source] anyhow::Error),
|
||||||
///
|
///
|
||||||
/// Getting Saved Processor Extended States error
|
/// Getting Saved Processor Extended States error
|
||||||
///
|
///
|
||||||
#[cfg(feature = "kvm")]
|
|
||||||
#[error("Failed to get Saved Processor Extended States: {0}")]
|
#[error("Failed to get Saved Processor Extended States: {0}")]
|
||||||
GetXsaveState(#[source] anyhow::Error),
|
GetXsaveState(#[source] anyhow::Error),
|
||||||
///
|
///
|
||||||
/// Getting the VP state components error
|
|
||||||
///
|
|
||||||
#[cfg(feature = "mshv")]
|
|
||||||
#[error("Failed to get VP State Components: {0}")]
|
|
||||||
GetAllVpStateComponents(#[source] anyhow::Error),
|
|
||||||
///
|
|
||||||
/// Setting the VP state components error
|
|
||||||
///
|
|
||||||
#[cfg(feature = "mshv")]
|
|
||||||
#[error("Failed to set VP State Components: {0}")]
|
|
||||||
SetAllVpStateComponents(#[source] anyhow::Error),
|
|
||||||
///
|
|
||||||
/// Setting Extended Control Registers error
|
/// Setting Extended Control Registers error
|
||||||
///
|
///
|
||||||
#[error("Failed to set Extended Control Registers: {0}")]
|
#[error("Failed to set Extended Control Registers: {0}")]
|
||||||
@@ -286,23 +272,18 @@ pub enum HypervisorCpuError {
|
|||||||
///
|
///
|
||||||
#[error("Failed to get CPUID entries: {0}")]
|
#[error("Failed to get CPUID entries: {0}")]
|
||||||
GetCpuidVales(#[source] anyhow::Error),
|
GetCpuidVales(#[source] anyhow::Error),
|
||||||
///
|
|
||||||
/// Setting SEV control register error
|
|
||||||
///
|
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
#[error("Failed to set sev control register: {0}")]
|
|
||||||
SetSevControlRegister(#[source] anyhow::Error),
|
|
||||||
|
|
||||||
/// Error injecting NMI
|
|
||||||
///
|
|
||||||
#[error("Failed to inject NMI")]
|
|
||||||
Nmi(#[source] anyhow::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum VmExit {
|
pub enum VmExit<'a> {
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
IoOut(u16 /* port */, &'a [u8] /* data */),
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
IoIn(u16 /* port */, &'a mut [u8] /* data */),
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
IoapicEoi(u8 /* vector */),
|
IoapicEoi(u8 /* vector */),
|
||||||
|
MmioRead(u64 /* address */, &'a mut [u8]),
|
||||||
|
MmioWrite(u64 /* address */, &'a [u8]),
|
||||||
Ignore,
|
Ignore,
|
||||||
Reset,
|
Reset,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
@@ -514,14 +495,4 @@ pub trait Vcpu: Send + Sync {
|
|||||||
) -> Result<[u32; 4]> {
|
) -> Result<[u32; 4]> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
#[cfg(feature = "mshv")]
|
|
||||||
fn set_sev_control_register(&self, _reg: u64) -> Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
|
||||||
/// Trigger NMI interrupt
|
|
||||||
///
|
|
||||||
fn nmi(&self) -> Result<()>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ use std::sync::Arc;
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
///
|
||||||
|
///
|
||||||
pub enum HypervisorError {
|
pub enum HypervisorError {
|
||||||
///
|
///
|
||||||
/// Hypervisor availability check error
|
/// Hypervisor availability check error
|
||||||
@@ -166,7 +168,7 @@ pub trait Hypervisor: Send + Sync {
|
|||||||
CpuVendor::AMD
|
CpuVendor::AMD
|
||||||
} else {
|
} else {
|
||||||
// Not known yet, the corresponding manufacturer manual should contain the
|
// Not known yet, the corresponding manufacturer manual should contain the
|
||||||
// necessary info. See also https://wiki.osdev.org/CPUID#CPU_Vendor_ID_String
|
// necesssary info. See also https://wiki.osdev.org/CPUID#CPU_Vendor_ID_String
|
||||||
CpuVendor::default()
|
CpuVendor::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
// Copyright 2022 Arm Limited (or its affiliates). All rights reserved.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
mod dist_regs;
|
mod dist_regs;
|
||||||
mod icc_regs;
|
mod icc_regs;
|
||||||
@@ -8,7 +6,7 @@ mod redist_regs;
|
|||||||
|
|
||||||
use crate::arch::aarch64::gic::{Error, Result, Vgic, VgicConfig};
|
use crate::arch::aarch64::gic::{Error, Result, Vgic, VgicConfig};
|
||||||
use crate::device::HypervisorDeviceError;
|
use crate::device::HypervisorDeviceError;
|
||||||
use crate::kvm::KvmVm;
|
use crate::kvm::{kvm_bindings, KvmVm};
|
||||||
use crate::{CpuState, Vm};
|
use crate::{CpuState, Vm};
|
||||||
use dist_regs::{get_dist_regs, read_ctlr, set_dist_regs, write_ctlr};
|
use dist_regs::{get_dist_regs, read_ctlr, set_dist_regs, write_ctlr};
|
||||||
use icc_regs::{get_icc_regs, set_icc_regs};
|
use icc_regs::{get_icc_regs, set_icc_regs};
|
||||||
@@ -16,6 +14,7 @@ use kvm_ioctls::DeviceFd;
|
|||||||
use redist_regs::{construct_gicr_typers, get_redist_regs, set_redist_regs};
|
use redist_regs::{construct_gicr_typers, get_redist_regs, set_redist_regs};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
const GITS_CTLR: u32 = 0x0000;
|
const GITS_CTLR: u32 = 0x0000;
|
||||||
const GITS_IIDR: u32 = 0x0004;
|
const GITS_IIDR: u32 = 0x0004;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ const KVM_ARM64_SYSREG_MPIDR_EL1: u64 = KVM_REG_ARM64
|
|||||||
| (((5_u64) << KVM_REG_ARM64_SYSREG_OP2_SHIFT) & KVM_REG_ARM64_SYSREG_OP2_MASK as u64);
|
| (((5_u64) << KVM_REG_ARM64_SYSREG_OP2_SHIFT) & KVM_REG_ARM64_SYSREG_OP2_MASK as u64);
|
||||||
|
|
||||||
/// This is how we represent the registers of a distributor.
|
/// This is how we represent the registers of a distributor.
|
||||||
/// It is relevant their offset from the base address of the
|
/// It is relrvant their offset from the base address of the
|
||||||
/// distributor.
|
/// distributor.
|
||||||
/// Each register has a different number
|
/// Each register has a different number
|
||||||
/// of bits_per_irq and is therefore variable length.
|
/// of bits_per_irq and is therefore variable length.
|
||||||
|
|||||||
@@ -106,23 +106,12 @@ pub fn is_system_register(regid: u64) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
||||||
macro_rules! check_extension {
|
if !kvm.check_extension(Cap::SignalMsi) {
|
||||||
($cap:expr) => {
|
return Err(KvmError::CapabilityMissing(Cap::SignalMsi));
|
||||||
if !kvm.check_extension($cap) {
|
}
|
||||||
return Err(KvmError::CapabilityMissing($cap));
|
if !kvm.check_extension(Cap::OneReg) {
|
||||||
}
|
return Err(KvmError::CapabilityMissing(Cap::OneReg));
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetGuestDebug is required but some kernels have it implemented without the capability flag.
|
|
||||||
check_extension!(Cap::ImmediateExit);
|
|
||||||
check_extension!(Cap::Ioeventfd);
|
|
||||||
check_extension!(Cap::Irqchip);
|
|
||||||
check_extension!(Cap::Irqfd);
|
|
||||||
check_extension!(Cap::IrqRouting);
|
|
||||||
check_extension!(Cap::MpState);
|
|
||||||
check_extension!(Cap::OneReg);
|
|
||||||
check_extension!(Cap::UserMemory);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ use crate::{arm64_core_reg_id, offset_of};
|
|||||||
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
|
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
use std::convert::TryInto;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
@@ -36,6 +38,7 @@ use std::os::unix::io::RawFd;
|
|||||||
use std::result;
|
use std::result;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
@@ -102,15 +105,6 @@ pub use {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
const KVM_CAP_SGX_ATTRIBUTE: u32 = 196;
|
const KVM_CAP_SGX_ATTRIBUTE: u32 = 196;
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use vmm_sys_util::ioctl_io_nr;
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "tdx"), target_arch = "x86_64"))]
|
|
||||||
use vmm_sys_util::ioctl_ioc_nr;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
ioctl_io_nr!(KVM_NMI, kvm_bindings::KVMIO, 0x9a);
|
|
||||||
|
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
const KVM_EXIT_TDX: u32 = 50;
|
const KVM_EXIT_TDX: u32 = 50;
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
@@ -321,7 +315,7 @@ impl From<CpuState> for VcpuKvmState {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
impl From<kvm_clock_data> for ClockData {
|
impl From<kvm_clock_data> for ClockData {
|
||||||
fn from(d: kvm_clock_data) -> Self {
|
fn from(d: kvm_clock_data) -> Self {
|
||||||
ClockData::Kvm(d)
|
ClockData::Kvm(d.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +323,7 @@ impl From<kvm_clock_data> for ClockData {
|
|||||||
impl From<ClockData> for kvm_clock_data {
|
impl From<ClockData> for kvm_clock_data {
|
||||||
fn from(ms: ClockData) -> Self {
|
fn from(ms: ClockData) -> Self {
|
||||||
match ms {
|
match ms {
|
||||||
ClockData::Kvm(s) => s,
|
ClockData::Kvm(s) => s.into(),
|
||||||
/* Needed in case other hypervisors are enabled */
|
/* Needed in case other hypervisors are enabled */
|
||||||
#[allow(unreachable_patterns)]
|
#[allow(unreachable_patterns)]
|
||||||
_ => panic!("CpuState is not valid"),
|
_ => panic!("CpuState is not valid"),
|
||||||
@@ -454,12 +448,12 @@ impl vm::Vm for KvmVm {
|
|||||||
id: u8,
|
id: u8,
|
||||||
vm_ops: Option<Arc<dyn VmOps>>,
|
vm_ops: Option<Arc<dyn VmOps>>,
|
||||||
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
|
) -> vm::Result<Arc<dyn cpu::Vcpu>> {
|
||||||
let fd = self
|
let vc = self
|
||||||
.fd
|
.fd
|
||||||
.create_vcpu(id as u64)
|
.create_vcpu(id as u64)
|
||||||
.map_err(|e| vm::HypervisorVmError::CreateVcpu(e.into()))?;
|
.map_err(|e| vm::HypervisorVmError::CreateVcpu(e.into()))?;
|
||||||
let vcpu = KvmVcpu {
|
let vcpu = KvmVcpu {
|
||||||
fd: Arc::new(Mutex::new(fd)),
|
fd: vc,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
msrs: self.msrs.clone(),
|
msrs: self.msrs.clone(),
|
||||||
vm_ops,
|
vm_ops,
|
||||||
@@ -535,9 +529,9 @@ impl vm::Vm for KvmVm {
|
|||||||
|
|
||||||
if self.check_extension(crate::kvm::Cap::MsiDevid) {
|
if self.check_extension(crate::kvm::Cap::MsiDevid) {
|
||||||
// On AArch64, there is limitation on the range of the 'devid',
|
// On AArch64, there is limitation on the range of the 'devid',
|
||||||
// it cannot be greater than 65536 (the max of u16).
|
// it can not be greater than 65536 (the max of u16).
|
||||||
//
|
//
|
||||||
// BDF cannot be used directly, because 'segment' is in high
|
// BDF can not be used directly, because 'segment' is in high
|
||||||
// 16 bits. The layout of the u32 BDF is:
|
// 16 bits. The layout of the u32 BDF is:
|
||||||
// |---- 16 bits ----|-- 8 bits --|-- 5 bits --|-- 3 bits --|
|
// |---- 16 bits ----|-- 8 bits --|-- 5 bits --|-- 3 bits --|
|
||||||
// | segment | bus | device | function |
|
// | segment | bus | device | function |
|
||||||
@@ -1169,7 +1163,7 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
|||||||
|
|
||||||
/// Vcpu struct for KVM
|
/// Vcpu struct for KVM
|
||||||
pub struct KvmVcpu {
|
pub struct KvmVcpu {
|
||||||
fd: Arc<Mutex<VcpuFd>>,
|
fd: VcpuFd,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
msrs: Vec<MsrEntry>,
|
msrs: Vec<MsrEntry>,
|
||||||
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
||||||
@@ -1197,8 +1191,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_regs(&self) -> cpu::Result<StandardRegisters> {
|
fn get_regs(&self) -> cpu::Result<StandardRegisters> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_regs()
|
.get_regs()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetStandardRegs(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetStandardRegs(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -1220,8 +1212,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
for i in 0..31 {
|
for i in 0..31 {
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.regs.regs[i] = u64::from_le_bytes(bytes);
|
state.regs.regs[i] = u64::from_le_bytes(bytes);
|
||||||
@@ -1233,8 +1223,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(user_pt_regs, sp);
|
let off = offset_of!(user_pt_regs, sp);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.regs.sp = u64::from_le_bytes(bytes);
|
state.regs.sp = u64::from_le_bytes(bytes);
|
||||||
@@ -1243,8 +1231,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(user_pt_regs, pc);
|
let off = offset_of!(user_pt_regs, pc);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.regs.pc = u64::from_le_bytes(bytes);
|
state.regs.pc = u64::from_le_bytes(bytes);
|
||||||
@@ -1253,8 +1239,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(user_pt_regs, pstate);
|
let off = offset_of!(user_pt_regs, pstate);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.regs.pstate = u64::from_le_bytes(bytes);
|
state.regs.pstate = u64::from_le_bytes(bytes);
|
||||||
@@ -1263,8 +1247,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(kvm_regs, sp_el1);
|
let off = offset_of!(kvm_regs, sp_el1);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.sp_el1 = u64::from_le_bytes(bytes);
|
state.sp_el1 = u64::from_le_bytes(bytes);
|
||||||
@@ -1274,8 +1256,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(kvm_regs, elr_el1);
|
let off = offset_of!(kvm_regs, elr_el1);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.elr_el1 = u64::from_le_bytes(bytes);
|
state.elr_el1 = u64::from_le_bytes(bytes);
|
||||||
@@ -1285,8 +1265,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
for i in 0..KVM_NR_SPSR as usize {
|
for i in 0..KVM_NR_SPSR as usize {
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U64, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.spsr[i] = u64::from_le_bytes(bytes);
|
state.spsr[i] = u64::from_le_bytes(bytes);
|
||||||
@@ -1299,8 +1277,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
let mut bytes = [0_u8; 16];
|
let mut bytes = [0_u8; 16];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U128, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U128, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.fp_regs.vregs[i] = u128::from_le_bytes(bytes);
|
state.fp_regs.vregs[i] = u128::from_le_bytes(bytes);
|
||||||
@@ -1311,8 +1287,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpsr);
|
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpsr);
|
||||||
let mut bytes = [0_u8; 4];
|
let mut bytes = [0_u8; 4];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U32, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U32, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.fp_regs.fpsr = u32::from_le_bytes(bytes);
|
state.fp_regs.fpsr = u32::from_le_bytes(bytes);
|
||||||
@@ -1321,8 +1295,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpcr);
|
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpcr);
|
||||||
let mut bytes = [0_u8; 4];
|
let mut bytes = [0_u8; 4];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U32, off), &mut bytes)
|
.get_one_reg(arm64_core_reg_id!(KVM_REG_SIZE_U32, off), &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCoreRegister(e.into()))?;
|
||||||
state.fp_regs.fpcr = u32::from_le_bytes(bytes);
|
state.fp_regs.fpcr = u32::from_le_bytes(bytes);
|
||||||
@@ -1336,8 +1308,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn set_regs(&self, regs: &StandardRegisters) -> cpu::Result<()> {
|
fn set_regs(&self, regs: &StandardRegisters) -> cpu::Result<()> {
|
||||||
let regs = (*regs).into();
|
let regs = (*regs).into();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_regs(®s)
|
.set_regs(®s)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetStandardRegs(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetStandardRegs(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1354,8 +1324,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let mut off = offset_of!(user_pt_regs, regs);
|
let mut off = offset_of!(user_pt_regs, regs);
|
||||||
for i in 0..31 {
|
for i in 0..31 {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.regs.regs[i].to_le_bytes(),
|
&state.regs.regs[i].to_le_bytes(),
|
||||||
@@ -1366,8 +1334,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(user_pt_regs, sp);
|
let off = offset_of!(user_pt_regs, sp);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.regs.sp.to_le_bytes(),
|
&state.regs.sp.to_le_bytes(),
|
||||||
@@ -1376,8 +1342,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(user_pt_regs, pc);
|
let off = offset_of!(user_pt_regs, pc);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.regs.pc.to_le_bytes(),
|
&state.regs.pc.to_le_bytes(),
|
||||||
@@ -1386,8 +1350,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(user_pt_regs, pstate);
|
let off = offset_of!(user_pt_regs, pstate);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.regs.pstate.to_le_bytes(),
|
&state.regs.pstate.to_le_bytes(),
|
||||||
@@ -1396,8 +1358,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(kvm_regs, sp_el1);
|
let off = offset_of!(kvm_regs, sp_el1);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.sp_el1.to_le_bytes(),
|
&state.sp_el1.to_le_bytes(),
|
||||||
@@ -1406,8 +1366,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(kvm_regs, elr_el1);
|
let off = offset_of!(kvm_regs, elr_el1);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.elr_el1.to_le_bytes(),
|
&state.elr_el1.to_le_bytes(),
|
||||||
@@ -1417,8 +1375,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let mut off = offset_of!(kvm_regs, spsr);
|
let mut off = offset_of!(kvm_regs, spsr);
|
||||||
for i in 0..KVM_NR_SPSR as usize {
|
for i in 0..KVM_NR_SPSR as usize {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, off),
|
||||||
&state.spsr[i].to_le_bytes(),
|
&state.spsr[i].to_le_bytes(),
|
||||||
@@ -1430,8 +1386,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let mut off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, vregs);
|
let mut off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, vregs);
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U128, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U128, off),
|
||||||
&state.fp_regs.vregs[i].to_le_bytes(),
|
&state.fp_regs.vregs[i].to_le_bytes(),
|
||||||
@@ -1442,8 +1396,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpsr);
|
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpsr);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U32, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U32, off),
|
||||||
&state.fp_regs.fpsr.to_le_bytes(),
|
&state.fp_regs.fpsr.to_le_bytes(),
|
||||||
@@ -1452,8 +1404,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpcr);
|
let off = offset_of!(kvm_regs, fp_regs) + offset_of!(user_fpsimd_state, fpcr);
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U32, off),
|
arm64_core_reg_id!(KVM_REG_SIZE_U32, off),
|
||||||
&state.fp_regs.fpcr.to_le_bytes(),
|
&state.fp_regs.fpcr.to_le_bytes(),
|
||||||
@@ -1469,8 +1419,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_sregs(&self) -> cpu::Result<SpecialRegisters> {
|
fn get_sregs(&self) -> cpu::Result<SpecialRegisters> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_sregs()
|
.get_sregs()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetSpecialRegs(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetSpecialRegs(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -1483,8 +1431,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn set_sregs(&self, sregs: &SpecialRegisters) -> cpu::Result<()> {
|
fn set_sregs(&self, sregs: &SpecialRegisters) -> cpu::Result<()> {
|
||||||
let sregs = (*sregs).into();
|
let sregs = (*sregs).into();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_sregs(&sregs)
|
.set_sregs(&sregs)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetSpecialRegs(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetSpecialRegs(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1496,8 +1442,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_fpu(&self) -> cpu::Result<FpuState> {
|
fn get_fpu(&self) -> cpu::Result<FpuState> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_fpu()
|
.get_fpu()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetFloatingPointRegs(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetFloatingPointRegs(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -1505,13 +1449,11 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
/// Set the floating point state (FPU) of a vCPU using the `KVM_SET_FPU` ioctl.
|
/// Set the floating point state (FPU) of a vCPU using the `KVM_SET_FPU` ioct.
|
||||||
///
|
///
|
||||||
fn set_fpu(&self, fpu: &FpuState) -> cpu::Result<()> {
|
fn set_fpu(&self, fpu: &FpuState) -> cpu::Result<()> {
|
||||||
let fpu: kvm_bindings::kvm_fpu = (*fpu).clone().into();
|
let fpu: kvm_bindings::kvm_fpu = (*fpu).clone().into();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_fpu(&fpu)
|
.set_fpu(&fpu)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetFloatingPointRegs(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetFloatingPointRegs(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1527,8 +1469,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.map_err(|_| cpu::HypervisorCpuError::SetCpuid(anyhow!("failed to create CpuId")))?;
|
.map_err(|_| cpu::HypervisorCpuError::SetCpuid(anyhow!("failed to create CpuId")))?;
|
||||||
|
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_cpuid2(&kvm_cpuid)
|
.set_cpuid2(&kvm_cpuid)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetCpuid(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetCpuid(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1547,8 +1487,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.enable_cap(&cap)
|
.enable_cap(&cap)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::EnableHyperVSyncIc(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::EnableHyperVSyncIc(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1560,8 +1498,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_cpuid2(&self, num_entries: usize) -> cpu::Result<Vec<CpuIdEntry>> {
|
fn get_cpuid2(&self, num_entries: usize) -> cpu::Result<Vec<CpuIdEntry>> {
|
||||||
let kvm_cpuid = self
|
let kvm_cpuid = self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_cpuid2(num_entries)
|
.get_cpuid2(num_entries)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetCpuid(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetCpuid(e.into()))?;
|
||||||
|
|
||||||
@@ -1577,8 +1513,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_lapic(&self) -> cpu::Result<LapicState> {
|
fn get_lapic(&self) -> cpu::Result<LapicState> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_lapic()
|
.get_lapic()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetlapicState(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetlapicState(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -1591,8 +1525,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn set_lapic(&self, klapic: &LapicState) -> cpu::Result<()> {
|
fn set_lapic(&self, klapic: &LapicState) -> cpu::Result<()> {
|
||||||
let klapic: kvm_bindings::kvm_lapic_state = (*klapic).clone().into();
|
let klapic: kvm_bindings::kvm_lapic_state = (*klapic).clone().into();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_lapic(&klapic)
|
.set_lapic(&klapic)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetLapicState(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetLapicState(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1606,8 +1538,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let mut kvm_msrs = MsrEntries::from_entries(&kvm_msrs).unwrap();
|
let mut kvm_msrs = MsrEntries::from_entries(&kvm_msrs).unwrap();
|
||||||
let succ = self
|
let succ = self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_msrs(&mut kvm_msrs)
|
.get_msrs(&mut kvm_msrs)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetMsrEntries(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetMsrEntries(e.into()))?;
|
||||||
|
|
||||||
@@ -1630,8 +1560,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let kvm_msrs: Vec<kvm_msr_entry> = msrs.iter().map(|e| (*e).into()).collect();
|
let kvm_msrs: Vec<kvm_msr_entry> = msrs.iter().map(|e| (*e).into()).collect();
|
||||||
let kvm_msrs = MsrEntries::from_entries(&kvm_msrs).unwrap();
|
let kvm_msrs = MsrEntries::from_entries(&kvm_msrs).unwrap();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_msrs(&kvm_msrs)
|
.set_msrs(&kvm_msrs)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetMsrEntries(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetMsrEntries(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1642,8 +1570,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn get_mp_state(&self) -> cpu::Result<MpState> {
|
fn get_mp_state(&self) -> cpu::Result<MpState> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_mp_state()
|
.get_mp_state()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetMpState(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetMpState(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -1654,8 +1580,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
///
|
///
|
||||||
fn set_mp_state(&self, mp_state: MpState) -> cpu::Result<()> {
|
fn set_mp_state(&self, mp_state: MpState) -> cpu::Result<()> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_mp_state(mp_state.into())
|
.set_mp_state(mp_state.into())
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetMpState(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetMpState(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1667,8 +1591,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
fn translate_gva(&self, gva: u64, _flags: u64) -> cpu::Result<(u64, u32)> {
|
fn translate_gva(&self, gva: u64, _flags: u64) -> cpu::Result<(u64, u32)> {
|
||||||
let tr = self
|
let tr = self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.translate_gva(gva)
|
.translate_gva(gva)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::TranslateVirtualAddress(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::TranslateVirtualAddress(e.into()))?;
|
||||||
// tr.valid is set if the GVA is mapped to valid GPA.
|
// tr.valid is set if the GVA is mapped to valid GPA.
|
||||||
@@ -1685,7 +1607,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// Triggers the running of the current virtual CPU returning an exit reason.
|
/// Triggers the running of the current virtual CPU returning an exit reason.
|
||||||
///
|
///
|
||||||
fn run(&self) -> std::result::Result<cpu::VmExit, cpu::HypervisorCpuError> {
|
fn run(&self) -> std::result::Result<cpu::VmExit, cpu::HypervisorCpuError> {
|
||||||
match self.fd.lock().unwrap().run() {
|
match self.fd.run() {
|
||||||
Ok(run) => match run {
|
Ok(run) => match run {
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
VcpuExit::IoIn(addr, data) => {
|
VcpuExit::IoIn(addr, data) => {
|
||||||
@@ -1696,7 +1618,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::IoIn(addr, data))
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
VcpuExit::IoOut(addr, data) => {
|
VcpuExit::IoOut(addr, data) => {
|
||||||
@@ -1707,7 +1629,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::IoOut(addr, data))
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
VcpuExit::IoapicEoi(vector) => Ok(cpu::VmExit::IoapicEoi(vector)),
|
VcpuExit::IoapicEoi(vector) => Ok(cpu::VmExit::IoapicEoi(vector)),
|
||||||
@@ -1740,7 +1662,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::MmioRead(addr, data))
|
||||||
}
|
}
|
||||||
VcpuExit::MmioWrite(addr, data) => {
|
VcpuExit::MmioWrite(addr, data) => {
|
||||||
if let Some(vm_ops) = &self.vm_ops {
|
if let Some(vm_ops) = &self.vm_ops {
|
||||||
@@ -1750,7 +1672,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::MmioWrite(addr, data))
|
||||||
}
|
}
|
||||||
VcpuExit::Hyperv => Ok(cpu::VmExit::Hyperv),
|
VcpuExit::Hyperv => Ok(cpu::VmExit::Hyperv),
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
@@ -1779,7 +1701,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// potential soft lockups when being resumed.
|
/// potential soft lockups when being resumed.
|
||||||
///
|
///
|
||||||
fn notify_guest_clock_paused(&self) -> cpu::Result<()> {
|
fn notify_guest_clock_paused(&self) -> cpu::Result<()> {
|
||||||
if let Err(e) = self.fd.lock().unwrap().kvmclock_ctrl() {
|
if let Err(e) = self.fd.kvmclock_ctrl() {
|
||||||
// Linux kernel returns -EINVAL if the PV clock isn't yet initialised
|
// Linux kernel returns -EINVAL if the PV clock isn't yet initialised
|
||||||
// which could be because we're still in firmware or the guest doesn't
|
// which could be because we're still in firmware or the guest doesn't
|
||||||
// use KVM clock.
|
// use KVM clock.
|
||||||
@@ -1841,8 +1763,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_guest_debug(&dbg)
|
.set_guest_debug(&dbg)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetDebugRegs(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetDebugRegs(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1850,8 +1770,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
fn vcpu_init(&self, kvi: &VcpuInit) -> cpu::Result<()> {
|
fn vcpu_init(&self, kvi: &VcpuInit) -> cpu::Result<()> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.vcpu_init(kvi)
|
.vcpu_init(kvi)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::VcpuInit(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::VcpuInit(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1863,8 +1781,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
fn get_reg_list(&self, reg_list: &mut RegList) -> cpu::Result<()> {
|
fn get_reg_list(&self, reg_list: &mut RegList) -> cpu::Result<()> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_reg_list(reg_list)
|
.get_reg_list(reg_list)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetRegList(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::GetRegList(e.into()))
|
||||||
}
|
}
|
||||||
@@ -1897,8 +1813,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
| KVM_REG_ARM64_SYSREG_OP2_MASK)) as u64);
|
| KVM_REG_ARM64_SYSREG_OP2_MASK)) as u64);
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(id, &mut bytes)
|
.get_one_reg(id, &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetSysRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetSysRegister(e.into()))?;
|
||||||
Ok(u64::from_le_bytes(bytes))
|
Ok(u64::from_le_bytes(bytes))
|
||||||
@@ -1926,8 +1840,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
// Get the register index of the PSTATE (Processor State) register.
|
// Get the register index of the PSTATE (Processor State) register.
|
||||||
let pstate = offset_of!(user_pt_regs, pstate) + kreg_off;
|
let pstate = offset_of!(user_pt_regs, pstate) + kreg_off;
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, pstate),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, pstate),
|
||||||
&PSTATE_FAULT_BITS_64.to_le_bytes(),
|
&PSTATE_FAULT_BITS_64.to_le_bytes(),
|
||||||
@@ -1939,8 +1851,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
// Setting the PC (Processor Counter) to the current program address (kernel address).
|
// Setting the PC (Processor Counter) to the current program address (kernel address).
|
||||||
let pc = offset_of!(user_pt_regs, pc) + kreg_off;
|
let pc = offset_of!(user_pt_regs, pc) + kreg_off;
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, pc),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, pc),
|
||||||
&boot_ip.to_le_bytes(),
|
&boot_ip.to_le_bytes(),
|
||||||
@@ -1953,8 +1863,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
// We are choosing to place it the end of DRAM. See `get_fdt_addr`.
|
// We are choosing to place it the end of DRAM. See `get_fdt_addr`.
|
||||||
let regs0 = offset_of!(user_pt_regs, regs) + kreg_off;
|
let regs0 = offset_of!(user_pt_regs, regs) + kreg_off;
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(
|
.set_one_reg(
|
||||||
arm64_core_reg_id!(KVM_REG_SIZE_U64, regs0),
|
arm64_core_reg_id!(KVM_REG_SIZE_U64, regs0),
|
||||||
&fdt_start.to_le_bytes(),
|
&fdt_start.to_le_bytes(),
|
||||||
@@ -1986,7 +1894,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// SREGS saves/restores a pending interrupt, similar to what
|
/// SREGS saves/restores a pending interrupt, similar to what
|
||||||
/// VCPU_EVENTS also does.
|
/// VCPU_EVENTS also does.
|
||||||
///
|
///
|
||||||
/// GET_MSRS requires a prepopulated data structure to do something
|
/// GET_MSRS requires a pre-populated data structure to do something
|
||||||
/// meaningful. For SET_MSRS it will then contain good data.
|
/// meaningful. For SET_MSRS it will then contain good data.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
@@ -2069,7 +1977,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
msr_entries
|
msr_entries
|
||||||
};
|
};
|
||||||
|
|
||||||
let vcpu_events = self.get_vcpu_events()?;
|
let vcpu_events = self.get_vcpu_events()?.into();
|
||||||
let tsc_khz = self.tsc_khz()?;
|
let tsc_khz = self.tsc_khz()?;
|
||||||
|
|
||||||
Ok(VcpuKvmState {
|
Ok(VcpuKvmState {
|
||||||
@@ -2106,8 +2014,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
let mut sys_regs: Vec<Register> = Vec::new();
|
let mut sys_regs: Vec<Register> = Vec::new();
|
||||||
let mut reg_list = RegList::new(500).unwrap();
|
let mut reg_list = RegList::new(500).unwrap();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_reg_list(&mut reg_list)
|
.get_reg_list(&mut reg_list)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetRegList(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetRegList(e.into()))?;
|
||||||
|
|
||||||
@@ -2126,8 +2032,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
for index in indices.iter() {
|
for index in indices.iter() {
|
||||||
let mut bytes = [0_u8; 8];
|
let mut bytes = [0_u8; 8];
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_one_reg(*index, &mut bytes)
|
.get_one_reg(*index, &mut bytes)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetSysRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetSysRegister(e.into()))?;
|
||||||
sys_regs.push(kvm_bindings::kvm_one_reg {
|
sys_regs.push(kvm_bindings::kvm_one_reg {
|
||||||
@@ -2226,7 +2130,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_vcpu_events(&state.vcpu_events)?;
|
self.set_vcpu_events(&state.vcpu_events.into())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -2242,8 +2146,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
// Set system registers
|
// Set system registers
|
||||||
for reg in &state.sys_regs {
|
for reg in &state.sys_regs {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_one_reg(reg.id, ®.addr.to_le_bytes())
|
.set_one_reg(reg.id, ®.addr.to_le_bytes())
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetSysRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::SetSysRegister(e.into()))?;
|
||||||
}
|
}
|
||||||
@@ -2258,20 +2160,15 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
///
|
///
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
fn tdx_init(&self, hob_address: u64) -> cpu::Result<()> {
|
fn tdx_init(&self, hob_address: u64) -> cpu::Result<()> {
|
||||||
tdx_command(
|
tdx_command(&self.fd.as_raw_fd(), TdxCommand::InitVcpu, 0, hob_address)
|
||||||
&self.fd.lock().unwrap().as_raw_fd(),
|
.map_err(cpu::HypervisorCpuError::InitializeTdx)
|
||||||
TdxCommand::InitVcpu,
|
|
||||||
0,
|
|
||||||
hob_address,
|
|
||||||
)
|
|
||||||
.map_err(cpu::HypervisorCpuError::InitializeTdx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Set the "immediate_exit" state
|
/// Set the "immediate_exit" state
|
||||||
///
|
///
|
||||||
fn set_immediate_exit(&self, exit: bool) {
|
fn set_immediate_exit(&self, exit: bool) {
|
||||||
self.fd.lock().unwrap().set_kvm_immediate_exit(exit.into());
|
self.fd.set_kvm_immediate_exit(exit.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -2279,8 +2176,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
///
|
///
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
fn get_tdx_exit_details(&mut self) -> cpu::Result<TdxExitDetails> {
|
fn get_tdx_exit_details(&mut self) -> cpu::Result<TdxExitDetails> {
|
||||||
let mut fd = self.fd.as_ref().lock().unwrap();
|
let kvm_run = self.fd.get_kvm_run();
|
||||||
let kvm_run = fd.get_kvm_run();
|
|
||||||
// SAFETY: accessing a union field in a valid structure
|
// SAFETY: accessing a union field in a valid structure
|
||||||
let tdx_vmcall = unsafe {
|
let tdx_vmcall = unsafe {
|
||||||
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
||||||
@@ -2309,8 +2205,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
///
|
///
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
fn set_tdx_status(&mut self, status: TdxExitStatus) {
|
fn set_tdx_status(&mut self, status: TdxExitStatus) {
|
||||||
let mut fd = self.fd.as_ref().lock().unwrap();
|
let kvm_run = self.fd.get_kvm_run();
|
||||||
let kvm_run = fd.get_kvm_run();
|
|
||||||
// SAFETY: accessing a union field in a valid structure
|
// SAFETY: accessing a union field in a valid structure
|
||||||
let tdx_vmcall = unsafe {
|
let tdx_vmcall = unsafe {
|
||||||
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
&mut (*((&mut kvm_run.__bindgen_anon_1) as *mut kvm_run__bindgen_ty_1
|
||||||
@@ -2359,7 +2254,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
addr: 0x0,
|
addr: 0x0,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
};
|
};
|
||||||
self.fd.lock().unwrap().has_device_attr(&cpu_attr).is_ok()
|
self.fd.has_device_attr(&cpu_attr).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
@@ -2377,13 +2272,9 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
flags: 0,
|
flags: 0,
|
||||||
};
|
};
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_device_attr(&cpu_attr_irq)
|
.set_device_attr(&cpu_attr_irq)
|
||||||
.map_err(|_| cpu::HypervisorCpuError::InitializePmu)?;
|
.map_err(|_| cpu::HypervisorCpuError::InitializePmu)?;
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_device_attr(&cpu_attr)
|
.set_device_attr(&cpu_attr)
|
||||||
.map_err(|_| cpu::HypervisorCpuError::InitializePmu)
|
.map_err(|_| cpu::HypervisorCpuError::InitializePmu)
|
||||||
}
|
}
|
||||||
@@ -2393,7 +2284,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// Get the frequency of the TSC if available
|
/// Get the frequency of the TSC if available
|
||||||
///
|
///
|
||||||
fn tsc_khz(&self) -> cpu::Result<Option<u32>> {
|
fn tsc_khz(&self) -> cpu::Result<Option<u32>> {
|
||||||
match self.fd.lock().unwrap().get_tsc_khz() {
|
match self.fd.get_tsc_khz() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.errno() == libc::EIO {
|
if e.errno() == libc::EIO {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -2410,7 +2301,7 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
/// Set the frequency of the TSC if available
|
/// Set the frequency of the TSC if available
|
||||||
///
|
///
|
||||||
fn set_tsc_khz(&self, freq: u32) -> cpu::Result<()> {
|
fn set_tsc_khz(&self, freq: u32) -> cpu::Result<()> {
|
||||||
match self.fd.lock().unwrap().set_tsc_khz(freq) {
|
match self.fd.set_tsc_khz(freq) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.errno() == libc::EIO {
|
if e.errno() == libc::EIO {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -2421,23 +2312,6 @@ impl cpu::Vcpu for KvmVcpu {
|
|||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
|
||||||
/// Trigger NMI interrupt
|
|
||||||
///
|
|
||||||
fn nmi(&self) -> cpu::Result<()> {
|
|
||||||
match self.fd.lock().unwrap().nmi() {
|
|
||||||
Err(e) => {
|
|
||||||
if e.errno() == libc::EIO {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(cpu::HypervisorCpuError::Nmi(e.into()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KvmVcpu {
|
impl KvmVcpu {
|
||||||
@@ -2448,8 +2322,6 @@ impl KvmVcpu {
|
|||||||
fn get_xsave(&self) -> cpu::Result<XsaveState> {
|
fn get_xsave(&self) -> cpu::Result<XsaveState> {
|
||||||
Ok(self
|
Ok(self
|
||||||
.fd
|
.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_xsave()
|
.get_xsave()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into()))?
|
.map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into()))?
|
||||||
.into())
|
.into())
|
||||||
@@ -2462,8 +2334,6 @@ impl KvmVcpu {
|
|||||||
fn set_xsave(&self, xsave: &XsaveState) -> cpu::Result<()> {
|
fn set_xsave(&self, xsave: &XsaveState) -> cpu::Result<()> {
|
||||||
let xsave: kvm_bindings::kvm_xsave = (*xsave).clone().into();
|
let xsave: kvm_bindings::kvm_xsave = (*xsave).clone().into();
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_xsave(&xsave)
|
.set_xsave(&xsave)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into()))
|
||||||
}
|
}
|
||||||
@@ -2474,8 +2344,6 @@ impl KvmVcpu {
|
|||||||
///
|
///
|
||||||
fn get_xcrs(&self) -> cpu::Result<ExtendedControlRegisters> {
|
fn get_xcrs(&self) -> cpu::Result<ExtendedControlRegisters> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_xcrs()
|
.get_xcrs()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetXcsr(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::GetXcsr(e.into()))
|
||||||
}
|
}
|
||||||
@@ -2486,8 +2354,6 @@ impl KvmVcpu {
|
|||||||
///
|
///
|
||||||
fn set_xcrs(&self, xcrs: &ExtendedControlRegisters) -> cpu::Result<()> {
|
fn set_xcrs(&self, xcrs: &ExtendedControlRegisters) -> cpu::Result<()> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_xcrs(xcrs)
|
.set_xcrs(xcrs)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetXcsr(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetXcsr(e.into()))
|
||||||
}
|
}
|
||||||
@@ -2499,8 +2365,6 @@ impl KvmVcpu {
|
|||||||
///
|
///
|
||||||
fn get_vcpu_events(&self) -> cpu::Result<VcpuEvents> {
|
fn get_vcpu_events(&self) -> cpu::Result<VcpuEvents> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.get_vcpu_events()
|
.get_vcpu_events()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetVcpuEvents(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::GetVcpuEvents(e.into()))
|
||||||
}
|
}
|
||||||
@@ -2512,8 +2376,6 @@ impl KvmVcpu {
|
|||||||
///
|
///
|
||||||
fn set_vcpu_events(&self, events: &VcpuEvents) -> cpu::Result<()> {
|
fn set_vcpu_events(&self, events: &VcpuEvents) -> cpu::Result<()> {
|
||||||
self.fd
|
self.fd
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_vcpu_events(events)
|
.set_vcpu_events(events)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetVcpuEvents(e.into()))
|
.map_err(|e| cpu::HypervisorCpuError::SetVcpuEvents(e.into()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub use {
|
|||||||
kvm_bindings::kvm_cpuid_entry2, kvm_bindings::kvm_dtable, kvm_bindings::kvm_fpu,
|
kvm_bindings::kvm_cpuid_entry2, kvm_bindings::kvm_dtable, kvm_bindings::kvm_fpu,
|
||||||
kvm_bindings::kvm_lapic_state, kvm_bindings::kvm_mp_state as MpState,
|
kvm_bindings::kvm_lapic_state, kvm_bindings::kvm_mp_state as MpState,
|
||||||
kvm_bindings::kvm_msr_entry, kvm_bindings::kvm_regs, kvm_bindings::kvm_segment,
|
kvm_bindings::kvm_msr_entry, kvm_bindings::kvm_regs, kvm_bindings::kvm_segment,
|
||||||
kvm_bindings::kvm_sregs, kvm_bindings::kvm_vcpu_events as VcpuEvents,
|
kvm_bindings::kvm_sregs, kvm_bindings::kvm_vcpu_events_old as VcpuEvents,
|
||||||
kvm_bindings::kvm_xcrs as ExtendedControlRegisters, kvm_bindings::kvm_xsave,
|
kvm_bindings::kvm_xcrs as ExtendedControlRegisters, kvm_bindings::kvm_xsave,
|
||||||
kvm_bindings::CpuId, kvm_bindings::MsrList, kvm_bindings::Msrs as MsrEntries,
|
kvm_bindings::CpuId, kvm_bindings::MsrList, kvm_bindings::Msrs as MsrEntries,
|
||||||
kvm_bindings::KVM_CPUID_FLAG_SIGNIFCANT_INDEX,
|
kvm_bindings::KVM_CPUID_FLAG_SIGNIFCANT_INDEX,
|
||||||
@@ -32,37 +32,29 @@ pub use {
|
|||||||
/// Check KVM extension for Linux
|
/// Check KVM extension for Linux
|
||||||
///
|
///
|
||||||
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
pub fn check_required_kvm_extensions(kvm: &Kvm) -> KvmResult<()> {
|
||||||
macro_rules! check_extension {
|
if !kvm.check_extension(Cap::SignalMsi) {
|
||||||
($cap:expr) => {
|
return Err(KvmError::CapabilityMissing(Cap::SignalMsi));
|
||||||
if !kvm.check_extension($cap) {
|
}
|
||||||
return Err(KvmError::CapabilityMissing($cap));
|
if !kvm.check_extension(Cap::TscDeadlineTimer) {
|
||||||
}
|
return Err(KvmError::CapabilityMissing(Cap::TscDeadlineTimer));
|
||||||
};
|
}
|
||||||
|
if !kvm.check_extension(Cap::SplitIrqchip) {
|
||||||
|
return Err(KvmError::CapabilityMissing(Cap::SplitIrqchip));
|
||||||
|
}
|
||||||
|
if !kvm.check_extension(Cap::SetIdentityMapAddr) {
|
||||||
|
return Err(KvmError::CapabilityMissing(Cap::SetIdentityMapAddr));
|
||||||
|
}
|
||||||
|
if !kvm.check_extension(Cap::SetTssAddr) {
|
||||||
|
return Err(KvmError::CapabilityMissing(Cap::SetTssAddr));
|
||||||
|
}
|
||||||
|
if !kvm.check_extension(Cap::ImmediateExit) {
|
||||||
|
return Err(KvmError::CapabilityMissing(Cap::ImmediateExit));
|
||||||
|
}
|
||||||
|
if !kvm.check_extension(Cap::GetTscKhz) {
|
||||||
|
return Err(KvmError::CapabilityMissing(Cap::GetTscKhz));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeviceCtrl, EnableCap, and SetGuestDebug are also required, but some kernels have
|
|
||||||
// the features implemented without the capability flags.
|
|
||||||
check_extension!(Cap::AdjustClock);
|
|
||||||
check_extension!(Cap::ExtCpuid);
|
|
||||||
check_extension!(Cap::GetTscKhz);
|
|
||||||
check_extension!(Cap::ImmediateExit);
|
|
||||||
check_extension!(Cap::Ioeventfd);
|
|
||||||
check_extension!(Cap::Irqchip);
|
|
||||||
check_extension!(Cap::Irqfd);
|
|
||||||
check_extension!(Cap::IrqRouting);
|
|
||||||
check_extension!(Cap::MpState);
|
|
||||||
check_extension!(Cap::SetIdentityMapAddr);
|
|
||||||
check_extension!(Cap::SetTssAddr);
|
|
||||||
check_extension!(Cap::SplitIrqchip);
|
|
||||||
check_extension!(Cap::TscDeadlineTimer);
|
|
||||||
check_extension!(Cap::UserMemory);
|
|
||||||
check_extension!(Cap::UserNmi);
|
|
||||||
check_extension!(Cap::VcpuEvents);
|
|
||||||
check_extension!(Cap::Xcrs);
|
|
||||||
check_extension!(Cap::Xsave);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct VcpuKvmState {
|
pub struct VcpuKvmState {
|
||||||
pub cpuid: Vec<CpuIdEntry>,
|
pub cpuid: Vec<CpuIdEntry>,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate anyhow;
|
extern crate anyhow;
|
||||||
#[allow(unused_imports)]
|
#[cfg(target_arch = "x86_64")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|
||||||
@@ -134,7 +134,6 @@ pub const USER_MEMORY_REGION_READ: u32 = 1;
|
|||||||
pub const USER_MEMORY_REGION_WRITE: u32 = 1 << 1;
|
pub const USER_MEMORY_REGION_WRITE: u32 = 1 << 1;
|
||||||
pub const USER_MEMORY_REGION_EXECUTE: u32 = 1 << 2;
|
pub const USER_MEMORY_REGION_EXECUTE: u32 = 1 << 2;
|
||||||
pub const USER_MEMORY_REGION_LOG_DIRTY: u32 = 1 << 3;
|
pub const USER_MEMORY_REGION_LOG_DIRTY: u32 = 1 << 3;
|
||||||
pub const USER_MEMORY_REGION_ADJUSTABLE: u32 = 1 << 4;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MpState {
|
pub enum MpState {
|
||||||
@@ -163,9 +162,9 @@ pub enum CpuState {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub enum ClockData {
|
pub enum ClockData {
|
||||||
#[cfg(feature = "kvm")]
|
#[cfg(feature = "kvm")]
|
||||||
Kvm(kvm_bindings::kvm_clock_data),
|
Kvm(kvm_bindings::kvm_clock_data_old),
|
||||||
#[cfg(feature = "mshv")]
|
#[cfg(feature = "mshv")]
|
||||||
Mshv(mshv::MshvClockData),
|
Mshv, /* MSHV does not support ClockData yet */
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use crate::hypervisor;
|
|||||||
use crate::vec_with_array_field;
|
use crate::vec_with_array_field;
|
||||||
use crate::vm::{self, InterruptSourceConfig, VmOps};
|
use crate::vm::{self, InterruptSourceConfig, VmOps};
|
||||||
use crate::HypervisorType;
|
use crate::HypervisorType;
|
||||||
use mshv_bindings::*;
|
pub use mshv_bindings::*;
|
||||||
use mshv_ioctls::{set_registers_64, InterruptRequest, Mshv, NoDatamatch, VcpuFd, VmFd, VmType};
|
use mshv_ioctls::{set_registers_64, Mshv, NoDatamatch, VcpuFd, VmFd, VmType};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
@@ -29,13 +29,9 @@ pub mod x86_64;
|
|||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
use snp_constants::*;
|
use snp_constants::*;
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
use crate::ClockData;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CpuState, IoEventAddress, IrqRoutingEntry, MpState, UserMemoryRegion,
|
ClockData, CpuState, IoEventAddress, IrqRoutingEntry, MpState, UserMemoryRegion,
|
||||||
USER_MEMORY_REGION_ADJUSTABLE, USER_MEMORY_REGION_EXECUTE, USER_MEMORY_REGION_READ,
|
USER_MEMORY_REGION_EXECUTE, USER_MEMORY_REGION_READ, USER_MEMORY_REGION_WRITE,
|
||||||
USER_MEMORY_REGION_WRITE,
|
|
||||||
};
|
};
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
use igvm_defs::IGVM_VHS_SNP_ID_BLOCK;
|
use igvm_defs::IGVM_VHS_SNP_ID_BLOCK;
|
||||||
@@ -77,9 +73,6 @@ impl From<mshv_user_mem_region> for UserMemoryRegion {
|
|||||||
if region.flags & HV_MAP_GPA_EXECUTABLE != 0 {
|
if region.flags & HV_MAP_GPA_EXECUTABLE != 0 {
|
||||||
flags |= USER_MEMORY_REGION_EXECUTE;
|
flags |= USER_MEMORY_REGION_EXECUTE;
|
||||||
}
|
}
|
||||||
if region.flags & HV_MAP_GPA_ADJUSTABLE != 0 {
|
|
||||||
flags |= USER_MEMORY_REGION_ADJUSTABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserMemoryRegion {
|
UserMemoryRegion {
|
||||||
guest_phys_addr: (region.guest_pfn << PAGE_SHIFT as u64)
|
guest_phys_addr: (region.guest_pfn << PAGE_SHIFT as u64)
|
||||||
@@ -92,25 +85,6 @@ impl From<mshv_user_mem_region> for UserMemoryRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
impl From<MshvClockData> for ClockData {
|
|
||||||
fn from(d: MshvClockData) -> Self {
|
|
||||||
ClockData::Mshv(d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
impl From<ClockData> for MshvClockData {
|
|
||||||
fn from(ms: ClockData) -> Self {
|
|
||||||
match ms {
|
|
||||||
ClockData::Mshv(s) => s,
|
|
||||||
/* Needed in case other hypervisors are enabled */
|
|
||||||
#[allow(unreachable_patterns)]
|
|
||||||
_ => unreachable!("MSHV clock data is not valid"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<UserMemoryRegion> for mshv_user_mem_region {
|
impl From<UserMemoryRegion> for mshv_user_mem_region {
|
||||||
fn from(region: UserMemoryRegion) -> Self {
|
fn from(region: UserMemoryRegion) -> Self {
|
||||||
let mut flags: u32 = 0;
|
let mut flags: u32 = 0;
|
||||||
@@ -123,9 +97,6 @@ impl From<UserMemoryRegion> for mshv_user_mem_region {
|
|||||||
if region.flags & USER_MEMORY_REGION_EXECUTE != 0 {
|
if region.flags & USER_MEMORY_REGION_EXECUTE != 0 {
|
||||||
flags |= HV_MAP_GPA_EXECUTABLE;
|
flags |= HV_MAP_GPA_EXECUTABLE;
|
||||||
}
|
}
|
||||||
if region.flags & USER_MEMORY_REGION_ADJUSTABLE != 0 {
|
|
||||||
flags |= HV_MAP_GPA_ADJUSTABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
mshv_user_mem_region {
|
mshv_user_mem_region {
|
||||||
guest_pfn: region.guest_phys_addr >> PAGE_SHIFT,
|
guest_pfn: region.guest_phys_addr >> PAGE_SHIFT,
|
||||||
@@ -273,7 +244,6 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set additional partition property for SEV-SNP partition.
|
// Set additional partition property for SEV-SNP partition.
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
if mshv_vm_type == VmType::Snp {
|
if mshv_vm_type == VmType::Snp {
|
||||||
let snp_policy = snp::get_default_snp_guest_policy();
|
let snp_policy = snp::get_default_snp_guest_policy();
|
||||||
let vmgexit_offloads = snp::get_default_vmgexit_offload_features();
|
let vmgexit_offloads = snp::get_default_vmgexit_offload_features();
|
||||||
@@ -305,53 +275,31 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
|||||||
// to override this behavior with a more suitable option i.e., ignore
|
// to override this behavior with a more suitable option i.e., ignore
|
||||||
// writes from the guest and return zero in attempt to read unimplemented
|
// writes from the guest and return zero in attempt to read unimplemented
|
||||||
// MSR.
|
// MSR.
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fd.set_partition_property(
|
fd.set_partition_property(
|
||||||
hv_partition_property_code_HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION,
|
hv_partition_property_code_HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION,
|
||||||
hv_unimplemented_msr_action_HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO as u64,
|
hv_unimplemented_msr_action_HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO as u64,
|
||||||
)
|
)
|
||||||
.map_err(|e| hypervisor::HypervisorError::SetPartitionProperty(e.into()))?;
|
.map_err(|e| hypervisor::HypervisorError::SetPartitionProperty(e.into()))?;
|
||||||
|
|
||||||
// Always create a frozen partition
|
let msr_list = self.get_msr_list()?;
|
||||||
fd.set_partition_property(
|
let num_msrs = msr_list.as_fam_struct_ref().nmsrs as usize;
|
||||||
hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE,
|
let mut msrs: Vec<MsrEntry> = vec![
|
||||||
1u64,
|
MsrEntry {
|
||||||
)
|
..Default::default()
|
||||||
.map_err(|e| hypervisor::HypervisorError::SetPartitionProperty(e.into()))?;
|
};
|
||||||
|
num_msrs
|
||||||
|
];
|
||||||
|
let indices = msr_list.as_slice();
|
||||||
|
for (pos, index) in indices.iter().enumerate() {
|
||||||
|
msrs[pos].index = *index;
|
||||||
|
}
|
||||||
let vm_fd = Arc::new(fd);
|
let vm_fd = Arc::new(fd);
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
Ok(Arc::new(MshvVm {
|
||||||
{
|
fd: vm_fd,
|
||||||
let msr_list = self.get_msr_list()?;
|
msrs,
|
||||||
let num_msrs = msr_list.as_fam_struct_ref().nmsrs as usize;
|
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
||||||
let mut msrs: Vec<MsrEntry> = vec![
|
}))
|
||||||
MsrEntry {
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
num_msrs
|
|
||||||
];
|
|
||||||
let indices = msr_list.as_slice();
|
|
||||||
for (pos, index) in indices.iter().enumerate() {
|
|
||||||
msrs[pos].index = *index;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Arc::new(MshvVm {
|
|
||||||
fd: vm_fd,
|
|
||||||
msrs,
|
|
||||||
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
sev_snp_enabled: mshv_vm_type == VmType::Snp,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
{
|
|
||||||
Ok(Arc::new(MshvVm {
|
|
||||||
fd: vm_fd,
|
|
||||||
dirty_log_slots: Arc::new(RwLock::new(HashMap::new())),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a mshv vm object and return the object as Vm trait object
|
/// Create a mshv vm object and return the object as Vm trait object
|
||||||
@@ -369,21 +317,11 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
|||||||
let vm_type = 0;
|
let vm_type = 0;
|
||||||
self.create_vm_with_type(vm_type)
|
self.create_vm_with_type(vm_type)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
///
|
||||||
/// Get the supported CpuID
|
/// Get the supported CpuID
|
||||||
///
|
///
|
||||||
fn get_supported_cpuid(&self) -> hypervisor::Result<Vec<CpuIdEntry>> {
|
fn get_supported_cpuid(&self) -> hypervisor::Result<Vec<CpuIdEntry>> {
|
||||||
let mut cpuid = Vec::new();
|
Ok(Vec::new())
|
||||||
let functions: [u32; 2] = [0x1, 0xb];
|
|
||||||
|
|
||||||
for function in functions {
|
|
||||||
cpuid.push(CpuIdEntry {
|
|
||||||
function,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(cpuid)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get maximum number of vCPUs
|
/// Get maximum number of vCPUs
|
||||||
@@ -398,11 +336,10 @@ impl hypervisor::Hypervisor for MshvHypervisor {
|
|||||||
pub struct MshvVcpu {
|
pub struct MshvVcpu {
|
||||||
fd: VcpuFd,
|
fd: VcpuFd,
|
||||||
vp_index: u8,
|
vp_index: u8,
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
cpuid: Vec<CpuIdEntry>,
|
cpuid: Vec<CpuIdEntry>,
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
msrs: Vec<MsrEntry>,
|
msrs: Vec<MsrEntry>,
|
||||||
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
vm_ops: Option<Arc<dyn vm::VmOps>>,
|
||||||
|
#[cfg(feature = "sev_snp")]
|
||||||
vm_fd: Arc<VmFd>,
|
vm_fd: Arc<VmFd>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,7 +482,6 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
warn!("TRIPLE FAULT");
|
warn!("TRIPLE FAULT");
|
||||||
Ok(cpu::VmExit::Shutdown)
|
Ok(cpu::VmExit::Shutdown)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT => {
|
hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT => {
|
||||||
let info = x.to_ioport_info().unwrap();
|
let info = x.to_ioport_info().unwrap();
|
||||||
let access_info = info.access_info;
|
let access_info = info.access_info;
|
||||||
@@ -636,7 +572,6 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
.map_err(|e| cpu::HypervisorCpuError::SetRegister(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::SetRegister(e.into()))?;
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::Ignore)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_UNMAPPED_GPA => {
|
hv_message_type_HVMSG_UNMAPPED_GPA => {
|
||||||
let info = x.to_memory_info().unwrap();
|
let info = x.to_memory_info().unwrap();
|
||||||
let insn_len = info.instruction_byte_count as usize;
|
let insn_len = info.instruction_byte_count as usize;
|
||||||
@@ -662,78 +597,11 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::Ignore)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
hv_message_type_HVMSG_GPA_ATTRIBUTE_INTERCEPT => {
|
|
||||||
let info = x.to_gpa_attribute_info().unwrap();
|
|
||||||
let host_vis = info.__bindgen_anon_1.host_visibility();
|
|
||||||
if host_vis >= HV_MAP_GPA_READABLE | HV_MAP_GPA_WRITABLE {
|
|
||||||
warn!("Ignored attribute intercept with full host visibility");
|
|
||||||
return Ok(cpu::VmExit::Ignore);
|
|
||||||
}
|
|
||||||
|
|
||||||
let num_ranges = info.__bindgen_anon_1.range_count();
|
|
||||||
assert!(num_ranges >= 1);
|
|
||||||
if num_ranges > 1 {
|
|
||||||
return Err(cpu::HypervisorCpuError::RunVcpu(anyhow!(
|
|
||||||
"Unhandled VCPU exit(GPA_ATTRIBUTE_INTERCEPT): Expected num_ranges to be 1 but found num_ranges {:?}",
|
|
||||||
num_ranges
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: we could also deny the request with HvCallCompleteIntercept
|
|
||||||
let mut gpas = Vec::new();
|
|
||||||
let ranges = info.ranges;
|
|
||||||
let (gfn_start, gfn_count) = snp::parse_gpa_range(ranges[0]).unwrap();
|
|
||||||
debug!(
|
|
||||||
"Releasing pages: gfn_start: {:x?}, gfn_count: {:?}",
|
|
||||||
gfn_start, gfn_count
|
|
||||||
);
|
|
||||||
let gpa_start = gfn_start * HV_PAGE_SIZE as u64;
|
|
||||||
for i in 0..gfn_count {
|
|
||||||
gpas.push(gpa_start + i * HV_PAGE_SIZE as u64);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut gpa_list =
|
|
||||||
vec_with_array_field::<mshv_modify_gpa_host_access, u64>(gpas.len());
|
|
||||||
gpa_list[0].gpa_list_size = gpas.len() as u64;
|
|
||||||
gpa_list[0].host_access = host_vis;
|
|
||||||
gpa_list[0].acquire = 0;
|
|
||||||
gpa_list[0].flags = 0;
|
|
||||||
|
|
||||||
// SAFETY: gpa_list initialized with gpas.len() and now it is being turned into
|
|
||||||
// gpas_slice with gpas.len() again. It is guaranteed to be large enough to hold
|
|
||||||
// everything from gpas.
|
|
||||||
unsafe {
|
|
||||||
let gpas_slice: &mut [u64] = gpa_list[0].gpa_list.as_mut_slice(gpas.len());
|
|
||||||
gpas_slice.copy_from_slice(gpas.as_slice());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.vm_fd
|
|
||||||
.modify_gpa_host_access(&gpa_list[0])
|
|
||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(anyhow!(
|
|
||||||
"Unhandled VCPU exit: attribute intercept - couldn't modify host access {}", e
|
|
||||||
)))?;
|
|
||||||
Ok(cpu::VmExit::Ignore)
|
|
||||||
}
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_UNACCEPTED_GPA => {
|
|
||||||
let info = x.to_memory_info().unwrap();
|
|
||||||
let gva = info.guest_virtual_address;
|
|
||||||
let gpa = info.guest_physical_address;
|
|
||||||
|
|
||||||
Err(cpu::HypervisorCpuError::RunVcpu(anyhow!(
|
|
||||||
"Unhandled VCPU exit: Unaccepted GPA({:x}) found at GVA({:x})",
|
|
||||||
gpa,
|
|
||||||
gva,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_X64_CPUID_INTERCEPT => {
|
hv_message_type_HVMSG_X64_CPUID_INTERCEPT => {
|
||||||
let info = x.to_cpuid_info().unwrap();
|
let info = x.to_cpuid_info().unwrap();
|
||||||
debug!("cpuid eax: {:x}", { info.rax });
|
debug!("cpuid eax: {:x}", { info.rax });
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::Ignore)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_X64_MSR_INTERCEPT => {
|
hv_message_type_HVMSG_X64_MSR_INTERCEPT => {
|
||||||
let info = x.to_msr_info().unwrap();
|
let info = x.to_msr_info().unwrap();
|
||||||
if info.header.intercept_access_type == 0 {
|
if info.header.intercept_access_type == 0 {
|
||||||
@@ -743,14 +611,12 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
}
|
}
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::Ignore)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT => {
|
hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT => {
|
||||||
//TODO: Handler for VMCALL here.
|
//TODO: Handler for VMCALL here.
|
||||||
let info = x.to_exception_info().unwrap();
|
let info = x.to_exception_info().unwrap();
|
||||||
debug!("Exception Info {:?}", { info.exception_vector });
|
debug!("Exception Info {:?}", { info.exception_vector });
|
||||||
Ok(cpu::VmExit::Ignore)
|
Ok(cpu::VmExit::Ignore)
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
hv_message_type_HVMSG_X64_APIC_EOI => {
|
hv_message_type_HVMSG_X64_APIC_EOI => {
|
||||||
let info = x.to_apic_eoi_info().unwrap();
|
let info = x.to_apic_eoi_info().unwrap();
|
||||||
// The kernel should dispatch the EOI to the correct thread.
|
// The kernel should dispatch the EOI to the correct thread.
|
||||||
@@ -1164,14 +1030,13 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
.sev_snp_ap_create(&mshv_ap_create_req)
|
.sev_snp_ap_create(&mshv_ap_create_req)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?;
|
||||||
|
|
||||||
let mut swei1_rw_gpa_arg = mshv_bindings::mshv_read_write_gpa {
|
let mut swei2_rw_gpa_arg = mshv_bindings::mshv_read_write_gpa {
|
||||||
base_gpa: ghcb_gpa + GHCB_SW_EXITINFO1_OFFSET,
|
base_gpa: ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET,
|
||||||
byte_count: std::mem::size_of::<u64>() as u32,
|
byte_count: std::mem::size_of::<u64>() as u32,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.fd
|
self.fd
|
||||||
.gpa_write(&mut swei1_rw_gpa_arg)
|
.gpa_write(&mut swei2_rw_gpa_arg)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?;
|
||||||
}
|
}
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
@@ -1201,46 +1066,6 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn init_pmu(&self, irq: u32) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn has_pmu_support(&self) -> bool {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn setup_regs(&self, cpu_id: u8, boot_ip: u64, fdt_start: u64) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn get_sys_reg(&self, sys_reg: u32) -> cpu::Result<u64> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn get_reg_list(&self, reg_list: &mut RegList) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn vcpu_init(&self, kvi: &VcpuInit) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn set_regs(&self, regs: &StandardRegisters) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn get_regs(&self) -> cpu::Result<StandardRegisters> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
/// X86 specific call to setup the CPUID registers.
|
/// X86 specific call to setup the CPUID registers.
|
||||||
@@ -1316,20 +1141,21 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
///
|
||||||
/// Set CPU state for x86_64 guest.
|
/// Set CPU state
|
||||||
///
|
///
|
||||||
fn set_state(&self, state: &CpuState) -> cpu::Result<()> {
|
fn set_state(&self, state: &CpuState) -> cpu::Result<()> {
|
||||||
let mut state: VcpuMshvState = state.clone().into();
|
let state: VcpuMshvState = state.clone().into();
|
||||||
self.set_msrs(&state.msrs)?;
|
self.set_msrs(&state.msrs)?;
|
||||||
self.set_vcpu_events(&state.vcpu_events)?;
|
self.set_vcpu_events(&state.vcpu_events)?;
|
||||||
self.set_regs(&state.regs.into())?;
|
self.set_regs(&state.regs.into())?;
|
||||||
self.set_sregs(&state.sregs.into())?;
|
self.set_sregs(&state.sregs.into())?;
|
||||||
self.set_fpu(&state.fpu)?;
|
self.set_fpu(&state.fpu)?;
|
||||||
self.set_xcrs(&state.xcrs)?;
|
self.set_xcrs(&state.xcrs)?;
|
||||||
|
self.set_lapic(&state.lapic)?;
|
||||||
|
self.set_xsave(&state.xsave)?;
|
||||||
// These registers are global and needed to be set only for first VCPU
|
// These registers are global and needed to be set only for first VCPU
|
||||||
// as Microsoft Hypervisor allows setting this register for only one VCPU
|
// as Microsoft Hypervisor allows setting this regsier for only one VCPU
|
||||||
if self.vp_index == 0 {
|
if self.vp_index == 0 {
|
||||||
self.fd
|
self.fd
|
||||||
.set_misc_regs(&state.misc)
|
.set_misc_regs(&state.misc)
|
||||||
@@ -1338,23 +1164,11 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
self.fd
|
self.fd
|
||||||
.set_debug_regs(&state.dbg)
|
.set_debug_regs(&state.dbg)
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetDebugRegs(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::SetDebugRegs(e.into()))?;
|
||||||
self.fd
|
|
||||||
.set_all_vp_state_components(&mut state.vp_states)
|
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetAllVpStateComponents(e.into()))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
///
|
///
|
||||||
/// Set CPU state for aarch64 guest.
|
/// Get CPU State
|
||||||
///
|
|
||||||
fn set_state(&self, state: &CpuState) -> cpu::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
|
||||||
/// Get CPU State for x86_64 guest
|
|
||||||
///
|
///
|
||||||
fn state(&self) -> cpu::Result<CpuState> {
|
fn state(&self) -> cpu::Result<CpuState> {
|
||||||
let regs = self.get_regs()?;
|
let regs = self.get_regs()?;
|
||||||
@@ -1364,6 +1178,8 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
let vcpu_events = self.get_vcpu_events()?;
|
let vcpu_events = self.get_vcpu_events()?;
|
||||||
let mut msrs = self.msrs.clone();
|
let mut msrs = self.msrs.clone();
|
||||||
self.get_msrs(&mut msrs)?;
|
self.get_msrs(&mut msrs)?;
|
||||||
|
let lapic = self.get_lapic()?;
|
||||||
|
let xsave = self.get_xsave()?;
|
||||||
let misc = self
|
let misc = self
|
||||||
.fd
|
.fd
|
||||||
.get_misc_regs()
|
.get_misc_regs()
|
||||||
@@ -1372,10 +1188,6 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
.fd
|
.fd
|
||||||
.get_debug_regs()
|
.get_debug_regs()
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetDebugRegs(e.into()))?;
|
.map_err(|e| cpu::HypervisorCpuError::GetDebugRegs(e.into()))?;
|
||||||
let vp_states = self
|
|
||||||
.fd
|
|
||||||
.get_all_vp_state_components()
|
|
||||||
.map_err(|e| cpu::HypervisorCpuError::GetAllVpStateComponents(e.into()))?;
|
|
||||||
|
|
||||||
Ok(VcpuMshvState {
|
Ok(VcpuMshvState {
|
||||||
msrs,
|
msrs,
|
||||||
@@ -1384,21 +1196,14 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
sregs: sregs.into(),
|
sregs: sregs.into(),
|
||||||
fpu,
|
fpu,
|
||||||
xcrs,
|
xcrs,
|
||||||
|
lapic,
|
||||||
dbg,
|
dbg,
|
||||||
|
xsave,
|
||||||
misc,
|
misc,
|
||||||
vp_states,
|
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
///
|
|
||||||
/// Get CPU state for aarch64 guest.
|
|
||||||
///
|
|
||||||
fn state(&self) -> cpu::Result<CpuState> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
/// Translate guest virtual address to guest physical address
|
/// Translate guest virtual address to guest physical address
|
||||||
@@ -1436,38 +1241,29 @@ impl cpu::Vcpu for MshvVcpu {
|
|||||||
]
|
]
|
||||||
.to_vec()
|
.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Sets the AMD specific vcpu's sev control register.
|
|
||||||
///
|
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
fn set_sev_control_register(&self, vmsa_pfn: u64) -> cpu::Result<()> {
|
|
||||||
let sev_control_reg = snp::get_sev_control_register(vmsa_pfn);
|
|
||||||
|
|
||||||
self.fd
|
|
||||||
.set_sev_control_register(sev_control_reg)
|
|
||||||
.map_err(|e| cpu::HypervisorCpuError::SetSevControlRegister(e.into()))
|
|
||||||
}
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
///
|
|
||||||
/// Trigger NMI interrupt
|
|
||||||
///
|
|
||||||
fn nmi(&self) -> cpu::Result<()> {
|
|
||||||
let cfg = InterruptRequest {
|
|
||||||
interrupt_type: hv_interrupt_type_HV_X64_INTERRUPT_TYPE_NMI,
|
|
||||||
apic_id: self.vp_index as u64,
|
|
||||||
level_triggered: false,
|
|
||||||
vector: 0,
|
|
||||||
logical_destination_mode: false,
|
|
||||||
long_mode: false,
|
|
||||||
};
|
|
||||||
self.vm_fd
|
|
||||||
.request_virtual_interrupt(&cfg)
|
|
||||||
.map_err(|e| cpu::HypervisorCpuError::Nmi(e.into()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MshvVcpu {
|
impl MshvVcpu {
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
///
|
||||||
|
/// X86 specific call that returns the vcpu's current "xsave struct".
|
||||||
|
///
|
||||||
|
fn get_xsave(&self) -> cpu::Result<Xsave> {
|
||||||
|
self.fd
|
||||||
|
.get_xsave()
|
||||||
|
.map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
///
|
||||||
|
/// X86 specific call that sets the vcpu's current "xsave struct".
|
||||||
|
///
|
||||||
|
fn set_xsave(&self, xsave: &Xsave) -> cpu::Result<()> {
|
||||||
|
self.fd
|
||||||
|
.set_xsave(xsave)
|
||||||
|
.map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into()))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
///
|
///
|
||||||
/// X86 specific call that returns the vcpu's current "xcrs".
|
/// X86 specific call that returns the vcpu's current "xcrs".
|
||||||
@@ -1511,13 +1307,11 @@ impl MshvVcpu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
struct MshvEmulatorContext<'a> {
|
struct MshvEmulatorContext<'a> {
|
||||||
vcpu: &'a MshvVcpu,
|
vcpu: &'a MshvVcpu,
|
||||||
map: (u64, u64), // Initial GVA to GPA mapping provided by the hypervisor
|
map: (u64, u64), // Initial GVA to GPA mapping provided by the hypervisor
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
impl<'a> MshvEmulatorContext<'a> {
|
impl<'a> MshvEmulatorContext<'a> {
|
||||||
// Do the actual gva -> gpa translation
|
// Do the actual gva -> gpa translation
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
@@ -1541,7 +1335,6 @@ impl<'a> MshvEmulatorContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
/// Platform emulation for Hyper-V
|
/// Platform emulation for Hyper-V
|
||||||
impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
|
impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
|
||||||
type CpuState = EmulatorCpuState;
|
type CpuState = EmulatorCpuState;
|
||||||
@@ -1642,11 +1435,8 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
|
|||||||
/// Wrapper over Mshv VM ioctls.
|
/// Wrapper over Mshv VM ioctls.
|
||||||
pub struct MshvVm {
|
pub struct MshvVm {
|
||||||
fd: Arc<VmFd>,
|
fd: Arc<VmFd>,
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
msrs: Vec<MsrEntry>,
|
msrs: Vec<MsrEntry>,
|
||||||
dirty_log_slots: Arc<RwLock<HashMap<u64, MshvDirtyLogSlot>>>,
|
dirty_log_slots: Arc<RwLock<HashMap<u64, MshvDirtyLogSlot>>>,
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
sev_snp_enabled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MshvVm {
|
impl MshvVm {
|
||||||
@@ -1741,11 +1531,10 @@ impl vm::Vm for MshvVm {
|
|||||||
let vcpu = MshvVcpu {
|
let vcpu = MshvVcpu {
|
||||||
fd: vcpu_fd,
|
fd: vcpu_fd,
|
||||||
vp_index: id,
|
vp_index: id,
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
cpuid: Vec::new(),
|
cpuid: Vec::new(),
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
msrs: self.msrs.clone(),
|
msrs: self.msrs.clone(),
|
||||||
vm_ops,
|
vm_ops,
|
||||||
|
#[cfg(feature = "sev_snp")]
|
||||||
vm_fd: self.fd.clone(),
|
vm_fd: self.fd.clone(),
|
||||||
};
|
};
|
||||||
Ok(Arc::new(vcpu))
|
Ok(Arc::new(vcpu))
|
||||||
@@ -1767,11 +1556,6 @@ impl vm::Vm for MshvVm {
|
|||||||
addr: &IoEventAddress,
|
addr: &IoEventAddress,
|
||||||
datamatch: Option<DataMatch>,
|
datamatch: Option<DataMatch>,
|
||||||
) -> vm::Result<()> {
|
) -> vm::Result<()> {
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
if self.sev_snp_enabled {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let addr = &mshv_ioctls::IoEventAddress::from(*addr);
|
let addr = &mshv_ioctls::IoEventAddress::from(*addr);
|
||||||
debug!(
|
debug!(
|
||||||
"register_ioevent fd {} addr {:x?} datamatch {:?}",
|
"register_ioevent fd {} addr {:x?} datamatch {:?}",
|
||||||
@@ -1799,11 +1583,6 @@ impl vm::Vm for MshvVm {
|
|||||||
|
|
||||||
/// Unregister an event from a certain address it has been previously registered to.
|
/// Unregister an event from a certain address it has been previously registered to.
|
||||||
fn unregister_ioevent(&self, fd: &EventFd, addr: &IoEventAddress) -> vm::Result<()> {
|
fn unregister_ioevent(&self, fd: &EventFd, addr: &IoEventAddress) -> vm::Result<()> {
|
||||||
#[cfg(feature = "sev_snp")]
|
|
||||||
if self.sev_snp_enabled {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let addr = &mshv_ioctls::IoEventAddress::from(*addr);
|
let addr = &mshv_ioctls::IoEventAddress::from(*addr);
|
||||||
debug!("unregister_ioevent fd {} addr {:x?}", fd.as_raw_fd(), addr);
|
debug!("unregister_ioevent fd {} addr {:x?}", fd.as_raw_fd(), addr);
|
||||||
|
|
||||||
@@ -1856,7 +1635,7 @@ impl vm::Vm for MshvVm {
|
|||||||
readonly: bool,
|
readonly: bool,
|
||||||
_log_dirty_pages: bool,
|
_log_dirty_pages: bool,
|
||||||
) -> UserMemoryRegion {
|
) -> UserMemoryRegion {
|
||||||
let mut flags = HV_MAP_GPA_READABLE | HV_MAP_GPA_EXECUTABLE | HV_MAP_GPA_ADJUSTABLE;
|
let mut flags = HV_MAP_GPA_READABLE | HV_MAP_GPA_EXECUTABLE;
|
||||||
if !readonly {
|
if !readonly {
|
||||||
flags |= HV_MAP_GPA_WRITABLE;
|
flags |= HV_MAP_GPA_WRITABLE;
|
||||||
}
|
}
|
||||||
@@ -1971,23 +1750,13 @@ impl vm::Vm for MshvVm {
|
|||||||
/// Retrieve guest clock.
|
/// Retrieve guest clock.
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn get_clock(&self) -> vm::Result<ClockData> {
|
fn get_clock(&self) -> vm::Result<ClockData> {
|
||||||
let val = self
|
Ok(ClockData::Mshv)
|
||||||
.fd
|
|
||||||
.get_partition_property(hv_partition_property_code_HV_PARTITION_PROPERTY_REFERENCE_TIME)
|
|
||||||
.map_err(|e| vm::HypervisorVmError::GetClock(e.into()))?;
|
|
||||||
Ok(MshvClockData { ref_time: val }.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set guest clock.
|
/// Set guest clock.
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn set_clock(&self, data: &ClockData) -> vm::Result<()> {
|
fn set_clock(&self, _data: &ClockData) -> vm::Result<()> {
|
||||||
let data: MshvClockData = (*data).into();
|
Ok(())
|
||||||
self.fd
|
|
||||||
.set_partition_property(
|
|
||||||
hv_partition_property_code_HV_PARTITION_PROPERTY_REFERENCE_TIME,
|
|
||||||
data.ref_time,
|
|
||||||
)
|
|
||||||
.map_err(|e| vm::HypervisorVmError::SetClock(e.into()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Downcast to the underlying MshvVm type
|
/// Downcast to the underlying MshvVm type
|
||||||
@@ -2045,7 +1814,7 @@ impl vm::Vm for MshvVm {
|
|||||||
fn complete_isolated_import(
|
fn complete_isolated_import(
|
||||||
&self,
|
&self,
|
||||||
snp_id_block: IGVM_VHS_SNP_ID_BLOCK,
|
snp_id_block: IGVM_VHS_SNP_ID_BLOCK,
|
||||||
host_data: [u8; 32],
|
host_data: &[u8],
|
||||||
id_block_enabled: u8,
|
id_block_enabled: u8,
|
||||||
) -> vm::Result<()> {
|
) -> vm::Result<()> {
|
||||||
let mut auth_info = hv_snp_id_auth_info {
|
let mut auth_info = hv_snp_id_auth_info {
|
||||||
@@ -2078,7 +1847,7 @@ impl vm::Vm for MshvVm {
|
|||||||
policy: get_default_snp_guest_policy(),
|
policy: get_default_snp_guest_policy(),
|
||||||
},
|
},
|
||||||
id_auth_info: auth_info,
|
id_auth_info: auth_info,
|
||||||
host_data,
|
host_data: host_data[0..32].try_into().unwrap(),
|
||||||
id_block_enabled,
|
id_block_enabled,
|
||||||
author_key_enabled: 0,
|
author_key_enabled: 0,
|
||||||
},
|
},
|
||||||
@@ -2088,46 +1857,4 @@ impl vm::Vm for MshvVm {
|
|||||||
.complete_isolated_import(&data)
|
.complete_isolated_import(&data)
|
||||||
.map_err(|e| vm::HypervisorVmError::CompleteIsolatedImport(e.into()))
|
.map_err(|e| vm::HypervisorVmError::CompleteIsolatedImport(e.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn create_vgic(&self, config: VgicConfig) -> vm::Result<Arc<Mutex<dyn Vgic>>> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
|
||||||
fn get_preferred_target(&self, kvi: &mut VcpuInit) -> vm::Result<()> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Pause the VM
|
|
||||||
fn pause(&self) -> vm::Result<()> {
|
|
||||||
// Freeze the partition
|
|
||||||
self.fd
|
|
||||||
.set_partition_property(
|
|
||||||
hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE,
|
|
||||||
1u64,
|
|
||||||
)
|
|
||||||
.map_err(|e| {
|
|
||||||
vm::HypervisorVmError::SetVmProperty(anyhow!(
|
|
||||||
"Failed to set partition property: {}",
|
|
||||||
e
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resume the VM
|
|
||||||
fn resume(&self) -> vm::Result<()> {
|
|
||||||
// Resuming the partition using TIME_FREEZE property
|
|
||||||
self.fd
|
|
||||||
.set_partition_property(
|
|
||||||
hv_partition_property_code_HV_PARTITION_PROPERTY_TIME_FREEZE,
|
|
||||||
0u64,
|
|
||||||
)
|
|
||||||
.map_err(|e| {
|
|
||||||
vm::HypervisorVmError::SetVmProperty(anyhow!(
|
|
||||||
"Failed to set partition property: {}",
|
|
||||||
e
|
|
||||||
))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ use std::fmt;
|
|||||||
///
|
///
|
||||||
pub use {
|
pub use {
|
||||||
mshv_bindings::hv_cpuid_entry, mshv_bindings::mshv_user_mem_region as MemoryRegion,
|
mshv_bindings::hv_cpuid_entry, mshv_bindings::mshv_user_mem_region as MemoryRegion,
|
||||||
mshv_bindings::msr_entry, mshv_bindings::AllVpStateComponents, mshv_bindings::CpuId,
|
mshv_bindings::msr_entry, mshv_bindings::CpuId, mshv_bindings::DebugRegisters,
|
||||||
mshv_bindings::DebugRegisters, mshv_bindings::FloatingPointUnit,
|
mshv_bindings::FloatingPointUnit, mshv_bindings::LapicState as MshvLapicState,
|
||||||
mshv_bindings::LapicState as MshvLapicState, mshv_bindings::MiscRegs as MiscRegisters,
|
mshv_bindings::MiscRegs as MiscRegisters, mshv_bindings::MsrList,
|
||||||
mshv_bindings::MsrList, mshv_bindings::Msrs as MsrEntries, mshv_bindings::Msrs,
|
mshv_bindings::Msrs as MsrEntries, mshv_bindings::Msrs,
|
||||||
mshv_bindings::SegmentRegister as MshvSegmentRegister,
|
mshv_bindings::SegmentRegister as MshvSegmentRegister,
|
||||||
mshv_bindings::SpecialRegisters as MshvSpecialRegisters,
|
mshv_bindings::SpecialRegisters as MshvSpecialRegisters,
|
||||||
mshv_bindings::StandardRegisters as MshvStandardRegisters, mshv_bindings::SuspendRegisters,
|
mshv_bindings::StandardRegisters as MshvStandardRegisters, mshv_bindings::SuspendRegisters,
|
||||||
@@ -38,14 +38,10 @@ pub struct VcpuMshvState {
|
|||||||
pub sregs: MshvSpecialRegisters,
|
pub sregs: MshvSpecialRegisters,
|
||||||
pub fpu: FpuState,
|
pub fpu: FpuState,
|
||||||
pub xcrs: ExtendedControlRegisters,
|
pub xcrs: ExtendedControlRegisters,
|
||||||
|
pub lapic: LapicState,
|
||||||
pub dbg: DebugRegisters,
|
pub dbg: DebugRegisters,
|
||||||
|
pub xsave: Xsave,
|
||||||
pub misc: MiscRegisters,
|
pub misc: MiscRegisters,
|
||||||
pub vp_states: AllVpStateComponents,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
|
|
||||||
pub struct MshvClockData {
|
|
||||||
pub ref_time: u64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for VcpuMshvState {
|
impl fmt::Display for VcpuMshvState {
|
||||||
@@ -57,7 +53,7 @@ impl fmt::Display for VcpuMshvState {
|
|||||||
msr_entries[i][1] = entry.data;
|
msr_entries[i][1] = entry.data;
|
||||||
msr_entries[i][0] = entry.index as u64;
|
msr_entries[i][0] = entry.index as u64;
|
||||||
}
|
}
|
||||||
write!(f, "Number of MSRs: {}: MSRs: {:#010X?}, -- VCPU Events: {:?} -- Standard registers: {:?} Special Registers: {:?} ---- Floating Point Unit: {:?} --- Extended Control Register: {:?} --- DBG: {:?} --- VP States: {:?}",
|
write!(f, "Number of MSRs: {}: MSRs: {:#010X?}, -- VCPU Events: {:?} -- Standard registers: {:?} Special Registers: {:?} ---- Floating Point Unit: {:?} --- Extended Control Register: {:?} --- Local APIC: {:?} --- DBG: {:?} --- Xsave: {:?}",
|
||||||
msr_entries.len(),
|
msr_entries.len(),
|
||||||
msr_entries,
|
msr_entries,
|
||||||
self.vcpu_events,
|
self.vcpu_events,
|
||||||
@@ -65,8 +61,9 @@ impl fmt::Display for VcpuMshvState {
|
|||||||
self.sregs,
|
self.sregs,
|
||||||
self.fpu,
|
self.fpu,
|
||||||
self.xcrs,
|
self.xcrs,
|
||||||
|
self.lapic,
|
||||||
self.dbg,
|
self.dbg,
|
||||||
self.vp_states,
|
self.xsave,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ pub enum HypervisorVmError {
|
|||||||
/// Assert virtual interrupt error
|
/// Assert virtual interrupt error
|
||||||
///
|
///
|
||||||
#[error("Failed to assert virtual Interrupt: {0}")]
|
#[error("Failed to assert virtual Interrupt: {0}")]
|
||||||
AssertVirtualInterrupt(#[source] anyhow::Error),
|
AsserttVirtualInterrupt(#[source] anyhow::Error),
|
||||||
|
|
||||||
#[cfg(feature = "sev_snp")]
|
#[cfg(feature = "sev_snp")]
|
||||||
///
|
///
|
||||||
@@ -231,10 +231,6 @@ pub enum HypervisorVmError {
|
|||||||
///
|
///
|
||||||
#[error("Failed to complete isolated import: {0}")]
|
#[error("Failed to complete isolated import: {0}")]
|
||||||
CompleteIsolatedImport(#[source] anyhow::Error),
|
CompleteIsolatedImport(#[source] anyhow::Error),
|
||||||
/// Failed to set VM property
|
|
||||||
///
|
|
||||||
#[error("Failed to set VM property: {0}")]
|
|
||||||
SetVmProperty(#[source] anyhow::Error),
|
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
/// Result type for returning from a function
|
/// Result type for returning from a function
|
||||||
@@ -389,21 +385,11 @@ pub trait Vm: Send + Sync + Any {
|
|||||||
fn complete_isolated_import(
|
fn complete_isolated_import(
|
||||||
&self,
|
&self,
|
||||||
_snp_id_block: IGVM_VHS_SNP_ID_BLOCK,
|
_snp_id_block: IGVM_VHS_SNP_ID_BLOCK,
|
||||||
_host_data: [u8; 32],
|
_host_data: &[u8],
|
||||||
_id_block_enabled: u8,
|
_id_block_enabled: u8,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pause the VM
|
|
||||||
fn pause(&self) -> Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resume the VM
|
|
||||||
fn resume(&self) -> Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait VmOps: Send + Sync {
|
pub trait VmOps: Send + Sync {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Chromium OS Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "net_gen"
|
name = "net_gen"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Chromium OS Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright TUNTAP, 2017 The Chromium OS Authors. All rights reserved.
|
// Copyright TUNTAP, 2017 The Chromium OS Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the THIRD-PARTY file.
|
// found in the THIRD-PARTY file.
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
||||||
|
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
[package]
|
[package]
|
||||||
authors = ["The Chromium OS Authors"]
|
|
||||||
edition = "2021"
|
|
||||||
name = "net_util"
|
name = "net_util"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["The Chromium OS Authors"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
epoll = "4.3.3"
|
epoll = "4.3.3"
|
||||||
getrandom = "0.2.14"
|
getrandom = "0.2.10"
|
||||||
libc = "0.2.153"
|
libc = "0.2.147"
|
||||||
log = "0.4.21"
|
log = "0.4.20"
|
||||||
net_gen = { path = "../net_gen" }
|
net_gen = { path = "../net_gen" }
|
||||||
rate_limiter = { path = "../rate_limiter" }
|
rate_limiter = { path = "../rate_limiter" }
|
||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = "1.0.168"
|
||||||
thiserror = "1.0.60"
|
thiserror = "1.0.52"
|
||||||
virtio-bindings = "0.2.2"
|
versionize = "0.2.0"
|
||||||
virtio-queue = "0.12.0"
|
versionize_derive = "0.1.6"
|
||||||
vm-memory = { version = "0.14.1", features = [
|
virtio-bindings = "0.2.0"
|
||||||
"backend-atomic",
|
virtio-queue = "0.11.0"
|
||||||
"backend-bitmap",
|
vm-memory = { version = "0.14.0", features = ["backend-mmap", "backend-atomic", "backend-bitmap"] }
|
||||||
"backend-mmap",
|
|
||||||
] }
|
|
||||||
vm-virtio = { path = "../vm-virtio" }
|
vm-virtio = { path = "../vm-virtio" }
|
||||||
vmm-sys-util = "0.12.1"
|
vmm-sys-util = "0.12.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.18.0"
|
||||||
pnet = "0.34.0"
|
pnet = "0.34.0"
|
||||||
pnet_datalink = "0.34.0"
|
pnet_datalink = "0.34.0"
|
||||||
serde_json = "1.0.115"
|
serde_json = "1.0.107"
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
// Copyright © 2024 Intel Corporation
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
//
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
println!("cargo::rustc-check-cfg=cfg(fuzzing)");
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user