Skip to contentSkip to conversation

KVM: MMU: make kvm_mmu_reset_context() flush the guest TLB

PATCH In review Avi Kivity 2 participants 3 messages Jun 12, 2011 – Jun 21, 2011

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 KVM: MMU: make kvm_mmu_reset_context() flush the guest TLB

kvm_set_cr0() and kvm_set_cr4(), and possible other functions, assume that kvm_mmu_reset_context() flushes the guest TLB. However, it does not.

Fix by flushing the tlb (and syncing the new root as well).

---
 arch/x86/kvm/mmu.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
arch/x86/kvm/mmu.c +11 -1
index 19ebb76..b439ab7 100644
@@ -3042,8 +3042,18 @@ static void destroy_kvm_mmu(struct kvm_vcpu *vcpu)
 
 int kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
 {
+	int r;
+
 	destroy_kvm_mmu(vcpu);
-	return init_kvm_mmu(vcpu);
+	r = init_kvm_mmu(vcpu);
+
+	if (r)
+		goto err;
+
+	kvm_mmu_sync_roots(vcpu);
+	kvm_mmu_flush_tlb(vcpu);
+err:
+	return r;
 }
 EXPORT_SYMBOL_GPL(kvm_mmu_reset_context);
 
Signature · 1 line
1.7.5.3
#1 lore raw
Quoted 3 lines · Avi Kivity

kvm_set_cr0() and kvm_set_cr4(), and possible other functions, assume that kvm_mmu_reset_context() flushes the guest TLB. However, it does not.

TLB flush should be done lazily during guest entry, in kvm_mmu_load(). Don't see why this patch is needed.

Quoted 4 lines

Fix by flushing the tlb (and syncing the new root as well).

author
#2 lore raw
Quoted 7 lines · Marcelo Tosatti
Quoted 3 lines · Avi Kivity

kvm_set_cr0() and kvm_set_cr4(), and possible other functions, assume that kvm_mmu_reset_context() flushes the guest TLB. However, it does not.

TLB flush should be done lazily during guest entry, in kvm_mmu_load(). Don't see why this patch is needed.

You're right. It should be reverted.

Signature · 1 line
error compiling committee.c: too many arguments to function