From: Hou Wenlong Date: Fri, 15 May 2026 22:26:34 +0000 (-0700) Subject: KVM: x86: Move KVM_GUESTDBG_SINGLESTEP handling into kvm_inject_emulated_db() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d79302b0834a8b162bfa551e7e0e22647676fb5;p=thirdparty%2Fkernel%2Flinux.git KVM: x86: Move KVM_GUESTDBG_SINGLESTEP handling into kvm_inject_emulated_db() Move KVM_GUESTDBG_SINGLESTEP handling from kvm_vcpu_do_singlestep() into kvm_inject_emulated_db() to dedup the USE_HW_BP vs. SINGLESTEP logic, and to allow for removing kvm_vcpu_do_singlestep() entirely. No functional change intended. Suggested-by: Lai Jiangshan Signed-off-by: Hou Wenlong [sean: massage changelog] Reviewed-by: Yosry Ahmed Link: https://patch.msgid.link/20260515222638.1949982-7-seanjc@google.com Signed-off-by: Sean Christopherson --- diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f50151d11fa2..c676863f7e11 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8995,7 +8995,7 @@ 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) { + if (vcpu->guest_debug & (KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_SINGLESTEP)) { kvm_run->debug.arch.dr6 = dr6 | DR6_ACTIVE_LOW; kvm_run->debug.arch.pc = kvm_get_linear_rip(vcpu); kvm_run->debug.arch.exception = DB_VECTOR; @@ -9280,17 +9280,7 @@ static int kvm_vcpu_check_hw_bp(unsigned long addr, u32 type, u32 dr7, static int kvm_vcpu_do_singlestep(struct kvm_vcpu *vcpu) { - struct kvm_run *kvm_run = vcpu->run; - - if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { - kvm_run->debug.arch.dr6 = DR6_BS | DR6_ACTIVE_LOW; - kvm_run->debug.arch.pc = kvm_get_linear_rip(vcpu); - kvm_run->debug.arch.exception = DB_VECTOR; - kvm_run->exit_reason = KVM_EXIT_DEBUG; - return 0; - } - kvm_queue_exception_p(vcpu, DB_VECTOR, DR6_BS); - return 1; + return kvm_inject_emulated_db(vcpu, DR6_BS); } int kvm_skip_emulated_instruction(struct kvm_vcpu *vcpu)