Skip to content

Commit

Permalink
KVM: MMU: make kvm_mmu_available_pages robust against n_used_mmu_page…
Browse files Browse the repository at this point in the history
…s > n_max_mmu_pages

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 f0f5933),
resulting in n_used_mmu_pages > n_max_mmu_pages.

Make code robust against n_used_mmu_pages > n_max_mmu_pages.

Reviewed-by: Xiao Guangrong <[email protected]>
Signed-off-by: Marcelo Tosatti <[email protected]>
Signed-off-by: Gleb Natapov <[email protected]>
  • Loading branch information
matosatti authored and Gleb Natapov committed Mar 13, 2013
1 parent 57f252f commit 5d21881
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions arch/x86/kvm/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5d21881

Please sign in to comment.