Implement the necessary ioctls for KVM (Kernel-based Virtual Machine) in Rust, specifically for interacting with /dev/kvm. This implementation must include the following functionalities:
Get KVM API Version: Implement the ioctl to retrieve the version of the KVM API:
Use the KVM_GET_API_VERSION ioctl command.
Ensure that the returned version matches the KVM_API_VERSION constant.
Create a VM File Descriptor: Implement the ioctl to create a new virtual machine:
Use the KVM_CREATE_VM ioctl command.
Ensure that the returned file descriptor is valid (>= 0).
Check VM Extension: Implement the ioctl to check for available extensions in KVM:
Use the KVM_CHECK_EXTENSION ioctl command to check for the KVM_CAP_USER_MEMORY capability.
Ensure the return value is 1 if the capability is supported.
Requirements
The implementation should reside in the /app/ directory.
The code must use the appropriate Rust language constructs and the kvm_bindings crate to define the ioctls.
The tests module provided must pass successfully after your implementation.
Use unsafe Rust features like open, from_raw_fd, and ioctl only where necessary and ensure that they are handled properly to avoid undefined behavior or memory leaks.
Make sure to include the appropriate error handling and safety checks in your implementation to ensure robustness.