KVM: x86/mmu: Respect user goal_nr_mmu_pages after zapping oldest pages
PATCH 1/1 KVM: x86/mmu: Respect user goal_nr_mmu_pages after zapping oldest pages
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.
--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -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;
Signature · 1 line
2.47.0