linux_kvm/ioctl/
vm.rs

1use linux_io::fd::ioctl::{
2    ioctl_write, ioctl_write_val, IoctlReqWrite, IoctlReqWriteVal, _IO, _IOW,
3};
4use linux_unsafe::{int, ulong};
5
6use super::system::KVMIO;
7use linux_io::File;
8
9/// The device type marker for the a KVM virtual machine file descriptor.
10#[derive(Debug)]
11pub struct KvmVm;
12
13impl linux_io::fd::ioctl::IoDevice for KvmVm {}
14
15/// Query whether the KVM subsystem in the current kernel supports a particular
16/// extension for a specific VM.
17///
18/// A result of zero indicates a lack of support while nonzero indicates
19/// support. The nonzero value may carry additional meanings for some
20/// extensions.
21pub const KVM_CHECK_EXTENSION: IoctlReqWrite<KvmVm, int, int> =
22    unsafe { ioctl_write(_IOW(KVMIO, 0x03, core::mem::size_of::<int>() as ulong)) };
23
24/// Create a new virtual CPU for an existing virtual machine and obtain the
25/// file that represents it.
26///
27/// The argument is a VCPU ID, which ranges from zero to the maximum number of
28/// supported VCPUs per VM, which is a kernel-decided limit.
29///
30/// The resulting file accepts the `ioctl` requests defined in [`super::vcpu`].
31pub const KVM_CREATE_VCPU: IoctlReqWriteVal<KvmVm, int, File<super::vcpu::KvmVcpu>> =
32    unsafe { ioctl_write_val(_IO(KVMIO, 0x41)) };
33
34/// Create, modify or delete a guest physical memory slot.
35pub const KVM_SET_USER_MEMORY_REGION: IoctlReqWrite<
36    KvmVm,
37    crate::raw::kvm_userspace_memory_region,
38    int,
39> = unsafe {
40    ioctl_write(_IOW(
41        KVMIO,
42        0x46,
43        core::mem::size_of::<crate::raw::kvm_userspace_memory_region>() as ulong,
44    ))
45};
46
47/// Track writes to this region if set in [`KVM_SET_USER_MEMORY_REGION`]'s
48/// `flags` field.
49pub const KVM_MEM_LOG_DIRTY_PAGES: u32 = 1 << 0;
50
51/// Marks a memory region as read-only in [`KVM_SET_USER_MEMORY_REGION`]'s
52/// `flags` field.
53pub const KVM_MEM_READONLY: u32 = 1 << 1;