From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753805AbcK1ET0 (ORCPT ); Sun, 27 Nov 2016 23:19:26 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35659 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752999AbcK1ETR (ORCPT ); Sun, 27 Nov 2016 23:19:17 -0500 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 0/5] KVM: VMX: Fix single stepping with emulated instructions. Date: Sun, 27 Nov 2016 20:18:51 -0800 Message-Id: <20161128041856.11420-1-khuey@kylehuey.com> X-Mailer: git-send-email 2.10.2 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, in skip_emulated_instruction we can check for RFLAGS.TF. Patch 5 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-4 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. These patches only fix this issue for VMX. I don't have AMD silicon to test on. A small patch to kvm-unit-tests is coming in a separate email.