From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH 1/3] KVM: emulator: check rex prefix inside decode_register() Date: Mon, 4 Nov 2013 16:06:03 +0200 Message-ID: <20131104140603.GG7513@redhat.com> References: <1383573163-17865-1-git-send-email-gleb@redhat.com> <5277A986.9070309@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: Paolo Bonzini Return-path: Received: from mx1.redhat.com ([209.132.183.28]:41162 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753189Ab3KDOGF (ORCPT ); Mon, 4 Nov 2013 09:06:05 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA4E65hk015493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Nov 2013 09:06:05 -0500 Content-Disposition: inline In-Reply-To: <5277A986.9070309@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Nov 04, 2013 at 03:04:54PM +0100, Paolo Bonzini wrote: > Il 04/11/2013 14:52, Gleb Natapov ha scritto: > > All decode_register() callers check if instruction has rex prefix > > to properly decode one byte operand. It make sense to move the check > > inside. > > > > Signed-off-by: Gleb Natapov > > Reviewed-by: Paolo Bonzini > > I guess you'd like to use Linus's extra week and get it in 3.13? > Yes, nothing serious here. > Paolo > > > --- > > arch/x86/kvm/emulate.c | 18 +++++++----------- > > 1 file changed, 7 insertions(+), 11 deletions(-) > > > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > > index 282d28c..0bd372f 100644 > > --- a/arch/x86/kvm/emulate.c > > +++ b/arch/x86/kvm/emulate.c > > @@ -785,9 +785,10 @@ static int do_insn_fetch(struct x86_emulate_ctxt *ctxt, > > * @highbyte_regs specifies whether to decode AH,CH,DH,BH. > > */ > > static void *decode_register(struct x86_emulate_ctxt *ctxt, u8 modrm_reg, > > - int highbyte_regs) > > + int byteop) > > { > > void *p; > > + int highbyte_regs = (ctxt->rex_prefix == 0) && byteop; > > > > if (highbyte_regs && modrm_reg >= 4 && modrm_reg < 8) > > p = (unsigned char *)reg_rmw(ctxt, modrm_reg & 3) + 1; > > @@ -1024,7 +1025,6 @@ static void decode_register_operand(struct x86_emulate_ctxt *ctxt, > > struct operand *op) > > { > > unsigned reg = ctxt->modrm_reg; > > - int highbyte_regs = ctxt->rex_prefix == 0; > > > > if (!(ctxt->d & ModRM)) > > reg = (ctxt->b & 7) | ((ctxt->rex_prefix & 1) << 3); > > @@ -1046,10 +1046,10 @@ static void decode_register_operand(struct x86_emulate_ctxt *ctxt, > > > > op->type = OP_REG; > > if (ctxt->d & ByteOp) { > > - op->addr.reg = decode_register(ctxt, reg, highbyte_regs); > > + op->addr.reg = decode_register(ctxt, reg, true); > > op->bytes = 1; > > } else { > > - op->addr.reg = decode_register(ctxt, reg, 0); > > + op->addr.reg = decode_register(ctxt, reg, false); > > op->bytes = ctxt->op_bytes; > > } > > fetch_register_operand(op); > > @@ -1082,12 +1082,10 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt, > > ctxt->modrm_seg = VCPU_SREG_DS; > > > > if (ctxt->modrm_mod == 3) { > > - int highbyte_regs = ctxt->rex_prefix == 0; > > - > > op->type = OP_REG; > > op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes; > > op->addr.reg = decode_register(ctxt, ctxt->modrm_rm, > > - highbyte_regs && (ctxt->d & ByteOp)); > > + ctxt->d & ByteOp); > > if (ctxt->d & Sse) { > > op->type = OP_XMM; > > op->bytes = 16; > > @@ -4117,10 +4115,8 @@ static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op, > > case OpMem8: > > ctxt->memop.bytes = 1; > > if (ctxt->memop.type == OP_REG) { > > - int highbyte_regs = ctxt->rex_prefix == 0; > > - > > - ctxt->memop.addr.reg = decode_register(ctxt, ctxt->modrm_rm, > > - highbyte_regs); > > + ctxt->memop.addr.reg = decode_register(ctxt, > > + ctxt->modrm_rm, true); > > fetch_register_operand(&ctxt->memop); > > } > > goto mem_common; > > -- Gleb.