Skip to content

Commit 5b34b76

Browse files
Christoph Hellwigakpm00
authored andcommitted
mm: move follow_phys to arch/x86/mm/pat/memtype.c
follow_phys is only used by two callers in arch/x86/mm/pat/memtype.c. Move it there and hardcode the two arguments that get the same values passed by both callers. [[email protected]: conflict resolutions] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Fei Li <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Nathan Chancellor <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cb10c28 commit 5b34b76

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

arch/x86/mm/pat/memtype.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/pfn_t.h>
4040
#include <linux/slab.h>
4141
#include <linux/mm.h>
42+
#include <linux/highmem.h>
4243
#include <linux/fs.h>
4344
#include <linux/rbtree.h>
4445

@@ -947,6 +948,32 @@ static void free_pfn_range(u64 paddr, unsigned long size)
947948
memtype_free(paddr, paddr + size);
948949
}
949950

951+
static int follow_phys(struct vm_area_struct *vma, unsigned long *prot,
952+
resource_size_t *phys)
953+
{
954+
pte_t *ptep, pte;
955+
spinlock_t *ptl;
956+
957+
if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
958+
return -EINVAL;
959+
960+
if (follow_pte(vma->vm_mm, vma->vm_start, &ptep, &ptl))
961+
return -EINVAL;
962+
963+
pte = ptep_get(ptep);
964+
965+
/* Never return PFNs of anon folios in COW mappings. */
966+
if (vm_normal_folio(vma, vma->vm_start, pte)) {
967+
pte_unmap_unlock(ptep, ptl);
968+
return -EINVAL;
969+
}
970+
971+
*prot = pgprot_val(pte_pgprot(pte));
972+
*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
973+
pte_unmap_unlock(ptep, ptl);
974+
return 0;
975+
}
976+
950977
static int get_pat_info(struct vm_area_struct *vma, resource_size_t *paddr,
951978
pgprot_t *pgprot)
952979
{
@@ -964,7 +991,7 @@ static int get_pat_info(struct vm_area_struct *vma, resource_size_t *paddr,
964991
* detect the PFN. If we need the cachemode as well, we're out of luck
965992
* for now and have to fail fork().
966993
*/
967-
if (!follow_phys(vma, vma->vm_start, 0, &prot, paddr)) {
994+
if (!follow_phys(vma, &prot, paddr)) {
968995
if (pgprot)
969996
*pgprot = __pgprot(prot);
970997
return 0;

include/linux/mm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,8 +2424,6 @@ int
24242424
copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma);
24252425
int follow_pte(struct mm_struct *mm, unsigned long address,
24262426
pte_t **ptepp, spinlock_t **ptlp);
2427-
int follow_phys(struct vm_area_struct *vma, unsigned long address,
2428-
unsigned int flags, unsigned long *prot, resource_size_t *phys);
24292427
int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
24302428
void *buf, int len, int write);
24312429

mm/memory.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5928,38 +5928,6 @@ int follow_pte(struct mm_struct *mm, unsigned long address,
59285928
EXPORT_SYMBOL_GPL(follow_pte);
59295929

59305930
#ifdef CONFIG_HAVE_IOREMAP_PROT
5931-
int follow_phys(struct vm_area_struct *vma,
5932-
unsigned long address, unsigned int flags,
5933-
unsigned long *prot, resource_size_t *phys)
5934-
{
5935-
int ret = -EINVAL;
5936-
pte_t *ptep, pte;
5937-
spinlock_t *ptl;
5938-
5939-
if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
5940-
goto out;
5941-
5942-
if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
5943-
goto out;
5944-
pte = ptep_get(ptep);
5945-
5946-
/* Never return PFNs of anon folios in COW mappings. */
5947-
if (vm_normal_folio(vma, address, pte))
5948-
goto unlock;
5949-
5950-
if ((flags & FOLL_WRITE) && !pte_write(pte))
5951-
goto unlock;
5952-
5953-
*prot = pgprot_val(pte_pgprot(pte));
5954-
*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
5955-
5956-
ret = 0;
5957-
unlock:
5958-
pte_unmap_unlock(ptep, ptl);
5959-
out:
5960-
return ret;
5961-
}
5962-
59635931
/**
59645932
* generic_access_phys - generic implementation for iomem mmap access
59655933
* @vma: the vma to access

0 commit comments

Comments
 (0)