Re: [PATCH 4/7] KVM: x86: Consolidate KVM_GUESTDBG_SINGLESTEP check into the kvm_inject_emulated_db()

From: Sean Christopherson

Date: Fri Dec 05 2025 - 12:58:06 EST


On Wed, Sep 10, 2025, Hou Wenlong wrote:
> Use kvm_inject_emulated_db() in kvm_vcpu_do_singlestep() to consolidate
> 'KVM_GUESTDBG_SINGLESTEP' check into kvm_inject_emulated_db() during
> emulation.
>
> No functional change intended.
>
> Suggested-by: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>
> Signed-off-by: Hou Wenlong <houwenlong.hwl@xxxxxxxxxxxx>
> ---
> arch/x86/kvm/x86.c | 17 +++++------------
> 1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 5af652916a19..83960214d5d8 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8632,7 +8632,10 @@ static int kvm_inject_emulated_db(struct kvm_vcpu *vcpu, unsigned long dr6)
> {
> struct kvm_run *kvm_run = vcpu->run;
>
> - if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
> + /* Data breakpoints are not supported in emulation for now. */
> + WARN_ON((dr6 & DR6_BS) && (dr6 & DR_TRAP_BITS));

If we keep this, it should be a WARN_ON_ONCE(). We've had at least one case where
a sanity check in the emulator caused major problems because a WARN_ON() spammed
the kernel log to the point where it overloaded things :-)

But I think the WARN will be subject to false positives. KVM doesn't emulate data
#DBs, but it does emulate code #DBs, and fault-like code #DBs can be coincident
with trap-like single-step #DBs. Ah, but kvm_vcpu_check_code_breakpoint() doesn't
account for RFLAGS.TF. That should probably be addressed in this series, especially
since it's consolidating KVM_GUESTDBG_SINGLESTEP handling.