hypervisor: add a generic guest-clock save/restore abstraction

Preserving the guest clock across pause/resume and snapshot/restore is
currently open-coded in the VMM against the x86-only
get_clock/set_clock. aarch64 needs the same correction but via a
different mechanism (i.e. the architected counter, CNTVCT). Having a
common backend-agnostic interface that VMM can drive uniformly allows us
to keep the architecture details behind the Hypervisor abstraction.

This commit only introduces the abstraction while the future commits
will actually move the implementation to use it.

Use this opportunity to fix the full path to get SystemTime as well.

Suggested-by: Sebastien Boeuf <sboeuf@meta.com>
Signed-off-by: Atish Patra <atishp@meta.com>
This commit is contained in:
Atish Patra
2026-06-11 14:51:01 -07:00
committed by Rob Bradford
parent 00edf5b34d
commit d68b93ea93
4 changed files with 56 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ use thiserror::Error;
use vmm_sys_util::eventfd::EventFd;
#[cfg(target_arch = "x86_64")]
use crate::ClockData;
use crate::{ClockData, ClockState};
#[cfg(target_arch = "aarch64")]
use crate::arch::aarch64::gic::{Vgic, VgicConfig};
#[cfg(target_arch = "riscv64")]
@@ -384,6 +384,17 @@ pub trait Vm: Send + Sync + Any {
/// Set guest clock.
#[cfg(target_arch = "x86_64")]
fn set_clock(&self, data: &ClockData) -> Result<()>;
/// Capture the guest clock for snapshot/migration while the VM is paused.
/// `Ok(None)` means this backend has no clock to preserve.
#[cfg(target_arch = "x86_64")]
fn snapshot_clock(&self) -> Result<Option<ClockState>> {
Ok(None)
}
/// Re-establish the guest clock before the vCPUs resume.
#[cfg(target_arch = "x86_64")]
fn restore_clock(&self, _state: &ClockState) -> Result<()> {
Ok(())
}
/// Create a device that is used for passthrough
fn create_passthrough_device(&self) -> Result<vfio_ioctls::VfioDeviceFd>;
/// Start logging dirty pages