[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/42] target/i386: disable/enable breakpoints on vmentry/vmexit
From: |
Paolo Bonzini |
Subject: |
[PULL 06/42] target/i386: disable/enable breakpoints on vmentry/vmexit |
Date: |
Sat, 8 Jun 2024 10:33:39 +0200 |
If the required DR7 (either from the VMCB or from the host save
area) disables a breakpoint that was enabled prior to vmentry
or vmexit, it is left enabled and will trigger EXCP_DEBUG.
This causes a spurious #DB on the next crossing of the breakpoint.
To disable it, vmentry/vmexit must use cpu_x86_update_dr7
to load DR7.
Because cpu_x86_update_dr7 takes a 32-bit argument, check
reserved bits prior to calling cpu_x86_update_dr7, and do the
same for DR6 as well for consistency.
This scenario is tested by the "host_rflags" test in kvm-unit-tests.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
target/i386/tcg/sysemu/svm_helper.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/target/i386/tcg/sysemu/svm_helper.c
b/target/i386/tcg/sysemu/svm_helper.c
index 5d6de2294fa..922d8964f8e 100644
--- a/target/i386/tcg/sysemu/svm_helper.c
+++ b/target/i386/tcg/sysemu/svm_helper.c
@@ -163,6 +163,8 @@ void helper_vmrun(CPUX86State *env, int aflag, int
next_eip_addend)
uint64_t new_cr0;
uint64_t new_cr3;
uint64_t new_cr4;
+ uint64_t new_dr6;
+ uint64_t new_dr7;
if (aflag == 2) {
addr = env->regs[R_EAX];
@@ -361,20 +363,22 @@ void helper_vmrun(CPUX86State *env, int aflag, int
next_eip_addend)
env->vm_vmcb + offsetof(struct vmcb,
save.rsp));
env->regs[R_EAX] = x86_ldq_phys(cs,
env->vm_vmcb + offsetof(struct vmcb,
save.rax));
- env->dr[7] = x86_ldq_phys(cs,
- env->vm_vmcb + offsetof(struct vmcb, save.dr7));
- env->dr[6] = x86_ldq_phys(cs,
- env->vm_vmcb + offsetof(struct vmcb, save.dr6));
+
+ new_dr7 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr7));
+ new_dr6 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr6));
#ifdef TARGET_X86_64
- if (env->dr[6] & DR_RESERVED_MASK) {
+ if (new_dr7 & DR_RESERVED_MASK) {
cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC());
}
- if (env->dr[7] & DR_RESERVED_MASK) {
+ if (new_dr6 & DR_RESERVED_MASK) {
cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC());
}
#endif
+ cpu_x86_update_dr7(env, new_dr7);
+ env->dr[6] = new_dr6;
+
if (is_efer_invalid_state(env)) {
cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC());
}
@@ -864,8 +868,11 @@ void do_vmexit(CPUX86State *env)
env->dr[6] = x86_ldq_phys(cs,
env->vm_hsave + offsetof(struct vmcb, save.dr6));
- env->dr[7] = x86_ldq_phys(cs,
- env->vm_hsave + offsetof(struct vmcb, save.dr7));
+
+ /* Disables all breakpoints in the host DR7 register. */
+ cpu_x86_update_dr7(env,
+ x86_ldq_phys(cs,
+ env->vm_hsave + offsetof(struct vmcb, save.dr7)) &
~0xff);
/* other setups */
x86_stl_phys(cs,
@@ -891,8 +898,6 @@ void do_vmexit(CPUX86State *env)
from the page table indicated the host's CR3. If the PDPEs contain
illegal state, the processor causes a shutdown. */
- /* Disables all breakpoints in the host DR7 register. */
-
/* Checks the reloaded host state for consistency. */
/* If the host's rIP reloaded by #VMEXIT is outside the limit of the
--
2.45.1
- [PULL 00/42] i386, scsi. hostmem fixes for 2024-06-08, Paolo Bonzini, 2024/06/08
- [PULL 01/42] target/i386: fix pushed value of EFLAGS.RF, Paolo Bonzini, 2024/06/08
- [PULL 02/42] target/i386: fix implementation of ICEBP, Paolo Bonzini, 2024/06/08
- [PULL 04/42] target/i386: cleanup PAUSE helpers, Paolo Bonzini, 2024/06/08
- [PULL 05/42] target/i386: implement DR7.GD, Paolo Bonzini, 2024/06/08
- [PULL 03/42] target/i386: cleanup HLT helpers, Paolo Bonzini, 2024/06/08
- [PULL 07/42] target/i386: fix INHIBIT_IRQ/TF/RF handling for VMRUN, Paolo Bonzini, 2024/06/08
- [PULL 08/42] target/i386: fix INHIBIT_IRQ/TF/RF handling for PAUSE, Paolo Bonzini, 2024/06/08
- [PULL 06/42] target/i386: disable/enable breakpoints on vmentry/vmexit,
Paolo Bonzini <=
- [PULL 09/42] target/i386: fix TF/RF handling for HLT, Paolo Bonzini, 2024/06/08
- [PULL 11/42] target/i386: document use of DISAS_NORETURN, Paolo Bonzini, 2024/06/08
- [PULL 10/42] target/i386: document incorrect semantics of watchpoint following MOV/POP SS, Paolo Bonzini, 2024/06/08
- [PULL 12/42] target/i386: use local X86DecodedOp in gen_POP(), Paolo Bonzini, 2024/06/08
- [PULL 13/42] target/i386: use gen_writeback() within gen_POP(), Paolo Bonzini, 2024/06/08
- [PULL 14/42] target/i386: fix SP when taking a memory fault during POP, Paolo Bonzini, 2024/06/08
- [PULL 15/42] target/i386: fix size of EBP writeback in gen_enter(), Paolo Bonzini, 2024/06/08
- [PULL 16/42] machine: default -M mem-merge to off is QEMU_MADV_MERGEABLE is not available, Paolo Bonzini, 2024/06/08
- [PULL 17/42] meson: Don't even detect posix_madvise() on Darwin, Paolo Bonzini, 2024/06/08
- [PULL 18/42] osdep: Make qemu_madvise() to set errno in all cases, Paolo Bonzini, 2024/06/08