From patchwork Tue Sep 30 17:49:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 5005371 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DFA7BBEEA6 for ; Tue, 30 Sep 2014 17:50:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2AE1020200 for ; Tue, 30 Sep 2014 17:50:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39266201C7 for ; Tue, 30 Sep 2014 17:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753638AbaI3Rty (ORCPT ); Tue, 30 Sep 2014 13:49:54 -0400 Received: from mailgw12.technion.ac.il ([132.68.225.12]:4433 "EHLO mailgw12.technion.ac.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753565AbaI3Rtn (ORCPT ); Tue, 30 Sep 2014 13:49:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiEFAGDsKlSERCAB/2dsb2JhbABggw5TV8okh1ECgQ0WAQF6hAQBBSdSEFFXGYg+uDSGRxiQHgcWhDUFi02EA4ZViG+UC4NmaYJKAQEB X-IPAS-Result: AiEFAGDsKlSERCAB/2dsb2JhbABggw5TV8okh1ECgQ0WAQF6hAQBBSdSEFFXGYg+uDSGRxiQHgcWhDUFi02EA4ZViG+UC4NmaYJKAQEB X-IronPort-AV: E=Sophos;i="5.04,628,1406581200"; d="scan'208";a="123967595" Received: from csa.cs.technion.ac.il ([132.68.32.1]) by mailgw12.technion.ac.il with ESMTP; 30 Sep 2014 20:49:38 +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 158D414003B; Tue, 30 Sep 2014 20:49:38 +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 10AECA0C6D; Tue, 30 Sep 2014 20:49:38 +0300 (IDT) From: Nadav Amit To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, nadav.amit@gmail.com, Nadav Amit Subject: [PATCH 1/6] KVM: x86: DR7.GD should be cleared upon any #DB exception Date: Tue, 30 Sep 2014 20:49:14 +0300 Message-Id: <1412099359-5316-2-git-send-email-namit@cs.technion.ac.il> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412099359-5316-1-git-send-email-namit@cs.technion.ac.il> References: <1412099359-5316-1-git-send-email-namit@cs.technion.ac.il> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Intel SDM 17.2.4 (Debug Control Register (DR7)) says: "The processor clears the GD flag upon entering to the debug exception handler." This sentence may be misunderstood as if it happens only on #DB due to debug-register protection, but it happens regardless to the cause of the #DB. Fix the behavior. Signed-off-by: Nadav Amit Reviewed-by: Radim Kr?má? --- arch/x86/kvm/vmx.c | 2 -- arch/x86/kvm/x86.c | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 04fa1b8..82d39f9 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5176,9 +5176,7 @@ static int handle_dr(struct kvm_vcpu *vcpu) vcpu->run->exit_reason = KVM_EXIT_DEBUG; return 0; } else { - vcpu->arch.dr7 &= ~DR7_GD; vcpu->arch.dr6 |= DR6_BD | DR6_RTM; - vmcs_writel(GUEST_DR7, vcpu->arch.dr7); kvm_queue_exception(vcpu, DB_VECTOR); return 1; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6857257..fb02371 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5935,6 +5935,12 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win) __kvm_set_rflags(vcpu, kvm_get_rflags(vcpu) | X86_EFLAGS_RF); + if (vcpu->arch.exception.nr == DB_VECTOR && + (vcpu->arch.dr7 & DR7_GD)) { + vcpu->arch.dr7 &= ~DR7_GD; + kvm_update_dr7(vcpu); + } + kvm_x86_ops->queue_exception(vcpu, vcpu->arch.exception.nr, vcpu->arch.exception.has_error_code, vcpu->arch.exception.error_code,