Re: [PATCH] KVM: Optimize kvm_arch_vcpu_ioctl_run function

From: Tianjia Zhang
Date: Mon Apr 13 2020 - 05:09:28 EST




On 2020/4/13 16:56, Marc Zyngier wrote:
Tianjia,

On 2020-04-13 04:45, Tianjia Zhang wrote:
kvm_arch_vcpu_ioctl_run() is only called in the file kvm_main.c,
where vcpu->run is the kvm_run parameter, so it has been replaced.

Signed-off-by: Tianjia Zhang <tianjia.zhang@xxxxxxxxxxxxxxxxx>
---
Âarch/x86/kvm/x86.c | 8 ++++----
Âvirt/kvm/arm/arm.c | 2 +-
Â2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3bf2ecafd027..70e3f4abbd4d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8726,18 +8726,18 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu
*vcpu, struct kvm_run *kvm_run)
ÂÂÂÂÂÂÂÂ r = -EAGAIN;
ÂÂÂÂÂÂÂÂ if (signal_pending(current)) {
ÂÂÂÂÂÂÂÂÂÂÂÂ r = -EINTR;
-ÂÂÂÂÂÂÂÂÂÂÂ vcpu->run->exit_reason = KVM_EXIT_INTR;
+ÂÂÂÂÂÂÂÂÂÂÂ kvm_run->exit_reason = KVM_EXIT_INTR;
ÂÂÂÂÂÂÂÂÂÂÂÂ ++vcpu->stat.signal_exits;
ÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ goto out;
ÂÂÂÂ }

-ÂÂÂ if (vcpu->run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) {
+ÂÂÂ if (kvm_run->kvm_valid_regs & ~KVM_SYNC_X86_VALID_FIELDS) {
ÂÂÂÂÂÂÂÂ r = -EINVAL;
ÂÂÂÂÂÂÂÂ goto out;
ÂÂÂÂ }

-ÂÂÂ if (vcpu->run->kvm_dirty_regs) {
+ÂÂÂ if (kvm_run->kvm_dirty_regs) {
ÂÂÂÂÂÂÂÂ r = sync_regs(vcpu);
ÂÂÂÂÂÂÂÂ if (r != 0)
ÂÂÂÂÂÂÂÂÂÂÂÂ goto out;
@@ -8767,7 +8767,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu
*vcpu, struct kvm_run *kvm_run)

Âout:
ÂÂÂÂ kvm_put_guest_fpu(vcpu);
-ÂÂÂ if (vcpu->run->kvm_valid_regs)
+ÂÂÂ if (kvm_run->kvm_valid_regs)
ÂÂÂÂÂÂÂÂ store_regs(vcpu);
ÂÂÂÂ post_kvm_run_save(vcpu);
ÂÂÂÂ kvm_sigset_deactivate(vcpu);
diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index 48d0ec44ad77..ab9d7966a4c8 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -659,7 +659,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu,
struct kvm_run *run)
ÂÂÂÂÂÂÂÂ return ret;

ÂÂÂÂ if (run->exit_reason == KVM_EXIT_MMIO) {
-ÂÂÂÂÂÂÂ ret = kvm_handle_mmio_return(vcpu, vcpu->run);
+ÂÂÂÂÂÂÂ ret = kvm_handle_mmio_return(vcpu, run);
ÂÂÂÂÂÂÂÂ if (ret)
ÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
ÂÂÂÂ }

Do you have any number supporting the idea that you are optimizing anything
here? Performance, code size, register pressure or any other relevant metric?

Thanks,

ÂÂÂÂÂÂÂ M.

This is only a simplified implementation of the function, the impact on performance and register pressure can be ignored.

Thanks,
Tianjia