From patchwork Mon Aug 23 13:33:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 124081 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7NDX9rG018538 for ; Mon, 23 Aug 2010 13:33:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586Ab0HWNdH (ORCPT ); Mon, 23 Aug 2010 09:33:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22266 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843Ab0HWNdF (ORCPT ); Mon, 23 Aug 2010 09:33:05 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7NDX5BJ029660 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Aug 2010 09:33:05 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7NDX4eC018414; Mon, 23 Aug 2010 09:33:04 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id DF5D9137796; Mon, 23 Aug 2010 16:33:03 +0300 (IDT) Date: Mon, 23 Aug 2010 16:33:03 +0300 From: Gleb Natapov To: Avi Kivity Cc: Marcelo Tosatti , kvm@vger.kernel.org Subject: Re: [PATCH 7/8] KVM: x86 emulator: simplify instruction decode flags for opcodes E0-FF Message-ID: <20100823133303.GQ10499@redhat.com> References: <1282561577-24491-1-git-send-email-avi@redhat.com> <1282561577-24491-8-git-send-email-avi@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1282561577-24491-8-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 23 Aug 2010 13:33:10 +0000 (UTC) === Some instructions has 32 bit operand even in long mode. Decode this through decode table instead of during instruction emulation. diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 3b35e13..b4361fa 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -84,6 +84,7 @@ #define Group (1<<14) /* Bits 3:5 of modrm byte extend opcode */ #define GroupDual (1<<15) /* Alternate decoding of mod == 3 */ /* Misc flags */ +#define Op32in64 (1<<22) /* Operand is 32b even in long mode */ #define NoAccess (1<<23) /* Don't access memory (lea/invlpg/verr etc) */ #define Op3264 (1<<24) /* Operand is 64b in long mode, 32b otherwise */ #define Undefined (1<<25) /* No Such Instruction */ @@ -2472,13 +2473,13 @@ static struct opcode opcode_table[256] = { N, N, N, N, N, N, N, N, /* 0xE0 - 0xE7 */ X3(D(SrcImmByte)), N, - D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc), - D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte), + D(ByteOp | SrcImmUByte | DstAcc), D(SrcImmUByte | DstAcc | Op32in64), + D(ByteOp | SrcAcc | DstImmUByte), D(SrcAcc | DstImmUByte | Op32in64), /* 0xE8 - 0xEF */ D(SrcImm | Stack), D(SrcImm | ImplicitOps), D(SrcImmFAddr | No64), D(SrcImmByte | ImplicitOps), - D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc), - D(ByteOp | SrcAcc | ImplicitOps), D(SrcAcc | ImplicitOps), + D(SrcNone | ByteOp | DstAcc), D(SrcNone | DstAcc | Op32in64), + D(ByteOp | SrcAcc | ImplicitOps), D(SrcAcc | ImplicitOps | Op32in64), /* 0xF0 - 0xF7 */ N, N, N, N, D(ImplicitOps | Priv), D(ImplicitOps), G(ByteOp, group3), G(0, group3), @@ -2750,6 +2751,9 @@ done_prefixes: c->op_bytes = 4; } + if (mode == X86EMUL_MODE_PROT64 && (c->d & Op32in64)) + c->op_bytes = 4; + /* ModRM and SIB bytes. */ if (c->d & ModRM) { rc = decode_modrm(ctxt, ops, &memop); @@ -3295,7 +3299,6 @@ special_insn: case 0xed: /* in (e/r)ax,dx */ c->src.val = c->regs[VCPU_REGS_RDX]; do_io_in: - c->dst.bytes = min(c->dst.bytes, 4u); if (!emulator_io_permited(ctxt, ops, c->src.val, c->dst.bytes)) { emulate_gp(ctxt, 0); goto done; @@ -3308,7 +3311,6 @@ special_insn: case 0xef: /* out dx,(e/r)ax */ c->dst.val = c->regs[VCPU_REGS_RDX]; do_io_out: - c->src.bytes = min(c->src.bytes, 4u); if (!emulator_io_permited(ctxt, ops, c->dst.val, c->src.bytes)) { emulate_gp(ctxt, 0);