From patchwork Mon Nov 28 04:18:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 9449075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 727516071E for ; Mon, 28 Nov 2016 04:19:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F1D42074F for ; Mon, 28 Nov 2016 04:19:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5249C21050; Mon, 28 Nov 2016 04:19:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECF49204C1 for ; Mon, 28 Nov 2016 04:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754071AbcK1ETe (ORCPT ); Sun, 27 Nov 2016 23:19:34 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35754 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753990AbcK1ETW (ORCPT ); Sun, 27 Nov 2016 23:19:22 -0500 Received: by mail-pg0-f65.google.com with SMTP id p66so11886980pga.2 for ; Sun, 27 Nov 2016 20:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=78GMGcwhO8Ci6cMdvLRxrD89lx/Q5bPW9haw2ASfo6U=; b=KVasmZphWBTAhEvY/bHDZQcRnnez6he/vsZ+y7KMl8L/yS1xdZ7tMVShFdIQkDlE0b eqKusyPRLMPndKYo0PJlPqFOw0eeQXCvLFyQqq3qA3nkwpOdpsVM22BoA+NLcJAEeefj PWq53v7Pu1T2S7a/y2f6zyb4e+GeKV9x8hNoao6KnK8yEE43lp1r1EsKTpwB1jRwEg8y wHllnKS4Ao4zyNu5kgtOEVoQZbwd7JmKLzKkR+7lD0U6clLaDk9WYLM9IynW/u65TMJS 5HnqskMoJj54vjthy0/CGWabJoOPImbsnkrsD9Lnou5g4SLPY61BgQvgU89+V5LBRTIN WAlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=78GMGcwhO8Ci6cMdvLRxrD89lx/Q5bPW9haw2ASfo6U=; b=HnBOgjdpsfdnVNaNOgOCZNCoIu3K50hoKQqlWXhLjUigrB9NutX32HV/cEpM0torWC jB1H/rIenlzpwE191OsQCbOqcHDbiUL+SvEHbFf7BW2ClfPpAwDJYX9Xo8UV5LHGV8a5 yBoS1br8onD3UpsDWmrF9E6nvcY2QuH9YTTRCma2EvZvgfKMti7cM0Ye9VkS1k7oBSpW stJeICREHYBnBZGBfbfVWJb6ykN23lBJaRQkLbCWdpzZF3KkJR97GlwC0yTSNyUiJb0M QvBn0/0L9pCocI9h5xvIYpsCYRtHp9rZxDPShwp0CC0gAW399H8snU7mqgAVXllqsn5e fVZA== X-Gm-Message-State: AKaTC00kPtnOTnyBDShapknxeaHccuBziY3icQyob2FSDOgII1G09sJYY75tAFwyb3H4Tw== X-Received: by 10.84.175.3 with SMTP id s3mr44603763plb.66.1480306761725; Sun, 27 Nov 2016 20:19:21 -0800 (PST) Received: from minbar.hsd1.ca.comcast.net (c-73-162-102-141.hsd1.ca.comcast.net. [73.162.102.141]) by smtp.gmail.com with ESMTPSA id t89sm83037711pfe.50.2016.11.27.20.19.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 27 Nov 2016 20:19:21 -0800 (PST) From: Kyle Huey X-Google-Original-From: Kyle Huey To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] KVM: VMX: Handle RFLAGS.TF in skip_emulated_instruction Date: Sun, 27 Nov 2016 20:18:56 -0800 Message-Id: <20161128041856.11420-6-khuey@kylehuey.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161128041856.11420-1-khuey@kylehuey.com> References: <20161128041856.11420-1-khuey@kylehuey.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similar to the code in kvm_vcpu_check_singlestep, check for TF and, depending on the origin, synthesize a DB exception or an exit to userspace. Signed-off-by: Kyle Huey --- arch/x86/kvm/vmx.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index f404aef..6583e97 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2470,16 +2470,37 @@ static void skip_emulated_instruction_no_trap(struct kvm_vcpu *vcpu) /* skipping an emulated instruction also counts */ vmx_set_interrupt_shadow(vcpu, 0); } static int skip_emulated_instruction(struct kvm_vcpu *vcpu) { skip_emulated_instruction_no_trap(vcpu); + + if (unlikely(vmx_get_rflags(vcpu) & X86_EFLAGS_TF)) { + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) { + vcpu->run->debug.arch.dr6 = DR6_BS | DR6_FIXED_1 | + DR6_RTM; + vcpu->run->debug.arch.pc = vcpu->arch.singlestep_rip; + vcpu->run->debug.arch.exception = DB_VECTOR; + vcpu->run->exit_reason = KVM_EXIT_DEBUG; + return 0; + } + + /* + * "Certain debug exceptions may clear bit 0-3. The + * remaining contents of the DR6 register are never + * cleared by the processor". + */ + vcpu->arch.dr6 &= ~15; + vcpu->arch.dr6 |= DR6_BS | DR6_RTM; + kvm_queue_exception(vcpu, DB_VECTOR); + } + return 1; } /* * KVM wants to inject page-faults which it got to the guest. This function * checks whether in a nested guest, we need to inject them to L1 or L2. */ static int nested_vmx_check_exception(struct kvm_vcpu *vcpu, unsigned nr)