Re: [PATCH 4/7] KVM: x86: Consolidate KVM_GUESTDBG_SINGLESTEP check into the kvm_inject_emulated_db()
From: Hou Wenlong
Date: Thu Dec 11 2025 - 09:05:30 EST
On Fri, Dec 05, 2025 at 09:58:04AM -0800, Sean Christopherson wrote:
> 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 :-)
>
I'll drop it.
> 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.
Sorry, I didn't follow it, how fault-like code #DBs can be coincident
with trap-like single-step #DBs, could you provide an example?
Thanks!