]> err.no Git - linux-2.6/commitdiff
[PATCH] ppc: make phys_mem_access_prot() work with pfns instead of addresses
authorRoland Dreier <rolandd@cisco.com>
Sat, 29 Oct 2005 00:46:18 +0000 (17:46 -0700)
committerPaul Mackerras <paulus@samba.org>
Sat, 29 Oct 2005 04:25:49 +0000 (14:25 +1000)
Change the phys_mem_access_prot() function to take a pfn instead of an
address.  This allows mmap64() to work on /dev/mem for addresses above 4G
on 32-bit architectures.  We start with a pfn in mmap_mem(), so there's no
need to convert to an address; in fact, it's actively bad, since the
conversion can overflow when the address is above 4G.

Similarly fix the ppc32 page_is_ram() function to avoid a conversion to an
address by directly comparing to max_pfn.  Working with max_pfn instead of
high_memory fixes page_is_ram() to give the right answer for highmem pages.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
Cc: Anton Blanchard <anton@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
12 files changed:
arch/powerpc/mm/mem.c
arch/ppc/kernel/pci.c
arch/ppc/mm/init.c
arch/ppc64/kernel/pci.c
drivers/char/mem.c
drivers/video/fbmem.c
include/asm-powerpc/machdep.h
include/asm-ppc/machdep.h
include/asm-ppc/pci.h
include/asm-ppc/pgtable.h
include/asm-ppc64/pci.h
include/asm-ppc64/pgtable.h

index 695db6a588cebad0e2371c6921c37717ce656b4b..3ca331728d212d3541e8c21940a7ebf9cb8b4f14 100644 (file)
@@ -88,13 +88,13 @@ int page_is_ram(unsigned long pfn)
 }
 EXPORT_SYMBOL(page_is_ram);
 
-pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
+pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
                              unsigned long size, pgprot_t vma_prot)
 {
        if (ppc_md.phys_mem_access_prot)
-               return ppc_md.phys_mem_access_prot(file, addr, size, vma_prot);
+               return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
 
-       if (!page_is_ram(addr >> PAGE_SHIFT))
+       if (!page_is_ram(pfn))
                vma_prot = __pgprot(pgprot_val(vma_prot)
                                    | _PAGE_GUARDED | _PAGE_NO_CACHE);
        return vma_prot;
index ad4ef2aaa6ab9c4c2f070e10d5fa12971013bced..e8f4e576750a07aa220d29f7871d33a5c1316ebf 100644 (file)
@@ -1594,16 +1594,17 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  * above routine
  */
 pgprot_t pci_phys_mem_access_prot(struct file *file,
-                                 unsigned long offset,
+                                 unsigned long pfn,
                                  unsigned long size,
                                  pgprot_t protection)
 {
        struct pci_dev *pdev = NULL;
        struct resource *found = NULL;
        unsigned long prot = pgprot_val(protection);
+       unsigned long offset = pfn << PAGE_SHIFT;
        int i;
 
-       if (page_is_ram(offset >> PAGE_SHIFT))
+       if (page_is_ram(pfn))
                return prot;
 
        prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
index db94efd253692890443aed18d09f145c8199e88e..99b48abd32969d8cfb485dc87b105bce9482bfb7 100644 (file)
@@ -637,18 +637,16 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
  */
 int page_is_ram(unsigned long pfn)
 {
-       unsigned long paddr = (pfn << PAGE_SHIFT);
-
-       return paddr < __pa(high_memory);
+       return pfn < max_pfn;
 }
 
-pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
+pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
                              unsigned long size, pgprot_t vma_prot)
 {
        if (ppc_md.phys_mem_access_prot)
-               return ppc_md.phys_mem_access_prot(file, addr, size, vma_prot);
+               return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
 
-       if (!page_is_ram(addr >> PAGE_SHIFT))
+       if (!page_is_ram(pfn))
                vma_prot = __pgprot(pgprot_val(vma_prot)
                                    | _PAGE_GUARDED | _PAGE_NO_CACHE);
        return vma_prot;
index b2fb6746f00b0bff6ccced3cb81263fba4398941..3d2106b022a11f1376947255374278e2b6d30fcb 100644 (file)
@@ -726,16 +726,17 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  * above routine
  */
 pgprot_t pci_phys_mem_access_prot(struct file *file,
-                                 unsigned long offset,
+                                 unsigned long pfn,
                                  unsigned long size,
                                  pgprot_t protection)
 {
        struct pci_dev *pdev = NULL;
        struct resource *found = NULL;
        unsigned long prot = pgprot_val(protection);
+       unsigned long offset = pfn << PAGE_SHIFT;
        int i;
 
-       if (page_is_ram(offset >> PAGE_SHIFT))
+       if (page_is_ram(pfn))
                return __pgprot(prot);
 
        prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
index f182752fe918b9b08bb601bd0bc827bb3e1f0cf2..9df928d4f68d42765fd35fe5e7764b2cd5a3e301 100644 (file)
@@ -231,9 +231,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
 static int mmap_mem(struct file * file, struct vm_area_struct * vma)
 {
 #if defined(__HAVE_PHYS_MEM_ACCESS_PROT)
-       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
-
-       vma->vm_page_prot = phys_mem_access_prot(file, offset,
+       vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
                                                 vma->vm_end - vma->vm_start,
                                                 vma->vm_page_prot);
 #elif defined(pgprot_noncached)
index 70be7009f8afc6af1fb7712c5ca21d17e9926f32..ca02aa2bfcece83594d920ee2df7ff9d7c03fa28 100644 (file)
@@ -918,7 +918,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
        }
 #endif
 #elif defined(__powerpc__)
-       vma->vm_page_prot = phys_mem_access_prot(file, off,
+       vma->vm_page_prot = phys_mem_access_prot(file, off >> PAGE_SHIFT,
                                                 vma->vm_end - vma->vm_start,
                                                 vma->vm_page_prot);
 #elif defined(__alpha__)
index 706508b1b04b997187f24f543c2eca981c69e01a..451b345cfc788b216bb8b7fe9f1b6c06accd7956 100644 (file)
@@ -144,7 +144,7 @@ struct machdep_calls {
        
        /* Get access protection for /dev/mem */
        pgprot_t        (*phys_mem_access_prot)(struct file *file,
-                                               unsigned long offset,
+                                               unsigned long pfn,
                                                unsigned long size,
                                                pgprot_t vma_prot);
 
index 6c6d23abbe916ac03ed1147d0ed45b6140800fd8..f01255bd1dc3739e8c71c5e4c88198ca6884d13a 100644 (file)
@@ -98,7 +98,7 @@ struct machdep_calls {
 
        /* Get access protection for /dev/mem */
        pgprot_t        (*phys_mem_access_prot)(struct file *file,
-                                               unsigned long offset,
+                                               unsigned long pfn,
                                                unsigned long size,
                                                pgprot_t vma_prot);
 
index 643740dd727be9f8d38518a99269ec38d2002e88..61434edbad7b7fd8489ca0a11743f0e604b565da 100644 (file)
@@ -126,7 +126,7 @@ extern void pcibios_add_platform_entries(struct pci_dev *dev);
 
 struct file;
 extern pgprot_t        pci_phys_mem_access_prot(struct file *file,
-                                        unsigned long offset,
+                                        unsigned long pfn,
                                         unsigned long size,
                                         pgprot_t prot);
 
index eee601bb9ada6fbcedcb954a9715bc9b8a681a29..b28a713ba862e48754afc3d409060d50153ad1a2 100644 (file)
@@ -705,7 +705,7 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
 #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
 
 struct file;
-extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
+extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
                                     unsigned long size, pgprot_t vma_prot);
 #define __HAVE_PHYS_MEM_ACCESS_PROT
 
index a88bbfc2696733bef9c138e593be95ed7a77aa8d..342e2d755550a1de3cf7907352e86b54ce53fcad 100644 (file)
@@ -168,7 +168,7 @@ extern void pcibios_add_platform_entries(struct pci_dev *dev);
 
 struct file;
 extern pgprot_t        pci_phys_mem_access_prot(struct file *file,
-                                        unsigned long offset,
+                                        unsigned long pfn,
                                         unsigned long size,
                                         pgprot_t prot);
 
index c83679c9d2b0f49d07ade70a6255c5af32d38074..8cf5991540e36630f946f555df66c82cd012228f 100644 (file)
@@ -471,7 +471,7 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
 #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
 
 struct file;
-extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long addr,
+extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
                                     unsigned long size, pgprot_t vma_prot);
 #define __HAVE_PHYS_MEM_ACCESS_PROT