Skip to content

Latest commit

 

History

History
75 lines (62 loc) · 1.86 KB

vmm-reference-kvmvcpu.md

File metadata and controls

75 lines (62 loc) · 1.86 KB

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 in kvm-ioctls and has methods to get and set various states about CPU such as get_regs, get_sregs and so on. We need not interact with this directly and can just talk to KvmVcpu.

KvmVcpu also has a IoManager, a Barrier, and a VcpuRunState.

VcpuRunState is just a synchronization wrapper over VmRunState. One can wait on VmRunState using a conditional variable and get notified when the VmRunState is changed. VmRunState is just enum of Running, Suspending, Exiting.

Barrier is shared across KvmVcpu so that it doesn't enter its run loop until every Vcpu is ready.

KvmVcpu has methods to save its state and to restore it from a state. CPU state is encapsulated in VcpuState.

pub struct 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,
}