Skip to content

Commit db5d175

Browse files
feat(opentmk): opentmk framework with first testcase (#1210)
OpenTMK framework for testing guest-based scenarios with a HCL. The above diagram illustrates relation between abstract modules. <img width="975" height="681" alt="image" src="https://github.com/user-attachments/assets/fd35cf31-7de0-472c-8ab5-5d99591353d1" /> ### UEFI Executor Design Decisions: 1. Allocator a. The allocator today switches between UEFI Runtime Allocator and LockedHeapAllocator. b. The decision to switch between the two allocator is to allow more control over which sections of the memory map is for the heap, this is helpful so that we know we are using a memory section which will not be used by UEFI runtime services after exit boot services. Using the UEFI allocator is important so that we can allocate any object before we call main. If a panic occurs before main, we need to allocate strings in the Panic handler. UEFI allocator can’t be used after exit boot services. 2. Panic Handler a. The panic handler today logs the panic info as string using the logger module and then loops. The test driver is informed of the panic and the test driver terminates the VM. b. Improvement planned to shutdown the VM. c. Today we use our own interrupt handler, using ud2 causes an fainterrupt but that does not cause a triple fault. 3. Test Configuration Handler a. In scope for a task being tracked ### Platform Design Decisions ARM64 implementation is a placeholder and out of scope, the work is tacked by <ADO WI>. The work is mostly around implementing Interrupt handling, VP bring up (just the implementation for default context), TPM specific changes and end-to-end testing. 1. HvCall a. Platform/hyperv/arch houses all the modules which require a platform specific implementation. b. VTL calls/return need to be handled carefully, as many of the general-purpose register values are not preserved across VTL switch. The requires us to push all the values to stack before a switch and restore back when we return. We also need to handle this carefully when VTL switch happens because of secure intercepts. c. Tests which require for secure intercepts to happen must use macro: create_function_with_restore to isolate the violating function. 2. Hyper-V platform test context implementation a. Today we hardcode the value for how many VPs are present. Earlier I had tried constructing the heuristics to read the CPU topology from CPU-ID but they returned differently for Intel and AMD. I intend to use ACPI table to construct this information/take the values as input in test configuration in the next set of improvements. b. The AP bring up in start_on_vp takes care of everything related to enabling the VTLs and scheduling the VpExecutor object. Working on changing the name as suggested in the PR. This change is mostly for simplicity, for complex tests where the heuristic has to be tested for boundary testing I recommend authoring a test with direct dependency on platform and calling the hypercall interface (HvCall is a pub field in HvTestCtx) without using the generic interface of the platform traits. 3. X86_64 Interrupt Management a. We depend on the x86_64 crate to provide structure and helpers, along with x86-interrupt ABI. b. Since custom ABI is a nightly feature, we keep the feature behind the nightly feature flag. c. We are tracking a task to move to naked functions as a part of the improvements. 4. TPM a. We currently use a duplicated module of protocol module from tpm crate, we can’t depend on tpm crate since it links to openssl which we want to avoid, apart from that we we can’t readily move the protocol because of some coupling between the protocol module and the errors struct from tpm ref crate. I’ll work on decoupling the modules once we are ok with other changes in this PR. I feel it may be better to take the decoupling in a follow up PR, since there are a lot of changes in this PR, isolating the PR to not touch TPM implementation will help reduce risk of breaking anything in the TPM crate. 5. Serial Port on AMD64 a. We have a separate implementation which is building on top of minimal_rt, the major reasons are to facilitate multiple process writing logs at the same time (by implementing locks) and to write to COM1/COM2 instead of the default COM3. --------- Co-authored-by: Matt LaFayette (Kurjanowicz) <[email protected]>
1 parent c85e6e7 commit db5d175

File tree

76 files changed

+9000
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+9000
-34
lines changed

Cargo.lock

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,15 @@ dependencies = [
37693769
"escape8259",
37703770
]
37713771

3772+
[[package]]
3773+
name = "linked_list_allocator"
3774+
version = "0.10.5"
3775+
source = "registry+https://github.com/rust-lang/crates.io-index"
3776+
checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286"
3777+
dependencies = [
3778+
"spinning_top",
3779+
]
3780+
37723781
[[package]]
37733782
name = "linkme"
37743783
version = "0.3.33"
@@ -4622,6 +4631,14 @@ dependencies = [
46224631
"libc",
46234632
]
46244633

4634+
[[package]]
4635+
name = "nostd_spin_channel"
4636+
version = "0.0.0"
4637+
dependencies = [
4638+
"spin 0.10.0",
4639+
"thiserror 2.0.16",
4640+
]
4641+
46254642
[[package]]
46264643
name = "ntapi"
46274644
version = "0.4.1"
@@ -5073,6 +5090,28 @@ dependencies = [
50735090
"thiserror 2.0.16",
50745091
]
50755092

5093+
[[package]]
5094+
name = "opentmk"
5095+
version = "0.0.0"
5096+
dependencies = [
5097+
"bitfield-struct 0.11.0",
5098+
"cfg-if",
5099+
"hvdef",
5100+
"lazy_static",
5101+
"linked_list_allocator",
5102+
"log",
5103+
"memory_range",
5104+
"minimal_rt",
5105+
"nostd_spin_channel",
5106+
"serde",
5107+
"serde_json",
5108+
"spin 0.10.0",
5109+
"thiserror 2.0.16",
5110+
"uefi",
5111+
"x86_64",
5112+
"zerocopy 0.8.25",
5113+
]
5114+
50765115
[[package]]
50775116
name = "openvmm"
50785117
version = "0.0.0"
@@ -6844,6 +6883,18 @@ name = "spin"
68446883
version = "0.10.0"
68456884
source = "registry+https://github.com/rust-lang/crates.io-index"
68466885
checksum = "d5fe4ccb98d9c292d56fec89a5e07da7fc4cf0dc11e156b41793132775d3e591"
6886+
dependencies = [
6887+
"lock_api",
6888+
]
6889+
6890+
[[package]]
6891+
name = "spinning_top"
6892+
version = "0.2.5"
6893+
source = "registry+https://github.com/rust-lang/crates.io-index"
6894+
checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
6895+
dependencies = [
6896+
"lock_api",
6897+
]
68476898

68486899
[[package]]
68496900
name = "spki"
@@ -9445,6 +9496,12 @@ dependencies = [
94459496
"vmsocket",
94469497
]
94479498

9499+
[[package]]
9500+
name = "volatile"
9501+
version = "0.4.6"
9502+
source = "registry+https://github.com/rust-lang/crates.io-index"
9503+
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
9504+
94489505
[[package]]
94499506
name = "vpci"
94509507
version = "0.0.0"
@@ -10178,6 +10235,18 @@ dependencies = [
1017810235
"tap",
1017910236
]
1018010237

10238+
[[package]]
10239+
name = "x86_64"
10240+
version = "0.15.2"
10241+
source = "registry+https://github.com/rust-lang/crates.io-index"
10242+
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
10243+
dependencies = [
10244+
"bit_field",
10245+
"bitflags 2.9.3",
10246+
"rustversion",
10247+
"volatile",
10248+
]
10249+
1018110250
[[package]]
1018210251
name = "x86defs"
1018310252
version = "0.0.0"

Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ members = [
4747
"vm/loader/igvmfilegen",
4848
"vm/vmgs/vmgs_lib",
4949
"vm/vmgs/vmgstool",
50+
# opentmk
51+
"opentmk",
5052
]
5153
exclude = [
5254
"xsync",
@@ -126,6 +128,7 @@ mesh_rpc = { path = "support/mesh/mesh_rpc" }
126128
mesh_worker = { path = "support/mesh/mesh_worker" }
127129
mesh_tracing = { path = "support/mesh_tracing" }
128130
minircu = { path = "support/minircu" }
131+
nostd_spin_channel = { path = "support/nostd_spin_channel"}
129132
open_enum = { path = "support/open_enum" }
130133
openssl_kdf = { path = "support/openssl_kdf" }
131134
openssl_crypto_only = { path = "support/openssl_crypto_only" }
@@ -467,9 +470,11 @@ jiff = "0.2.14"
467470
kvm-bindings = "0.14.0"
468471
# Use of these specific REPO will go away when changes are taken upstream.
469472
landlock = "0.4.1"
473+
lazy_static = "1.4.0"
470474
libc = "0.2"
471475
libfuzzer-sys = "0.4"
472476
libtest-mimic = "0.8"
477+
linked_list_allocator = "0.10.5"
473478
linkme = "0.3.9"
474479
log = "0.4"
475480
loom = "0.7.2"
@@ -506,8 +511,8 @@ rusqlite = "0.37"
506511
rustc-hash = "2.1.1"
507512
rustyline = "17"
508513
seccompiler = "0.5"
509-
serde = "1.0.185"
510-
serde_json = "1.0"
514+
serde = { version = "1.0.185", default-features = false }
515+
serde_json = { version = "1.0", default-features = false }
511516
serde_yaml = "0.9"
512517
sha2 = { version = "0.10.8", default-features = false }
513518
shell-words = "1.1"
@@ -517,6 +522,7 @@ smallbox = "0.8"
517522
smallvec = "1.8"
518523
smoltcp = { version = "0.8", default-features = false }
519524
socket2 = "0.6"
525+
spin = "0.10.0"
520526
stackfuture = "0.3"
521527
static_assertions = "1.1"
522528
syn = "2"
@@ -544,6 +550,7 @@ windows = "0.62"
544550
windows-service = "0.8"
545551
windows-sys = "0.61"
546552
windows-version = "0.1.4"
553+
x86_64 = { version = "0.15.2", default-features = false }
547554
xshell = "=0.2.2" # pin to 0.2.2 to work around https://github.com/matklad/xshell/issues/63
548555
xshell-macros = "0.2"
549556
# We add the derive feature here since the vast majority of our crates use it.

flowey/flowey_cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ fs-err.workspace = true
1818
log.workspace = true
1919
parking_lot.workspace = true
2020
petgraph.workspace = true
21-
serde = { workspace = true, features = ["derive"] }
22-
serde_json = { workspace = true, features = ["raw_value"] }
21+
serde = { workspace = true, features = ["std", "derive"] }
22+
serde_json = { workspace = true, features = ["std", "raw_value"] }
2323
serde_yaml.workspace = true
2424
toml_edit = { workspace = true, features = ["serde"] }
2525
xshell.workspace = true

flowey/flowey_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ anyhow.workspace = true
1111
fs-err.workspace = true
1212
linkme.workspace = true
1313
serde = { workspace = true, features = ["derive"] }
14-
serde_json.workspace = true
14+
serde_json = { workspace = true, features = ["std"] }
1515
serde_yaml.workspace = true
1616

1717
[dev-dependencies]

flowey/flowey_hvlite/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ vmm_test_images = { workspace = true, features = ["serde", "clap"] }
1717
anyhow.workspace = true
1818
clap = { workspace = true, features = ["derive"] }
1919
log.workspace = true
20-
serde.workspace = true
20+
serde = { workspace = true, features = ["std"] }
2121
target-lexicon = { workspace = true, features = ["serde_support"] }
2222

2323
[lints]

flowey/flowey_lib_common/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ home.workspace = true
1616
log.workspace = true
1717
rlimit.workspace = true
1818
rustc-hash.workspace = true
19-
serde.workspace = true
20-
serde_json.workspace = true
19+
serde = { workspace = true, features = ["std"] }
20+
serde_json = { workspace = true, features = ["std"] }
2121
target-lexicon = { workspace = true, features = ["serde_support"] }
2222
toml_edit.workspace = true
2323
which.workspace = true

flowey/flowey_lib_hvlite/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ igvmfilegen_config.workspace = true
1717
anyhow.workspace = true
1818
fs-err.workspace = true
1919
log.workspace = true
20-
serde.workspace = true
21-
serde_json.workspace = true
20+
serde = { workspace = true, features = ["std"] }
21+
serde_json = { workspace = true, features = ["std"] }
2222
target-lexicon = { workspace = true, features = ["serde_support"] }
2323
which.workspace = true
2424
xshell.workspace = true

openhcl/openhcl_attestation_protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ base64.workspace = true
1818
base64-serde.workspace = true
1919
hex.workspace = true
2020
serde = { workspace = true, features = ["derive"] }
21-
serde_json.workspace = true
21+
serde_json = { workspace = true, features = ["std"] }
2222
zerocopy.workspace = true
2323

2424
[lints]

openhcl/underhill_attestation/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ base64.workspace = true
2828
base64-serde.workspace = true
2929
getrandom.workspace = true
3030
openssl.workspace = true
31-
serde.workspace = true
32-
serde_json.workspace = true
31+
serde = { workspace = true, features = ["std"] }
32+
serde_json = { workspace = true, features = ["std"] }
3333
static_assertions.workspace = true
3434
thiserror.workspace = true
3535
time = { workspace = true, features = ["macros"] }

openhcl/underhill_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ libc.workspace = true
164164
parking_lot.workspace = true
165165
serde = { workspace = true, features = ["derive"] }
166166
serde_helpers.workspace = true
167-
serde_json.workspace = true
167+
serde_json = { workspace = true, features = ["std"] }
168168
socket2.workspace = true
169169
thiserror = { workspace = true, features = ["std"] }
170170
time = { workspace = true, features = ["macros"] }

0 commit comments

Comments
 (0)