[Trusty][SRU][PATCH 2/2] KVM: x86: Emulator should set DR6 upon GD like real CPU

Seyeong Kim seyeong.kim at canonical.com
Wed Feb 1 00:39:40 UTC 2017


From: Nadav Amit <namit at cs.technion.ac.il>

BugLink: http://bugs.launchpad.net/bugs/1660519

It should clear B0-B3 and set BD.

Signed-off-by: Nadav Amit <namit at cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
(cherry picked from commit 6d2a0526b09e551d0f395cfb63e7cb965db825af)
Signed-off-by: Seyeong Kim <seyeong.kim at canonical.com>
---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/emulate.c          | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 70427d1..4d2cfd8 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -157,6 +157,7 @@ enum {
 
 #define DR6_BD		(1 << 13)
 #define DR6_BS		(1 << 14)
+#define DR6_RTM         (1 << 16)
 #define DR6_FIXED_1	0xffff0ff0
 #define DR6_VOLATILE	0x0000e00f
 
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index f8eea19..46d0145 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3533,8 +3533,15 @@ static int check_dr_read(struct x86_emulate_ctxt *ctxt)
 	if ((cr4 & X86_CR4_DE) && (dr == 4 || dr == 5))
 		return emulate_ud(ctxt);
 
-	if (check_dr7_gd(ctxt))
+	if (check_dr7_gd(ctxt)) {
+		ulong dr6;
+
+		ctxt->ops->get_dr(ctxt, 6, &dr6);
+		dr6 &= ~15;
+		dr6 |= DR6_BD | DR6_RTM;
+		ctxt->ops->set_dr(ctxt, 6, dr6);
 		return emulate_db(ctxt);
+	}
 
 	return X86EMUL_CONTINUE;
 }
-- 
2.7.4





More information about the kernel-team mailing list