Skip to content

Commit 9ce661d

Browse files
Lai Jiangshanksacilotto
authored andcommitted
KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run()
BugLink: https://bugs.launchpad.net/bugs/1939440 commit f85d401 upstream. When the host is using debug registers but the guest is not using them nor is the guest in guest-debug state, the kvm code does not reset the host debug registers before kvm_x86->run(). Rather, it relies on the hardware vmentry instruction to automatically reset the dr7 registers which ensures that the host breakpoints do not affect the guest. This however violates the non-instrumentable nature around VM entry and exit; for example, when a host breakpoint is set on vcpu->arch.cr2, Another issue is consistency. When the guest debug registers are active, the host breakpoints are reset before kvm_x86->run(). But when the guest debug registers are inactive, the host breakpoints are delayed to be disabled. The host tracing tools may see different results depending on what the guest is doing. To fix the problems, we clear %db7 unconditionally before kvm_x86->run() if the host has set any breakpoints, no matter if the guest is using them or not. Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com> Message-Id: <20210628172632.81029-1-jiangshanlai@gmail.com> Cc: stable@vger.kernel.org [Only clear %db7 instead of reloading all debug registers. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent b61b4fc commit 9ce661d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/x86/kvm/x86.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8271,6 +8271,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
82718271
set_debugreg(vcpu->arch.eff_db[3], 3);
82728272
set_debugreg(vcpu->arch.dr6, 6);
82738273
vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD;
8274+
} else if (unlikely(hw_breakpoint_active())) {
8275+
set_debugreg(0, 7);
82748276
}
82758277

82768278
kvm_x86_ops->run(vcpu);

0 commit comments

Comments
 (0)