From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takuya Yoshikawa 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 Message-ID: <4B6FE68B.9070506@oss.ntt.co.jp> References: <20100205175246.9479766b.yoshikawa.takuya@oss.ntt.co.jp> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: avi@redhat.com, mtosatti@redhat.com Return-path: Received: from serv2.oss.ntt.co.jp ([222.151.198.100]:35712 "EHLO serv2.oss.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752673Ab0BHKXN (ORCPT ); Mon, 8 Feb 2010 05:23:13 -0500 In-Reply-To: <20100205175246.9479766b.yoshikawa.takuya@oss.ntt.co.jp> Sender: kvm-owner@vger.kernel.org List-ID: 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 > --- > 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);