Skip to content

Commit 85de906

Browse files
mkroeningandreeaflorescu
authored andcommitted
Return kvm_debug_exit_arch with VcpuExit::Debug
Signed-off-by: Martin Kröning <[email protected]>
1 parent abd7e89 commit 85de906

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
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.4,
2+
"coverage_score": 91.2,
33
"exclude_path": "",
44
"crate_features": ""
55
}

src/ioctls/vcpu.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub enum VcpuExit<'a> {
4747
/// Corresponds to KVM_EXIT_HYPERCALL.
4848
Hypercall,
4949
/// Corresponds to KVM_EXIT_DEBUG.
50-
Debug,
50+
///
51+
/// Provides architecture specific information for the debug event.
52+
Debug(kvm_debug_exit_arch),
5153
/// Corresponds to KVM_EXIT_HLT.
5254
Hlt,
5355
/// Corresponds to KVM_EXIT_IRQ_WINDOW_OPEN.
@@ -1278,7 +1280,12 @@ impl VcpuFd {
12781280
}
12791281
}
12801282
KVM_EXIT_HYPERCALL => Ok(VcpuExit::Hypercall),
1281-
KVM_EXIT_DEBUG => Ok(VcpuExit::Debug),
1283+
KVM_EXIT_DEBUG => {
1284+
// Safe because the exit_reason (which comes from the kernel) told us which
1285+
// union field to use.
1286+
let debug = unsafe { run.__bindgen_anon_1.debug };
1287+
Ok(VcpuExit::Debug(debug.arch))
1288+
}
12821289
KVM_EXIT_HLT => Ok(VcpuExit::Hlt),
12831290
KVM_EXIT_MMIO => {
12841291
// Safe because the exit_reason (which comes from the kernel) told us which
@@ -1932,7 +1939,7 @@ mod tests {
19321939
assert_eq!(data.len(), 1);
19331940
assert_eq!(data[0], 0);
19341941
}
1935-
VcpuExit::Debug => {
1942+
VcpuExit::Debug(debug) => {
19361943
if instr_idx == expected_rips.len() - 1 {
19371944
// Disabling debugging/single-stepping
19381945
debug_struct.control = 0;
@@ -1942,6 +1949,13 @@ mod tests {
19421949
}
19431950
let vcpu_regs = vcpu_fd.get_regs().unwrap();
19441951
assert_eq!(vcpu_regs.rip, expected_rips[instr_idx]);
1952+
assert_eq!(debug.exception, 1);
1953+
assert_eq!(debug.pc, expected_rips[instr_idx]);
1954+
// Check first 15 bits of DR6
1955+
let mask = (1 << 16) - 1;
1956+
assert_eq!(debug.dr6 & mask, 0b100111111110000);
1957+
// Bit 10 in DR7 is always 1
1958+
assert_eq!(debug.dr7, 1 << 10);
19451959
instr_idx += 1;
19461960
}
19471961
VcpuExit::Hlt => {

0 commit comments

Comments
 (0)