aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/mmu.c
diff options
context:
space:
mode:
authorXiao Guangrong <xiaoguangrong@cn.fujitsu.com>2010-05-24 03:40:07 -0400
committerAvi Kivity <avi@redhat.com>2010-08-01 03:35:51 -0400
commit9cf5cf5ad43b293581e5b87678ea5783c06d1a41 (patch)
treebe4a4ad779ff4330e016eb390653e526d90a17db /arch/x86/kvm/mmu.c
parent221d059d15f1c8bd070a63fd45cd8d2598af5f99 (diff)
KVM: MMU: allow more page become unsync at gfn mapping time
In current code, shadow page can become asynchronous only if one shadow page for a gfn, this rule is too strict, in fact, we can let all last mapping page(i.e, it's the pte page) become unsync, and sync them at invlpg or flush tlb time. This patch allow more page become asynchronous at gfn mapping time Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/mmu.c')
-rw-r--r--arch/x86/kvm/mmu.c82
1 files changed, 38 insertions, 44 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 25d3bb2543e2..ba119dae890e 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1170,26 +1170,6 @@ static int mmu_unsync_walk(struct kvm_mmu_page *sp,
1170 return __mmu_unsync_walk(sp, pvec); 1170 return __mmu_unsync_walk(sp, pvec);
1171} 1171}
1172 1172
1173static struct kvm_mmu_page *kvm_mmu_lookup_page(struct kvm *kvm, gfn_t gfn)
1174{
1175 unsigned index;
1176 struct hlist_head *bucket;
1177 struct kvm_mmu_page *sp;
1178 struct hlist_node *node;
1179
1180 pgprintk("%s: looking for gfn %lx\n", __func__, gfn);
1181 index = kvm_page_table_hashfn(gfn);
1182 bucket = &kvm->arch.mmu_page_hash[index];
1183 hlist_for_each_entry(sp, node, bucket, hash_link)
1184 if (sp->gfn == gfn && !sp->role.direct
1185 && !sp->role.invalid) {
1186 pgprintk("%s: found role %x\n",
1187 __func__, sp->role.word);
1188 return sp;
1189 }
1190 return NULL;
1191}
1192
1193static void kvm_unlink_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp) 1173static void kvm_unlink_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
1194{ 1174{
1195 WARN_ON(!sp->unsync); 1175 WARN_ON(!sp->unsync);
@@ -1759,47 +1739,61 @@ u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn)
1759} 1739}
1760EXPORT_SYMBOL_GPL(kvm_get_guest_memory_type); 1740EXPORT_SYMBOL_GPL(kvm_get_guest_memory_type);
1761 1741
1762static int kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) 1742static void __kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
1743{
1744 trace_kvm_mmu_unsync_page(sp);
1745 ++vcpu->kvm->stat.mmu_unsync;
1746 sp->unsync = 1;
1747
1748 kvm_mmu_mark_parents_unsync(sp);
1749 mmu_convert_notrap(sp);
1750}
1751
1752static void kvm_unsync_pages(struct kvm_vcpu *vcpu, gfn_t gfn)
1763{ 1753{
1764 unsigned index;
1765 struct hlist_head *bucket; 1754 struct hlist_head *bucket;
1766 struct kvm_mmu_page *s; 1755 struct kvm_mmu_page *s;
1767 struct hlist_node *node, *n; 1756 struct hlist_node *node, *n;
1757 unsigned index;
1768 1758
1769 index = kvm_page_table_hashfn(sp->gfn); 1759 index = kvm_page_table_hashfn(gfn);
1770 bucket = &vcpu->kvm->arch.mmu_page_hash[index]; 1760 bucket = &vcpu->kvm->arch.mmu_page_hash[index];
1771 /* don't unsync if pagetable is shadowed with multiple roles */ 1761
1772 hlist_for_each_entry_safe(s, node, n, bucket, hash_link) { 1762 hlist_for_each_entry_safe(s, node, n, bucket, hash_link) {
1773 if (s->gfn != sp->gfn || s->role.direct) 1763 if (s->gfn != gfn || s->role.direct || s->unsync ||
1764 s->role.invalid)
1774 continue; 1765 continue;
1775 if (s->role.word != sp->role.word) 1766 WARN_ON(s->role.level != PT_PAGE_TABLE_LEVEL);
1776 return 1; 1767 __kvm_unsync_page(vcpu, s);
1777 } 1768 }
1778 trace_kvm_mmu_unsync_page(sp);
1779 ++vcpu->kvm->stat.mmu_unsync;
1780 sp->unsync = 1;
1781
1782 kvm_mmu_mark_parents_unsync(sp);
1783
1784 mmu_convert_notrap(sp);
1785 return 0;
1786} 1769}
1787 1770
1788static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn, 1771static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
1789 bool can_unsync) 1772 bool can_unsync)
1790{ 1773{
1791 struct kvm_mmu_page *shadow; 1774 unsigned index;
1775 struct hlist_head *bucket;
1776 struct kvm_mmu_page *s;
1777 struct hlist_node *node, *n;
1778 bool need_unsync = false;
1779
1780 index = kvm_page_table_hashfn(gfn);
1781 bucket = &vcpu->kvm->arch.mmu_page_hash[index];
1782 hlist_for_each_entry_safe(s, node, n, bucket, hash_link) {
1783 if (s->gfn != gfn || s->role.direct || s->role.invalid)
1784 continue;
1792 1785
1793 shadow = kvm_mmu_lookup_page(vcpu->kvm, gfn); 1786 if (s->role.level != PT_PAGE_TABLE_LEVEL)
1794 if (shadow) {
1795 if (shadow->role.level != PT_PAGE_TABLE_LEVEL)
1796 return 1; 1787 return 1;
1797 if (shadow->unsync) 1788
1798 return 0; 1789 if (!need_unsync && !s->unsync) {
1799 if (can_unsync && oos_shadow) 1790 if (!can_unsync || !oos_shadow)
1800 return kvm_unsync_page(vcpu, shadow); 1791 return 1;
1801 return 1; 1792 need_unsync = true;
1793 }
1802 } 1794 }
1795 if (need_unsync)
1796 kvm_unsync_pages(vcpu, gfn);
1803 return 0; 1797 return 0;
1804} 1798}
1805 1799