Skip to content

Commit b0c0eb6

Browse files
cxdongvijaydhanraj
authored andcommitted
dm: Add initial device model project
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]>
1 parent afcfa8d commit b0c0eb6

File tree

8 files changed

+100
-3
lines changed

8 files changed

+100
-3
lines changed

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions-rs/cargo@v1
6363
with:
6464
command: clippy
65-
args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
65+
args: --workspace --all-features --exclude svsm --exclude svsm-fuzz --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings
6666

6767
- name: Clippy on svsm-fuzz
6868
uses: actions-rs/cargo@v1

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ members = [
1616
"syscall",
1717
# init process
1818
"init",
19+
# device model application
20+
"dm",
1921
]
2022

2123

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ IGVMBIN = bin/igvmbld
4545
IGVMMEASURE = "target/x86_64-unknown-linux-gnu/${TARGET_PATH}/igvmmeasure"
4646
IGVMMEASUREBIN = bin/igvmmeasure
4747
INITELF = "target/x86_64-unknown-none/${TARGET_PATH}/init"
48+
DMELF = "target/x86_64-unknown-none/${TARGET_PATH}/dm"
4849

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

143-
user: bin/init
144+
bin/dm: bin
145+
cargo build --manifest-path dm/Cargo.toml ${CARGO_ARGS} --bin dm
146+
objcopy -O elf64-x86-64 --strip-unneeded ${DMELF} $@
147+
148+
user: bin/init bin/dm
144149

145150
${FS_BIN}: bin
146151
ifneq ($(FS_FILE), none)
@@ -183,7 +188,7 @@ bin/svsm-test.bin: bin/stage1-test
183188

184189
clippy:
185190
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude igvmbuilder --exclude igvmmeasure -- -D warnings
186-
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --target=x86_64-unknown-linux-gnu -- -D warnings
191+
cargo clippy --workspace --all-features --exclude svsm-fuzz --exclude svsm --exclude init --exclude dm --target=x86_64-unknown-linux-gnu -- -D warnings
187192
RUSTFLAGS="--cfg fuzzing" cargo clippy --package svsm-fuzz --all-features --target=x86_64-unknown-linux-gnu -- -D warnings
188193
cargo clippy --workspace --all-features --tests --target=x86_64-unknown-linux-gnu -- -D warnings
189194

dm/Cargo.toml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "dm"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "dm"
8+
path = "src/main.rs"
9+
test = false
10+
11+
[dependencies]
12+
syscall = { path = "../syscall" }
13+
14+
[lints]
15+
workspace = true

dm/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
fn main() {
3+
println!("cargo:rustc-link-arg-bin=dm=-nostdlib");
4+
println!("cargo:rustc-link-arg-bin=dm=-no-pie");
5+
println!("cargo:rustc-link-arg-bin=dm=-Tdm/dm.lds");
6+
}

dm/dm.lds

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Temporary WA until p_vaddr alignment issue is fixed in our ELF parser */
2+
3+
OUTPUT_ARCH(i386:x86-64)
4+
5+
PHDRS
6+
{
7+
text PT_LOAD FLAGS(5); /* Read + Execute */
8+
rodata PT_LOAD FLAGS(4); /* Read-only */
9+
data PT_LOAD FLAGS(6); /* Read + Write */
10+
bss PT_LOAD FLAGS(6); /* Read + Write */
11+
}
12+
13+
SECTIONS
14+
{
15+
.text : {
16+
*(.text)
17+
*(.text.*)
18+
} :text
19+
. = ALIGN(4096);
20+
.rodata : {
21+
*(.rodata)
22+
*(.rodata.*)
23+
} :rodata
24+
. = ALIGN(4096);
25+
.data : {
26+
*(.data)
27+
*(.data.*)
28+
} :data
29+
. = ALIGN(4096);
30+
.bss : {
31+
*(.bss) *(.bss.*)
32+
. = ALIGN(4096);
33+
} :bss
34+
. = ALIGN(4096);
35+
}
36+
37+
ENTRY(dm_start)

dm/src/main.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
//
3+
// Copyright (c) 2024 Intel Corporation.
4+
//
5+
// Author: Chuanxiao Dong <[email protected]>
6+
7+
#![no_std]
8+
#![no_main]
9+
10+
use core::panic::PanicInfo;
11+
use syscall::exit;
12+
13+
fn dm_exit() -> ! {
14+
exit(0);
15+
}
16+
17+
#[no_mangle]
18+
pub extern "C" fn dm_start() -> ! {
19+
dm_exit();
20+
}
21+
22+
#[panic_handler]
23+
fn panic(_info: &PanicInfo<'_>) -> ! {
24+
dm_exit();
25+
}

0 commit comments

Comments
 (0)