From patchwork Sun Apr 19 12:18:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 6238251 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 402D39F1BE for ; Sun, 19 Apr 2015 12:18:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6FAD8202DD for ; Sun, 19 Apr 2015 12:18:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A3DB200F2 for ; Sun, 19 Apr 2015 12:18:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752042AbbDSMSc (ORCPT ); Sun, 19 Apr 2015 08:18:32 -0400 Received: from mailgw10.technion.ac.il ([132.68.225.10]:5960 "EHLO mailgw10.technion.ac.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751610AbbDSMSb (ORCPT ); Sun, 19 Apr 2015 08:18:31 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CyAwDpmzNVjAEgRIRchDq2IgOCP41fgUCGEoEhOhIBAQEBAQEBEQEBASdChE5SgVGIK8M5hSKQOx2EFwWLOpExijuCMIcYgWeCMWyCRAEBAQ X-IPAS-Result: A2CyAwDpmzNVjAEgRIRchDq2IgOCP41fgUCGEoEhOhIBAQEBAQEBEQEBASdChE5SgVGIK8M5hSKQOx2EFwWLOpExijuCMIcYgWeCMWyCRAEBAQ X-IronPort-AV: E=Sophos;i="5.11,603,1422914400"; d="scan'208";a="20000745" Received: from csa.cs.technion.ac.il ([132.68.32.1]) by mailgw10.technion.ac.il with ESMTP; 19 Apr 2015 15:18:30 +0300 Received: from csn.cs.technion.ac.il (csn.cs.technion.ac.il [132.68.32.15]) by csa.cs.technion.ac.il (Postfix) with ESMTP id 47481140036; Sun, 19 Apr 2015 15:18:29 +0300 (IDT) Received: from csl-tapuz20.cs.technion.ac.il (csl-tapuz20.cs.technion.ac.il [132.68.206.58]) by csn.cs.technion.ac.il (Postfix) with ESMTPSA id 42617A03FE; Sun, 19 Apr 2015 15:18:29 +0300 (IDT) From: Nadav Amit To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, Nadav Amit Subject: [PATCH] KVM: x86: Mask DR7 correctly on task-switch while debugging Date: Sun, 19 Apr 2015 15:18:24 +0300 Message-Id: <1429445904-5105-1-git-send-email-namit@cs.technion.ac.il> X-Mailer: git-send-email 1.9.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the host sets hardware breakpoints to debug the guest, and a task-switch occurs in the guest, the architectural DR7 will not be updated. The effective DR7 would be updated instead. This fix uses the standard DR setting mechanism instead of the one that was previously used. As a bonus, the update of DR7 will now be effective for AMD as well. Signed-off-by: Nadav Amit --- arch/x86/kvm/vmx.c | 3 --- arch/x86/kvm/x86.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index f7a0a7f..8f731c0 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5703,9 +5703,6 @@ static int handle_task_switch(struct kvm_vcpu *vcpu) return 0; } - /* clear all local breakpoint enable flags */ - vmcs_writel(GUEST_DR7, vmcs_readl(GUEST_DR7) & ~0x155); - /* * TODO: What about debug traps on tss switch? * Are we supposed to inject them and update dr6? diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2046be4..a170c35 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6816,6 +6816,9 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, kvm_rip_write(vcpu, ctxt->eip); kvm_set_rflags(vcpu, ctxt->eflags); + ret = __kvm_set_dr(vcpu, 7, vcpu->arch.dr7 & ~(DR_LOCAL_ENABLE_MASK | + DR_LOCAL_SLOWDOWN)); + WARN_ON(ret != 0); kvm_make_request(KVM_REQ_EVENT, vcpu); return EMULATE_DONE; }