hypervisor: implement Display for MSHV VcpuState

This functionality is useful for Snapshot/Restore debugging.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam 2021-06-17 15:57:20 -07:00 committed by Bo Chen
parent 5cd82cb2e2
commit e214bb9eed

View File

@ -7,9 +7,10 @@
// Copyright 2018-2019 CrowdStrike, Inc.
//
//
use crate::arch::x86::{msr_index, SegmentRegisterOps, MTRR_ENABLE, MTRR_MEM_TYPE_WB};
use serde_derive::{Deserialize, Serialize};
use std::fmt;
///
/// Export generically-named wrappers of mshv_bindings for Unix-based platforms
///
@ -36,6 +37,30 @@ pub struct VcpuMshvState {
pub xsave: Xsave,
}
impl fmt::Display for VcpuMshvState {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let expected_num_msrs = self.msrs.as_fam_struct_ref().nmsrs as usize;
let mut msr_entries = vec![vec![0; 2]; expected_num_msrs];
for (i, entry) in self.msrs.as_slice().iter().enumerate() {
msr_entries[i][1] = entry.data;
msr_entries[i][0] = entry.index as u64;
}
write!(f, "Number of MSRs: {}: MSRs: {:#010X?}, -- VCPU Events: {:?} -- Standard registers: {:?} Special Registers: {:?} ---- Floating Point Unit: {:?} --- Extended Control Register: {:?} --- Local APIC: {:?} --- DBG: {:?} --- Xsave: {:?}",
msr_entries.len(),
msr_entries,
self.vcpu_events,
self.regs,
self.sregs,
self.fpu,
self.xcrs,
self.lapic,
self.dbg,
self.xsave,
)
}
}
pub struct CreateDevice {}
pub struct DeviceAttr {}
pub struct IrqRouting {}