aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Majtyka <marek.majtyka@tieto.com>2015-09-16 06:04:55 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2015-09-16 09:50:45 -0400
commitca09f02f122b2ecb0f5ddfc5fd47b29ed657d4fd (patch)
tree5af4246ef7b215b3e689be3812cd197b410fc185
parent1713e5aa05fff3951e747548b373bd2c81be4e7a (diff)
arm: KVM: Fix incorrect device to IPA mapping
A critical bug has been found in device memory stage1 translation for VMs with more then 4GB of address space. Once vm_pgoff size is smaller then pa (which is true for LPAE case, u32 and u64 respectively) some more significant bits of pa may be lost as a shift operation is performed on u32 and later cast onto u64. Example: vm_pgoff(u32)=0x00210030, PAGE_SHIFT=12 expected pa(u64): 0x0000002010030000 produced pa(u64): 0x0000000010030000 The fix is to change the order of operations (casting first onto phys_addr_t and then shifting). Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> [maz: fixed changelog and patch formatting] Cc: stable@vger.kernel.org Signed-off-by: Marek Majtyka <marek.majtyka@tieto.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
-rw-r--r--arch/arm/kvm/mmu.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 7b4201294187..6984342da13d 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -1792,8 +1792,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
1792 if (vma->vm_flags & VM_PFNMAP) { 1792 if (vma->vm_flags & VM_PFNMAP) {
1793 gpa_t gpa = mem->guest_phys_addr + 1793 gpa_t gpa = mem->guest_phys_addr +
1794 (vm_start - mem->userspace_addr); 1794 (vm_start - mem->userspace_addr);
1795 phys_addr_t pa = (vma->vm_pgoff << PAGE_SHIFT) + 1795 phys_addr_t pa;
1796 vm_start - vma->vm_start; 1796
1797 pa = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT;
1798 pa += vm_start - vma->vm_start;
1797 1799
1798 /* IO region dirty page logging not allowed */ 1800 /* IO region dirty page logging not allowed */
1799 if (memslot->flags & KVM_MEM_LOG_DIRTY_PAGES) 1801 if (memslot->flags & KVM_MEM_LOG_DIRTY_PAGES)