snp: support SNP host data and guest requests - #4401
snp: support SNP host data and guest requests#4401Nikola Bojanic (nbojanic) wants to merge 2 commits into
Conversation
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
There was a problem hiding this comment.
🟡 Changes recommended
MSHV SNP launch completion currently becomes silently idempotent, which can mask repeated/incorrect initial-page finalization and diverges from the stricter KVM SNP behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR extends SEV-SNP support across the OpenVMM stack by (1) threading optional 32-byte SNP host data from the TTRPC VM service through the core config into the hypervisor backends (KVM/MSHV) and (2) adding MSHV handling for SNP guest requests (PSP guest request ioctl) so guests can fetch attestation reports and validate host-data binding. It also expands IGVM tooling/docs to cover restricted interrupt injection variants.
Changes:
- Add
host_dataplumbing for SNP launch-finish from TTRPC →HypervisorConfig→ IGVM SNP config → MSHV/KVM launch finish. - Implement MSHV SNP guest request handling (VMGEXIT
SVM_EXITCODE_SNP_GUEST_REQUEST) and update MSHV IGVM SNP launch handling to preserve IGVM measurement order and import an IGVM-provided VMSA mapping. - Extend IGVM generator/config/docs with restricted-injection SNP Linux-direct artifacts and update CLI/manifest docs accordingly.
File summaries
| File | Description |
|---|---|
| vmm_core/virt/src/x86/snp.rs | Add reusable helpers for SNP ID block + ID auth page construction, plus unit tests. |
| vmm_core/virt/src/generic.rs | Extend backend-neutral SnpConfig with optional 32-byte host_data. |
| vmm_core/virt_mshv/src/x86_64/snp.rs | Add prepared IGVM SNP config, preserve IGVM measurement order, add VMSA mapping/import logic, add SNP guest request handling, and expand tests. |
| vmm_core/virt_mshv/src/x86_64/mod.rs | Teach MSHV proto-partition build to pre-parse IGVM SNP config before partition build and carry it through isolation setup. |
| vmm_core/virt_mshv/src/lib.rs | Store proto-partition isolation state (including optional IGVM SNP config) instead of a single SNP CPUID-offload flag. |
| vmm_core/virt_kvm/src/snp.rs | Pass optional host_data into KVM_SEV_SNP_LAUNCH_FINISH; update SNP config test helper. |
| vm/x86/x86defs/src/snp.rs | Define zerocopy-friendly structs for the SNP PSP ID auth (ID_AUTH) page with size assertion. |
| vm/loader/manifests/snp-linux-direct-restricted.json | Add a restricted-injection SNP Linux-direct manifest profile (intended for MSHV bring-up). |
| vm/loader/manifests/README.md | Document normal vs restricted injection outputs and update example invocation. |
| vm/loader/igvmfilegen/src/snp_linux_direct.rs | Parameterize injection mode and ensure generated VMSA reflects normal vs restricted injection; add test. |
| vm/loader/igvmfilegen/src/main.rs | Allow snp_linux_direct IGVM generation with restricted injection mode (remove prior restriction). |
| vm/loader/igvmfilegen_config/src/lib.rs | Add config test coverage for parsing the new restricted SNP Linux-direct manifest. |
| petri/src/vm/openvmm/construct.rs | Initialize new HypervisorConfig::snp_host_data field in Petri config construction. |
| openvmm/openvmm_ttrpc_vmservice/src/vmservice.proto | Add IGVM boot option and IsolationConfig (including optional SNP host data) to the VM service API. |
| openvmm/openvmm_entry/src/ttrpc/mod.rs | Parse isolation + host data from TTRPC requests, enforce SNP+IGVM constraints, and populate HypervisorConfig. |
| openvmm/openvmm_entry/src/lib.rs | Initialize HypervisorConfig::snp_host_data for CLI-created configs. |
| openvmm/openvmm_defs/src/config.rs | Add HypervisorConfig::snp_host_data: Option<[u8; 32]>. |
| openvmm/openvmm_core/src/worker/vm_loaders/igvm.rs | Build SNP isolation config from IGVM metadata plus optional host-provided host data. |
| openvmm/openvmm_core/src/worker/dispatch.rs | Thread host data into IGVM SNP config build; relax a KVM SNP guest_memfd constraint around with_hv. |
| Guide/src/reference/openvmm/management/cli.md | Update SNP CLI documentation to include IGVM boot support details and a minimal MSHV IGVM example. |
Review details
Suppressed comments (1)
vmm_core/virt_mshv/src/x86_64/snp.rs:703
- Returning
Ok(())when the SNP launch state is alreadyFinishedcan mask a real loader bug: a secondaccept_initial_pagescall with non-empty pages would be silently ignored. It’s safer (and consistent with the KVM SNP path) to return an explicit error when the launch is already complete.
match *state {
SnpLaunchState::NotStarted => *state = SnpLaunchState::Started,
SnpLaunchState::Started => return Err(SnpError::LaunchInProgress.into()),
SnpLaunchState::Finished => return Ok(()),
SnpLaunchState::Failed => return Err(SnpError::LaunchFailed.into()),
- Files reviewed: 20/20 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #[error("SNP launch is already in progress")] | ||
| LaunchInProgress, | ||
| #[error("SNP launch is already complete")] | ||
| LaunchAlreadyFinished, | ||
| #[error("SNP launch previously failed")] | ||
| LaunchFailed, |
Add an IGVM boot option and an explicit isolation configuration to the VM-service API. Map SNP IGVM requests to the existing IGVM loader.
Pass optional host data from the VM-service API through the SNP launch configuration to KVM and MSHV. Handle SNP guest requests through the MSHV PSP ioctl and complete the GHCB response, allowing guests to retrieve attestation reports and verify the host data binding.
c948d92 to
207d533
Compare
There was a problem hiding this comment.
🟡 Changes recommended
It introduces a MeshPayload wire-compatibility risk in HypervisorConfig field ordering and needs stricter GHCB field validation in the new MSHV SNP guest-request handler.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 2
- Review effort level: Lite
| pub with_hv: bool, | ||
| pub with_vtl2: Option<Vtl2Config>, | ||
| pub with_isolation: Option<IsolationType>, | ||
| /// Optional host-provided data included in SNP launch finish. | ||
| pub snp_host_data: Option<[u8; 32]>, |
| if !ghcb_exit_info2_is_valid(ghcb) | ||
| || ghcb.save.sw_exit_info2 != response_gpa | ||
| || !request_gpa.is_multiple_of(hvdef::HV_PAGE_SIZE) | ||
| || !response_gpa.is_multiple_of(hvdef::HV_PAGE_SIZE) | ||
| || !self.partition.mem_layout.ram().iter().any(|range| { | ||
| range.range.contains(&MemoryRange::new(request_gpa..request_end)) | ||
| }) | ||
| || !self.partition.mem_layout.ram().iter().any(|range| { | ||
| range.range.contains(&MemoryRange::new(response_gpa..response_end)) | ||
| }) | ||
| { | ||
| return Err(VpHaltReason::TripleFault { vtl: Vtl::Vtl0 }); | ||
| } |
Pass optional SNP host data from TTRPC to MSHV/KVM.
Handle SNP guest requests using the MSHV PSP guest request ioctl, allowing guests to retrieve attestation reports and verify the host data binding.
Builds on #4361 and #4399, which should be merged first.