Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] make valid_mmap_phys_addr_range() take a pfn

Newer ARMs have a 40 bit physical address space, but mapping physical
memory above 4G needs a special page table format which we (currently?) do
not use for userspace mappings, so what happens instead is that mapping an
address >= 4G will happily discard the upper bits and wrap.

There is a valid_mmap_phys_addr_range() arch hook where we could check for
>= 4G addresses and deny the mapping, but this hook takes an unsigned long
address:

static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t size);

And drivers/char/mem.c:mmap_mem() calls it like this:

static int mmap_mem(struct file * file, struct vm_area_struct * vma)
{
size_t size = vma->vm_end - vma->vm_start;

if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size))

So that's not much help either.

This patch makes the hook take a pfn instead of a phys address.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Lennert Buytenhek and committed by
Linus Torvalds
06c67bef 49c0dab7

+5 -5
+1 -1
arch/ia64/kernel/efi.c
··· 759 759 } 760 760 761 761 int 762 - valid_mmap_phys_addr_range (unsigned long phys_addr, unsigned long size) 762 + valid_mmap_phys_addr_range (unsigned long pfn, unsigned long size) 763 763 { 764 764 /* 765 765 * MMIO regions are often missing from the EFI memory map.
+1 -1
arch/ia64/pci/pci.c
··· 650 650 * Avoid attribute aliasing. See Documentation/ia64/aliasing.txt 651 651 * for more details. 652 652 */ 653 - if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size)) 653 + if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) 654 654 return -EINVAL; 655 655 prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size, 656 656 vma->vm_page_prot);
+2 -2
drivers/char/mem.c
··· 95 95 return 1; 96 96 } 97 97 98 - static inline int valid_mmap_phys_addr_range(unsigned long addr, size_t size) 98 + static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size) 99 99 { 100 100 return 1; 101 101 } ··· 242 242 { 243 243 size_t size = vma->vm_end - vma->vm_start; 244 244 245 - if (!valid_mmap_phys_addr_range(vma->vm_pgoff << PAGE_SHIFT, size)) 245 + if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) 246 246 return -EINVAL; 247 247 248 248 vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
+1 -1
include/asm-ia64/io.h
··· 90 90 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE 91 91 extern u64 kern_mem_attribute (unsigned long phys_addr, unsigned long size); 92 92 extern int valid_phys_addr_range (unsigned long addr, size_t count); /* efi.c */ 93 - extern int valid_mmap_phys_addr_range (unsigned long addr, size_t count); 93 + extern int valid_mmap_phys_addr_range (unsigned long pfn, size_t count); 94 94 95 95 /* 96 96 * The following two macros are deprecated and scheduled for removal.