linux_kvm/ioctl/
system.rs

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