ARM: 8293/1: kernel: fix pci_mmap_page_range() offset calculation
authorLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Tue, 27 Jan 2015 09:43:13 +0000 (10:43 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 23 Feb 2015 14:43:58 +0000 (14:43 +0000)
The pci_mmap_page_range() API should be written to expect offset
values representing PCI memory resource addresses as seen by user
space, through the pci_resource_to_user() API.

ARM relies on the standard implementation of pci_resource_to_user()
which actually is an identity map and exports to user space
PCI memory resources as they are stored in PCI devices resources
structures, which represent CPU physical addresses (fixed-up using
BUS to CPU address conversions) not PCI bus addresses.

Therefore, on ARM platforms where the mapping between CPU and BUS
address is not a 1:1 the current pci_mmap_page_range() implementation is
erroneous, in that an additional shift is applied to an already fixed-up
offset passed from userspace.

Hence, this patch removes the mem_offset from the pgoff calculation
since the offset as passed from user space already represents the CPU
physical address corresponding to the resource to be mapped, ie no
additional offset should be applied.

Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/kernel/bios32.c

index ab19b7c03423690adac07fd99e525a5f4ac3f359..fcbbbb1b9e9578b64371785385b6074e256ff26d 100644 (file)
@@ -618,21 +618,15 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
                        enum pci_mmap_state mmap_state, int write_combine)
 {
-       struct pci_sys_data *root = dev->sysdata;
-       unsigned long phys;
-
-       if (mmap_state == pci_mmap_io) {
+       if (mmap_state == pci_mmap_io)
                return -EINVAL;
-       } else {
-               phys = vma->vm_pgoff + (root->mem_offset >> PAGE_SHIFT);
-       }
 
        /*
         * Mark this as IO
         */
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
-       if (remap_pfn_range(vma, vma->vm_start, phys,
+       if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
                             vma->vm_end - vma->vm_start,
                             vma->vm_page_prot))
                return -EAGAIN;