linux_kvm/ioctl/system.rs
1use linux_io::fd::ioctl::{ioctl_no_arg, ioctl_write, IoctlReqNoArgs, IoctlReqWrite, _IO, _IOW};
2use linux_io::File;
3use linux_unsafe::{int, ulong};
4
5/// The device type marker for the main KVM file descriptor, typically obtained
6/// by opening `/dev/kvm`.
7#[derive(Debug)]
8pub struct KvmSystem;
9
10impl linux_io::fd::ioctl::IoDevice for KvmSystem {}
11
12pub(crate) const KVMIO: ulong = 0xAE;
13
14/// Identifies the version of the KVM API used by the current kernel.
15///
16/// The stable API always returns version 12. The kernel documentation suggests
17/// that applications should always call this and refuse to run if it returns
18/// any value other than that; the version number is not expected to change
19/// in the future because future API additions will use [`KVM_CHECK_EXTENSION`]
20/// instead.
21pub const KVM_GET_API_VERSION: IoctlReqNoArgs<KvmSystem, int> =
22 unsafe { ioctl_no_arg(_IO(KVMIO, 0x00)) };
23
24/// Create a new virtual machine and obtain the file that represents it.
25///
26/// The resulting file accepts the `ioctl` requests defined in [`super::vm`].
27pub const KVM_CREATE_VM: IoctlReqNoArgs<KvmSystem, File<super::vm::KvmVm>> =
28 unsafe { ioctl_no_arg(_IO(KVMIO, 0x01)) };
29
30/// Query whether the KVM subsystem in the current kernel supports a particular
31/// extension.
32///
33/// A result of zero indicates a lack of support while nonzero indicates
34/// support. The nonzero value may carry additional meanings for some
35/// extensions.
36///
37/// This is also supported for virtual machine file descriptors, but you must
38/// use [`super::vm::KVM_CHECK_EXTENSION`] instead for those.
39pub const KVM_CHECK_EXTENSION: IoctlReqWrite<KvmSystem, int, int> =
40 unsafe { ioctl_write(_IOW(KVMIO, 0x03, core::mem::size_of::<int>() as ulong)) };
41
42/// Returns the size of the shared memory region that will be used to
43/// communicate with userspace for each VCPU.
44///
45/// The [`super::vcpu::KVM_RUN`] ioctl request communicates with userspace via
46/// a shared memory region. This ioctl request returns the size of that region.
47pub const KVM_GET_VCPU_MMAP_SIZE: IoctlReqNoArgs<KvmSystem, int> =
48 unsafe { ioctl_no_arg(_IO(KVMIO, 0x04)) };