Skip to content

Commit 4827569

Browse files
committed
x86_64 support for saving and restoring kvm vcpu state
Coverage slightly decreased because kvm api errors cannot be covered. Signed-off-by: Adrian Catangiu <[email protected]>
1 parent b7c3e83 commit 4827569

File tree

5 files changed

+285
-26
lines changed

5 files changed

+285
-26
lines changed

src/arch/src/x86_64/msr.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
use std::result;
66

77
use arch_gen::x86::msr_index::*;
8-
use kvm_bindings::{kvm_msr_entry, Msrs};
9-
use kvm_ioctls::VcpuFd;
8+
use kvm_bindings::{kvm_msr_entry, MsrList, Msrs};
9+
use kvm_ioctls::{Kvm, VcpuFd};
1010

1111
#[derive(Debug)]
1212
/// MSR related errors.
1313
pub enum Error {
14+
/// Getting supported MSRs failed.
15+
GetSupportedModelSpecificRegisters(kvm_ioctls::Error),
1416
/// Setting up MSRs failed.
1517
SetModelSpecificRegisters(kvm_ioctls::Error),
1618
/// Failed to set all MSRs.
@@ -227,6 +229,21 @@ pub fn setup_msrs(vcpu: &VcpuFd) -> Result<()> {
227229
})
228230
}
229231

232+
/// Returns the list of supported, serializable MSRs.
233+
///
234+
/// # Arguments
235+
///
236+
/// * `kvm_fd` - Structure that holds the KVM's fd.
237+
pub fn supported_guest_msrs(kvm_fd: &Kvm) -> Result<MsrList> {
238+
let mut msr_list = kvm_fd
239+
.get_msr_index_list()
240+
.map_err(Error::GetSupportedModelSpecificRegisters)?;
241+
242+
msr_list.retain(|msr_index| msr_should_serialize(*msr_index));
243+
244+
Ok(msr_list)
245+
}
246+
230247
#[cfg(test)]
231248
mod tests {
232249
use super::*;

src/vmm/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,9 @@ mod tests {
816816
ErrorKind::Internal
817817
);
818818
assert_eq!(
819-
error_kind(StartMicrovmError::VcpuConfigure(
820-
vstate::Error::SetSupportedCpusFailed(utils::errno::Error::new(0))
821-
)),
819+
error_kind(StartMicrovmError::VcpuConfigure(vstate::Error::VcpuFd(
820+
utils::errno::Error::new(0)
821+
))),
822822
ErrorKind::Internal
823823
);
824824
assert_eq!(

src/vmm/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ impl Vmm {
885885
cpu_index,
886886
self.vm.fd(),
887887
self.vm.supported_cpuid().clone(),
888+
self.vm.supported_msrs().clone(),
888889
self.pio_device_manager.io_bus.clone(),
889890
vcpu_exit_evt,
890891
request_ts.clone(),

0 commit comments

Comments
 (0)