KVM: x86: Zap the oldest MMU pages, not the newest
authorSean Christopherson <seanjc@google.com>
Wed, 13 Jan 2021 20:50:30 +0000 (12:50 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Feb 2021 09:13:00 +0000 (10:13 +0100)
commitd2cbae37c3d8f9ce1f33ae690421be6ecf3809d1
tree344ebb9469cadf31f52fde20e8914da9237ee8f3
parent729fbb8cb27654c75171d6fa4d9cdfe10bc212eb
KVM: x86: Zap the oldest MMU pages, not the newest

commit 8fc517267fb28576dfca2380cc2497a2454b8fae upstream.

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 <zkaspar82@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210113205030.3481307-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/mmu/mmu.c