Skip to content

Commit

Permalink
dm: Add initial device model project
Browse files Browse the repository at this point in the history
The device model is a user mode program which manages VM's life cycles
and handles various vmexits events. The initial version just calls exit()
syscall without doing anything else.

As this is a user mode program, not sure what is the preferred way to
put this project, just put it as a sub folder in coconut-svsm and in the
workspace. If in the workspace is not preferred, this can be changed in
the future.

Co-developed-by: Vijay Dhanraj <[email protected]>
Signed-off-by: Chuanxiao Dong <[email protected]>
  • Loading branch information
cxdong authored and vijaydhanraj committed Oct 16, 2024
1 parent ea9fafd commit f3d3fd0
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings

- name: Clippy on svsm-fuzz
uses: actions-rs/cargo@v1
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ members = [
"syscall",
# init process
"init",
# device model application
"dm",
]


Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ IGVMBIN = bin/igvmbld
IGVMMEASURE = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmmeasure"
IGVMMEASUREBIN = bin/igvmmeasure
INITELF = "target/x86_64-unknown-none/${TARGET_PATH}/init"
DMELF = "target/x86_64-unknown-none/${TARGET_PATH}/dm"

RUSTDOC_OUTPUT = target/x86_64-unknown-none/doc
DOC_SITE = target/x86_64-unknown-none/site
Expand Down Expand Up @@ -140,7 +141,11 @@ bin/init: bin
cargo build --manifest-path init/Cargo.toml ${CARGO_ARGS} --bin init
objcopy -O elf64-x86-64 --strip-unneeded ${INITELF} $@

user: bin/init
bin/dm: bin
cargo build --manifest-path dm/Cargo.toml ${CARGO_ARGS} --bin dm
objcopy -O elf64-x86-64 --strip-unneeded ${DMELF} $@

user: bin/init bin/dm

${FS_BIN}: bin
ifneq ($(FS_FILE), none)
Expand Down Expand Up @@ -183,7 +188,7 @@ bin/svsm-test.bin: bin/stage1-test

clippy:
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude igvmbuilder --exclude igvmmeasure -- -D warnings
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings
RUSTFLAGS="--cfg fuzzing" cargo clippy --package svsm-fuzz --all-features --target=x86_64-unknown-linux-gnu -- -D warnings
cargo clippy --workspace --all-features --tests --target=x86_64-unknown-linux-gnu -- -D warnings

Expand Down
15 changes: 15 additions & 0 deletions dm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "dm"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "dm"
path = "src/main.rs"
test = false

[dependencies]
syscall = { path = "../syscall" }

[lints]
workspace = true
6 changes: 6 additions & 0 deletions dm/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
fn main() {
println!("cargo:rustc-link-arg-bin=dm=-nostdlib");
println!("cargo:rustc-link-arg-bin=dm=-no-pie");
println!("cargo:rustc-link-arg-bin=dm=-Tdm/dm.lds");
}
37 changes: 37 additions & 0 deletions dm/dm.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Temporary WA until p_vaddr alignment issue is fixed in our ELF parser */

OUTPUT_ARCH(i386:x86-64)

PHDRS
{
text PT_LOAD FLAGS(5); /* Read + Execute */
rodata PT_LOAD FLAGS(4); /* Read-only */
data PT_LOAD FLAGS(6); /* Read + Write */
bss PT_LOAD FLAGS(6); /* Read + Write */
}

SECTIONS
{
.text : {
*(.text)
*(.text.*)
} :text
. = ALIGN(4096);
.rodata : {
*(.rodata)
*(.rodata.*)
} :rodata
. = ALIGN(4096);
.data : {
*(.data)
*(.data.*)
} :data
. = ALIGN(4096);
.bss : {
*(.bss) *(.bss.*)
. = ALIGN(4096);
} :bss
. = ALIGN(4096);
}

ENTRY(dm_start)
25 changes: 25 additions & 0 deletions dm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2024 Intel Corporation.
//
// Author: Chuanxiao Dong <[email protected]>

#![no_std]
#![no_main]

use core::panic::PanicInfo;
use syscall::exit;

fn dm_exit() -> ! {
exit(0);
}

#[no_mangle]
pub extern "C" fn dm_start() -> ! {
dm_exit();
}

#[panic_handler]
fn panic(_info: &PanicInfo<'_>) -> ! {
dm_exit();
}

0 comments on commit f3d3fd0

Please sign in to comment.