diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index f3773522edfcb0e08d973235e6e59fe7753ed6c9..27cfc3992293c1241b58e9463388a0536fad8249 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) */