-
Notifications
You must be signed in to change notification settings - Fork 141
feat(opentmk): opentmk framework with first testcase #1210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6d32033
351199b
3e1673e
056bf7d
6d37a84
53e0da2
7eb38ff
2d2aec4
4cd03a5
bb22270
e9fef3a
9a0ef26
e02ee17
48d300a
7bdf91f
1104901
c0f3e0a
7f33bbd
a49da94
9bdf302
fc0b866
7019671
7d70c67
43e04f0
4560aa6
d28f9c3
1b31943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ members = [ | |
"support/sparse_mmap/fuzz", | ||
"support/ucs2/fuzz", | ||
"vm/devices/chipset/fuzz", | ||
#opentmk support | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this doesn't need to be a member so long as it's a dependency used somewhere else |
||
"support/nostd_spin_channel", | ||
"vm/devices/firmware/firmware_uefi/fuzz", | ||
"vm/devices/storage/disk_nvme/nvme_driver/fuzz", | ||
"vm/devices/storage/ide/fuzz", | ||
|
@@ -42,6 +44,8 @@ members = [ | |
"vm/loader/igvmfilegen", | ||
"vm/vmgs/vmgs_lib", | ||
"vm/vmgs/vmgstool", | ||
# opentmk | ||
"opentmk/", | ||
] | ||
exclude = [ | ||
"xsync", | ||
|
@@ -374,6 +378,9 @@ vnc_worker_defs = { path = "workers/vnc_worker_defs" } | |
vnc = { path = "workers/vnc_worker/vnc" } | ||
profiler_worker = { path = "openhcl/profiler_worker" } | ||
|
||
# opentmk | ||
nostd_spin_channel = { path = "support/nostd_spin_channel"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group with the rest of the support crates |
||
|
||
# crates.io | ||
anyhow = "1.0" | ||
arbitrary = "1.3" | ||
|
@@ -445,9 +452,11 @@ jiff = "0.1" | |
kvm-bindings = "0.7" | ||
# Use of these specific REPO will go away when changes are taken upstream. | ||
landlock = "0.3.1" | ||
lazy_static = "1.4.0" | ||
libc = "0.2" | ||
libfuzzer-sys = "0.4" | ||
libtest-mimic = "0.8" | ||
linked_list_allocator = "0.10.5" | ||
linkme = "0.3.9" | ||
log = "0.4" | ||
macaddr = "1.0" | ||
|
@@ -493,6 +502,7 @@ smallbox = "0.8" | |
smallvec = "1.8" | ||
smoltcp = { version = "0.8", default-features = false } | ||
socket2 = "0.5" | ||
spin = "0.10.0" | ||
stackfuture = "0.3" | ||
static_assertions = "1.1" | ||
syn = "2" | ||
|
@@ -520,6 +530,7 @@ winapi = "0.3" | |
windows = "0.59" | ||
windows-service = "0.7" | ||
windows-sys = "0.52" | ||
x86_64 = { version = "0.15.2", default-features = false } | ||
xshell = "=0.2.2" # pin to 0.2.2 to work around https://github.com/matklad/xshell/issues/63 | ||
xshell-macros = "0.2" | ||
# We add the derive feature here since the vast majority of our crates use it. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ HYPERCALL_PAGE: | |
/// input/output pages are not being concurrently used elsewhere. For fast | ||
/// hypercalls, the caller must ensure that there are no output words so that | ||
/// there is no register corruption. | ||
#[inline(never)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I need to remove this. |
||
pub unsafe fn invoke_hypercall( | ||
control: hvdef::hypercall::Control, | ||
input_gpa_or_fast1: u64, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
[package] | ||
name = "opentmk" | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
|
||
[features] | ||
default = ["nightly"] | ||
nightly = ["x86_64-nightly"] | ||
x86_64-nightly = ["x86_64/nightly"] | ||
|
||
[dependencies] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: sort and switch to dotted syntax for crates that don't need features. Also move all crates to be workspaced. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smalis-msft There is one issue where I want to use the serde package with default features off as I want to use a no_std env. Should I disable the feature in workspace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you'll have to. |
||
arrayvec.workspace = true | ||
bitfield-struct.workspace = true | ||
cfg-if.workspace = true | ||
hvdef = {workspace = true} | ||
iced-x86 = { workspace = true, features = ["decoder", "nasm", "no_std"]} | ||
lazy_static = { workspace = true, features = ["spin_no_std"] } | ||
linked_list_allocator.workspace = true | ||
log.workspace = true | ||
memory_range.workspace = true | ||
minimal_rt.workspace = true | ||
spin.workspace = true | ||
serde = { version = "1.0", default-features = false, features = ["derive"]} | ||
serde_json = { version = "1.0", default-features = false, features = ["alloc"] } | ||
thiserror.workspace = true | ||
uefi = { workspace = true, features = ["alloc"] } | ||
x86_64 = { workspace = true, features = ["instructions"] } | ||
x86defs.workspace = true | ||
zerocopy.workspace = true | ||
nostd_spin_channel.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[build-dependencies] | ||
minimal_rt_build.workspace = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# OpenTMK | ||
|
||
See the guide for more info on how to build/run the code in this crate. | ||
smalis-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RUST_BACKTRACE=1 CARGO_PROFILE_RELEASE_force_frame_pointers=yes cargo build -p opentmk --target x86_64-unknown-uefi --release #--target-dir ./target/x86_64-unknown-uefi/debug | ||
cargo xtask guest-test uefi --bootx64 ~/projects-local/openvmm/target/x86_64-unknown-uefi/release/opentmk.efi | ||
qemu-img convert -f raw -O vhdx ~/projects-local/openvmm/target/x86_64-unknown-uefi/release/opentmk.img ~/projects/opentmk.vhdx | ||
#CARGO_PROFILE_RELEASE_OPT_LEVEL=0 | ||
#+nightly-2025-05-09 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
imports_granularity = "Item" # Expands `use foo::{bar, baz};` into separate `use` lines | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will need to go away, although if these options are stabilized they could move to our root rustfmt.toml. |
||
reorder_imports = true # Optional: sort imports | ||
normalize_imports = true # Optional: standardize style (e.g., remove leading ::) | ||
group_imports = "StdExternalCrate" # Optional: group std/external/local with blank lines |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/// Writes a synthehtic register to tell the hypervisor the OS ID. | ||
fn report_os_id(guest_os_id: u64) { | ||
// On ARM64, to be able to make hypercalls, one needs first to set the Guest OS ID | ||
// synthetic register using a hypercall. Can't use `Hvcall::set_register` at that will | ||
// lead to the infinite recursion as that function will first try initializing hypercalls | ||
// with setting a register. | ||
// | ||
// Only one very specific HvSetVpRegisters hypercall is allowed to set the Guest OS ID | ||
// (this is TLFS section 17.4.4.1.1 and 5.3), and that must be the fast hypercall. | ||
let _ = minimal_rt::arch::hypercall::set_register_fast( | ||
hvdef::HvArm64RegisterName::GuestOsId.into(), | ||
guest_os_id.into(), | ||
); | ||
} | ||
|
||
pub(crate) fn initialize(guest_os_id: u64) { | ||
// We are assuming we are running under a Microsoft hypervisor. | ||
report_os_id(guest_os_id); | ||
} | ||
|
||
/// Call before jumping to kernel. | ||
pub(crate) fn uninitialize() { | ||
report_os_id(0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod serial; | ||
|
||
pub mod hypercall; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we unify on the same version of spin that lazy_static is pulling in, so we only have the one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will work on versioning and package related changes as I resolve the merge conflicts.