public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH RFC: not fully tested yet] Fix the x86 emulation of in: remove redandancy
Date: Mon, 08 Feb 2010 19:25:15 +0900	[thread overview]
Message-ID: <4B6FE68B.9070506@oss.ntt.co.jp> (raw)
In-Reply-To: <20100205175246.9479766b.yoshikawa.takuya@oss.ntt.co.jp>

Takuya Yoshikawa wrote:
> Fix the x86 emulation of in:
> 
> kvm_emulate_pio() and complete_pio() both read out the
> RAX register value and copy it to a place into which
> the value read out from the port will be copied later.
> This patch removes this redundancy.
> 
> /*** snippet from arch/x86/kvm/x86.c ***/
> int complete_pio(struct kvm_vcpu *vcpu)
> {
> 	...
> 	if (!io->string) {
> 		if (io->in) {
> 			val = kvm_register_read(vcpu, VCPU_REGS_RAX);
> 			memcpy(&val, vcpu->arch.pio_data, io->size);
> 			kvm_register_write(vcpu, VCPU_REGS_RAX, val);
> 		}
> 	...
> 

Self explanation: reading RAX before copying pio data is for preserving
higher bits of the register. If we are sure that pio emulation ends by
complete_pio() and complete_pio() does this higher bits preservation,
we no longer need to mind preserving the higer bits of arch.pio_data
in each device's read handler: may reduce some switches and memcpies,
if we want.

Anyway, if no device's read handler depends on the memcpied 4 bytes of
RAX, I hope so, this patch seems to work and reduces extra memcpy.

> Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
> ---
>  arch/x86/kvm/x86.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d47ceda..fcbe3a7 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3550,8 +3550,10 @@ int kvm_emulate_pio(struct kvm_vcpu *vcpu, int in, int size, unsigned port)
>  	trace_kvm_pio(vcpu->run->io.direction == KVM_EXIT_IO_OUT, port,
>  		      size, 1);
>  
> -	val = kvm_register_read(vcpu, VCPU_REGS_RAX);
> -	memcpy(vcpu->arch.pio_data, &val, 4);
> +	if (!vcpu->arch.pio.in) {
> +		val = kvm_register_read(vcpu, VCPU_REGS_RAX);
> +		memcpy(vcpu->arch.pio_data, &val, 4);
> +	}
>  
>  	if (!kernel_pio(vcpu, vcpu->arch.pio_data)) {
>  		complete_pio(vcpu);


  reply	other threads:[~2010-02-08 10:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-05  8:52 [PATCH RFC: not fully tested yet] Fix the x86 emulation of in: remove redandancy Takuya Yoshikawa
2010-02-08 10:25 ` Takuya Yoshikawa [this message]
2010-02-08 10:32 ` Avi Kivity

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=4B6FE68B.9070506@oss.ntt.co.jp \
    --to=yoshikawa.takuya@oss.ntt.co.jp \
    --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