Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44874f84 authored by Joerg Roedel's avatar Joerg Roedel Committed by Avi Kivity
Browse files

KVM: SVM: fix random segfaults with NPT enabled



This patch introduces a guest TLB flush on every NPF exit in KVM. This fixes
random segfaults and #UD exceptions in the guest seen under some workloads
(e.g. long running compile workloads or tbench). A kernbench run with and
without that fix showed that it has a slowdown lower than 0.5%

Cc: stable@kernel.org
Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent adee14b2
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,7 @@ static int npt = 1;
module_param(npt, int, S_IRUGO);
module_param(npt, int, S_IRUGO);


static void kvm_reput_irq(struct vcpu_svm *svm);
static void kvm_reput_irq(struct vcpu_svm *svm);
static void svm_flush_tlb(struct kvm_vcpu *vcpu);


static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
{
{
@@ -1027,6 +1028,13 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
		KVMTRACE_3D(TDP_FAULT, &svm->vcpu, error_code,
		KVMTRACE_3D(TDP_FAULT, &svm->vcpu, error_code,
			    (u32)fault_address, (u32)(fault_address >> 32),
			    (u32)fault_address, (u32)(fault_address >> 32),
			    handler);
			    handler);
	/*
	 * FIXME: Tis shouldn't be necessary here, but there is a flush
	 * missing in the MMU code. Until we find this bug, flush the
	 * complete TLB here on an NPF
	 */
	if (npt_enabled)
		svm_flush_tlb(&svm->vcpu);


	if (event_injection)
	if (event_injection)
		kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address);
		kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address);