From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCHv2 4/5] KVM: emulator: move linearize() out of emulator code. Date: Sun, 24 Jun 2012 16:27:10 +0300 Message-ID: <20120624132710.GW6533@redhat.com> References: <1339502487-30049-1-git-send-email-gleb@redhat.com> <1339502487-30049-5-git-send-email-gleb@redhat.com> <4FE71225.2010504@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, mtosatti@redhat.com To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:33007 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753383Ab2FXN1M (ORCPT ); Sun, 24 Jun 2012 09:27:12 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5ODRChn014852 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 24 Jun 2012 09:27:12 -0400 Content-Disposition: inline In-Reply-To: <4FE71225.2010504@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Sun, Jun 24, 2012 at 04:12:05PM +0300, Avi Kivity wrote: > On 06/12/2012 03:01 PM, Gleb Natapov wrote: > > The function will be used outside of the emulator. > > > > /* > > * x86_emulate_ops: > > * > > @@ -194,6 +199,10 @@ struct x86_emulate_ops { > > > > bool (*get_cpuid)(struct x86_emulate_ctxt *ctxt, > > u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); > > + > > + int (*linearize)(struct x86_emulate_ctxt *ctxt, > > + struct segmented_address addr, unsigned size, > > + bool write, bool fetch, ulong *linear); > > }; > > > > linearize is defined in terms of the other ops; this means that if we > get a second user they will have to replicate it. > What do you mean? This patch series adds another user, so now there are two: one inside the emulator another is outside. > Why not make the current linearize available to users? > Code outside of the emulator does not call the emulator except when emulation is actually needed. To call linearize() from the emulator.c almost fully functional emulation ctxt will have to be set up (including fake instruction decoding, hacky and slower). To not duplicate the logic I moved linearize() to generic code and made it available to emulator via callback. It actually saves a couple of callback invocations when emulator calls linearize() IIRC. -- Gleb.