Skip to contentSkip to conversation

KVM: MMU: make kvm_mmu_available_pages robust against n_used_mmu_pages > n_max_mmu_pages

PATCH Applied Marcelo Tosatti 3 participants 3 messages Mar 13, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

As noticed by Ulrich Obergfell <[email protected]>, the mmu counters are for beancounting purposes only - so n_used_mmu_pages and n_max_mmu_pages could be relaxed (example: before f0f5933a1626c8df7b), resulting in n_used_mmu_pages > n_max_mmu_pages.

Make code robust against n_used_mmu_pages > n_max_mmu_pages.

arch/x86/kvm/mmu.h +5 -2
index 6987108..3b1ad00 100644
@@ -57,8 +57,11 @@ int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context);
 
 static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
 {
-	return kvm->arch.n_max_mmu_pages -
-		kvm->arch.n_used_mmu_pages;
+	if (kvm->arch.n_max_mmu_pages > kvm->arch.n_used_mmu_pages)
+		return kvm->arch.n_max_mmu_pages -
+			kvm->arch.n_used_mmu_pages;
+
+	return 0;
 }
 
 static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
Reviewed-by
#1 lore raw
Quoted 6 lines · Marcelo Tosatti

As noticed by Ulrich Obergfell <[email protected]>, the mmu counters are for beancounting purposes only - so n_used_mmu_pages and n_max_mmu_pages could be relaxed (example: before f0f5933a1626c8df7b), resulting in n_used_mmu_pages > n_max_mmu_pages.

Interesting.

Quoted 1 line

Make code robust against n_used_mmu_pages > n_max_mmu_pages.

Applied
#2 lore raw
In reply to Marcelo Tosatti
Quoted 10 lines · Marcelo Tosatti

As noticed by Ulrich Obergfell <[email protected]>, the mmu counters are for beancounting purposes only - so n_used_mmu_pages and n_max_mmu_pages could be relaxed (example: before f0f5933a1626c8df7b), resulting in n_used_mmu_pages > n_max_mmu_pages.

Make code robust against n_used_mmu_pages > n_max_mmu_pages.

Applied, thanks.

Quoted 8 lines
arch/x86/kvm/mmu.h +0 -0
index 6987108..3b1ad00 100644
@@ -57,8 +57,11 @@ int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context);
 
 static inline unsigned int kvm_mmu_available_pages(struct kvm *kvm)
 {

arch/x86/kvm/mmu.h int kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, struct kvm_mmu *context); · line 67

Quoted 10 lines
arch/x86/kvm/mmu.h +5 -2
-	return kvm->arch.n_max_mmu_pages -
-		kvm->arch.n_used_mmu_pages;
+	if (kvm->arch.n_max_mmu_pages > kvm->arch.n_used_mmu_pages)
+		return kvm->arch.n_max_mmu_pages -
+			kvm->arch.n_used_mmu_pages;
+
+	return 0;
 }
 
 static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)

--
Gleb.