yeahuh / rpms / qemu-kvm

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