Skip to contentSkip to conversation

KVM: avoid unnecessary memcpy in kvm_emulate_pio

PATCH Marcelo Tosatti 2 participants 2 messages May 25, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

When emulating in instructions there's no point in copying the destination register contents to vcpu->arch.pio_data since it will be overwritten by the ioport handler.

Also remove the ->decache_regs() call, since as you mentioned there is no register change to writeback.

arch/x86/kvm/x86.c +2 -2
index e537005..f43f770 100644
@@ -2254,8 +2254,8 @@ int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 			    handler);
 
 	kvm_x86_ops->cache_regs(vcpu);
-	memcpy(vcpu->arch.pio_data, &vcpu->arch.regs[VCPU_REGS_RAX], 4);
-	kvm_x86_ops->decache_regs(vcpu);
+	if (!in)
+		memcpy(vcpu->arch.pio_data, &vcpu->arch.regs[VCPU_REGS_RAX], 4);
 
 	kvm_x86_ops->skip_emulated_instruction(vcpu);
 
#1 lore raw
Quoted 14 lines · Marcelo Tosatti

When emulating in instructions there's no point in copying the destination register contents to vcpu->arch.pio_data since it will be overwritten by the ioport handler.

Also remove the ->decache_regs() call, since as you mentioned there is no register change to writeback.

arch/x86/kvm/x86.c +0 -0
index e537005..f43f770 100644

arch/x86/kvm/x86.c int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, · line 2261

Quoted 10 lines
arch/x86/kvm/x86.c +2 -2
@@ -2254,8 +2254,8 @@ int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
 			    handler);
 
 	kvm_x86_ops->cache_regs(vcpu);
-	memcpy(vcpu->arch.pio_data, &vcpu->arch.regs[VCPU_REGS_RAX], 4);
-	kvm_x86_ops->decache_regs(vcpu);
+	if (!in)
+		memcpy(vcpu->arch.pio_data, &vcpu->arch.regs[VCPU_REGS_RAX], 4);
 
 	kvm_x86_ops->skip_emulated_instruction(vcpu);
 

The memcpy() compiles to just one mov instruction, so I didn't change it. I dropped the ->decache_regs() call (as it can take 100 cycles on Intel).

Signature · 1 line
error compiling committee.c: too many arguments to function