pub struct KvmVcpu {
pub index: u8,
pub fd: VcpuFd,
pub peripherals: Peripherals,
/* private fields */
}Expand description
A wrapper around creating and using a kvm x86_64 vcpu.
Fields§
§index: u8Index of vcpu.
fd: VcpuFdKVM vcpu fd.
peripherals: PeripheralsVcpu peripherals, such as buses
Implementations§
Source§impl KvmVcpu
impl KvmVcpu
Sourcepub fn new(index: u8, vm: &Vm) -> Result<Self, KvmVcpuError>
pub fn new(index: u8, vm: &Vm) -> Result<Self, KvmVcpuError>
Constructs a new kvm vcpu with arch specific functionality.
§Arguments
index- Represents the 0-based CPU index between [0, max vcpus).vm- The vm to which this vcpu will get attached.
Sourcepub fn configure(
&mut self,
guest_mem: &GuestMemoryMmap,
kernel_entry_point: EntryPoint,
vcpu_config: &VcpuConfig,
) -> Result<(), KvmVcpuConfigureError>
pub fn configure( &mut self, guest_mem: &GuestMemoryMmap, kernel_entry_point: EntryPoint, vcpu_config: &VcpuConfig, ) -> Result<(), KvmVcpuConfigureError>
Configures a x86_64 specific vcpu for booting Linux and should be called once per vcpu.
§Arguments
guest_mem- The guest memory used by this microvm.kernel_entry_point- Specifies the boot protocol and offset fromguest_memat which the kernel starts.vcpu_config- The vCPU configuration.cpuid- The capabilities exposed by this vCPU.
Sourcepub fn set_pio_bus(&mut self, pio_bus: Arc<Bus>)
pub fn set_pio_bus(&mut self, pio_bus: Arc<Bus>)
Sets a Port Mapped IO bus for this vcpu.
Sourcepub fn kvmclock_ctrl(&self)
pub fn kvmclock_ctrl(&self)
Calls KVM_KVMCLOCK_CTRL to avoid guest soft lockup watchdog panics on resume. See https://docs.kernel.org/virt/kvm/api.html .
Sourcepub fn get_tsc_khz(&self) -> Result<u32, GetTscError>
pub fn get_tsc_khz(&self) -> Result<u32, GetTscError>
Sourcepub fn get_msr_chunk(
&self,
msr_index_iter: impl Iterator<Item = u32>,
chunk_size: usize,
) -> Result<Msrs, KvmVcpuError>
pub fn get_msr_chunk( &self, msr_index_iter: impl Iterator<Item = u32>, chunk_size: usize, ) -> Result<Msrs, KvmVcpuError>
Get single MSR chunk for the given MSR index iterator with specified length. Iterator should have enough elements to fill the chunk with indices, otherwise KVM will return an error when processing half filled chunk.
§Arguments
msr_index_iter: Iterator over MSR indices.chunk_size: Length of a chunk.
§Errors
- When [
kvm_bindings::Msrs::new] returns errors. - When [
kvm_ioctls::VcpuFd::get_msrs] returns errors. - When the return value of [
kvm_ioctls::VcpuFd::get_msrs] (the number of entries that could be gotten) is less than expected.
Sourcepub fn get_msrs(
&self,
msr_index_iter: impl ExactSizeIterator<Item = u32>,
) -> Result<BTreeMap<u32, u64>, KvmVcpuError>
pub fn get_msrs( &self, msr_index_iter: impl ExactSizeIterator<Item = u32>, ) -> Result<BTreeMap<u32, u64>, KvmVcpuError>
Sourcepub fn save_state(&self) -> Result<VcpuState, KvmVcpuError>
pub fn save_state(&self) -> Result<VcpuState, KvmVcpuError>
Save the KVM internal state.
Sourcepub fn dump_cpu_config(&self) -> Result<CpuConfiguration, KvmVcpuError>
pub fn dump_cpu_config(&self) -> Result<CpuConfiguration, KvmVcpuError>
Dumps CPU configuration (CPUID and MSRs).
Opposed to save_state(), this dumps all the supported and dumpable MSRs not limited to
serializable ones.
Sourcepub fn is_tsc_scaling_required(
&self,
state_tsc_freq: u32,
) -> Result<bool, GetTscError>
pub fn is_tsc_scaling_required( &self, state_tsc_freq: u32, ) -> Result<bool, GetTscError>
Sourcepub fn set_tsc_khz(&self, tsc_freq: u32) -> Result<(), SetTscError>
pub fn set_tsc_khz(&self, tsc_freq: u32) -> Result<(), SetTscError>
Scale the TSC frequency of this vCPU to the one provided as a parameter.
Sourcepub fn restore_state(&self, state: &VcpuState) -> Result<(), KvmVcpuError>
pub fn restore_state(&self, state: &VcpuState) -> Result<(), KvmVcpuError>
Use provided state to populate KVM internal state.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KvmVcpu
impl RefUnwindSafe for KvmVcpu
impl Send for KvmVcpu
impl Sync for KvmVcpu
impl Unpin for KvmVcpu
impl UnwindSafe for KvmVcpu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.