Skip to content

vmm: fix non_x86_64 && non-TEE memory region setup#592

Open
yzewei wants to merge 1 commit intocontainers:mainfrom
yzewei:no_tee_nonx86
Open

vmm: fix non_x86_64 && non-TEE memory region setup#592
yzewei wants to merge 1 commit intocontainers:mainfrom
yzewei:no_tee_nonx86

Conversation

@yzewei
Copy link
Copy Markdown
Contributor

@yzewei yzewei commented Mar 17, 2026

Background

In non-x86 builds that don't use TEE features, vstate.rs uses cfg!() to distinguish between TEE and non-TEE paths.

cfg!() only generates a compile-time constant; the code in the branch still participates in compilation and type checking. As a result, in a normal riscv64 build, code related to guest_memfd and memory attributes will also be flagged for errors, leading to compilation failures.

Verify CMD
cargo check -p vmm --target riscv64gc-unknown-linux-gnu

Copy link
Copy Markdown
Member

@jakecorrenti jakecorrenti left a comment

Choose a reason for hiding this comment

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

Can you populate the commit message with your PR description?

@yzewei
Copy link
Copy Markdown
Contributor Author

yzewei commented Mar 18, 2026

Can you populate the commit message with your PR description?

sure.

@yzewei yzewei requested a review from jakecorrenti March 18, 2026 02:14
@yzewei yzewei changed the title vmm: fix riscv64 non-TEE memory region setup vmm: fix nonx86_64 && non-TEE memory region setup Mar 18, 2026
@yzewei yzewei changed the title vmm: fix nonx86_64 && non-TEE memory region setup vmm: fix non_x86_64 && non-TEE memory region setup Mar 18, 2026
In non-x86 builds that don't use TEE features, vstate.rs used cfg!() to
distinguish between TEE and non-TEE memory setup paths.

cfg!() only evaluates to a compile-time constant; code in both branches
still participates in compilation and type checking. As a result, normal
riscv64 builds still type-check guest_memfd and memory attribute code,
which leads to build failures.

Refactor the memory-region setup into cfg-gated helpers so non-TEE builds
do not compile TEE-only memory setup code, and reject unsupported
TEE+architecture combinations during VM setup instead of during memory
initialization.

Verify with:
cargo check -p vmm --target riscv64gc-unknown-linux-gnu

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
Copy link
Copy Markdown
Collaborator

@dorindabassey dorindabassey left a comment

Choose a reason for hiding this comment

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

code LGTM, Thanks.

@slp
Copy link
Copy Markdown
Collaborator

slp commented Apr 13, 2026

/gemini review

Copy link
Copy Markdown
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

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

LGTM. @jakecorrenti you've requested changes, PTAAL.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors TEE (Trusted Execution Environment) support to be more architecture-specific, primarily targeting x86_64 while providing explicit error paths for other architectures. Key changes include the introduction of a TEE configuration validation step and the modularization of guest physical memory slot creation into conditional implementations. The review feedback highlights a potential scope issue with the Sender type import in fallback compilation paths and recommends replacing an unwrap() call with proper error handling during host address translation to improve the codebase's robustness.

Comment on lines +9 to 10
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
use crossbeam_channel::Sender;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The Sender type from crossbeam_channel is now only imported when both the tee feature is enabled and the target architecture is x86_64. However, Sender is used in the fallback path of match_worker_message (line 70) which is compiled when these conditions are NOT met. While the compiler might infer the type from the enum variant in some cases, it is better practice to ensure the type is in scope for all paths that use it, or import it unconditionally since Receiver is already imported unconditionally at line 8.

Suggested change
#[cfg(all(feature = "tee", target_arch = "x86_64"))]
use crossbeam_channel::Sender;
use crossbeam_channel::{Receiver, Sender};

@slp slp added the 1.x label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants