From patchwork Sun Sep 22 14:44:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 2924491 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 B0BDF9F288 for ; Sun, 22 Sep 2013 14:46:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E487320111 for ; Sun, 22 Sep 2013 14:46:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A7E3200EC for ; Sun, 22 Sep 2013 14:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752391Ab3IVOpH (ORCPT ); Sun, 22 Sep 2013 10:45:07 -0400 Received: from mail.skyhub.de ([78.46.96.112]:53474 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752338Ab3IVOpG (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=4/7DcKdwF58JspZsHesCCw6Tkl+dDOrloTwH7S+Rkec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GpEf HJKJ2fOdSWPgUHQYJtd2HpiJwiAUrdNiJfijtYtjyk7dblTk3tpgmJNcVCYppGXcQeC 8Su9ijUfDKiPpudUF1EKXLPy/Y1aFER5ZVOENF/xGoL6XKpw0Nrdysnt01HBlJ7lVoE 81zzEMtQRxrnI8EkvNuRkiOgO3TuRSl8g= 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 BXAyEYOeaNWm; 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 989AF1DA238; 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=4/7DcKdwF58JspZsHesCCw6Tkl+dDOrloTwH7S+Rkec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=GpEf HJKJ2fOdSWPgUHQYJtd2HpiJwiAUrdNiJfijtYtjyk7dblTk3tpgmJNcVCYppGXcQeC 8Su9ijUfDKiPpudUF1EKXLPy/Y1aFER5ZVOENF/xGoL6XKpw0Nrdysnt01HBlJ7lVoE 81zzEMtQRxrnI8EkvNuRkiOgO3TuRSl8g= Received: by liondog.tnic (Postfix, from userid 1000) id D86EB10218C; 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 2/6] kvm, emulator: Use opcode length Date: Sun, 22 Sep 2013 16:44:51 +0200 Message-Id: <1379861095-628-3-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=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 From: Borislav Petkov Add a field to the current emulation context which contains the instruction opcode length. This will streamline handling of opcodes of different length. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/kvm_emulate.h | 8 ++++++-- arch/x86/kvm/emulate.c | 5 +++-- arch/x86/kvm/x86.c | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 15f960c06ff7..92a176ad456c 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -279,8 +279,12 @@ struct x86_emulate_ctxt { bool have_exception; struct x86_exception exception; - /* decode cache */ - u8 twobyte; + /* + * decode cache + */ + + /* current opcode length in bytes */ + u8 opcode_len; u8 b; u8 intercept; u8 lock_prefix; diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2bc1e81045b0..bfae4a433091 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -4114,6 +4114,7 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) ctxt->_eip = ctxt->eip; ctxt->fetch.start = ctxt->_eip; ctxt->fetch.end = ctxt->fetch.start + insn_len; + ctxt->opcode_len = 1; if (insn_len > 0) memcpy(ctxt->fetch.data, insn, insn_len); @@ -4196,7 +4197,7 @@ done_prefixes: opcode = opcode_table[ctxt->b]; /* Two-byte opcode? */ if (ctxt->b == 0x0f) { - ctxt->twobyte = 1; + ctxt->opcode_len = 2; ctxt->b = insn_fetch(u8, ctxt); opcode = twobyte_table[ctxt->b]; } @@ -4528,7 +4529,7 @@ special_insn: goto writeback; } - if (ctxt->twobyte) + if (ctxt->opcode_len == 2) goto twobyte_insn; switch (ctxt->b) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8dfde7a52dab..6f2ea40b80cf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4778,8 +4778,8 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu) static void init_decode_cache(struct x86_emulate_ctxt *ctxt) { - memset(&ctxt->twobyte, 0, - (void *)&ctxt->_regs - (void *)&ctxt->twobyte); + memset(&ctxt->opcode_len, 0, + (void *)&ctxt->_regs - (void *)&ctxt->opcode_len); ctxt->fetch.start = 0; ctxt->fetch.end = 0;