Skip to content

Commit

Permalink
ioctls: vcpu: Add KVM_KVMCLOCK_CTRL support
Browse files Browse the repository at this point in the history
The KVM_KVMCLOCK_CTRL lets the guest know that it has been paused, which
will prevent from detecting soft lockups due to pausing and resuming
operations.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
  • Loading branch information
Sebastien Boeuf committed Sep 7, 2020
1 parent 113e6aa commit 334c9a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
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": 91.3,
"coverage_score": 91.2,
"exclude_path": "",
"crate_features": ""
}
20 changes: 20 additions & 0 deletions src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,22 @@ impl VcpuFd {
Ok(reg_value)
}

/// Notify the guest about the vCPU being paused.
///
/// See the documentation for `KVM_KVMCLOCK_CTRL` in the
/// [KVM API documentation](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt).
///
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn kvmclock_ctrl(&self) -> Result<()> {
// Safe because we know that our file is a KVM fd and that the request
// is one of the ones defined by kernel.
let ret = unsafe { ioctl(self, KVM_KVMCLOCK_CTRL()) };
if ret != 0 {
return Err(errno::Error::last());
}
Ok(())
}

/// Triggers the running of the current virtual CPU returning an exit reason.
///
/// See documentation for `KVM_RUN`.
Expand Down Expand Up @@ -1877,6 +1893,10 @@ mod tests {
badf_errno
);
assert_eq!(faulty_vcpu_fd.run().unwrap_err().errno(), badf_errno);
assert_eq!(
faulty_vcpu_fd.kvmclock_ctrl().unwrap_err().errno(),
badf_errno
);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/kvm_ioctls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ ioctl_ior_nr!(KVM_GET_XCRS, KVMIO, 0xa6, kvm_xcrs);
/* Available with KVM_CAP_XCRS */
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
ioctl_iow_nr!(KVM_SET_XCRS, KVMIO, 0xa7, kvm_xcrs);
/* Available with KVM_CAP_KVMCLOCK_CTRL */
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
ioctl_io_nr!(KVM_KVMCLOCK_CTRL, KVMIO, 0xad);

/* Available with KVM_CAP_ENABLE_CAP */
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
Expand Down

0 comments on commit 334c9a3

Please sign in to comment.