From a22522787098d63eb1edf16dec585bc1cf503078 Mon Sep 17 00:00:00 2001 From: Zenghui Yu Date: Tue, 26 May 2020 12:07:47 +0800 Subject: [PATCH] KVM: arm64: Only flush VM for the first and the last vcpu euleros inclusion category: bugfix ------------------------------------------------- stage_flush_vm() can be pretty time-consuming if lots of stage-2 mappings had been setup before booting secondary processors. Sidestep the heavy D-cache maintenance operations on D05 *only*. Signed-off-by: Zenghui Yu Reviewed-by: zhanghailiang Signed-off-by: Yang Yingliang --- virt/kvm/arm/mmu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index f3773522edfc..27cfc3992293 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -2474,6 +2474,19 @@ void kvm_set_way_flush(struct kvm_vcpu *vcpu) } } +static bool kvm_need_flush_vm(struct kvm_vcpu *vcpu) +{ + if (kvm_ncsnp_support) + return false; + + /* Hackish... */ + if (vcpu->vcpu_id == 0 || (vcpu->vcpu_id + 1 == + atomic_read(&vcpu->kvm->online_vcpus))) + return true; + + return false; +} + void kvm_toggle_cache(struct kvm_vcpu *vcpu, bool was_enabled) { bool now_enabled = vcpu_has_cache_enabled(vcpu); @@ -2483,7 +2496,7 @@ void kvm_toggle_cache(struct kvm_vcpu *vcpu, bool was_enabled) * If switching it off, need to clean the caches. * Clean + invalidate does the trick always. */ - if (now_enabled != was_enabled && !kvm_ncsnp_support) + if (now_enabled != was_enabled && kvm_need_flush_vm(vcpu)) stage2_flush_vm(vcpu->kvm); /* Caches are now on, stop trapping VM ops (until a S/W op) */ -- GitLab