From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755683AbcK1WnO (ORCPT ); Mon, 28 Nov 2016 17:43:14 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35541 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755071AbcK1WnJ (ORCPT ); Mon, 28 Nov 2016 17:43:09 -0500 Subject: Re: [PATCH 5/5] KVM: VMX: Handle RFLAGS.TF in skip_emulated_instruction To: Kyle Huey References: <20161128041856.11420-1-khuey@kylehuey.com> <20161128041856.11420-6-khuey@kylehuey.com> <9eff6257-0420-102d-539a-d3b8b57ba05b@redhat.com> Cc: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , kvm list , open list From: Paolo Bonzini Message-ID: Date: Mon, 28 Nov 2016 23:43:02 +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: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/11/2016 19:34, Kyle Huey wrote: >> > The Intel manual says "The processor clears the TF flag before calling >> > the exception handler" (17.3.1.4), so I think you should do it too. > The processor does this automatically. "When accessing an exception or > interrupt handler through either an interrupt gate or a trap gate, the > processor clears the TF flag in the EFLAGS register after it saves the > contents of the EFLAGS register on the stack." (Vol 3, 6.12.1.2) > Empirically, this holds when injecting an exception on VM entry. If > you take the x86/debug.c test from kvm-unit-tests and inspect RFLAGS > in handle_db (not regs->rflags, but the actual RFLAGS register while > running the exception handler) the TF is clear. And, if you modify my > patch to clear TF before returning, the single stepping ceases after > the CPUID instruction because the TF was in fact cleared for good. Ok, then that would be a bug in kvm_vcpu_check_singlestep (because kvm_vcpu_check_singlestep is mostly interesting for real mode emulation, I checked kvm_inject_realmode_interrupt and it clears TF too, in __emulate_int_real). Paolo