Skip to content

Commit

Permalink
ioctls: Don't panic on unsupported exit reason
Browse files Browse the repository at this point in the history
In case the underlying KVM version is more recent than what is known
and supported by the kvm-ioctls crate, and in case KVM reports an
unknown reason for a VM exit, we don't want the vCPU run() to panic.

A more elegant way of handling such situation is by propagating the exit
reason up to the consumer's crate as it might know what to do with it.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
  • Loading branch information
Sebastien Boeuf authored and jiangliu committed Feb 15, 2022
1 parent b5b9b75 commit f499ce9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 85.4,
"coverage_score": 85.3,
"exclude_path": "",
"crate_features": ""
}
6 changes: 5 additions & 1 deletion src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ pub enum VcpuExit<'a> {
IoapicEoi(u8 /* vector */),
/// Corresponds to KVM_EXIT_HYPERV.
Hyperv,
/// Corresponds to an exit reason that is unknown from the current version
/// of the kvm-ioctls crate. Let the consumer decide about what to do with
/// it.
Unsupported(u32),
}

/// Wrapper over KVM vCPU ioctls.
Expand Down Expand Up @@ -1405,7 +1409,7 @@ impl VcpuFd {
Ok(VcpuExit::IoapicEoi(eoi.vector))
}
KVM_EXIT_HYPERV => Ok(VcpuExit::Hyperv),
r => panic!("unknown kvm exit reason: {}", r),
r => Ok(VcpuExit::Unsupported(r)),
}
} else {
Err(errno::Error::last())
Expand Down

0 comments on commit f499ce9

Please sign in to comment.