Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vmm_core/virt_mshv/src/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ impl virt::ResetPartition for MshvPartition {
type Error = Error;

fn reset(&self) -> Result<(), Error> {
self.inner.scrub_partition()?;
self.inner.freeze_time()?;
Ok(())
}
Expand Down
22 changes: 15 additions & 7 deletions vmm_core/virt_mshv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ impl MshvPartitionInner {
&self.vps[vp_index.index() as usize]
}

fn scrub_partition(&self) -> Result<(), Error> {
const HVCALL_SCRUB_PARTITION: libc::c_ulong = 0x008d;

// SAFETY: `vmfd` is a valid MSHV partition fd. The private MSHV ABI
// exposes HvCallScrubPartition directly as an argument-less ioctl.
let ret = unsafe { libc::ioctl(self.vmfd.as_raw_fd(), HVCALL_SCRUB_PARTITION) };
Comment thread
Copilot marked this conversation as resolved.
if ret < 0 {
return Err(ErrorInner::ScrubPartition(io::Error::last_os_error()).into());
}

Ok(())
}

/// Freezes partition time. Time will remain frozen until [`thaw_time`] is
/// called (typically on the first VP run after reset).
fn freeze_time(&self) -> Result<(), Error> {
Expand Down Expand Up @@ -608,13 +621,6 @@ impl virt::Processor for MshvProcessor<'_> {
}

fn reset(&mut self) -> Result<(), impl std::error::Error + Send + Sync + 'static> {
use virt::vp::AccessVpState;

let vp_info = self.inner.vp_info;
self.access_state(Vtl::Vtl0)
.reset_all(&vp_info)
.map_err(|e| ErrorInner::ResetState(Box::new(e)))?;

self.reset_synic_state();

Ok::<(), Error>(())
Expand Down Expand Up @@ -670,6 +676,8 @@ enum ErrorInner {
GetPartitionProperty(#[source] KernelError),
#[error("failed to set partition property")]
SetPartitionProperty(#[source] KernelError),
#[error("failed to scrub partition")]
ScrubPartition(#[source] io::Error),
#[error("register access error")]
Register(#[source] KernelError),
#[cfg(guest_arch = "x86_64")]
Expand Down
2 changes: 2 additions & 0 deletions vmm_core/virt_mshv/src/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ impl virt::ResetPartition for MshvPartition {
fn reset(&self) -> Result<(), Error> {
use virt::x86::vm::AccessVmState;

self.inner.scrub_partition()?;

for irq in 0..virt::irqcon::IRQ_LINES as u8 {
self.inner.irq_routes.set_irq_route(irq, None);
}
Expand Down
Loading