Skip to content

Commit 334c9a3

Browse files
author
Sebastien Boeuf
committed
ioctls: vcpu: Add KVM_KVMCLOCK_CTRL support
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 <[email protected]>
1 parent 113e6aa commit 334c9a3

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 91.3,
2+
"coverage_score": 91.2,
33
"exclude_path": "",
44
"crate_features": ""
55
}

src/ioctls/vcpu.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,22 @@ impl VcpuFd {
10491049
Ok(reg_value)
10501050
}
10511051

1052+
/// Notify the guest about the vCPU being paused.
1053+
///
1054+
/// See the documentation for `KVM_KVMCLOCK_CTRL` in the
1055+
/// [KVM API documentation](https://www.kernel.org/doc/Documentation/virtual/kvm/api.txt).
1056+
///
1057+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1058+
pub fn kvmclock_ctrl(&self) -> Result<()> {
1059+
// Safe because we know that our file is a KVM fd and that the request
1060+
// is one of the ones defined by kernel.
1061+
let ret = unsafe { ioctl(self, KVM_KVMCLOCK_CTRL()) };
1062+
if ret != 0 {
1063+
return Err(errno::Error::last());
1064+
}
1065+
Ok(())
1066+
}
1067+
10521068
/// Triggers the running of the current virtual CPU returning an exit reason.
10531069
///
10541070
/// See documentation for `KVM_RUN`.
@@ -1877,6 +1893,10 @@ mod tests {
18771893
badf_errno
18781894
);
18791895
assert_eq!(faulty_vcpu_fd.run().unwrap_err().errno(), badf_errno);
1896+
assert_eq!(
1897+
faulty_vcpu_fd.kvmclock_ctrl().unwrap_err().errno(),
1898+
badf_errno
1899+
);
18801900
}
18811901

18821902
#[test]

src/kvm_ioctls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ ioctl_ior_nr!(KVM_GET_XCRS, KVMIO, 0xa6, kvm_xcrs);
190190
/* Available with KVM_CAP_XCRS */
191191
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
192192
ioctl_iow_nr!(KVM_SET_XCRS, KVMIO, 0xa7, kvm_xcrs);
193+
/* Available with KVM_CAP_KVMCLOCK_CTRL */
194+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
195+
ioctl_io_nr!(KVM_KVMCLOCK_CTRL, KVMIO, 0xad);
193196

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

0 commit comments

Comments
 (0)