KvmVcpu
contains methods for interacting with the VCPU. It has reference to VcpuFd
.
pub struct KvmVcpu {
/// KVM file descriptor for a vCPU.
pub(crate) vcpu_fd: VcpuFd,
/// Device manager for bus accesses.
device_mgr: Arc<Mutex<IoManager>>,
config: VcpuConfig,
run_barrier: Arc<Barrier>,
pub(crate) run_state: Arc<VcpuRunState>,
}
VcpuFd
lives inkvm-ioctls
and has methods to get and set various states about CPU such asget_regs
,get_sregs
and so on. We need not interact with this directly and can just talk toKvmVcpu
.
KvmVcpu also has a IoManager
, a Barrier
, and a VcpuRunState
.
VcpuRunState
is just a synchronization wrapper overVmRunState
. One can wait onVmRunState
using a conditional variable and get notified when theVmRunState
is changed.VmRunState
is just enum ofRunning
,Suspending
,Exiting
.
Barrier
is shared acrossKvmVcpu
so that it doesn't enter itsrun
loop until everyVcpu
is ready.
KvmVcpu
has methods to save its state and to restore it from a state. CPU
state is encapsulated in VcpuState
.
pub regs: kvm_regs,
pub sregs: kvm_sregs,
[[x86-registers]]
pub cpuid: CpuId,
pub msrs: Msrs,
pub debug_regs: kvm_debugregs,
[[x86-debugregs]]
pub lapic: kvm_lapic_state,
[[x86-lapic]]
pub mp_state: kvm_mp_state,
[[x86-mpstate]]
pub vcpu_events: kvm_vcpu_events,
pub xcrs: kvm_xcrs,
pub xsave: kvm_xsave,
pub config: VcpuConfig,
}