Blame SOURCES/kvm-target-i386-kvm-Re-inject-DB-to-guest-with-updated-D.patch

b38b0f
From c31315e765df0137cb7dfedb3869db72d6d2ca57 Mon Sep 17 00:00:00 2001
b38b0f
From: Paolo Bonzini <pbonzini@redhat.com>
b38b0f
Date: Mon, 22 Jul 2019 18:22:10 +0100
b38b0f
Subject: [PATCH 29/39] target/i386: kvm: Re-inject #DB to guest with updated
b38b0f
 DR6
b38b0f
b38b0f
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
b38b0f
Message-id: <20190722182220.19374-9-pbonzini@redhat.com>
b38b0f
Patchwork-id: 89626
b38b0f
O-Subject: [RHEL-8.1.0 PATCH qemu-kvm v3 08/18] target/i386: kvm: Re-inject #DB to guest with updated DR6
b38b0f
Bugzilla: 1689269
b38b0f
RH-Acked-by: Peter Xu <zhexu@redhat.com>
b38b0f
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
b38b0f
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
b38b0f
b38b0f
From: Liran Alon <liran.alon@oracle.com>
b38b0f
b38b0f
If userspace (QEMU) debug guest, when #DB is raised in guest and
b38b0f
intercepted by KVM, KVM forwards information on #DB to userspace
b38b0f
instead of injecting #DB to guest.
b38b0f
While doing so, KVM don't update vCPU DR6 but instead report the #DB DR6
b38b0f
value to userspace for further handling.
b38b0f
See KVM's handle_exception() DB_VECTOR handler.
b38b0f
b38b0f
QEMU handler for this case is kvm_handle_debug(). This handler basically
b38b0f
checks if #DB is related to one of user set hardware breakpoints and if
b38b0f
not, it re-inject #DB into guest.
b38b0f
The re-injection is done by setting env->exception_injected to #DB which
b38b0f
will later be passed as events.exception.nr to KVM_SET_VCPU_EVENTS ioctl
b38b0f
by kvm_put_vcpu_events().
b38b0f
b38b0f
However, in case userspace re-injects #DB, KVM expects userspace to set
b38b0f
vCPU DR6 as reported to userspace when #DB was intercepted! Otherwise,
b38b0f
KVM_REQ_EVENT handler will inject #DB with wrong DR6 to guest.
b38b0f
b38b0f
Fix this issue by updating vCPU DR6 appropriately when re-inject #DB to
b38b0f
guest.
b38b0f
b38b0f
Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
b38b0f
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
b38b0f
Signed-off-by: Liran Alon <liran.alon@oracle.com>
b38b0f
Message-Id: <20190619162140.133674-5-liran.alon@oracle.com>
b38b0f
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
b38b0f
(cherry picked from commit bceeeef9e7544057659118688243260c390eceb9)
b38b0f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
b38b0f
---
b38b0f
 target/i386/kvm.c | 3 +++
b38b0f
 1 file changed, 3 insertions(+)
b38b0f
b38b0f
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
b38b0f
index 4138fe9..1a4ff3c 100644
b38b0f
--- a/target/i386/kvm.c
b38b0f
+++ b/target/i386/kvm.c
b38b0f
@@ -3363,6 +3363,9 @@ static int kvm_handle_debug(X86CPU *cpu,
b38b0f
         /* pass to guest */
b38b0f
         env->exception_injected = arch_info->exception;
b38b0f
         env->has_error_code = 0;
b38b0f
+        if (arch_info->exception == EXCP01_DB) {
b38b0f
+            env->dr[6] = arch_info->dr6;
b38b0f
+        }
b38b0f
     }
b38b0f
 
b38b0f
     return ret;
b38b0f
-- 
b38b0f
1.8.3.1
b38b0f