From d860c4a63ee453ab5455f37ca3c60a329ed0f25e Mon Sep 17 00:00:00 2001 From: Chuanxiao Dong Date: Mon, 8 Jul 2024 15:59:04 +0800 Subject: [PATCH] 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. Signed-off-by: Chuanxiao Dong --- Cargo.lock | 7 +++++++ Cargo.toml | 2 ++ Makefile | 9 +++++++-- dm/Cargo.toml | 15 +++++++++++++++ dm/build.rs | 6 ++++++ dm/dm.lds | 21 +++++++++++++++++++++ dm/src/main.rs | 25 +++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 dm/Cargo.toml create mode 100644 dm/build.rs create mode 100644 dm/dm.lds create mode 100644 dm/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 577ea5d15..451b15fa9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -336,6 +336,13 @@ dependencies = [ "subtle", ] +[[package]] +name = "dm" +version = "0.1.0" +dependencies = [ + "syscall", +] + [[package]] name = "ecdsa" version = "0.16.9" diff --git a/Cargo.toml b/Cargo.toml index d73ea81b9..59dfac94b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,8 @@ members = [ "syscall", # init process "init", + # device model application + "dm", ] diff --git a/Makefile b/Makefile index efdb2500c..de55f8c9f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -134,7 +135,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) @@ -177,7 +182,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 diff --git a/dm/Cargo.toml b/dm/Cargo.toml new file mode 100644 index 000000000..0032aab13 --- /dev/null +++ b/dm/Cargo.toml @@ -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 diff --git a/dm/build.rs b/dm/build.rs new file mode 100644 index 000000000..298fb377f --- /dev/null +++ b/dm/build.rs @@ -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"); +} diff --git a/dm/dm.lds b/dm/dm.lds new file mode 100644 index 000000000..3b154843b --- /dev/null +++ b/dm/dm.lds @@ -0,0 +1,21 @@ +OUTPUT_ARCH(i386:x86-64) + +SECTIONS +{ + .text : { + *(.text) + *(.text.*) + } + . = ALIGN(4096); + .rodata : { *(.rodata) *(.rodata.*) } + . = ALIGN(4096); + .data : { *(.data) *(.data.*) } + . = ALIGN(4096); + .bss : { + *(.bss) *(.bss.*) + . = ALIGN(4096); + } + . = ALIGN(4096); +} + +ENTRY(dm_start) diff --git a/dm/src/main.rs b/dm/src/main.rs new file mode 100644 index 000000000..f7ea0a532 --- /dev/null +++ b/dm/src/main.rs @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 Intel Corporation. +// +// Author: Chuanxiao Dong + +#![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(); +}