From patchwork Tue Jun 17 07:04:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 4364391 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 44CDC9F758 for ; Tue, 17 Jun 2014 07:05:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 60AD4202EB for ; Tue, 17 Jun 2014 07:05:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D265202D1 for ; Tue, 17 Jun 2014 07:05:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753553AbaFQHF3 (ORCPT ); Tue, 17 Jun 2014 03:05:29 -0400 Received: from goliath.siemens.de ([192.35.17.28]:42859 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752160AbaFQHEv (ORCPT ); Tue, 17 Jun 2014 03:04:51 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.14.3/8.14.3) with ESMTP id s5H74jVv017189; Tue, 17 Jun 2014 09:04:45 +0200 Received: from mchn199C.mchp.siemens.de.com ([146.254.78.6]) by mail1.siemens.de (8.14.3/8.14.3) with SMTP id s5H74iXn009397; Tue, 17 Jun 2014 09:04:45 +0200 From: Jan Kiszka To: Paolo Bonzini Cc: kvm , Bandan Das Subject: [PATCH v2 1/6] VMX: Add tests for CR3 and CR8 interception Date: Tue, 17 Jun 2014 09:04:38 +0200 Message-Id: <52c87cba22c1cce0b98e40ae23224c6d03795898.1402988683.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.8.1.1.298.ge7eed54 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Need to fix FIELD_* constants for this to make the exit qualification check work. Signed-off-by: Jan Kiszka --- x86/vmx.h | 2 ++ x86/vmx_tests.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/x86/vmx.h b/x86/vmx.h index 26dd161..69a5385 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -357,6 +357,8 @@ enum Ctrl0 { CPU_RDTSC = 1ul << 12, CPU_CR3_LOAD = 1ul << 15, CPU_CR3_STORE = 1ul << 16, + CPU_CR8_LOAD = 1ul << 19, + CPU_CR8_STORE = 1ul << 20, CPU_TPR_SHADOW = 1ul << 21, CPU_NMI_WINDOW = 1ul << 22, CPU_IO = 1ul << 24, diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index a40cb18..149a591 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -820,8 +820,8 @@ static int iobmp_exit_handler() #define INSN_ALWAYS_TRAP 2 #define INSN_NEVER_TRAP 3 -#define FIELD_EXIT_QUAL 0 -#define FIELD_INSN_INFO 1 +#define FIELD_EXIT_QUAL (1 << 1) +#define FIELD_INSN_INFO (1 << 2) asm( "insn_hlt: hlt;ret\n\t" @@ -829,6 +829,12 @@ asm( "insn_mwait: mwait;ret\n\t" "insn_rdpmc: rdpmc;ret\n\t" "insn_rdtsc: rdtsc;ret\n\t" + "insn_cr3_load: mov %rax,%cr3;ret\n\t" + "insn_cr3_store: mov %cr3,%rax;ret\n\t" +#ifdef __x86_64__ + "insn_cr8_load: mov %rax,%cr8;ret\n\t" + "insn_cr8_store: mov %cr8,%rax;ret\n\t" +#endif "insn_monitor: monitor;ret\n\t" "insn_pause: pause;ret\n\t" "insn_wbinvd: wbinvd;ret\n\t" @@ -840,6 +846,12 @@ extern void insn_invlpg(); extern void insn_mwait(); extern void insn_rdpmc(); extern void insn_rdtsc(); +extern void insn_cr3_load(); +extern void insn_cr3_store(); +#ifdef __x86_64__ +extern void insn_cr8_load(); +extern void insn_cr8_store(); +#endif extern void insn_monitor(); extern void insn_pause(); extern void insn_wbinvd(); @@ -856,7 +868,7 @@ struct insn_table { u32 reason; ulong exit_qual; u32 insn_info; - // Use FIELD_EXIT_QUAL and FIELD_INSN_INFO to efines + // Use FIELD_EXIT_QUAL and FIELD_INSN_INFO to define // which field need to be tested, reason is always tested u32 test_field; }; @@ -877,6 +889,16 @@ static struct insn_table insn_table[] = { {"MWAIT", CPU_MWAIT, insn_mwait, INSN_CPU0, 36, 0, 0, 0}, {"RDPMC", CPU_RDPMC, insn_rdpmc, INSN_CPU0, 15, 0, 0, 0}, {"RDTSC", CPU_RDTSC, insn_rdtsc, INSN_CPU0, 16, 0, 0, 0}, + {"CR3 load", CPU_CR3_LOAD, insn_cr3_load, INSN_CPU0, 28, 0x3, 0, + FIELD_EXIT_QUAL}, + {"CR3 store", CPU_CR3_STORE, insn_cr3_store, INSN_CPU0, 28, 0x13, 0, + FIELD_EXIT_QUAL}, +#ifdef __x86_64__ + {"CR8 load", CPU_CR8_LOAD, insn_cr8_load, INSN_CPU0, 28, 0x8, 0, + FIELD_EXIT_QUAL}, + {"CR8 store", CPU_CR8_STORE, insn_cr8_store, INSN_CPU0, 28, 0x18, 0, + FIELD_EXIT_QUAL}, +#endif {"MONITOR", CPU_MONITOR, insn_monitor, INSN_CPU0, 39, 0, 0, 0}, {"PAUSE", CPU_PAUSE, insn_pause, INSN_CPU0, 40, 0, 0, 0}, // Flags for Secondary Processor-Based VM-Execution Controls @@ -894,6 +916,10 @@ static int insn_intercept_init() ctrl_cpu[0] = vmcs_read(CPU_EXEC_CTRL0); ctrl_cpu[0] |= CPU_HLT | CPU_INVLPG | CPU_MWAIT | CPU_RDPMC | CPU_RDTSC | + CPU_CR3_LOAD | CPU_CR3_STORE | +#ifdef __x86_64__ + CPU_CR8_LOAD | CPU_CR8_STORE | +#endif CPU_MONITOR | CPU_PAUSE | CPU_SECONDARY; ctrl_cpu[0] &= ctrl_cpu_rev[0].clr; vmcs_write(CPU_EXEC_CTRL0, ctrl_cpu[0]);