public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC: not fully tested yet] Fix the x86 emulation of in: remove redandancy
@ 2010-02-05  8:52 Takuya Yoshikawa
  2010-02-08 10:25 ` Takuya Yoshikawa
  2010-02-08 10:32 ` Avi Kivity
  0 siblings, 2 replies; 3+ messages in thread
From: Takuya Yoshikawa @ 2010-02-05  8:52 UTC (permalink / raw)
  To: avi, mtosatti; +Cc: kvm

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);
		}
	...

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);
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC: not fully tested yet] Fix the x86 emulation of in: remove redandancy
  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
  2010-02-08 10:32 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Takuya Yoshikawa @ 2010-02-08 10:25 UTC (permalink / raw)
  To: avi, mtosatti; +Cc: kvm

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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RFC: not fully tested yet] Fix the x86 emulation of in: remove redandancy
  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
@ 2010-02-08 10:32 ` Avi Kivity
  1 sibling, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2010-02-08 10:32 UTC (permalink / raw)
  To: Takuya Yoshikawa; +Cc: mtosatti, kvm

On 02/05/2010 10:52 AM, 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.
>
>    

Applied, thanks.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-08 10:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2010-02-08 10:32 ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox