From 85de906f75b9f2f621703cebc30cc2904a0749cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 21 Jul 2021 16:12:50 +0200 Subject: [PATCH] Return kvm_debug_exit_arch with VcpuExit::Debug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- coverage_config_x86_64.json | 2 +- src/ioctls/vcpu.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index d0bb9002..debc8fb4 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,5 @@ { - "coverage_score": 91.4, + "coverage_score": 91.2, "exclude_path": "", "crate_features": "" } diff --git a/src/ioctls/vcpu.rs b/src/ioctls/vcpu.rs index 38ceaeeb..16dcc741 100644 --- a/src/ioctls/vcpu.rs +++ b/src/ioctls/vcpu.rs @@ -47,7 +47,9 @@ pub enum VcpuExit<'a> { /// Corresponds to KVM_EXIT_HYPERCALL. Hypercall, /// Corresponds to KVM_EXIT_DEBUG. - Debug, + /// + /// Provides architecture specific information for the debug event. + Debug(kvm_debug_exit_arch), /// Corresponds to KVM_EXIT_HLT. Hlt, /// Corresponds to KVM_EXIT_IRQ_WINDOW_OPEN. @@ -1278,7 +1280,12 @@ impl VcpuFd { } } KVM_EXIT_HYPERCALL => Ok(VcpuExit::Hypercall), - KVM_EXIT_DEBUG => Ok(VcpuExit::Debug), + KVM_EXIT_DEBUG => { + // Safe because the exit_reason (which comes from the kernel) told us which + // union field to use. + let debug = unsafe { run.__bindgen_anon_1.debug }; + Ok(VcpuExit::Debug(debug.arch)) + } KVM_EXIT_HLT => Ok(VcpuExit::Hlt), KVM_EXIT_MMIO => { // Safe because the exit_reason (which comes from the kernel) told us which @@ -1932,7 +1939,7 @@ mod tests { assert_eq!(data.len(), 1); assert_eq!(data[0], 0); } - VcpuExit::Debug => { + VcpuExit::Debug(debug) => { if instr_idx == expected_rips.len() - 1 { // Disabling debugging/single-stepping debug_struct.control = 0; @@ -1942,6 +1949,13 @@ mod tests { } let vcpu_regs = vcpu_fd.get_regs().unwrap(); assert_eq!(vcpu_regs.rip, expected_rips[instr_idx]); + assert_eq!(debug.exception, 1); + assert_eq!(debug.pc, expected_rips[instr_idx]); + // Check first 15 bits of DR6 + let mask = (1 << 16) - 1; + assert_eq!(debug.dr6 & mask, 0b100111111110000); + // Bit 10 in DR7 is always 1 + assert_eq!(debug.dr7, 1 << 10); instr_idx += 1; } VcpuExit::Hlt => {