From patchwork Mon Mar 9 20:00:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 5970791 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4560F9F318 for ; Mon, 9 Mar 2015 20:00:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 818F020456 for ; Mon, 9 Mar 2015 20:00:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 979812021A for ; Mon, 9 Mar 2015 20:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753090AbbCIUAV (ORCPT ); Mon, 9 Mar 2015 16:00:21 -0400 Received: from goliath.siemens.de ([192.35.17.28]:52780 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752528AbbCIUAU (ORCPT ); Mon, 9 Mar 2015 16:00:20 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.14.3/8.14.3) with ESMTP id t29K0Bh6013494; Mon, 9 Mar 2015 21:00:11 +0100 Received: from md1f2u6c.ww002.siemens.net (md1f2u6c.mch.sbs.de [139.25.40.156] (may be forged)) by mail1.siemens.de (8.14.3/8.14.3) with ESMTP id t29K0B80025129; Mon, 9 Mar 2015 21:00:11 +0100 Message-ID: <54FDFBCB.9030806@siemens.com> Date: Mon, 09 Mar 2015 21:00:11 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: kvm , Paolo Bonzini , Marcelo Tosatti Subject: [PATCH kvm-unit-test] x86: vmx: Check #UD triggering of vmmcall Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 KVM tends to patch and emulated vmmcall on Intel. But that must not happen for L2. Signed-off-by: Jan Kiszka --- If the recently posted fixed for KVM are applied, this test passes. x86/vmx_tests.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 41a9a82..4f8ace1 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -11,6 +11,7 @@ #include "fwcfg.h" #include "isr.h" #include "apic.h" +#include "types.h" u64 ia32_pat; u64 ia32_efer; @@ -1493,6 +1494,44 @@ static int msr_switch_exit_handler() return VMX_TEST_EXIT; } +static int vmmcall_init(struct vmcs *vmcs ) +{ + vmcs_write(EXC_BITMAP, 1 << UD_VECTOR); + return VMX_TEST_START; +} + +static void vmmcall_main(void) +{ + asm volatile( + "mov $0xABCD, %%rax\n\t" + "vmmcall\n\t" + ::: "rax"); + + report("VMMCALL", 0); +} + +static int vmmcall_exit_handler() +{ + ulong reason; + + reason = vmcs_read(EXI_REASON); + switch (reason) { + case VMX_VMCALL: + printf("here\n"); + report("VMMCALL triggers #UD", 0); + break; + case VMX_EXC_NMI: + report("VMMCALL triggers #UD", + (vmcs_read(EXI_INTR_INFO) & 0xff) == UD_VECTOR); + break; + default: + printf("Unknown exit reason, %d\n", reason); + print_vmexit_info(); + } + + return VMX_TEST_VMEXIT; +} + /* name/init/guest_main/exit_handler/syscall_handler/guest_regs */ struct vmx_test vmx_tests[] = { { "null", NULL, basic_guest_main, basic_exit_handler, NULL, {0} }, @@ -1516,5 +1555,6 @@ struct vmx_test vmx_tests[] = { NULL, {0} }, { "MSR switch", msr_switch_init, msr_switch_main, msr_switch_exit_handler, NULL, {0} }, + { "vmmcall", vmmcall_init, vmmcall_main, vmmcall_exit_handler, NULL, {0} }, { NULL, NULL, NULL, NULL, NULL, {0} }, };