kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, avi@redhat.com
Subject: Re: [PATCHv2 5/5] KVM: Provide fast path for "rep ins" emulation if possible.
Date: Sun, 1 Jul 2012 14:24:54 +0300	[thread overview]
Message-ID: <20120701112454.GC6533@redhat.com> (raw)
In-Reply-To: <20120629222638.GA12437@amt.cnet>

On Fri, Jun 29, 2012 at 07:26:38PM -0300, Marcelo Tosatti wrote:
> On Tue, Jun 12, 2012 at 03:01:27PM +0300, Gleb Natapov wrote:
> > "rep ins" emulation is going through emulator now. This is slow because
> > emulator knows how to write back only one datum at a time. This patch
> > provides fast path for the instruction in certain conditions. The
> > conditions are: DF flag is not set, destination memory is RAM and single
> > datum does not cross page boundary. If fast path code fails it falls
> > back to emulation.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > ---
> >  arch/x86/include/asm/kvm_host.h |    6 ++
> >  arch/x86/kvm/svm.c              |   20 +++++--
> >  arch/x86/kvm/vmx.c              |   25 +++++--
> >  arch/x86/kvm/x86.c              |  133 ++++++++++++++++++++++++++++++++++++--
> >  4 files changed, 165 insertions(+), 19 deletions(-)
> > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> > index 7a41878..f3e7bb3 100644
> > --- a/arch/x86/kvm/svm.c
> > +++ b/arch/x86/kvm/svm.c
> > @@ -1887,21 +1887,31 @@ static int io_interception(struct vcpu_svm *svm)
> >  {
> >  	struct kvm_vcpu *vcpu = &svm->vcpu;
> >  	u32 io_info = svm->vmcb->control.exit_info_1; /* address size bug? */
> > -	int size, in, string;
> > +	int size, in, string, rep;
> >  	unsigned port;
> >  
> >  	++svm->vcpu.stat.io_exits;
> >  	string = (io_info & SVM_IOIO_STR_MASK) != 0;
> > +	rep = (io_info & SVM_IOIO_REP_MASK) != 0;
> >  	in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
> > -	if (string || in)
> > -		return emulate_instruction(vcpu, 0) == EMULATE_DONE;
> >  
> >  	port = io_info >> 16;
> >  	size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
> >  	svm->next_rip = svm->vmcb->control.exit_info_2;
> > -	skip_emulated_instruction(&svm->vcpu);
> >  
> > -	return kvm_fast_pio_out(vcpu, size, port);
> > +	if (!string && !in) {
> > +		skip_emulated_instruction(&svm->vcpu);
> > +		return kvm_fast_pio_out(vcpu, size, port);
> > +	} else if (string && in && rep) {
> 
> Is there a reason to restrict optimization to rep ? That is, 
> it should be easy to extend to normal in?
> 
Normal "in" does not have performance problem to the best of my knowledge.
Going through emulator for non performance critical code means less logic
to duplicate.

> > +		kvm_x86_ops->skip_emulated_instruction(vcpu);
> > +		return EMULATE_DONE;
> > +	}
> > +	if (kvm_get_rflags(vcpu) & X86_EFLAGS_DF)
> > +		return EMULATE_FAIL;
> > +	if (ad_bytes_idx > 2)
> > +		return EMULATE_FAIL;
> > +
> > +	ad_bytes = (u8[]){2, 4, 8}[ad_bytes_idx];
> > +
> > +	rdi = kvm_address_mask(ad_bytes, rdi);
> > +
> > +	count = (PAGE_SIZE - offset_in_page(rdi))/size;
> > +
> > +	if (count == 0) /* 'in' crosses page boundry */
> > +		return EMULATE_FAIL;
> > +
> > +	count = min(count, kvm_address_mask(ad_bytes, rcx));
> > + 
> > +	r = kvm_linearize_address(vcpu, get_emulation_mode(vcpu),
> > +			rdi, VCPU_SREG_ES, count, true, false, ad_bytes,
> > +			&linear_addr);
> 
> kvm_linearize_address expects size parameter in bytes?
Yes.

--
			Gleb.

      reply	other threads:[~2012-07-01 11:24 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
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 [this message]

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=20120701112454.GC6533@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).