From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754680AbcK1LmU (ORCPT ); Mon, 28 Nov 2016 06:42:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60746 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753751AbcK1LmM (ORCPT ); Mon, 28 Nov 2016 06:42:12 -0500 Subject: Re: [PATCH 5/5] KVM: VMX: Handle RFLAGS.TF in skip_emulated_instruction To: Kyle Huey , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel References: <20161128041856.11420-1-khuey@kylehuey.com> <20161128041856.11420-6-khuey@kylehuey.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <9eff6257-0420-102d-539a-d3b8b57ba05b@redhat.com> Date: Mon, 28 Nov 2016 12:42:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161128041856.11420-6-khuey@kylehuey.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 28 Nov 2016 11:42:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/11/2016 05:18, Kyle Huey wrote: > + > + 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); > + } This code is pretty much the same as kvm_vcpu_check_singlestep. Let's not duplicate the code and implement skip_emulated_instruction can be implemented in x86.c, like unsigned long rflags = kvm_x86_ops->get_rflags(vcpu); int r = EMULATE_DONE; /* This would be the no_trap variant */ kvm_x86_ops->skip_emulated_instruction(vcpu); kvm_vcpu_check_singlestep(vcpu, rflags, &r); return r == EMULATE_DONE; (because x86.c/vmx.c/svm.c are separate modules, when moving the function to x86.c you should rename it to kvm_skip_emulated_instruction). Paolo