mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-22 17:01:14 +00:00
KVM: PPC: Book3S HV: Fix calculation of guest phys address for MMIO emulation
In the case where the host kernel is using a 64kB base page size and the guest uses a 4k HPTE (hashed page table entry) to map an emulated MMIO device, we were calculating the guest physical address wrongly. We were calculating a gfn as the guest physical address shifted right 16 bits (PAGE_SHIFT) but then only adding back in 12 bits from the effective address, since the HPTE had a 4k page size. Thus the gpa reported to userspace was missing 4 bits. Instead, we now compute the guest physical address from the HPTE without reference to the host page size, and then compute the gfn by shifting the gpa right PAGE_SHIFT bits. Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru> Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
964ee98ccd
commit
70bddfefbd
1 changed files with 4 additions and 5 deletions
|
@ -571,7 +571,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
|
||||||
struct kvm *kvm = vcpu->kvm;
|
struct kvm *kvm = vcpu->kvm;
|
||||||
unsigned long *hptep, hpte[3], r;
|
unsigned long *hptep, hpte[3], r;
|
||||||
unsigned long mmu_seq, psize, pte_size;
|
unsigned long mmu_seq, psize, pte_size;
|
||||||
unsigned long gfn, hva, pfn;
|
unsigned long gpa, gfn, hva, pfn;
|
||||||
struct kvm_memory_slot *memslot;
|
struct kvm_memory_slot *memslot;
|
||||||
unsigned long *rmap;
|
unsigned long *rmap;
|
||||||
struct revmap_entry *rev;
|
struct revmap_entry *rev;
|
||||||
|
@ -609,15 +609,14 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
|
||||||
|
|
||||||
/* Translate the logical address and get the page */
|
/* Translate the logical address and get the page */
|
||||||
psize = hpte_page_size(hpte[0], r);
|
psize = hpte_page_size(hpte[0], r);
|
||||||
gfn = hpte_rpn(r, psize);
|
gpa = (r & HPTE_R_RPN & ~(psize - 1)) | (ea & (psize - 1));
|
||||||
|
gfn = gpa >> PAGE_SHIFT;
|
||||||
memslot = gfn_to_memslot(kvm, gfn);
|
memslot = gfn_to_memslot(kvm, gfn);
|
||||||
|
|
||||||
/* No memslot means it's an emulated MMIO region */
|
/* No memslot means it's an emulated MMIO region */
|
||||||
if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID)) {
|
if (!memslot || (memslot->flags & KVM_MEMSLOT_INVALID))
|
||||||
unsigned long gpa = (gfn << PAGE_SHIFT) | (ea & (psize - 1));
|
|
||||||
return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea,
|
return kvmppc_hv_emulate_mmio(run, vcpu, gpa, ea,
|
||||||
dsisr & DSISR_ISSTORE);
|
dsisr & DSISR_ISSTORE);
|
||||||
}
|
|
||||||
|
|
||||||
if (!kvm->arch.using_mmu_notifiers)
|
if (!kvm->arch.using_mmu_notifiers)
|
||||||
return -EFAULT; /* should never get here */
|
return -EFAULT; /* should never get here */
|
||||||
|
|
Loading…
Reference in a new issue