Commit 77662e00 authored by Xiao Guangrong's avatar Xiao Guangrong Committed by Avi Kivity

KVM: MMU: fix kvm_mmu_zap_page() and its calling path

This patch fix:

- calculate zapped page number properly in mmu_zap_unsync_children()
- calculate freeed page number properly kvm_mmu_change_mmu_pages()
- if zapped children page it shoud restart hlist walking

KVM-Stable-Tag.
Signed-off-by: default avatarXiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent 78ac8b47
...@@ -1490,8 +1490,8 @@ static int mmu_zap_unsync_children(struct kvm *kvm, ...@@ -1490,8 +1490,8 @@ static int mmu_zap_unsync_children(struct kvm *kvm,
for_each_sp(pages, sp, parents, i) { for_each_sp(pages, sp, parents, i) {
kvm_mmu_zap_page(kvm, sp); kvm_mmu_zap_page(kvm, sp);
mmu_pages_clear_parents(&parents); mmu_pages_clear_parents(&parents);
zapped++;
} }
zapped += pages.nr;
kvm_mmu_pages_init(parent, &parents, &pages); kvm_mmu_pages_init(parent, &parents, &pages);
} }
...@@ -1542,14 +1542,16 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages) ...@@ -1542,14 +1542,16 @@ void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages)
*/ */
if (used_pages > kvm_nr_mmu_pages) { if (used_pages > kvm_nr_mmu_pages) {
while (used_pages > kvm_nr_mmu_pages) { while (used_pages > kvm_nr_mmu_pages &&
!list_empty(&kvm->arch.active_mmu_pages)) {
struct kvm_mmu_page *page; struct kvm_mmu_page *page;
page = container_of(kvm->arch.active_mmu_pages.prev, page = container_of(kvm->arch.active_mmu_pages.prev,
struct kvm_mmu_page, link); struct kvm_mmu_page, link);
kvm_mmu_zap_page(kvm, page); used_pages -= kvm_mmu_zap_page(kvm, page);
used_pages--; used_pages--;
} }
kvm_nr_mmu_pages = used_pages;
kvm->arch.n_free_mmu_pages = 0; kvm->arch.n_free_mmu_pages = 0;
} }
else else
...@@ -1596,7 +1598,8 @@ static void mmu_unshadow(struct kvm *kvm, gfn_t gfn) ...@@ -1596,7 +1598,8 @@ static void mmu_unshadow(struct kvm *kvm, gfn_t gfn)
&& !sp->role.invalid) { && !sp->role.invalid) {
pgprintk("%s: zap %lx %x\n", pgprintk("%s: zap %lx %x\n",
__func__, gfn, sp->role.word); __func__, gfn, sp->role.word);
kvm_mmu_zap_page(kvm, sp); if (kvm_mmu_zap_page(kvm, sp))
nn = bucket->first;
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment