Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422793AbcK3Sw5 (ORCPT ); Wed, 30 Nov 2016 13:52:57 -0500 Received: from mail-ua0-f196.google.com ([209.85.217.196]:35083 "EHLO mail-ua0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964817AbcK3Swv (ORCPT ); Wed, 30 Nov 2016 13:52:51 -0500 MIME-Version: 1.0 In-Reply-To: <20161130184156.GF1682@potion> References: <20161129204041.8839-1-khuey@kylehuey.com> <20161130184156.GF1682@potion> From: Kyle Huey Date: Wed, 30 Nov 2016 10:52:49 -0800 Message-ID: Subject: Re: [PATCH v2 0/5] KVM: VMX: Fix single stepping with emulated instructions To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Cc: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , kvm list , open list Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAUIr1fN016273 Content-Length: 1614 Lines: 36 On Wed, Nov 30, 2016 at 10:41 AM, Radim Krčmář wrote: > 2016-11-29 12:40-0800, Kyle Huey: >> KVM does not currently honor the trap flag when emulating instructions that >> cause VM exits. This is observable from guest userspace, try stepping on a >> CPUID instruction in gdb in a KVM guest. The program will stop two >> instructions after CPUID. >> >> To fix this, add kvm_skip_emulated_instruction that calls >> kvm_x86_ops->skip_emulated_instruction and then kvm_vcpu_check_singlestep to >> check for RFLAGS.TF. Patch 4 does this. To handle both the guest setting TF >> and the KVM_GUESTDBG_SINGLESTEP cases we need to be able to indicate to >> callees that an exit to userspace is required. Patches 1-3 are largely >> plumbing to make this possible. >> >> Traps triggered by task switch instructions require some additional handling >> and are not implemented. KVM_GUESTDBG_SINGLESTEP traps can be squashed by >> certain instructions which also trigger userspace exits, such as HALT, >> MOV CR8, and IO instructions. I believe (although I have not tested) that >> KVM will simply generate another trap on the next instruction, so this is >> no worse than the current behavior. >> >> Patch 5 fixes an existing bug where kvm_vcpu_check_singlestep clears >> RFLAGS.TF when generating a singlestep trap. Bare silicon does not do this. > > Looks good, applied to kvm/queue. Great! Thank you. >> These patches only fix this issue for VMX, and the handful of SVM cases that >> call the shared kvm_complete_insn_gp. I don't have AMD silicon to test on. > > Added to TODO, > > Thanks. - Kyle