KVM: MMU: make kvm_mmu_available_pages robust against n_used_mmu_pages > 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 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
@@ -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)
Xiao Guangrong
Reviewed-byQuoted 6 lines · Marcelo Tosatti
As noticed by Ulrich Obergfell <[email protected]>, the mmu counters are for beancounting purposes only - so
n_used_mmu_pagesandn_max_mmu_pagescould be relaxed (example: beforef0f5933a1626c8df7b), resulting inn_used_mmu_pages>n_max_mmu_pages.
Interesting.
Quoted 1 line
Make code robust against
n_used_mmu_pages>n_max_mmu_pages.
Gleb Natapov
AppliedQuoted 10 lines · Marcelo Tosatti
As noticed by Ulrich Obergfell <[email protected]>, the mmu counters are for beancounting purposes only - so
n_used_mmu_pagesandn_max_mmu_pagescould be relaxed (example: beforef0f5933a1626c8df7b), resulting inn_used_mmu_pages>n_max_mmu_pages.Make code robust against
n_used_mmu_pages>n_max_mmu_pages.Signed-off-by Marcelo Tosatti <[email protected]>
Applied, thanks.
Quoted 8 lines
arch/x86/kvm/mmu.h +0
-0@@ -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.