From b3c9856ae6862582d98376ed4940bce1be18de2a Mon Sep 17 00:00:00 2001 From: Vijay Dhanraj Date: Tue, 3 Dec 2024 12:47:59 -0800 Subject: [PATCH] dm: Add initial device model 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. Signed-off-by: Vijay Dhanraj Signed-off-by: Chuanxiao Dong --- Cargo.lock | 8 ++++++++ Cargo.toml | 3 +++ Makefile | 6 +++--- configs/all-targets.json | 3 +++ configs/hyperv-target.json | 3 +++ configs/qemu-target.json | 3 +++ configs/vanadium-target.json | 3 +++ user/dm/Cargo.toml | 11 +++++++++++ user/dm/build.rs | 4 ++++ user/dm/src/main.rs | 25 +++++++++++++++++++++++++ 10 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 user/dm/Cargo.toml create mode 100644 user/dm/build.rs create mode 100644 user/dm/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 83ebd7385..ed3189d01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -366,6 +366,14 @@ dependencies = [ "subtle", ] +[[package]] +name = "dm" +version = "0.1.0" +dependencies = [ + "syscall", + "userlib", +] + [[package]] name = "ecdsa" version = "0.16.9" diff --git a/Cargo.toml b/Cargo.toml index 75524ed4b..530afb7d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,8 @@ members = [ "user/lib", # Init user-space module "user/init", + # device model module + "user/dm", ] @@ -38,6 +40,7 @@ syscall = { path = "syscall" } packit = { path = "packit" } userlib = { path = "user/lib" } userinit = { path = "user/init" } +dm = { path = "user/dm" } # crates.io aes-gcm = { version = "0.10.3", default-features = false } diff --git a/Makefile b/Makefile index 4281eabc9..ae0cdcffc 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ bin/coconut-test-vanadium.igvm: $(IGVMBUILDER) $(IGVMMEASURE) bin/stage1-trampol $(IGVMMEASURE) --check-kvm --native-zero $@ measure test: - cargo test ${CARGO_ARGS} ${SVSM_ARGS_TEST} --workspace --exclude=user* --target=x86_64-unknown-linux-gnu + cargo test ${CARGO_ARGS} ${SVSM_ARGS_TEST} --workspace --exclude=user* --exclude=dm --target=x86_64-unknown-linux-gnu test-igvm: bin/coconut-test-qemu.igvm bin/coconut-test-hyperv.igvm bin/coconut-test-vanadium.igvm @@ -176,9 +176,9 @@ bin/svsm-test.bin: bin/stage1-test clippy: cargo clippy --workspace --all-features --exclude packit --exclude svsm-fuzz --exclude igvmbuilder --exclude igvmmeasure -- -D warnings - cargo clippy --workspace --all-features --exclude packit --exclude svsm-fuzz --exclude svsm --exclude 'user*' --target=x86_64-unknown-linux-gnu -- -D warnings + cargo clippy --workspace --all-features --exclude packit --exclude svsm-fuzz --exclude svsm --exclude 'user*' --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 --exclude packit --exclude 'user*' --tests --target=x86_64-unknown-linux-gnu -- -D warnings + cargo clippy --workspace --all-features --exclude packit --exclude 'user*' --exclude 'dm' --tests --target=x86_64-unknown-linux-gnu -- -D warnings clean: cargo clean diff --git a/configs/all-targets.json b/configs/all-targets.json index 3a4a7f820..f6983c323 100644 --- a/configs/all-targets.json +++ b/configs/all-targets.json @@ -53,6 +53,9 @@ "modules": { "userinit": { "path": "/init" + }, + "dm": { + "path": "/dm" } } } diff --git a/configs/hyperv-target.json b/configs/hyperv-target.json index 1472fef03..3b3c6f508 100644 --- a/configs/hyperv-target.json +++ b/configs/hyperv-target.json @@ -32,6 +32,9 @@ "modules": { "userinit": { "path": "/init" + }, + "dm": { + "path": "/dm" } } } diff --git a/configs/qemu-target.json b/configs/qemu-target.json index ceb60bd07..16bdd091f 100644 --- a/configs/qemu-target.json +++ b/configs/qemu-target.json @@ -34,6 +34,9 @@ "modules": { "userinit": { "path": "/init" + }, + "dm": { + "path": "/dm" } } } diff --git a/configs/vanadium-target.json b/configs/vanadium-target.json index 4a000095d..77038491e 100644 --- a/configs/vanadium-target.json +++ b/configs/vanadium-target.json @@ -35,6 +35,9 @@ "modules": { "userinit": { "path": "/init" + }, + "dm": { + "path": "/dm" } } } diff --git a/user/dm/Cargo.toml b/user/dm/Cargo.toml new file mode 100644 index 000000000..9e1baf421 --- /dev/null +++ b/user/dm/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "dm" +version = "0.1.0" +edition = "2021" + +[dependencies] +userlib.workspace = true +syscall = { path = "../../syscall" } + +[lints] +workspace = true \ No newline at end of file diff --git a/user/dm/build.rs b/user/dm/build.rs new file mode 100644 index 000000000..563023a57 --- /dev/null +++ b/user/dm/build.rs @@ -0,0 +1,4 @@ +fn main() { + println!("cargo:rustc-link-arg=-Tuser/lib/module.lds"); + println!("cargo:rustc-link-arg=-no-pie"); +} diff --git a/user/dm/src/main.rs b/user/dm/src/main.rs new file mode 100644 index 000000000..bdc29fa8f --- /dev/null +++ b/user/dm/src/main.rs @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: MIT +// +// 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 _start() -> ! { + dm_exit(); +} + +#[panic_handler] +fn panic(_info: &PanicInfo<'_>) -> ! { + dm_exit(); +}