aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/mmu.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-03-23 03:55:25 -0400
committerAvi Kivity <avi@qumranet.com>2007-05-03 03:52:27 -0400
commitd28c6cfbbc5e2d4fccfe6d733995ed5971ca87f6 (patch)
tree0da31407f97a92c81d189b18608e54ad2064ebad /drivers/kvm/mmu.c
parent916ce2360fadc71d924e02403b31280112a31280 (diff)
KVM: MMU: Fix hugepage pdes mapping same physical address with different access
The kvm mmu keeps a shadow page for hugepage pdes; if several such pdes map the same physical address, they share the same shadow page. This is a fairly common case (kernel mappings on i386 nonpae Linux, for example). However, if the two pdes map the same memory but with different permissions, kvm will happily use the cached shadow page. If the access through the more permissive pde will occur after the access to the strict pde, an endless pagefault loop will be generated and the guest will make no progress. Fix by making the access permissions part of the cache lookup key. The fix allows Xen pae to boot on kvm and run guest domains. Thanks to Jeremy Fitzhardinge for reporting the bug and testing the fix. Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/mmu.c')
-rw-r--r--drivers/kvm/mmu.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 2930d7cc7c06..c738fb1cea30 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -568,6 +568,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
568 gva_t gaddr, 568 gva_t gaddr,
569 unsigned level, 569 unsigned level,
570 int metaphysical, 570 int metaphysical,
571 unsigned hugepage_access,
571 u64 *parent_pte) 572 u64 *parent_pte)
572{ 573{
573 union kvm_mmu_page_role role; 574 union kvm_mmu_page_role role;
@@ -581,6 +582,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
581 role.glevels = vcpu->mmu.root_level; 582 role.glevels = vcpu->mmu.root_level;
582 role.level = level; 583 role.level = level;
583 role.metaphysical = metaphysical; 584 role.metaphysical = metaphysical;
585 role.hugepage_access = hugepage_access;
584 if (vcpu->mmu.root_level <= PT32_ROOT_LEVEL) { 586 if (vcpu->mmu.root_level <= PT32_ROOT_LEVEL) {
585 quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); 587 quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
586 quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1; 588 quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
@@ -780,7 +782,7 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
780 >> PAGE_SHIFT; 782 >> PAGE_SHIFT;
781 new_table = kvm_mmu_get_page(vcpu, pseudo_gfn, 783 new_table = kvm_mmu_get_page(vcpu, pseudo_gfn,
782 v, level - 1, 784 v, level - 1,
783 1, &table[index]); 785 1, 0, &table[index]);
784 if (!new_table) { 786 if (!new_table) {
785 pgprintk("nonpaging_map: ENOMEM\n"); 787 pgprintk("nonpaging_map: ENOMEM\n");
786 return -ENOMEM; 788 return -ENOMEM;
@@ -835,7 +837,7 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
835 837
836 ASSERT(!VALID_PAGE(root)); 838 ASSERT(!VALID_PAGE(root));
837 page = kvm_mmu_get_page(vcpu, root_gfn, 0, 839 page = kvm_mmu_get_page(vcpu, root_gfn, 0,
838 PT64_ROOT_LEVEL, 0, NULL); 840 PT64_ROOT_LEVEL, 0, 0, NULL);
839 root = page->page_hpa; 841 root = page->page_hpa;
840 ++page->root_count; 842 ++page->root_count;
841 vcpu->mmu.root_hpa = root; 843 vcpu->mmu.root_hpa = root;
@@ -852,7 +854,7 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
852 root_gfn = 0; 854 root_gfn = 0;
853 page = kvm_mmu_get_page(vcpu, root_gfn, i << 30, 855 page = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
854 PT32_ROOT_LEVEL, !is_paging(vcpu), 856 PT32_ROOT_LEVEL, !is_paging(vcpu),
855 NULL); 857 0, NULL);
856 root = page->page_hpa; 858 root = page->page_hpa;
857 ++page->root_count; 859 ++page->root_count;
858 vcpu->mmu.pae_root[i] = root | PT_PRESENT_MASK; 860 vcpu->mmu.pae_root[i] = root | PT_PRESENT_MASK;