Commit 03668a4d authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds

mm: use generic follow_pte() in follow_phys()

Signed-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Cc: Christoph Hellwig <hch@infradead.org>
Acked-by: default avatarMagnus Damm <magnus.damm@gmail.com>
Cc: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f8ad0f49
...@@ -3145,50 +3145,24 @@ int follow_phys(struct vm_area_struct *vma, ...@@ -3145,50 +3145,24 @@ int follow_phys(struct vm_area_struct *vma,
unsigned long address, unsigned int flags, unsigned long address, unsigned int flags,
unsigned long *prot, resource_size_t *phys) unsigned long *prot, resource_size_t *phys)
{ {
pgd_t *pgd; int ret = -EINVAL;
pud_t *pud;
pmd_t *pmd;
pte_t *ptep, pte; pte_t *ptep, pte;
spinlock_t *ptl; spinlock_t *ptl;
resource_size_t phys_addr = 0;
struct mm_struct *mm = vma->vm_mm;
int ret = -EINVAL;
if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
goto out; goto out;
pgd = pgd_offset(mm, address); if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
goto out;
pud = pud_offset(pgd, address);
if (pud_none(*pud) || unlikely(pud_bad(*pud)))
goto out;
pmd = pmd_offset(pud, address);
if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
goto out;
/* We cannot handle huge page PFN maps. Luckily they don't exist. */
if (pmd_huge(*pmd))
goto out; goto out;
ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
if (!ptep)
goto out;
pte = *ptep; pte = *ptep;
if (!pte_present(pte))
goto unlock;
if ((flags & FOLL_WRITE) && !pte_write(pte)) if ((flags & FOLL_WRITE) && !pte_write(pte))
goto unlock; goto unlock;
phys_addr = pte_pfn(pte);
phys_addr <<= PAGE_SHIFT; /* Shift here to avoid overflow on PAE */
*prot = pgprot_val(pte_pgprot(pte)); *prot = pgprot_val(pte_pgprot(pte));
*phys = phys_addr; *phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
ret = 0;
ret = 0;
unlock: unlock:
pte_unmap_unlock(ptep, ptl); pte_unmap_unlock(ptep, ptl);
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment