diff options
author | Izik Eidus <ieidus@redhat.com> | 2008-10-03 10:40:32 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2008-12-31 09:51:50 -0500 |
commit | 2843099fee32a6020e1caa95c6026f28b5d43bff (patch) | |
tree | 774ddfeec4091adddf9bd9ce938648dad14c378e /arch/x86 | |
parent | 6eb55818c043b097c83828da8430fcb9a02fdb89 (diff) |
KVM: MMU: Fix aliased gfns treated as unaliased
Some areas of kvm x86 mmu are using gfn offset inside a slot without
unaliasing the gfn first. This patch makes sure that the gfn will be
unaliased and add gfn_to_memslot_unaliased() to save the calculating
of the gfn unaliasing in case we have it unaliased already.
Signed-off-by: Izik Eidus <ieidus@redhat.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 2 | ||||
-rw-r--r-- | arch/x86/kvm/mmu.c | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 09e6c56572cb..99e3cc149d21 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -617,6 +617,8 @@ void kvm_disable_tdp(void); | |||
617 | int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3); | 617 | int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3); |
618 | int complete_pio(struct kvm_vcpu *vcpu); | 618 | int complete_pio(struct kvm_vcpu *vcpu); |
619 | 619 | ||
620 | struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn); | ||
621 | |||
620 | static inline struct kvm_mmu_page *page_header(hpa_t shadow_page) | 622 | static inline struct kvm_mmu_page *page_header(hpa_t shadow_page) |
621 | { | 623 | { |
622 | struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT); | 624 | struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT); |
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 8687758b5295..8904e8ada978 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -386,7 +386,9 @@ static void account_shadowed(struct kvm *kvm, gfn_t gfn) | |||
386 | { | 386 | { |
387 | int *write_count; | 387 | int *write_count; |
388 | 388 | ||
389 | write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn)); | 389 | gfn = unalias_gfn(kvm, gfn); |
390 | write_count = slot_largepage_idx(gfn, | ||
391 | gfn_to_memslot_unaliased(kvm, gfn)); | ||
390 | *write_count += 1; | 392 | *write_count += 1; |
391 | } | 393 | } |
392 | 394 | ||
@@ -394,16 +396,20 @@ static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn) | |||
394 | { | 396 | { |
395 | int *write_count; | 397 | int *write_count; |
396 | 398 | ||
397 | write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn)); | 399 | gfn = unalias_gfn(kvm, gfn); |
400 | write_count = slot_largepage_idx(gfn, | ||
401 | gfn_to_memslot_unaliased(kvm, gfn)); | ||
398 | *write_count -= 1; | 402 | *write_count -= 1; |
399 | WARN_ON(*write_count < 0); | 403 | WARN_ON(*write_count < 0); |
400 | } | 404 | } |
401 | 405 | ||
402 | static int has_wrprotected_page(struct kvm *kvm, gfn_t gfn) | 406 | static int has_wrprotected_page(struct kvm *kvm, gfn_t gfn) |
403 | { | 407 | { |
404 | struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); | 408 | struct kvm_memory_slot *slot; |
405 | int *largepage_idx; | 409 | int *largepage_idx; |
406 | 410 | ||
411 | gfn = unalias_gfn(kvm, gfn); | ||
412 | slot = gfn_to_memslot_unaliased(kvm, gfn); | ||
407 | if (slot) { | 413 | if (slot) { |
408 | largepage_idx = slot_largepage_idx(gfn, slot); | 414 | largepage_idx = slot_largepage_idx(gfn, slot); |
409 | return *largepage_idx; | 415 | return *largepage_idx; |
@@ -2973,8 +2979,8 @@ static void audit_write_protection(struct kvm_vcpu *vcpu) | |||
2973 | if (sp->role.metaphysical) | 2979 | if (sp->role.metaphysical) |
2974 | continue; | 2980 | continue; |
2975 | 2981 | ||
2976 | slot = gfn_to_memslot(vcpu->kvm, sp->gfn); | ||
2977 | gfn = unalias_gfn(vcpu->kvm, sp->gfn); | 2982 | gfn = unalias_gfn(vcpu->kvm, sp->gfn); |
2983 | slot = gfn_to_memslot_unaliased(vcpu->kvm, sp->gfn); | ||
2978 | rmapp = &slot->rmap[gfn - slot->base_gfn]; | 2984 | rmapp = &slot->rmap[gfn - slot->base_gfn]; |
2979 | if (*rmapp) | 2985 | if (*rmapp) |
2980 | printk(KERN_ERR "%s: (%s) shadow page has writable" | 2986 | printk(KERN_ERR "%s: (%s) shadow page has writable" |