KVM: x86: Zap the oldest MMU pages, not the newest
Sean Christopherson
maintainerPATCH 1/1 KVM: x86: Zap the oldest MMU pages, not the newest
Walk the list of MMU pages in reverse in kvm_mmu_zap_oldest_mmu_pages(). The list is FIFO, meaning new pages are inserted at the head and thus the oldest pages are at the tail. Using a "forward" iterator causes KVM to zap MMU pages that were just added, which obliterates guest performance once the max number of shadow MMU pages is reached.
--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -2417,7 +2417,7 @@ static unsigned long kvm_mmu_zap_oldest_mmu_pages(struct kvm *kvm,return 0 ; restart: -list_for_each_entry_safe (sp, tmp, &kvm->arch.active_mmu_pages, link) { +list_for_each_entry_safe_reverse (sp, tmp, &kvm->arch.active_mmu_pages, link) {/* * Don't zap active root pages, the page itself can't be freed * and zapping it will just force vCPUs to realloc and reload.
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Quoted 20 lines · Sean Christopherson
Walk the list of MMU pages in reverse in
kvm_mmu_zap_oldest_mmu_pages(). The list is FIFO, meaning new pages are inserted at the head and thus the oldest pages are at the tail. Using a "forward" iterator causes KVM to zap MMU pages that were just added, which obliterates guest performance once the max number of shadow MMU pages is reached.Fixes 6b82ef2c9cf1 ("KVM: x86/mmu: Batch zap MMU pages when recycling oldest pages")Reported-by Zdenek Kaspar <[email protected]>Signed-off-by Sean Christopherson <[email protected]>--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/mmu/mmu.c +0
-0
arch/x86/kvm/mmu/mmu.c static unsigned long kvm_mmu_zap_oldest_mmu_pages(struct kvm *kvm, · line 2423
Quoted 8 lines
arch/x86/kvm/mmu/mmu.c +1
-1@@ -2417,7 +2417,7 @@ static unsigned long kvm_mmu_zap_oldest_mmu_pages(struct kvm *kvm,return 0 ; restart: -list_for_each_entry_safe (sp, tmp, &kvm->arch.active_mmu_pages, link) { +list_for_each_entry_safe_reverse (sp, tmp, &kvm->arch.active_mmu_pages, link) {/* * Don't zap active root pages, the page itself can't be freed * and zapping it will just force vCPUs to realloc and reload.
Queued for 5.11, thanks.
Paolo