Skip pinned shadow pages when selecting pages to zap. Signed-off-by: Marcelo Tosatti <mtosa...@redhat.com>
--- arch/x86/kvm/mmu.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) Index: kvm/arch/x86/kvm/mmu.c =================================================================== --- kvm.orig/arch/x86/kvm/mmu.c +++ kvm/arch/x86/kvm/mmu.c @@ -2279,16 +2279,24 @@ static void kvm_mmu_commit_zap_page(stru static bool prepare_zap_oldest_mmu_page(struct kvm *kvm, struct list_head *invalid_list) { - struct kvm_mmu_page *sp; - - if (list_empty(&kvm->arch.active_mmu_pages)) - return false; + struct kvm_mmu_page *sp, *nsp; + LIST_HEAD(pinned_list); - sp = list_entry(kvm->arch.active_mmu_pages.prev, - struct kvm_mmu_page, link); - kvm_mmu_prepare_zap_page(kvm, sp, invalid_list); + list_for_each_entry_safe_reverse(sp, nsp, + &kvm->arch.active_mmu_pages, link) { + if (sp->pinned) { + list_move(&sp->link, &pinned_list); + continue; + } + if (!list_empty(&pinned_list)) + list_move(&pinned_list, &kvm->arch.active_mmu_pages); + kvm_mmu_prepare_zap_page(kvm, sp, invalid_list); + return true; + } - return true; + if (!list_empty(&pinned_list)) + list_move(&pinned_list, &kvm->arch.active_mmu_pages); + return false; } /* @@ -4660,6 +4668,8 @@ void kvm_mmu_invalidate_zap_all_pages(st * Notify all vcpus to reload its shadow page table * and flush TLB. Then all vcpus will switch to new * shadow page table with the new mmu_valid_gen. + * MMU reload request also forces fault of + * sptes for pinned ranges. * * Note: we should do this under the protection of * mmu-lock, otherwise, vcpu would purge shadow page -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html