aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2021-12-11 22:02:02 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2021-12-11 22:02:02 +0100
commit58be7ebbf86c4185276250867eb74a6dd19aaca6 (patch)
treeb34b55b5b5fe4b789c82d10250e90549a660bd7e
parent748c675afbfa0fd717bd84c7a7301d75efabd945 (diff)
downloadmini-kvm-rs-58be7ebbf86c4185276250867eb74a6dd19aaca6.tar.gz
mini-kvm-rs-58be7ebbf86c4185276250867eb74a6dd19aaca6.zip
vcpu: set/get debug regs
-rw-r--r--src/vcpu.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/vcpu.rs b/src/vcpu.rs
index 239c663..147f602 100644
--- a/src/vcpu.rs
+++ b/src/vcpu.rs
@@ -18,6 +18,7 @@ pub enum KvmExit<'cpu> {
IoOut(u16, &'cpu [u8]),
MmioRead(u64, &'cpu mut [u8]),
MmioWrite(u64, &'cpu [u8]),
+ Debug(u64),
}
/// Wrapper for VCPU ioctls.
@@ -86,6 +87,36 @@ impl Vcpu {
.map(|_| ())
}
+ /// Get the debug registers with the [`KVM_GET_DEBUGREGS`][kvm-get-debugregs] ioctl in form of
+ /// [`kvm_debugregs`](crate::kvm_sys::kvm_debugregs).
+ ///
+ /// [kvm-get-debugregs]:
+ /// https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-get-debugregs
+ #[cfg(target_arch = "x86_64")]
+ pub fn get_debugregs(&self) -> io::Result<kvm_sys::kvm_debugregs> {
+ let mut dregs = kvm_sys::kvm_debugregs::default();
+ ioctl(
+ &self.vcpu,
+ kvm_sys::KVM_GET_DEBUGREGS,
+ &mut dregs as *mut _ as u64,
+ )?;
+ Ok(dregs)
+ }
+
+ /// Set the debug registers with the [`KVM_SET_DEBUGREGS`][kvm-set-debugregs] ioctl in form of
+ /// [`kvm_debugregs`](crate::kvm_sys::kvm_debugregs).
+ ///
+ /// [kvm-set-debugregs]:
+ /// https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-set-debugregs
+ pub fn set_debugregs(&self, dregs: kvm_sys::kvm_debugregs) -> io::Result<()> {
+ ioctl(
+ &self.vcpu,
+ kvm_sys::KVM_SET_DEBUGREGS,
+ &dregs as *const _ as u64,
+ )
+ .map(|_| ())
+ }
+
/// Run the guest VCPU with the [`KVM_RUN`][kvm-run] ioctl until it exits with one of the exit
/// reasons described in [`KvmExit`](crate::vcpu::KvmExit).
///
@@ -128,6 +159,12 @@ impl Vcpu {
_ => unreachable!(),
}
}
+ kvm_sys::KVM_EXIT_DEBUG => {
+ // Safe to use union `debug` field, as Kernel instructed us to.
+ let debug = unsafe { kvm_run.inner.debug };
+
+ Ok(KvmExit::Debug(debug.pc))
+ }
r @ _ => {
todo!("KVM_EXIT_... (exit_reason={}) not implemented!", r)
}