Skip to content

Commit 113a694

Browse files
committed
Merge branch 'main' into add-dd-test
2 parents e467423 + e850033 commit 113a694

File tree

6 files changed

+98
-11
lines changed

6 files changed

+98
-11
lines changed

openvmm/hvlite_helpers/src/underhill.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use get_resources::ged::GuestServicingFlags;
99
use hvlite_defs::rpc::VmRpc;
1010
use mesh::rpc::RpcSend;
1111

12-
/// Replace the running version of Underhill.
13-
pub async fn service_underhill(
12+
/// Save the running state of Underhill and stage the new version.
13+
pub async fn save_underhill(
1414
vm_send: &mesh::Sender<VmRpc>,
1515
send: &mesh::Sender<GuestEmulationRequest>,
1616
flags: GuestServicingFlags,
@@ -37,9 +37,16 @@ pub async fn service_underhill(
3737
// Clear the staged IGVM file.
3838
tracing::debug!(?r, "save state failed, clearing staged IGVM file");
3939
let _ = vm_send.call(VmRpc::CompleteReloadIgvm, false).await;
40-
return r;
4140
}
4241

42+
r
43+
}
44+
45+
/// Restore Underhill from a previously saved state. This should always be called after save_underhill.
46+
pub async fn restore_underhill(
47+
vm_send: &mesh::Sender<VmRpc>,
48+
send: &mesh::Sender<GuestEmulationRequest>,
49+
) -> anyhow::Result<()> {
4350
// Reload the IGVM file and reset VTL2 state.
4451
tracing::debug!("reloading IGVM file");
4552
vm_send

openvmm/openvmm_entry/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2798,13 +2798,18 @@ async fn run_control(driver: &DefaultDriver, mesh: &VmmMesh, opt: Options) -> an
27982798
let path = igvm.context("no igvm file loaded")?;
27992799
let file = fs_err::File::open(path)?;
28002800
start = Instant::now();
2801-
hvlite_helpers::underhill::service_underhill(
2801+
hvlite_helpers::underhill::save_underhill(
28022802
&vm_rpc,
28032803
ged_rpc.as_ref().context("no GED")?,
28042804
GuestServicingFlags::default(),
28052805
file.into(),
28062806
)
28072807
.await?;
2808+
hvlite_helpers::underhill::restore_underhill(
2809+
&vm_rpc,
2810+
ged_rpc.as_ref().context("no GED")?,
2811+
)
2812+
.await?;
28082813
}
28092814
let end = Instant::now();
28102815
Ok(end - start)

petri/src/vm/hyperv/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ impl PetriVmRuntime for HyperVPetriRuntime {
537537
self.vm.restart_openhcl(flags).await
538538
}
539539

540+
async fn save_openhcl(
541+
&mut self,
542+
_new_openhcl: &ResolvedArtifact,
543+
_flags: OpenHclServicingFlags,
544+
) -> anyhow::Result<()> {
545+
anyhow::bail!("saving OpenHCL firmware separately is not yet supported on Hyper-V");
546+
}
547+
548+
async fn restore_openhcl(&mut self) -> anyhow::Result<()> {
549+
anyhow::bail!("restoring OpenHCL firmware separately is not yet supported on Hyper-V");
550+
}
551+
540552
fn take_framebuffer_access(&mut self) -> Option<vm::HyperVFramebufferAccess> {
541553
(!self.is_isolated).then(|| self.vm.get_framebuffer_access())
542554
}

petri/src/vm/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,22 @@ impl<T: PetriVmmBackend> PetriVm<T> {
835835
.await
836836
}
837837

838+
/// Instruct the OpenHCL to save the state of the VTL2 paravisor. Will fail if the VM
839+
/// is not running OpenHCL. Will also fail if the VM is not running of if this is called twice in succession
840+
pub async fn save_openhcl(
841+
&mut self,
842+
new_openhcl: ResolvedArtifact<impl IsOpenhclIgvm>,
843+
flags: OpenHclServicingFlags,
844+
) -> anyhow::Result<()> {
845+
self.runtime.save_openhcl(&new_openhcl.erase(), flags).await
846+
}
847+
848+
/// Instruct the OpenHCL to restore the state of the VTL2 paravisor. Will fail if the VM
849+
/// is not running OpenHCL. Will also fail if the VM is running of if this is called without prior save
850+
pub async fn restore_openhcl(&mut self) -> anyhow::Result<()> {
851+
self.runtime.restore_openhcl().await
852+
}
853+
838854
/// Get VM's guest OS flavor
839855
pub fn arch(&self) -> MachineArch {
840856
self.arch
@@ -926,6 +942,17 @@ pub trait PetriVmRuntime: Send + Sync + 'static {
926942
new_openhcl: &ResolvedArtifact,
927943
flags: OpenHclServicingFlags,
928944
) -> anyhow::Result<()>;
945+
/// Instruct the OpenHCL to save the state of the VTL2 paravisor. Will fail if the VM
946+
/// is not running OpenHCL. Will also fail if the VM is not running or if this is called twice in succession
947+
/// without a call to `restore_openhcl`.
948+
async fn save_openhcl(
949+
&mut self,
950+
new_openhcl: &ResolvedArtifact,
951+
flags: OpenHclServicingFlags,
952+
) -> anyhow::Result<()>;
953+
/// Instruct the OpenHCL to restore the state of the VTL2 paravisor. Will fail if the VM
954+
/// is not running OpenHCL. Will also fail if the VM is running or if this is called without prior save.
955+
async fn restore_openhcl(&mut self) -> anyhow::Result<()>;
929956
/// If the backend supports it, get an inspect interface
930957
fn inspector(&self) -> Option<Self::VmInspector> {
931958
None

petri/src/vm/openvmm/runtime.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,20 @@ impl PetriVmRuntime for PetriVmOpenVmm {
130130
new_openhcl: &ResolvedArtifact,
131131
flags: OpenHclServicingFlags,
132132
) -> anyhow::Result<()> {
133-
Self::restart_openhcl(self, new_openhcl, flags).await
133+
Self::save_openhcl(self, new_openhcl, flags).await?;
134+
Self::restore_openhcl(self).await
135+
}
136+
137+
async fn save_openhcl(
138+
&mut self,
139+
new_openhcl: &ResolvedArtifact,
140+
flags: OpenHclServicingFlags,
141+
) -> anyhow::Result<()> {
142+
Self::save_openhcl(self, new_openhcl, flags).await
143+
}
144+
145+
async fn restore_openhcl(&mut self) -> anyhow::Result<()> {
146+
Self::restore_openhcl(self).await
134147
}
135148

136149
fn inspector(&self) -> Option<OpenVmmInspector> {
@@ -212,13 +225,19 @@ impl PetriVmOpenVmm {
212225
pub async fn wait_for_kvp(&mut self) -> anyhow::Result<mesh::Sender<hyperv_ic_resources::kvp::KvpRpc>>
213226
);
214227
petri_vm_fn!(
215-
/// Restarts OpenHCL.
216-
pub async fn restart_openhcl(
228+
/// Stages the new OpenHCL file and saves the existing state.
229+
pub async fn save_openhcl(
217230
&mut self,
218231
new_openhcl: &ResolvedArtifact,
219232
flags: OpenHclServicingFlags
220233
) -> anyhow::Result<()>
221234
);
235+
petri_vm_fn!(
236+
/// Restores OpenHCL from a previously saved state.
237+
pub async fn restore_openhcl(
238+
&mut self
239+
) -> anyhow::Result<()>
240+
);
222241
petri_vm_fn!(
223242
/// Resets the hardware state of the VM, simulating a power cycle.
224243
pub async fn reset(&mut self) -> anyhow::Result<()>
@@ -369,7 +388,7 @@ impl PetriVmInner {
369388
Ok(send)
370389
}
371390

372-
async fn restart_openhcl(
391+
async fn save_openhcl(
373392
&self,
374393
new_openhcl: &ResolvedArtifact,
375394
flags: OpenHclServicingFlags,
@@ -382,10 +401,20 @@ impl PetriVmInner {
382401

383402
let igvm_file = fs_err::File::open(new_openhcl).context("failed to open igvm file")?;
384403
self.worker
385-
.restart_openhcl(ged_send, flags, igvm_file.into())
404+
.save_openhcl(ged_send, flags, igvm_file.into())
386405
.await
387406
}
388407

408+
async fn restore_openhcl(&self) -> anyhow::Result<()> {
409+
let ged_send = self
410+
.resources
411+
.ged_send
412+
.as_ref()
413+
.context("openhcl not configured")?;
414+
415+
self.worker.restore_openhcl(ged_send).await
416+
}
417+
389418
async fn modify_vtl2_settings(
390419
&mut self,
391420
f: impl FnOnce(&mut Vtl2Settings),

petri/src/worker.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ impl Worker {
5858
self.rpc.call_failable(VmRpc::PulseSaveRestore, ()).await
5959
}
6060

61-
pub(crate) async fn restart_openhcl(
61+
pub(crate) async fn save_openhcl(
6262
&self,
6363
send: &mesh::Sender<get_resources::ged::GuestEmulationRequest>,
6464
flags: OpenHclServicingFlags,
6565
file: std::fs::File,
6666
) -> anyhow::Result<()> {
67-
hvlite_helpers::underhill::service_underhill(
67+
hvlite_helpers::underhill::save_underhill(
6868
&self.rpc,
6969
send,
7070
GuestServicingFlags {
@@ -75,6 +75,13 @@ impl Worker {
7575
.await
7676
}
7777

78+
pub(crate) async fn restore_openhcl(
79+
&self,
80+
send: &mesh::Sender<get_resources::ged::GuestEmulationRequest>,
81+
) -> anyhow::Result<()> {
82+
hvlite_helpers::underhill::restore_underhill(&self.rpc, send).await
83+
}
84+
7885
pub(crate) async fn inspect_all(&self) -> inspect::Node {
7986
let mut inspection = inspect::inspect("", &self.handle);
8087
inspection.resolve().await;

0 commit comments

Comments
 (0)