From patchwork Sun Sep 22 14:44:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 2924441 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56024BFF05 for ; Sun, 22 Sep 2013 14:46:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F3D4D20111 for ; Sun, 22 Sep 2013 14:46:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 205762053B for ; Sun, 22 Sep 2013 14:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752429Ab3IVOpJ (ORCPT ); Sun, 22 Sep 2013 10:45:09 -0400 Received: from mail.skyhub.de ([78.46.96.112]:53478 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353Ab3IVOpG (ORCPT ); Sun, 22 Sep 2013 10:45:06 -0400 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alien8.de; s=alien8; t=1379861105; bh=6FX4viMnkU26eVibQff6zmH7iKJFk/pcyYZ0+lgl1fY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=h3Pr LGpZ9KUP9bHLDeoBFze0RPyE9QtQWj13P+KoN2fJ85JzekqQwePCvuOjIkui3PK+51j lAm6USC97qfYWo70sPVL8Jf3cDapWYfC0NoLhKXzSyRX2WYLN4YihnL1g9iSPZ3zjbM 6H5FUrKdtoHVKyz79KKfSxa4ONH3OKNHc= Received: from mail.skyhub.de ([127.0.0.1]) by localhost (door.skyhub.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id HsoSQyg0f8oz; Sun, 22 Sep 2013 16:45:05 +0200 (CEST) Received: from liondog.tnic (p54B47BC4.dip0.t-ipconnect.de [84.180.123.196]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id CAB0B1DA23E; Sun, 22 Sep 2013 16:45:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alien8.de; s=alien8; t=1379861105; bh=6FX4viMnkU26eVibQff6zmH7iKJFk/pcyYZ0+lgl1fY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=h3Pr LGpZ9KUP9bHLDeoBFze0RPyE9QtQWj13P+KoN2fJ85JzekqQwePCvuOjIkui3PK+51j lAm6USC97qfYWo70sPVL8Jf3cDapWYfC0NoLhKXzSyRX2WYLN4YihnL1g9iSPZ3zjbM 6H5FUrKdtoHVKyz79KKfSxa4ONH3OKNHc= Received: by liondog.tnic (Postfix, from userid 1000) id E653C10219D; Sun, 22 Sep 2013 16:44:56 +0200 (CEST) From: Borislav Petkov To: LKML Cc: Borislav Petkov , "H. Peter Anvin" , Gleb Natapov , Paolo Bonzini , Andre Przywara , Joerg Roedel , X86 ML , KVM Subject: [PATCH 4/6] kvm, emulator: Add initial three-byte insns support Date: Sun, 22 Sep 2013 16:44:53 +0200 Message-Id: <1379861095-628-5-git-send-email-bp@alien8.de> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1379861095-628-1-git-send-email-bp@alien8.de> References: <1379861095-628-1-git-send-email-bp@alien8.de> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 From: Borislav Petkov Add initial support for handling three-byte instructions in the emulator. Signed-off-by: Borislav Petkov --- arch/x86/kvm/emulate.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 67277bcb377a..72093d76c769 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3880,6 +3880,25 @@ static const struct opcode twobyte_table[256] = { N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N }; +static const struct gprefix third_opcode_byte_0xf0 = { + N, N, N, N +}; + +static const struct gprefix third_opcode_byte_0xf1 = { + N, N, N, N +}; + +/* + * Insns below are selected by the prefix which indexed by the third opcode + * byte. + */ +static const struct opcode opcode_map_0f_38[256] = { + /* 0x00 - 0x7f */ + X16(N), X16(N), X16(N), X16(N), X16(N), X16(N), X16(N), X16(N), + /* 0x80 - 0xff */ + X16(N), X16(N), X16(N), X16(N), X16(N), X16(N), X16(N), X16(N) +}; + #undef D #undef N #undef G @@ -4200,6 +4219,13 @@ done_prefixes: ctxt->opcode_len = 2; ctxt->b = insn_fetch(u8, ctxt); opcode = twobyte_table[ctxt->b]; + + /* 0F_38 opcode map */ + if (ctxt->b == 0x38) { + ctxt->opcode_len = 3; + ctxt->b = insn_fetch(u8, ctxt); + opcode = opcode_map_0f_38[ctxt->b]; + } } ctxt->d = opcode.flags; @@ -4531,6 +4557,8 @@ special_insn: if (ctxt->opcode_len == 2) goto twobyte_insn; + else if (ctxt->opcode_len == 3) + goto threebyte_insn; switch (ctxt->b) { case 0x63: /* movsxd */ @@ -4715,6 +4743,8 @@ twobyte_insn: goto cannot_emulate; } +threebyte_insn: + if (rc != X86EMUL_CONTINUE) goto done;