From patchwork Wed Jun 17 13:50:31 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 30876 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5HDlWKD005199 for ; Wed, 17 Jun 2009 13:47:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758985AbZFQNr1 (ORCPT ); Wed, 17 Jun 2009 09:47:27 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757688AbZFQNr1 (ORCPT ); Wed, 17 Jun 2009 09:47:27 -0400 Received: from sg2ehsobe004.messaging.microsoft.com ([207.46.51.78]:35322 "EHLO SG2EHSOBE004.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757333AbZFQNr0 (ORCPT ); Wed, 17 Jun 2009 09:47:26 -0400 Received: from mail29-sin-R.bigfish.com (10.210.100.245) by SG2EHSOBE004.bigfish.com (10.210.112.24) with Microsoft SMTP Server id 8.1.340.0; Wed, 17 Jun 2009 13:47:27 +0000 Received: from mail29-sin (localhost.localdomain [127.0.0.1]) by mail29-sin-R.bigfish.com (Postfix) with ESMTP id 979D684010A; Wed, 17 Jun 2009 13:47:27 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzzz32i17ch63h) X-Spam-TCS-SCL: 2:0 Received: by mail29-sin (MessageSwitch) id 1245246446766271_1816; Wed, 17 Jun 2009 13:47:26 +0000 (UCT) Received: from ausb3extmailp02.amd.com (ausb3extmailp02.amd.com [163.181.251.22]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail29-sin.bigfish.com (Postfix) with ESMTP id 13B93830053; Wed, 17 Jun 2009 13:47:25 +0000 (UTC) Received: from ausb3twp02.amd.com ([163.181.250.38]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id n5HDlIwC016157; Wed, 17 Jun 2009 08:47:21 -0500 X-WSS-ID: 0KLDYAN-02-MG8-01 Received: from sausexbh1.amd.com (sausexbh1.amd.com [163.181.22.101]) by ausb3twp02.amd.com (Tumbleweed MailGate 3.5.1) with ESMTP id 2BC8116A03CF; Wed, 17 Jun 2009 08:47:10 -0500 (CDT) Received: from SAUSEXMB3.amd.com ([163.181.22.202]) by sausexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 17 Jun 2009 08:47:18 -0500 Received: from SDRSEXMB1.amd.com ([172.20.3.116]) by SAUSEXMB3.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 17 Jun 2009 08:47:17 -0500 Received: from localhost.localdomain ([165.204.15.42]) by SDRSEXMB1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 17 Jun 2009 15:47:05 +0200 From: Andre Przywara To: avi@redhat.com CC: kvm@vger.kernel.org, Andre Przywara , Christoph Egger , Amit Shah Subject: [PATCH 1/6] allow emulation of syscalls instructions on #UD Date: Wed, 17 Jun 2009 15:50:31 +0200 Message-ID: <1245246636-30760-2-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.1.3 In-Reply-To: <1245246636-30760-1-git-send-email-andre.przywara@amd.com> References: <1245246636-30760-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 17 Jun 2009 13:47:05.0787 (UTC) FILETIME=[19E9A8B0:01C9EF52] MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add the opcodes for syscall, sysenter and sysexit to the list of instructions handled by the undefined opcode handler. Signed-off-by: Christoph Egger Signed-off-by: Amit Shah Signed-off-by: Andre Przywara --- arch/x86/kvm/x86.c | 33 ++++++++++++++++++++++++++------- 1 files changed, 26 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 6025e5b..88e159c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2632,14 +2632,33 @@ int emulate_instruction(struct kvm_vcpu *vcpu, r = x86_decode_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); - /* Reject the instructions other than VMCALL/VMMCALL when - * try to emulate invalid opcode */ + /* Only allow emulation of specific instructions on #UD + * (namely VMMCALL, sysenter, sysexit, syscall)*/ c = &vcpu->arch.emulate_ctxt.decode; - if ((emulation_type & EMULTYPE_TRAP_UD) && - (!(c->twobyte && c->b == 0x01 && - (c->modrm_reg == 0 || c->modrm_reg == 3) && - c->modrm_mod == 3 && c->modrm_rm == 1))) - return EMULATE_FAIL; + if (emulation_type & EMULTYPE_TRAP_UD) { + if (!c->twobyte) + return EMULATE_FAIL; + switch (c->b) { + case 0x01: /* VMMCALL */ + if (c->modrm_mod != 3 || c->modrm_rm != 1) + return EMULATE_FAIL; + break; + case 0x34: /* sysenter */ + case 0x35: /* sysexit */ + if (c->modrm_mod != 0 || c->modrm_rm != 0) + return EMULATE_FAIL; + break; + case 0x05: /* syscall */ + if (c->modrm_mod != 0 || c->modrm_rm != 0) + return EMULATE_FAIL; + break; + default: + return EMULATE_FAIL; + } + + if (!(c->modrm_reg == 0 || c->modrm_reg == 3)) + return EMULATE_FAIL; + } ++vcpu->stat.insn_emulation; if (r) {