From mboxrd@z Thu Jan 1 00:00:00 1970 From: Borislav Petkov Subject: Re: [PATCH -v2] kvm: Emulate MOVBE Date: Mon, 22 Apr 2013 11:52:03 +0200 Message-ID: <20130422095203.GE4637@pd.tnic> References: <20130410121639.GE17919@redhat.com> <20130411001815.GA17544@pd.tnic> <20130414084303.GE17919@redhat.com> <20130414210218.GF20547@pd.tnic> <516D37A0.2070706@redhat.com> <20130421114649.GC4594@pd.tnic> <20130421122321.GD4594@pd.tnic> <5174FA96.1040807@redhat.com> <20130422093810.GC4637@pd.tnic> <20130422094246.GN8997@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: Paolo Bonzini , Andre Przywara , kvm@vger.kernel.org, =?utf-8?B?SsO2cmcgUsO2ZGVs?= , "H. Peter Anvin" , x86-ml To: Gleb Natapov Return-path: Received: from mail.skyhub.de ([78.46.96.112]:49137 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752421Ab3DVJwG (ORCPT ); Mon, 22 Apr 2013 05:52:06 -0400 Content-Disposition: inline In-Reply-To: <20130422094246.GN8997@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Apr 22, 2013 at 12:42:46PM +0300, Gleb Natapov wrote: > > Btw, I wanted to ask: when kvm commits the results, does it look at > > ctxt->op_bytes to know exactly how many bytes to write to the guest? > > Because if it does, we can save ourselves the trouble here. > > > > Or does it simply write both the full sizeof(unsigned long) bytes of > > ->src.val and ->dst.val to the guest? > > > No, it does this in case of register operand: > > static void write_register_operand(struct operand *op) > { > /* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */ > switch (op->bytes) { > case 1: > *(u8 *)op->addr.reg = (u8)op->val; > break; > case 2: > *(u16 *)op->addr.reg = (u16)op->val; > break; > case 4: > *op->addr.reg = (u32)op->val; > break; /* 64b: zero-extend */ > case 8: > *op->addr.reg = op->val; > break; > } > } Ok, and for OP_MEM it does look at ctxt->dst.bytes in writeback(), AFAICT. And I see other emulated instructions like POPF, for example, do this: ctxt->dst.bytes = ctxt->op_bytes; Which means, we can drop all the bullshit in em_movbe and even destroy some of the bytes in dst.val but only write out the correct ones. Which means, a simpler code and a lot less jumping through hoops. Would that be the more accepted practice? Thanks. -- Regards/Gruss, Boris. Sent from a fat crate under my desk. Formatting is fine. --