From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v2 25/30] KVM: x86 emulator: fix in/out emulation. Date: Mon, 15 Mar 2010 09:41:51 +0200 Message-ID: <4B9DE4BF.1080203@redhat.com> References: <1268583675-3101-1-git-send-email-gleb@redhat.com> <1268583675-3101-26-git-send-email-gleb@redhat.com> <4B9D14B3.2020002@redhat.com> <20100314173555.GA5406@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org To: Gleb Natapov Return-path: Received: from mx1.redhat.com ([209.132.183.28]:29507 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755326Ab0COHlx (ORCPT ); Mon, 15 Mar 2010 03:41:53 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2F7frqQ003180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 15 Mar 2010 03:41:53 -0400 In-Reply-To: <20100314173555.GA5406@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 03/14/2010 07:35 PM, Gleb Natapov wrote: > On Sun, Mar 14, 2010 at 06:54:11PM +0200, Avi Kivity wrote: > >> On 03/14/2010 06:21 PM, Gleb Natapov wrote: >> >>> in/out emulation is broken now. The breakage is different depending >>> on where IO device resides. If it is in userspace emulator reports >>> emulation failure since it incorrectly interprets kvm_emulate_pio() >>> return value. If IO device is in the kernel emulation of 'in' will do >>> nothing since kvm_emulate_pio() stores result directly into vcpu >>> registers, so emulator will overwrite result of emulation during >>> commit of shadowed register. >>> >>> >>> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c >>> index 8f5e4c8..344e17b 100644 >>> --- a/arch/x86/kvm/emulate.c >>> +++ b/arch/x86/kvm/emulate.c >>> @@ -210,13 +210,13 @@ static u32 opcode_table[256] = { >>> 0, 0, 0, 0, 0, 0, 0, 0, >>> /* 0xE0 - 0xE7 */ >>> 0, 0, 0, 0, >>> - ByteOp | SrcImmUByte, SrcImmUByte, >>> - ByteOp | SrcImmUByte, SrcImmUByte, >>> + ByteOp | SrcImmUByte | DstAcc, SrcImmUByte | DstAcc, >>> + ByteOp | SrcImmUByte | DstAcc, SrcImmUByte | DstAcc, >>> >> REX prefix shouldn't expand DstAcc to 64 bits here. Might cause >> problems further down in the pipeline.+ >> > Is REX prefix allowed with this opcodes? > > If yes: > > if (c->dst.bytes == 8) > c->dst.bytes = 4; > > inside IN/OUT emulation will fix this. > I don't know, but I guess REX is allowed and ignored. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.