Skip to content

Commit a925779

Browse files
benhillistjones60kmehtaintel
authored
vmm_tests: vmbus relay test for TDX (#1472) (#1672)
Fix for issue #1268 - Added changes to petri to be able to run test vm with vmbus relay enabled. - Implement the petri vmbus relay config for Hyper-V and OpenVMM - Added a new boot test with vmbus relay enable for TDX. Cherry-pick of #1472 --------- Co-authored-by: Trevor Jones <trevor@thjmedia.net> Co-authored-by: Kunal Mehta <100309140+kmehtaintel@users.noreply.github.com>
1 parent 6711354 commit a925779

File tree

13 files changed

+743
-605
lines changed

13 files changed

+743
-605
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,6 +5430,7 @@ dependencies = [
54305430
"petri_artifacts_core",
54315431
"petri_artifacts_vmm_test",
54325432
"pipette_client",
5433+
"powershell_builder",
54335434
"prost",
54345435
"scsidisk_resources",
54355436
"serde",
@@ -5665,6 +5666,14 @@ version = "0.2.0"
56655666
source = "registry+https://github.com/rust-lang/crates.io-index"
56665667
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
56675668

5669+
[[package]]
5670+
name = "powershell_builder"
5671+
version = "0.0.0"
5672+
dependencies = [
5673+
"guid",
5674+
"jiff",
5675+
]
5676+
56685677
[[package]]
56695678
name = "prettyplease"
56705679
version = "0.1.25"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pal_async = { path = "support/pal/pal_async" }
134134
pal_async_test = { path = "support/pal/pal_async_test" }
135135
pal_event = { path = "support/pal/pal_event" }
136136
pal_uring = { path = "support/pal/pal_uring" }
137+
powershell_builder = { path = "support/powershell_builder" }
137138
safeatomic = { path = "support/safeatomic" }
138139
serde_helpers = { path = "support/serde_helpers" }
139140
sev_guest_device = { path = "support/sev_guest_device" }

petri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mesh_worker.workspace = true
5757
mesh.workspace = true
5858
pal_async.workspace = true
5959
pal.workspace = true
60+
powershell_builder.workspace = true
6061
unix_socket.workspace = true
6162
sparse_mmap.workspace = true
6263

petri/src/vm/hyperv/hvc.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
//! Functions for interacting with Hyper-V VMs.
55
6-
use super::CommandError;
6+
use super::vm::CommandError;
77
use anyhow::Context;
88
use guid::Guid;
9-
use jiff::Timestamp;
10-
use std::ffi::OsStr;
11-
use std::process::Stdio;
129

1310
pub fn hvc_start(vmid: &Guid) -> Result<(), CommandError> {
1411
hvc_output(|cmd| cmd.arg("start").arg(vmid.to_string())).map(|_| ())
@@ -95,37 +92,7 @@ fn hvc_output(
9592
f: impl FnOnce(&mut std::process::Command) -> &mut std::process::Command,
9693
) -> Result<String, CommandError> {
9794
let mut cmd = std::process::Command::new("hvc.exe");
98-
cmd.stderr(Stdio::piped()).stdin(Stdio::null());
9995
f(&mut cmd);
10096

101-
let hvc_cmd = format!(
102-
"{} {}",
103-
cmd.get_program().to_string_lossy(),
104-
cmd.get_args()
105-
.collect::<Vec<_>>()
106-
.join(OsStr::new(" "))
107-
.to_string_lossy()
108-
);
109-
tracing::debug!(hvc_cmd, "executing hvc command");
110-
111-
let start = Timestamp::now();
112-
let output = cmd.output()?;
113-
let time_elapsed = Timestamp::now() - start;
114-
115-
let hvc_stdout = String::from_utf8_lossy(&output.stdout).to_string();
116-
let hvc_stderr = String::from_utf8_lossy(&output.stderr).to_string();
117-
tracing::debug!(
118-
hvc_cmd,
119-
hvc_stdout,
120-
hvc_stderr,
121-
"hvc command exited in {:.3}s with status {}",
122-
time_elapsed.total(jiff::Unit::Second).unwrap_or(-1.0),
123-
output.status
124-
);
125-
126-
if !output.status.success() {
127-
return Err(CommandError::Command(output.status, hvc_stderr));
128-
}
129-
130-
Ok(String::from_utf8(output.stdout)?.trim().to_owned())
97+
super::vm::run_cmd(cmd)
13198
}

petri/src/vm/hyperv/hyperv.psm1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,23 @@ function Set-VmScsiControllerTargetVtl
197197
$rasd.TargetVtl = $TargetVtl
198198
$rasd | Set-VmResourceSettings
199199
}
200+
201+
function Set-VMBusRedirect
202+
{
203+
[CmdletBinding()]
204+
Param (
205+
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
206+
[System.Object]
207+
$Vm,
208+
209+
[Parameter(Mandatory = $true)]
210+
[bool] $Enable
211+
)
212+
213+
$vssd = Get-Vssd $Vm
214+
$vssd | ForEach-Object {
215+
$_.VMBusMessageRedirection = [int]$Enable
216+
$_
217+
}
218+
Set-VmSystemSettings $vssd
219+
}

petri/src/vm/hyperv/mod.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use std::io::Write;
3838
use std::path::Path;
3939
use std::path::PathBuf;
4040
use std::time::Duration;
41-
use thiserror::Error;
4241
use vm::HyperVVM;
4342
use vmm_core_defs::HaltReason;
4443

@@ -61,6 +60,7 @@ pub struct PetriVmConfigHyperV {
6160
openhcl_igvm: Option<ResolvedArtifact>,
6261
openhcl_command_line: String,
6362
disable_frontpage: bool,
63+
vmbus_redirect: bool,
6464

6565
driver: DefaultDriver,
6666
agent_image: AgentImage,
@@ -128,6 +128,14 @@ impl PetriVmConfig for PetriVmConfigHyperV {
128128
fn with_uefi_frontpage(self: Box<Self>, enable: bool) -> Box<dyn PetriVmConfig> {
129129
Box::new(Self::with_uefi_frontpage(*self, enable))
130130
}
131+
132+
fn with_vmbus_redirect(self: Box<Self>, enable: bool) -> Box<dyn PetriVmConfig> {
133+
Box::new(Self::with_vmbus_redirect(*self, enable))
134+
}
135+
136+
fn os_flavor(&self) -> OsFlavor {
137+
self.os_flavor
138+
}
131139
}
132140

133141
/// A running VM that tests can interact with.
@@ -297,6 +305,7 @@ impl PetriVmConfigHyperV {
297305
temp_dir,
298306
log_source: params.logger.clone(),
299307
disable_frontpage: true,
308+
vmbus_redirect: false,
300309
openhcl_command_line: String::new(),
301310
})
302311
}
@@ -477,6 +486,9 @@ impl PetriVmConfigHyperV {
477486
Some(0),
478487
Some(controller_number),
479488
)?;
489+
490+
// Enable/Disable VMBusRedirect if requested in config
491+
vm.set_vmbus_redirect(self.vmbus_redirect)?;
480492
}
481493

482494
let mut log_tasks = Vec::new();
@@ -578,6 +590,12 @@ impl PetriVmConfigHyperV {
578590
self.disable_frontpage = !enable;
579591
self
580592
}
593+
594+
/// Enables VMBus relay for the VM
595+
pub fn with_vmbus_redirect(mut self, enable: bool) -> Self {
596+
self.vmbus_redirect = enable;
597+
self
598+
}
581599
}
582600

583601
impl PetriVmHyperV {
@@ -717,20 +735,6 @@ impl PetriVmHyperV {
717735
}
718736
}
719737

720-
/// Error running command
721-
#[derive(Error, Debug)]
722-
pub enum CommandError {
723-
/// failed to launch command
724-
#[error("failed to launch command")]
725-
Launch(#[from] std::io::Error),
726-
/// command exited with non-zero status
727-
#[error("command exited with non-zero status ({0}): {1}")]
728-
Command(std::process::ExitStatus, String),
729-
/// command output is not utf-8
730-
#[error("command output is not utf-8")]
731-
Utf8(#[from] std::string::FromUtf8Error),
732-
}
733-
734738
fn acl_read_for_vm(path: &Path, id: Option<guid::Guid>) -> anyhow::Result<()> {
735739
let sid_arg = format!(
736740
"NT VIRTUAL MACHINE\\{name}:R",

0 commit comments

Comments
 (0)