Skip to main content

absorb_stale_single_step

Function absorb_stale_single_step 

Source
pub fn absorb_stale_single_step(
    vcpu: &VcpuFd,
    d: &kvm_debug_exit_arch,
) -> Result<bool>
Expand description

Handles a KVM_EXIT_DEBUG that arrives while a vCPU is not being traced. Returns true if it was a stale single-step trap, now absorbed: re-enter the vCPU. false means it is the guest’s own (or a VMM debugger’s) #DB: hand the exit to the VMM as usual (QEMU passes such exceptions back to the guest).

§Why stale traps exist

While KVM single-steps a vCPU, the hardware trap flag is set. KVM hides it from register reads, but not from copies the guest itself saves: the RFLAGS image in every interrupt or exception frame, and every pushf. If the guest restores such a copy after tracing has stopped (a task preempted during the window resumes; a handler that was interrupted mid-way returns), TF comes back on and the CPU traps after the next instruction. A user program gets SIGTRAP and usually dies.

The guard absorbs that trap: it clears TF in the vCPU’s RFLAGS and lets the guest go on, as if the copy had never had it.