Commit a2252278 authored by Zenghui Yu's avatar Zenghui Yu Committed by Yang Yingliang
Browse files

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: default avatarZenghui Yu <yuzenghui@huawei.com>
Reviewed-by: default avatarzhanghailiang <zhang.zhanghailiang@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent ae0237a0
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -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) */