All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, mtosatti@redhat.com
Subject: Re: [PATCHv2 4/5] KVM: emulator: move linearize() out of emulator code.
Date: Tue, 26 Jun 2012 11:30:41 +0300	[thread overview]
Message-ID: <20120626083041.GY6533@redhat.com> (raw)
In-Reply-To: <4FE888AE.80801@redhat.com>

On Mon, Jun 25, 2012 at 06:50:06PM +0300, Avi Kivity wrote:
> >> >>              Later we can extend x86_decode_insn() and the other
> >> >> functions to follow the same rule.
> >> >> 
> >> > What rule? We cannot not initialize a context. You can reduce things
> >> > that should be initialized to minimum (getting GP registers on demand,
> >> > etc), but still some initialization is needed since ctxt holds emulation
> >> > state and it needs to be reset before each emulation.
> >> 
> >> An alternative is to use two contexts, the base context only holds ops
> >> and is the parameter to all the callbacks on the non-state APIs, the
> >> derived context holds the state:
> >> 
> >> struct x86_emulation_ctxt {
> >>     struct x86_ops *ops;
> >>     /* state that always needs to be initialized, preferablt none */
> >> };
> >> 
> >> struct x86_insn_ctxt {
> >>     struct x86_emulation_ctxt em;
> >>     /* instruction state */
> >> }
> >> 
> >> and so we have a compile-time split between users of the state and
> >> non-users.
> >> 
> > I do not understand how you will divide current ctxt structure between
> > those two.
> > 
> > Where will you put those for instance: interruptibility, have_exception,
> > perm_ok, only_vendor_specific_insn and how can they not be initialized
> > before each instruction emulation?
> 
> x86_emulate_ops::get_interruptibility()
> x86_emulate_ops::set_interruptibility()
> x86_emulate_ops::exception()
> 
They do not remove the need for initialization before instruction
execution, they just move things that need to be initialized somewhere
else (to kvm_arch_vcpu likely).

> x86_decode_insn(struct x86_insn_ctxt *ctxt, unsigned flags)
> {
>     ctxt->flags = flags;
>     ctxt->perm_ok = false;
> }
> 
> In short, instruction emulation state is only seen by instruction
> emulation functions, the others don't get to see it.
> 
So you want to divide emulator.c to two types of function: those without
side effect, that do some kind of calculations on vcpu state according
to weird x86 rules, and those that change vcpu state and write it back
eventually. I do not see the justification for that complication really.
emulator.c is complicated enough already and the line between two may be
blurred.

If you dislike linearize() callback so much I can make
kvm_linearize_address() to do calculation base on its parameters only.
It is almost there, only cpl and seg base/desc are missing from
parameter list. I can put it into header and x86.c/emulator.c will both
be able to use it.

--
			Gleb.

  reply	other threads:[~2012-06-26  8:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-12 12:01 [PATCHv2 0/5] improve speed of "rep ins" emulation Gleb Natapov
2012-06-12 12:01 ` [PATCHv2 1/5] Provide userspace IO exit completion callback Gleb Natapov
2012-06-29  0:51   ` Marcelo Tosatti
2012-07-01  8:15     ` Gleb Natapov
2012-06-12 12:01 ` [PATCHv2 2/5] KVM: emulator: make x86 emulation modes enum instead of defines Gleb Natapov
2012-06-12 12:01 ` [PATCHv2 3/5] KVM: emulator: move some address manipulation function out of emulator code Gleb Natapov
2012-06-12 12:01 ` [PATCHv2 4/5] KVM: emulator: move linearize() " Gleb Natapov
2012-06-24 13:12   ` Avi Kivity
2012-06-24 13:27     ` Gleb Natapov
2012-06-24 13:39       ` Avi Kivity
2012-06-24 14:27         ` Gleb Natapov
2012-06-25 12:57           ` Avi Kivity
2012-06-25 13:12             ` Gleb Natapov
2012-06-25 13:40               ` Avi Kivity
2012-06-25 14:17                 ` Gleb Natapov
2012-06-25 14:32                   ` Avi Kivity
2012-06-25 14:55                     ` Gleb Natapov
2012-06-25 15:03                       ` Avi Kivity
2012-06-25 15:35                         ` Gleb Natapov
2012-06-25 15:50                           ` Avi Kivity
2012-06-26  8:30                             ` Gleb Natapov [this message]
2012-06-26  9:19                               ` Avi Kivity
2012-06-12 12:01 ` [PATCHv2 5/5] KVM: Provide fast path for "rep ins" emulation if possible Gleb Natapov
2012-06-29 22:26   ` Marcelo Tosatti
2012-07-01 11:24     ` Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120626083041.GY6533@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.