When kvm_mmu_change_mmu_pages() shrinks the shadow page limit and the current number of shadow pages exceeds the requested goal, it zaps the oldest MMU pages and then updates n_max_mmu_pages. Previously the new limit was set unconditionally to the current mmu_shadow_pages value observed after zapping. However, zapping can reduce mmu_shadow_pages below the user-requested goal_nr_mmu_pages, since a single __kvm_mmu_prepare_zap_page() may reclaim more than one MMU page (it also zaps unsync/child pages). This could then clamp the limit below the user's intent. Use max(mmu_shadow_pages, goal_nr_mmu_pages) so the user-requested goal is honored even if zapping overshoots. Signed-off-by: fuqiang wang --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 064ecc33b926..efeba58936a6 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2913,7 +2913,7 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned long goal_nr_mmu_pages) kvm_mmu_zap_oldest_mmu_pages(kvm, kvm->stat.mmu_shadow_pages - goal_nr_mmu_pages); - goal_nr_mmu_pages = kvm->stat.mmu_shadow_pages; + goal_nr_mmu_pages = max(kvm->stat.mmu_shadow_pages, goal_nr_mmu_pages); } kvm->arch.n_max_mmu_pages = goal_nr_mmu_pages; -- 2.47.0