Skip to content

Conversation

mayank-microsoft
Copy link

@mayank-microsoft mayank-microsoft commented Apr 21, 2025

OpenTMK framework for testing guest-based scenarios with a HCL.

feat: opentmk init

feat: opentmk init

feat: opentmk init

feat: opentmk init

feat: opentmk init

feat: opentmk init

feat: init 1

feat: init 2

feat: init 1

feat: opentmk

feat: opentmk init 3

feat: opentmk init 4

feat: opentmk init 4
edition.workspace = true
rust-version.workspace = true

[dependencies]
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you'll have to.

/// 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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I need to remove this.

@@ -0,0 +1,4 @@
imports_granularity = "Item" # Expands `use foo::{bar, baz};` into separate `use` lines
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

@mayank-microsoft mayank-microsoft Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this before checking in. These options are not stable.

Copy link
Contributor

@smalis-msft smalis-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking great. There's a lot of cleanups needed, but I absolutely love how the tests themselves look.

/// Returns Ok(()) if successful, Err(SendError) if all receivers have been dropped
pub fn send(&self, value: T) -> Result<(), SendError<T>> {
// Check if there are any receivers left
if self.inner.receivers.load(Ordering::SeqCst) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

John would know better than me, but is SeqCst needed for all these atomic operations? It does have some overhead, though I suppose if this is a test-only crate that's not a big deal

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently thinking of it as a test crate we can probably improve on it.


//! TPM 2.0 Protocol types, as defined in the spec

//! NOTE: once the `tpm-rs` project matures, this hand-rolled code should be *deleted* and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't duplicate all of this code. If we can't depend on the tpm crate here we should just move this file to a new tpm_defs or tpm_proto crate that can be shared.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that makes sense, but we need some changes to work with no std. I want to do that with a lower priority. Lets get the other changes approved and then I can take this change up?

}

/// Call before jumping to kernel.
pub fn uninitialize() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need uninitialize? Do we ever call it and/or jump to an OS kernel?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just for sanity if we do need to uninit the hypercall pages.

@mayank-microsoft mayank-microsoft requested a review from a team as a code owner September 8, 2025 07:14
@chris-oo
Copy link
Member

please add more to the description of the change - rationale, design, etc.

Copy link
Member

@chris-oo chris-oo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review much of the PR, but i'm missing a lot of design rational and why we have chosen to make the choices we have. Are we adding a writeup on the structure here and what we're doing?

There are many cases where we need to split the unsafe code into smaller chunks as well.

@@ -0,0 +1,286 @@
#![no_std]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there really no off-the-shelf crate that does what we want?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially we had a requirement where we wanted to peek into the queue (peek and then insert back, so I had implemented the lib) we no longer depend on that. But I am not really aware of any blocking channel implementation for no_std. I am open to changing this if you are aware of something.

@@ -0,0 +1,286 @@
#![no_std]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing module header, comments, forbid(unsafe_code)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing unittests


/// An unbounded channel implementation with priority send capability.
/// This implementation works in no_std environments using spin-rs.
/// It uses a VecDeque as the underlying buffer and provides blocking and non-blocking interfaces.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see any indication any methods actually block - this is stale? or what's the actual design here?

"vm/vmgs/vmgs_lib",
"vm/vmgs/vmgstool",
# opentmk
"opentmk/",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the trailing slash mean here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove that. It doesn't mean anything.

windows = "0.59"
windows-service = "0.7"
windows-sys = "0.52"
x86_64 = { version = "0.15.2", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are we getting from this dep that we don't already have in x86defs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use x86_64 heavily for interrupt management. For the IDT structs, helpers and interrupt abi.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't live in the repo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I'll remove this before merging.

rust-version.workspace = true

[features]
default = ["nightly"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't do this - you will break everyone's rust-analyzer. Are we required to have nightly for this? why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this change got push while locally validating the changes, I'll not push the nightly feature as a dependency for default.

@@ -0,0 +1,4 @@
imports_granularity = "Item" # Expands `use foo::{bar, baz};` into separate `use` lines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this here? why are we not using the root repo's one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this, Its there for aiding the linting. Most of these are not supported on stable.

cmd: Option<Box<dyn FnOnce(&mut T)>>,
}

impl<T> VpExecutor<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executor already has a well-defined meaning in the rust ecosystem for async code. Is there another term we can use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll work on that.

@@ -0,0 +1,96 @@
use core::alloc::GlobalAlloc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard for me to reason why we have our own allocator here instead of either relying on UEFI's, or using an off the shelf crate - why?

@chris-oo
Copy link
Member

To be more explicit - I cannot review this code well until we have some documentation in the description about why we are making this change. Help answer the why and what we are doing here, so that I can give better feedback on the overall direction, and what parts need to be scrutinized more.

Without it, I can't give useful feedback. I think also this PR is much too large, and we should see if there are ways to split it up, which I can't do without some more context and rationale.

@mayank-microsoft
Copy link
Author

mayank-microsoft commented Sep 16, 2025

@chris-oo let me work on it and get back to you. I will go over the decisions we have made here and summarise the earlier discussions as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants