From patchwork Sun Jul 5 17:08:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Mihai_Don=C8=9Bu?= X-Patchwork-Id: 6718601 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ADE1BC05AC for ; Sun, 5 Jul 2015 17:16:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4CAF205E1 for ; Sun, 5 Jul 2015 17:16:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B2BAB205DC for ; Sun, 5 Jul 2015 17:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752975AbbGERQb (ORCPT ); Sun, 5 Jul 2015 13:16:31 -0400 Received: from mx01.buh.bitdefender.com ([91.199.104.161]:53871 "EHLO mx.bitdefender.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752641AbbGERQ3 (ORCPT ); Sun, 5 Jul 2015 13:16:29 -0400 X-Greylist: delayed 439 seconds by postgrey-1.27 at vger.kernel.org; Sun, 05 Jul 2015 13:16:29 EDT Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=uluhVeINB3FXg+NThspzV+6fIC0C2beFXza9n8Lmp7FgvQRsLEyz3BeyBEMWDD272mVPtg5/p8W6WG4yCGwJJi2/MK6eeK64bxOTFbOaFLojSpp2NkNr7zua8hXiKF/b6G3CG5eFKP5d3Gd4WBrd5J3u3iFH9Krwy1rcKWuduRfIAeQXaZx5X2lNNa/+s8e8aWGvYahvDu5pTzU3p6ev42lPJMuj9waeqi18jlkrWeg9H63gI3T5bzsgBbFACib4pi6jl4qD3+soAjNkSxOMDMs8VOEnz52k2dY41Lg21/NhBvQnpGpqomoqvuBJZcwmPJWxrxIS31ktiXUyxot0NQ==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version:Content-Type:Content-Transfer-Encoding:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=+st8gAihsly7o2yixB6BSU nv1yw=; b=CzHRTzCEDbgtBqJl/JCIKg3vsC2NlHJzTSu4Tcwmj1bZg5HOq63nBz 8AF1X5Biq89nHwMB5z1Oo0hjy9DAC23ijpJvUitpETbbIapOAeRXbZ0UhXkblp3g 7iye96R8CQHNZLlypsbbcYPfFJXs1PuApFB7T+ovS1Y25BPASVDYFX2fv8E76T5Z UMzISNDpot91vgyk5nCGCVTH7+6nDmbTbw3vJQCPleD57+UsOrUb0YR6SsdpiSJ5 HuHmhyaBpwhQ+dry4SqkX8g7F2vv282zclZaeiQiC7EqH7M7KZpmSaepIXnfEeBu 1vbqN2jwyVPXgR1qsxG9mM5TlWuSUcxQ== Received: (qmail 23284 invoked from network); 5 Jul 2015 20:09:06 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 5 Jul 2015 20:09:06 +0300 Received: from smtp03.buh.bitdefender.org (unknown [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 174F7804F2 for ; Sun, 5 Jul 2015 20:09:06 +0300 (EEST) Received: (qmail 8682 invoked from network); 5 Jul 2015 20:09:05 +0300 Received: from 5-12-114-141.residential.rdsnet.ro (HELO mdontu-l.dsd.ro) (mdontu@bitdefender.com@5.12.114.141) by smtp03.buh.bitdefender.org with SMTP; 5 Jul 2015 20:09:04 +0300 From: =?UTF-8?q?Mihai=20Don=C8=9Bu?= To: kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, gleb@kernel.org, pbonzini@redhat.com, wanpeng.li@linux.intel.com, guangrong.xiao@linux.intel.com, kai.huang@linux.intel.com, rkrcmar@redhat.com, jan.kiszka@siemens.com, mtosatti@redhat.com, pmatouse@redhat.com, fanwenyi0529@gmail.com, linux-kernel@vger.kernel.org, =?UTF-8?q?Mihai=20Don=C8=9Bu?= Subject: [PATCH] kvm/x86: add support for MONITOR_TRAP_FLAG Date: Sun, 5 Jul 2015 20:08:57 +0300 Message-Id: <1436116137-20262-1-git-send-email-mdontu@bitdefender.com> X-Mailer: git-send-email 2.4.5 MIME-Version: 1.0 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.4 on smtp03.buh.bitdefender.org, sigver: 7.61405 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.684, Dats: 394828, Stamp: 3], Multi: [Enabled], BW: [Enabled], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500], SGN: [Enabled], URL: [Enabled], RTDA: [Enabled, Hit: No, Details: v2.2.10; Id: 2m1ghar.19pbmb009.1npe0], total: 0(775) X-BitDefender-CF-Stamp: none Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow a nested hypervisor to single step its guests. Signed-off-by: Mihai Don?u Reviewed-by: Jan Kiszka --- This patch applies on top of current linux-next. --- arch/x86/include/asm/vmx.h | 1 + arch/x86/include/uapi/asm/vmx.h | 2 ++ arch/x86/kvm/vmx.c | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index da772ed..9299ae5 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -47,6 +47,7 @@ #define CPU_BASED_MOV_DR_EXITING 0x00800000 #define CPU_BASED_UNCOND_IO_EXITING 0x01000000 #define CPU_BASED_USE_IO_BITMAPS 0x02000000 +#define CPU_BASED_MONITOR_TRAP_FLAG 0x08000000 #define CPU_BASED_USE_MSR_BITMAPS 0x10000000 #define CPU_BASED_MONITOR_EXITING 0x20000000 #define CPU_BASED_PAUSE_EXITING 0x40000000 diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vmx.h index 1fe9218..37fee27 100644 --- a/arch/x86/include/uapi/asm/vmx.h +++ b/arch/x86/include/uapi/asm/vmx.h @@ -58,6 +58,7 @@ #define EXIT_REASON_INVALID_STATE 33 #define EXIT_REASON_MSR_LOAD_FAIL 34 #define EXIT_REASON_MWAIT_INSTRUCTION 36 +#define EXIT_REASON_MONITOR_TRAP_FLAG 37 #define EXIT_REASON_MONITOR_INSTRUCTION 39 #define EXIT_REASON_PAUSE_INSTRUCTION 40 #define EXIT_REASON_MCE_DURING_VMENTRY 41 @@ -106,6 +107,7 @@ { EXIT_REASON_MSR_READ, "MSR_READ" }, \ { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, \ { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, \ + { EXIT_REASON_MONITOR_TRAP_FLAG, "MONITOR_TRAP_FLAG" }, \ { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, \ { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, \ { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, \ diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index e856dd5..6d7c650 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2443,7 +2443,7 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx) CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING | #endif CPU_BASED_MOV_DR_EXITING | CPU_BASED_UNCOND_IO_EXITING | - CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_EXITING | + CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_TRAP_FLAG | CPU_BASED_MONITOR_EXITING | CPU_BASED_RDPMC_EXITING | CPU_BASED_RDTSC_EXITING | CPU_BASED_PAUSE_EXITING | CPU_BASED_TPR_SHADOW | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS; @@ -6246,6 +6246,11 @@ static int handle_mwait(struct kvm_vcpu *vcpu) return handle_nop(vcpu); } +static int handle_monitor_trap(struct kvm_vcpu *vcpu) +{ + return 1; +} + static int handle_monitor(struct kvm_vcpu *vcpu) { printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); @@ -7282,6 +7287,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { [EXIT_REASON_EPT_MISCONFIG] = handle_ept_misconfig, [EXIT_REASON_PAUSE_INSTRUCTION] = handle_pause, [EXIT_REASON_MWAIT_INSTRUCTION] = handle_mwait, + [EXIT_REASON_MONITOR_TRAP_FLAG] = handle_monitor_trap, [EXIT_REASON_MONITOR_INSTRUCTION] = handle_monitor, [EXIT_REASON_INVEPT] = handle_invept, [EXIT_REASON_INVVPID] = handle_invvpid, @@ -7542,6 +7548,8 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu) return true; case EXIT_REASON_MWAIT_INSTRUCTION: return nested_cpu_has(vmcs12, CPU_BASED_MWAIT_EXITING); + case EXIT_REASON_MONITOR_TRAP_FLAG: + return nested_cpu_has(vmcs12, CPU_BASED_MONITOR_TRAP_FLAG); case EXIT_REASON_MONITOR_INSTRUCTION: return nested_cpu_has(vmcs12, CPU_BASED_MONITOR_EXITING); case EXIT_REASON_PAUSE_INSTRUCTION: