Commit 1755fbcc authored by Avi Kivity's avatar Avi Kivity

KVM: MMU: Introduce gfn_to_gpa()

Converting a frame number to an address is tricky since the data type changes
size.  Introduce a function to do it.  This fixes an actual bug when
accessing guest ptes.
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 38c335f1
...@@ -499,6 +499,10 @@ static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot) ...@@ -499,6 +499,10 @@ static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
return slot - kvm->memslots; return slot - kvm->memslots;
} }
static inline gpa_t gfn_to_gpa(gfn_t gfn)
{
return (gpa_t)gfn << PAGE_SHIFT;
}
enum kvm_stat_kind { enum kvm_stat_kind {
KVM_STAT_VM, KVM_STAT_VM,
......
...@@ -110,7 +110,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker, ...@@ -110,7 +110,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
index = PT_INDEX(addr, walker->level); index = PT_INDEX(addr, walker->level);
table_gfn = gpte_to_gfn(pte); table_gfn = gpte_to_gfn(pte);
pte_gpa = table_gfn << PAGE_SHIFT; pte_gpa = gfn_to_gpa(table_gfn);
pte_gpa += index * sizeof(pt_element_t); pte_gpa += index * sizeof(pt_element_t);
walker->table_gfn[walker->level - 1] = table_gfn; walker->table_gfn[walker->level - 1] = table_gfn;
pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__, pgprintk("%s: table_gfn[%d] %lx\n", __FUNCTION__,
...@@ -442,7 +442,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) ...@@ -442,7 +442,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0); r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
if (r) { if (r) {
gpa = (gpa_t)walker.gfn << PAGE_SHIFT; gpa = gfn_to_gpa(walker.gfn);
gpa |= vaddr & ~PAGE_MASK; gpa |= vaddr & ~PAGE_MASK;
} }
......
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