Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b150478 authored by Roland Dreier's avatar Roland Dreier Committed by Paul Mackerras
Browse files

[PATCH] ppc: make phys_mem_access_prot() work with pfns instead of addresses



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: default avatarRoland Dreier <rolandd@cisco.com>
Cc: Anton Blanchard <anton@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent d49b3401
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -88,13 +88,13 @@ int page_is_ram(unsigned long pfn)
}
}
EXPORT_SYMBOL(page_is_ram);
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)
			      unsigned long size, pgprot_t vma_prot)
{
{
	if (ppc_md.phys_mem_access_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)
		vma_prot = __pgprot(pgprot_val(vma_prot)
				    | _PAGE_GUARDED | _PAGE_NO_CACHE);
				    | _PAGE_GUARDED | _PAGE_NO_CACHE);
	return vma_prot;
	return vma_prot;
+3 −2
Original line number Original line Diff line number Diff line
@@ -1594,16 +1594,17 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
 * above routine
 * above routine
 */
 */
pgprot_t pci_phys_mem_access_prot(struct file *file,
pgprot_t pci_phys_mem_access_prot(struct file *file,
				  unsigned long offset,
				  unsigned long pfn,
				  unsigned long size,
				  unsigned long size,
				  pgprot_t protection)
				  pgprot_t protection)
{
{
	struct pci_dev *pdev = NULL;
	struct pci_dev *pdev = NULL;
	struct resource *found = NULL;
	struct resource *found = NULL;
	unsigned long prot = pgprot_val(protection);
	unsigned long prot = pgprot_val(protection);
	unsigned long offset = pfn << PAGE_SHIFT;
	int i;
	int i;


	if (page_is_ram(offset >> PAGE_SHIFT))
	if (page_is_ram(pfn))
		return prot;
		return prot;


	prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
	prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
+4 −6
Original line number Original line Diff line number Diff line
@@ -637,18 +637,16 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
 */
 */
int page_is_ram(unsigned long pfn)
int page_is_ram(unsigned long pfn)
{
{
	unsigned long paddr = (pfn << PAGE_SHIFT);
	return pfn < max_pfn;

	return paddr < __pa(high_memory);
}
}


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)
			      unsigned long size, pgprot_t vma_prot)
{
{
	if (ppc_md.phys_mem_access_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)
		vma_prot = __pgprot(pgprot_val(vma_prot)
				    | _PAGE_GUARDED | _PAGE_NO_CACHE);
				    | _PAGE_GUARDED | _PAGE_NO_CACHE);
	return vma_prot;
	return vma_prot;
+3 −2
Original line number Original line Diff line number Diff line
@@ -726,16 +726,17 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
 * above routine
 * above routine
 */
 */
pgprot_t pci_phys_mem_access_prot(struct file *file,
pgprot_t pci_phys_mem_access_prot(struct file *file,
				  unsigned long offset,
				  unsigned long pfn,
				  unsigned long size,
				  unsigned long size,
				  pgprot_t protection)
				  pgprot_t protection)
{
{
	struct pci_dev *pdev = NULL;
	struct pci_dev *pdev = NULL;
	struct resource *found = NULL;
	struct resource *found = NULL;
	unsigned long prot = pgprot_val(protection);
	unsigned long prot = pgprot_val(protection);
	unsigned long offset = pfn << PAGE_SHIFT;
	int i;
	int i;


	if (page_is_ram(offset >> PAGE_SHIFT))
	if (page_is_ram(pfn))
		return __pgprot(prot);
		return __pgprot(prot);


	prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
	prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
+1 −3
Original line number Original line Diff line number Diff line
@@ -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)
static int mmap_mem(struct file * file, struct vm_area_struct * vma)
{
{
#if defined(__HAVE_PHYS_MEM_ACCESS_PROT)
#if defined(__HAVE_PHYS_MEM_ACCESS_PROT)
	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
	vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,

	vma->vm_page_prot = phys_mem_access_prot(file, offset,
						 vma->vm_end - vma->vm_start,
						 vma->vm_end - vma->vm_start,
						 vma->vm_page_prot);
						 vma->vm_page_prot);
#elif defined(pgprot_noncached)
#elif defined(pgprot_noncached)
Loading