aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/mmu.c
diff options
context:
space:
mode:
authorIzik Eidus <ieidus@redhat.com>2008-10-03 10:40:32 -0400
committerAvi Kivity <avi@redhat.com>2008-12-31 09:51:50 -0500
commit2843099fee32a6020e1caa95c6026f28b5d43bff (patch)
tree774ddfeec4091adddf9bd9ce938648dad14c378e /arch/x86/kvm/mmu.c
parent6eb55818c043b097c83828da8430fcb9a02fdb89 (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/kvm/mmu.c')
-rw-r--r--arch/x86/kvm/mmu.c14
1 files changed, 10 insertions, 4 deletions
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
402static int has_wrprotected_page(struct kvm *kvm, gfn_t gfn) 406static 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"