Skip to content

Commit

Permalink
Improve example code of VmFd::create_device() for ARM.
Browse files Browse the repository at this point in the history
On ARM, the example code tried to create VGIC v3, it may fail due to
hardware dependency. The error can be seen on machines with GIC v2,
like Raspberry PI 4. Now we retry VGICv2 in that case.

Change-Id: Ie4a5b2b86c234350e444f2f9e94630e4d68af7ab
Signed-off-by: Michael Zhao <michael.zhao@arm.com>
  • Loading branch information
michael2012z authored and andreeaflorescu committed Jan 13, 2020
1 parent 18bc6b9 commit 4bdd6d5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ impl VmFd {
/// # use kvm_ioctls::Kvm;
/// use kvm_bindings::{
/// kvm_device_type_KVM_DEV_TYPE_VFIO,
/// kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2,
/// kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3,
/// KVM_CREATE_DEVICE_TEST,
/// };
Expand All @@ -1087,8 +1088,17 @@ impl VmFd {
/// fd: 0,
/// flags: KVM_CREATE_DEVICE_TEST,
/// };
/// let device_fd = vm
/// .create_device(&mut device).unwrap();
/// // On ARM, creating VGICv3 may fail due to hardware dependency.
/// // Retry to create VGICv2 in that case.
/// let device_fd = vm.create_device(&mut device).unwrap_or_else(|_| {
/// #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
/// panic!("Cannot create VFIO device.");
/// #[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
/// {
/// device.type_ = kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V2;
/// vm.create_device(&mut device).expect("Cannot create vGIC device")
/// }
/// });
/// ```
///
pub fn create_device(&self, device: &mut kvm_create_device) -> Result<DeviceFd> {
Expand Down

0 comments on commit 4bdd6d5

Please sign in to comment.